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,7 +42,7 @@ import org.apache.commons.configuration.Configuration; | ||
42 | 42 | ||
43 | public interface ConfigurationValueExtractor { | 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 | boolean isSupported(Field field); | 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,7 +50,7 @@ import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | ||
50 | public class ConfigurationArrayValueExtractor implements ConfigurationValueExtractor { | 50 | public class ConfigurationArrayValueExtractor implements ConfigurationValueExtractor { |
51 | 51 | ||
52 | @Override | 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 | return new DataConfiguration(configuration).getArray(field.getType().getComponentType(), prefix + key); | 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,25 +43,20 @@ import java.lang.reflect.Field; | ||
43 | import org.apache.commons.configuration.Configuration; | 43 | import org.apache.commons.configuration.Configuration; |
44 | 44 | ||
45 | import br.gov.frameworkdemoiselle.annotation.Priority; | 45 | import br.gov.frameworkdemoiselle.annotation.Priority; |
46 | -import br.gov.frameworkdemoiselle.configuration.ConfigurationException; | ||
47 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | 46 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
48 | import br.gov.frameworkdemoiselle.util.Reflections; | 47 | import br.gov.frameworkdemoiselle.util.Reflections; |
48 | +import br.gov.frameworkdemoiselle.util.Strings; | ||
49 | 49 | ||
50 | @Priority(EXTENSIONS_L1_PRIORITY) | 50 | @Priority(EXTENSIONS_L1_PRIORITY) |
51 | public class ConfigurationClassValueExtractor implements ConfigurationValueExtractor { | 51 | public class ConfigurationClassValueExtractor implements ConfigurationValueExtractor { |
52 | 52 | ||
53 | @Override | 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 | Object value = null; | 55 | Object value = null; |
56 | String canonicalName = configuration.getString(prefix + key); | 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 | return value; | 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,8 +232,21 @@ public class ConfigurationLoader implements Serializable { | ||
232 | } | 232 | } |
233 | 233 | ||
234 | private Object getValue(Field field, Class<?> type, String key, Object defaultValue) { | 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 | private ConfigurationValueExtractor getValueExtractor(Field field) { | 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,7 +54,7 @@ import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | ||
54 | public class ConfigurationMapValueExtractor implements ConfigurationValueExtractor { | 54 | public class ConfigurationMapValueExtractor implements ConfigurationValueExtractor { |
55 | 55 | ||
56 | @Override | 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 | Map<String, Object> value = null; | 58 | Map<String, Object> value = null; |
59 | 59 | ||
60 | String regexp = "^(" + prefix + ")((.+)\\.)?(" + key + ")$"; | 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,13 +43,13 @@ import java.util.HashSet; | ||
43 | import java.util.Set; | 43 | import java.util.Set; |
44 | 44 | ||
45 | import org.apache.commons.configuration.Configuration; | 45 | import org.apache.commons.configuration.Configuration; |
46 | -import org.apache.commons.configuration.ConfigurationException; | ||
47 | import org.apache.commons.configuration.ConversionException; | 46 | import org.apache.commons.configuration.ConversionException; |
48 | import org.apache.commons.configuration.DataConfiguration; | 47 | import org.apache.commons.configuration.DataConfiguration; |
49 | import org.apache.commons.lang.ClassUtils; | 48 | import org.apache.commons.lang.ClassUtils; |
50 | 49 | ||
51 | import br.gov.frameworkdemoiselle.annotation.Priority; | 50 | import br.gov.frameworkdemoiselle.annotation.Priority; |
52 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | 51 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
52 | +import br.gov.frameworkdemoiselle.util.Strings; | ||
53 | 53 | ||
54 | @Priority(EXTENSIONS_L1_PRIORITY) | 54 | @Priority(EXTENSIONS_L1_PRIORITY) |
55 | public class ConfigurationPrimitiveOrWrapperValueExtractor implements ConfigurationValueExtractor { | 55 | public class ConfigurationPrimitiveOrWrapperValueExtractor implements ConfigurationValueExtractor { |
@@ -70,21 +70,27 @@ public class ConfigurationPrimitiveOrWrapperValueExtractor implements Configurat | @@ -70,21 +70,27 @@ public class ConfigurationPrimitiveOrWrapperValueExtractor implements Configurat | ||
70 | 70 | ||
71 | @Override | 71 | @Override |
72 | @SuppressWarnings("unchecked") | 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 | Object value; | 74 | Object value; |
75 | + | ||
75 | try { | 76 | try { |
76 | value = new DataConfiguration(configuration).get(ClassUtils.primitiveToWrapper(field.getType()), prefix | 77 | value = new DataConfiguration(configuration).get(ClassUtils.primitiveToWrapper(field.getType()), prefix |
77 | + key); | 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 | return value; | 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 | @Override | 94 | @Override |
89 | public boolean isSupported(Field field) { | 95 | public boolean isSupported(Field field) { |
90 | return field.getType().isPrimitive() || wrappers.contains(field.getType()); | 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,15 +44,16 @@ import org.apache.commons.configuration.Configuration; | ||
44 | 44 | ||
45 | import br.gov.frameworkdemoiselle.annotation.Priority; | 45 | import br.gov.frameworkdemoiselle.annotation.Priority; |
46 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | 46 | import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; |
47 | +import br.gov.frameworkdemoiselle.util.Strings; | ||
47 | 48 | ||
48 | @Priority(EXTENSIONS_L1_PRIORITY) | 49 | @Priority(EXTENSIONS_L1_PRIORITY) |
49 | public class ConfigurationStringValueExtractor implements ConfigurationValueExtractor { | 50 | public class ConfigurationStringValueExtractor implements ConfigurationValueExtractor { |
50 | 51 | ||
51 | @Override | 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 | value = null; | 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,7 +9,7 @@ import br.gov.frameworkdemoiselle.configuration.ConfigurationValueExtractor; | ||
9 | public class MyValueExtractor implements ConfigurationValueExtractor { | 9 | public class MyValueExtractor implements ConfigurationValueExtractor { |
10 | 10 | ||
11 | @Override | 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 | return new MappedClass(); | 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,8 +43,6 @@ import java.io.File; | ||
43 | 43 | ||
44 | import javax.inject.Inject; | 44 | import javax.inject.Inject; |
45 | 45 | ||
46 | -import junit.framework.Assert; | ||
47 | - | ||
48 | import org.apache.commons.configuration.ConversionException; | 46 | import org.apache.commons.configuration.ConversionException; |
49 | import org.jboss.arquillian.container.test.api.Deployment; | 47 | import org.jboss.arquillian.container.test.api.Deployment; |
50 | import org.jboss.arquillian.junit.Arquillian; | 48 | import org.jboss.arquillian.junit.Arquillian; |
@@ -52,7 +50,6 @@ import org.jboss.shrinkwrap.api.asset.FileAsset; | @@ -52,7 +50,6 @@ import org.jboss.shrinkwrap.api.asset.FileAsset; | ||
52 | import org.jboss.shrinkwrap.api.spec.JavaArchive; | 50 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
53 | import org.junit.BeforeClass; | 51 | import org.junit.BeforeClass; |
54 | import org.junit.Test; | 52 | import org.junit.Test; |
55 | -import org.junit.internal.runners.statements.Fail; | ||
56 | import org.junit.runner.RunWith; | 53 | import org.junit.runner.RunWith; |
57 | 54 | ||
58 | import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; | 55 | import br.gov.frameworkdemoiselle.configuration.AbstractConfigurationTest; |
@@ -69,7 +66,7 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat | @@ -69,7 +66,7 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat | ||
69 | 66 | ||
70 | @Inject | 67 | @Inject |
71 | private SystemPrimitiveOrWrapperFieldConfig systemConfig; | 68 | private SystemPrimitiveOrWrapperFieldConfig systemConfig; |
72 | - | 69 | + |
73 | @Inject | 70 | @Inject |
74 | private PropertiesPrimitiveOrWrapperErrorFieldConfig propertiesErrorConfig; | 71 | private PropertiesPrimitiveOrWrapperErrorFieldConfig propertiesErrorConfig; |
75 | 72 | ||
@@ -77,7 +74,7 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat | @@ -77,7 +74,7 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat | ||
77 | private XMLPrimitiveOrWrapperErrorFieldConfig xmlErrorConfig; | 74 | private XMLPrimitiveOrWrapperErrorFieldConfig xmlErrorConfig; |
78 | 75 | ||
79 | @Inject | 76 | @Inject |
80 | - private SystemPrimitiveOrWrapperErrorFieldConfig systemErrorConfig; | 77 | + private SystemPrimitiveOrWrapperErrorFieldConfig systemErrorConfig; |
81 | 78 | ||
82 | @Deployment | 79 | @Deployment |
83 | public static JavaArchive createDeployment() { | 80 | public static JavaArchive createDeployment() { |
@@ -147,24 +144,23 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat | @@ -147,24 +144,23 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat | ||
147 | try { | 144 | try { |
148 | assertEquals(expected, propertiesErrorConfig.getErrorPrimitiveInteger()); | 145 | assertEquals(expected, propertiesErrorConfig.getErrorPrimitiveInteger()); |
149 | fail(); | 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 | try { | 151 | try { |
155 | assertEquals(expected, propertiesErrorConfig.getErrorPrimitiveInteger()); | 152 | assertEquals(expected, propertiesErrorConfig.getErrorPrimitiveInteger()); |
156 | fail(); | 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 | try { | 158 | try { |
162 | assertEquals(expected, xmlErrorConfig.getErrorPrimitiveInteger()); | 159 | assertEquals(expected, xmlErrorConfig.getErrorPrimitiveInteger()); |
163 | fail(); | 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 | @Test | 166 | @Test |
@@ -174,22 +170,22 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat | @@ -174,22 +170,22 @@ public class ConfigurationPrimitiveOrWrapperFieldTest extends AbstractConfigurat | ||
174 | try { | 170 | try { |
175 | assertEquals(expected, propertiesErrorConfig.getErrorWrappedInteger()); | 171 | assertEquals(expected, propertiesErrorConfig.getErrorWrappedInteger()); |
176 | fail(); | 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 | try { | 177 | try { |
182 | assertEquals(expected, propertiesErrorConfig.getErrorWrappedInteger()); | 178 | assertEquals(expected, propertiesErrorConfig.getErrorWrappedInteger()); |
183 | fail(); | 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 | try { | 184 | try { |
189 | assertEquals(expected, xmlErrorConfig.getErrorWrappedInteger()); | 185 | assertEquals(expected, xmlErrorConfig.getErrorWrappedInteger()); |
190 | fail(); | 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,7 +45,7 @@ | ||
45 | <parent> | 45 | <parent> |
46 | <groupId>br.gov.frameworkdemoiselle</groupId> | 46 | <groupId>br.gov.frameworkdemoiselle</groupId> |
47 | <artifactId>demoiselle-parent</artifactId> | 47 | <artifactId>demoiselle-parent</artifactId> |
48 | - <version>8</version> | 48 | + <version>9-SNAPSHOT</version> |
49 | <relativePath>../../../internal/parent/demoiselle</relativePath> | 49 | <relativePath>../../../internal/parent/demoiselle</relativePath> |
50 | </parent> | 50 | </parent> |
51 | 51 |