Commit 89476e5f72a861fd2ebd5a22b86317500ed82730
Exists in
master
Merge branch '2.4.0' of git@github.com:demoiselle/framework.git into 2.4.0
Showing
10 changed files
with
56 additions
and
45 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/ConfigurationValueExtractor.java
| ... | ... | @@ -42,7 +42,7 @@ import org.apache.commons.configuration.Configuration; |
| 42 | 42 | |
| 43 | 43 | public interface ConfigurationValueExtractor { |
| 44 | 44 | |
| 45 | - Object getValue(String prefix, String key, Field field, Configuration configuration); | |
| 45 | + Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception; | |
| 46 | 46 | |
| 47 | 47 | boolean isSupported(Field field); |
| 48 | 48 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationArrayValueExtractor.java
| ... | ... | @@ -50,7 +50,7 @@ import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
| 50 | 50 | public class ConfigurationArrayValueExtractor implements ConfigurationValueExtractor { |
| 51 | 51 | |
| 52 | 52 | @Override |
| 53 | - public Object getValue(String prefix, String key, Field field, Configuration configuration) { | |
| 53 | + public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | |
| 54 | 54 | return new DataConfiguration(configuration).getArray(field.getType().getComponentType(), prefix + key); |
| 55 | 55 | } |
| 56 | 56 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationClassValueExtractor.java
| ... | ... | @@ -43,25 +43,20 @@ import java.lang.reflect.Field; |
| 43 | 43 | import org.apache.commons.configuration.Configuration; |
| 44 | 44 | |
| 45 | 45 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 46 | -import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | |
| 47 | 46 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
| 48 | 47 | import br.gov.frameworkdemoiselle.util.Reflections; |
| 48 | +import br.gov.frameworkdemoiselle.util.Strings; | |
| 49 | 49 | |
| 50 | 50 | @Priority(EXTENSIONS_L1_PRIORITY) |
| 51 | 51 | public class ConfigurationClassValueExtractor implements ConfigurationValueExtractor { |
| 52 | 52 | |
| 53 | 53 | @Override |
| 54 | - public Object getValue(String prefix, String key, Field field, Configuration configuration) { | |
| 54 | + public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | |
| 55 | 55 | Object value = null; |
| 56 | 56 | String canonicalName = configuration.getString(prefix + key); |
| 57 | 57 | |
| 58 | - if (!canonicalName.equals("")) { | |
| 59 | - try { | |
| 60 | - value = Reflections.forName(canonicalName); | |
| 61 | - } catch (ClassNotFoundException cause) { | |
| 62 | - // TODO Lançar a mensagem correta | |
| 63 | - throw new ConfigurationException("", cause); | |
| 64 | - } | |
| 58 | + if (!Strings.isEmpty(canonicalName)) { | |
| 59 | + value = Reflections.forName(canonicalName); | |
| 65 | 60 | } |
| 66 | 61 | |
| 67 | 62 | return value; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationLoader.java
| ... | ... | @@ -232,8 +232,21 @@ public class ConfigurationLoader implements Serializable { |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | private Object getValue(Field field, Class<?> type, String key, Object defaultValue) { |
| 235 | - ConfigurationValueExtractor extractor = getValueExtractor(field); | |
| 236 | - return extractor.getValue(this.prefix, key, field, this.configuration); | |
| 235 | + Object value = null; | |
| 236 | + | |
| 237 | + try { | |
| 238 | + ConfigurationValueExtractor extractor = getValueExtractor(field); | |
| 239 | + value = extractor.getValue(this.prefix, key, field, this.configuration); | |
| 240 | + | |
| 241 | + } catch (ConfigurationException cause) { | |
| 242 | + throw cause; | |
| 243 | + | |
| 244 | + } catch (Exception cause) { | |
| 245 | + // TODO Lançar mensagem informando que houve erro ao tentar extrair o valor com o extrator tal. | |
| 246 | + throw new ConfigurationException("", cause); | |
| 247 | + } | |
| 248 | + | |
| 249 | + return value; | |
| 237 | 250 | } |
| 238 | 251 | |
| 239 | 252 | private ConfigurationValueExtractor getValueExtractor(Field field) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationMapValueExtractor.java
| ... | ... | @@ -54,7 +54,7 @@ import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
| 54 | 54 | public class ConfigurationMapValueExtractor implements ConfigurationValueExtractor { |
| 55 | 55 | |
| 56 | 56 | @Override |
| 57 | - public Object getValue(String prefix, String key, Field field, Configuration configuration) { | |
| 57 | + public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | |
| 58 | 58 | Map<String, Object> value = null; |
| 59 | 59 | |
| 60 | 60 | String regexp = "^(" + prefix + ")((.+)\\.)?(" + key + ")$"; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationPrimitiveOrWrapperValueExtractor.java
| ... | ... | @@ -43,13 +43,13 @@ import java.util.HashSet; |
| 43 | 43 | import java.util.Set; |
| 44 | 44 | |
| 45 | 45 | import org.apache.commons.configuration.Configuration; |
| 46 | -import org.apache.commons.configuration.ConfigurationException; | |
| 47 | 46 | import org.apache.commons.configuration.ConversionException; |
| 48 | 47 | import org.apache.commons.configuration.DataConfiguration; |
| 49 | 48 | import org.apache.commons.lang.ClassUtils; |
| 50 | 49 | |
| 51 | 50 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 52 | 51 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
| 52 | +import br.gov.frameworkdemoiselle.util.Strings; | |
| 53 | 53 | |
| 54 | 54 | @Priority(EXTENSIONS_L1_PRIORITY) |
| 55 | 55 | public class ConfigurationPrimitiveOrWrapperValueExtractor implements ConfigurationValueExtractor { |
| ... | ... | @@ -70,21 +70,27 @@ public class ConfigurationPrimitiveOrWrapperValueExtractor implements Configurat |
| 70 | 70 | |
| 71 | 71 | @Override |
| 72 | 72 | @SuppressWarnings("unchecked") |
| 73 | - public Object getValue(String prefix, String key, Field field, Configuration configuration) { | |
| 73 | + public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | |
| 74 | 74 | Object value; |
| 75 | + | |
| 75 | 76 | try { |
| 76 | 77 | value = new DataConfiguration(configuration).get(ClassUtils.primitiveToWrapper(field.getType()), prefix |
| 77 | 78 | + key); |
| 78 | - } catch (ConversionException e) { | |
| 79 | - value = new DataConfiguration(configuration).get(ClassUtils.primitiveToWrapper(String.class), prefix + key); | |
| 80 | - if (value.equals("")) { | |
| 81 | - value = null; | |
| 82 | - } else | |
| 83 | - throw e; | |
| 79 | + | |
| 80 | + } catch (ConversionException cause) { | |
| 81 | + validate(prefix, key, configuration, cause); | |
| 82 | + value = null; | |
| 84 | 83 | } |
| 84 | + | |
| 85 | 85 | return value; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | + private void validate(String prefix, String key, Configuration configuration, ConversionException cause) { | |
| 89 | + if (!Strings.isEmpty(configuration.getString(prefix + key))) { | |
| 90 | + throw cause; | |
| 91 | + } | |
| 92 | + } | |
| 93 | + | |
| 88 | 94 | @Override |
| 89 | 95 | public boolean isSupported(Field field) { |
| 90 | 96 | return field.getType().isPrimitive() || wrappers.contains(field.getType()); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/ConfigurationStringValueExtractor.java
| ... | ... | @@ -44,15 +44,16 @@ import org.apache.commons.configuration.Configuration; |
| 44 | 44 | |
| 45 | 45 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 46 | 46 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
| 47 | +import br.gov.frameworkdemoiselle.util.Strings; | |
| 47 | 48 | |
| 48 | 49 | @Priority(EXTENSIONS_L1_PRIORITY) |
| 49 | 50 | public class ConfigurationStringValueExtractor implements ConfigurationValueExtractor { |
| 50 | 51 | |
| 51 | 52 | @Override |
| 52 | - public Object getValue(String prefix, String key, Field field, Configuration configuration) { | |
| 53 | - Object value = configuration.getString(prefix + key); | |
| 53 | + public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | |
| 54 | + String value = configuration.getString(prefix + key); | |
| 54 | 55 | |
| 55 | - if ((value !=null) && (value.equals(""))) { | |
| 56 | + if (Strings.isEmpty(value)) { | |
| 56 | 57 | value = null; |
| 57 | 58 | } |
| 58 | 59 | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/custom/MyValueExtractor.java
| ... | ... | @@ -9,7 +9,7 @@ import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
| 9 | 9 | public class MyValueExtractor implements ConfigurationValueExtractor { |
| 10 | 10 | |
| 11 | 11 | @Override |
| 12 | - public Object getValue(String prefix, String key, Field field, Configuration configuration) { | |
| 12 | + public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception { | |
| 13 | 13 | return new MappedClass(); |
| 14 | 14 | } |
| 15 | 15 | ... | ... |
impl/core/src/test/java/br/gov/frameworkdemoiselle/configuration/field/primitiveorwrapper/ConfigurationPrimitiveOrWrapperFieldTest.java
| ... | ... | @@ -43,8 +43,6 @@ import java.io.File; |
| 43 | 43 | |
| 44 | 44 | import javax.inject.Inject; |
| 45 | 45 | |
| 46 | -import junit.framework.Assert; | |
| 47 | - | |
| 48 | 46 | import org.apache.commons.configuration.ConversionException; |
| 49 | 47 | import org.jboss.arquillian.container.test.api.Deployment; |
| 50 | 48 | import org.jboss.arquillian.junit.Arquillian; |
| ... | ... | @@ -52,7 +50,6 @@ import org.jboss.shrinkwrap.api.asset.FileAsset; |
| 52 | 50 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 53 | 51 | import org.junit.BeforeClass; |
| 54 | 52 | import org.junit.Test; |
| 55 | -import org.junit.internal.runners.statements.Fail; | |
| 56 | 53 | import org.junit.runner.RunWith; |
| 57 | 54 | |
| 58 | 55 | import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; |
| ... | ... | @@ -69,7 +66,7 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat |
| 69 | 66 | |
| 70 | 67 | @Inject |
| 71 | 68 | private SystemPrimitiveOrWrapperFieldConfig systemConfig; |
| 72 | - | |
| 69 | + | |
| 73 | 70 | @Inject |
| 74 | 71 | private PropertiesPrimitiveOrWrapperErrorFieldConfig propertiesErrorConfig; |
| 75 | 72 | |
| ... | ... | @@ -77,7 +74,7 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat |
| 77 | 74 | private XMLPrimitiveOrWrapperErrorFieldConfig xmlErrorConfig; |
| 78 | 75 | |
| 79 | 76 | @Inject |
| 80 | - private SystemPrimitiveOrWrapperErrorFieldConfig systemErrorConfig; | |
| 77 | + private SystemPrimitiveOrWrapperErrorFieldConfig systemErrorConfig; | |
| 81 | 78 | |
| 82 | 79 | @Deployment |
| 83 | 80 | public static JavaArchive createDeployment() { |
| ... | ... | @@ -147,24 +144,23 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat |
| 147 | 144 | try { |
| 148 | 145 | assertEquals(expected, propertiesErrorConfig.getErrorPrimitiveInteger()); |
| 149 | 146 | fail(); |
| 150 | - } catch (ConversionException cause) { | |
| 151 | - Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 147 | + } catch (ConfigurationException cause) { | |
| 148 | + assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 152 | 149 | } |
| 153 | 150 | |
| 154 | 151 | try { |
| 155 | 152 | assertEquals(expected, propertiesErrorConfig.getErrorPrimitiveInteger()); |
| 156 | 153 | fail(); |
| 157 | - } catch (ConversionException cause) { | |
| 158 | - Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 154 | + } catch (ConfigurationException cause) { | |
| 155 | + assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 159 | 156 | } |
| 160 | 157 | |
| 161 | 158 | try { |
| 162 | 159 | assertEquals(expected, xmlErrorConfig.getErrorPrimitiveInteger()); |
| 163 | 160 | fail(); |
| 164 | - } catch (ConversionException cause) { | |
| 165 | - Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 161 | + } catch (ConfigurationException cause) { | |
| 162 | + assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 166 | 163 | } |
| 167 | - | |
| 168 | 164 | } |
| 169 | 165 | |
| 170 | 166 | @Test |
| ... | ... | @@ -174,22 +170,22 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat |
| 174 | 170 | try { |
| 175 | 171 | assertEquals(expected, propertiesErrorConfig.getErrorWrappedInteger()); |
| 176 | 172 | fail(); |
| 177 | - } catch (ConversionException cause) { | |
| 178 | - Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 173 | + } catch (ConfigurationException cause) { | |
| 174 | + assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 179 | 175 | } |
| 180 | 176 | |
| 181 | 177 | try { |
| 182 | 178 | assertEquals(expected, propertiesErrorConfig.getErrorWrappedInteger()); |
| 183 | 179 | fail(); |
| 184 | - } catch (ConversionException cause) { | |
| 185 | - Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 180 | + } catch (ConfigurationException cause) { | |
| 181 | + assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 186 | 182 | } |
| 187 | 183 | |
| 188 | 184 | try { |
| 189 | 185 | assertEquals(expected, xmlErrorConfig.getErrorWrappedInteger()); |
| 190 | 186 | fail(); |
| 191 | - } catch (ConversionException cause) { | |
| 192 | - Assert.assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 187 | + } catch (ConfigurationException cause) { | |
| 188 | + assertEquals(ConversionException.class, cause.getCause().getClass()); | |
| 193 | 189 | } |
| 194 | 190 | } |
| 195 | 191 | } | ... | ... |
parent/framework/pom.xml
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | <parent> |
| 46 | 46 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 47 | 47 | <artifactId>demoiselle-parent</artifactId> |
| 48 | - <version>8</version> | |
| 48 | + <version>9-SNAPSHOT</version> | |
| 49 | 49 | <relativePath>../../../internal/parent/demoiselle</relativePath> |
| 50 | 50 | </parent> |
| 51 | 51 | ... | ... |