tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [2/9] incubator-tamaya git commit: TAMAYA-62: Unified Configuration access. Fixed some FindBugs and checkstyle issues.
Date Sat, 24 Jan 2015 20:06:32 GMT
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
index 5e4db2a..2ee5aa2 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredField.java
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.Objects;
 
 import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.TypeLiteral;
 import org.apache.tamaya.inject.ConfigRoot;
 import org.apache.tamaya.inject.ConfiguredProperty;
 
@@ -77,7 +78,7 @@ public class ConfiguredField {
                 configValue = InjectionUtils.evaluateValue(configValue);
             }
             // Check for adapter/filter
-            Object value = InjectionUtils.adaptValue(this.annotatedField, this.annotatedField.getType(),
configValue);
+            Object value = InjectionUtils.adaptValue(this.annotatedField, TypeLiteral.of(this.annotatedField.getType()),
configValue);
             annotatedField.setAccessible(true);
             annotatedField.set(target, value);
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
index 7a41ac9..2784e2d 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/ConfiguredSetterMethod.java
@@ -24,6 +24,7 @@ import java.util.Optional;
 import java.util.function.Consumer;
 
 import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.TypeLiteral;
 import org.apache.tamaya.inject.ConfigRoot;
 import org.apache.tamaya.inject.ConfiguredProperty;
 import org.apache.tamaya.event.PropertyChangeSet;
@@ -87,7 +88,7 @@ public class ConfiguredSetterMethod {
                 configValue = InjectionUtils.evaluateValue(configValue);
             }
             // Check for adapter/filter
-            Object value = InjectionUtils.adaptValue(this.setterMethod, this.setterMethod.getParameterTypes()[0],
configValue);
+            Object value = InjectionUtils.adaptValue(this.setterMethod,  TypeLiteral.of(this.setterMethod.getParameterTypes()[0]),
configValue);
             setterMethod.setAccessible(true);
             setterMethod.invoke(target, value);
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
----------------------------------------------------------------------
diff --git a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
index bf4f77d..765331b 100644
--- a/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
+++ b/modules/injection/src/main/java/org/apache/tamaya/inject/internal/InjectionUtils.java
@@ -30,7 +30,8 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.TypeLiteral;
 import org.apache.tamaya.inject.ConfigRoot;
 import org.apache.tamaya.inject.ConfiguredProperty;
 import org.apache.tamaya.inject.DefaultValue;
@@ -38,7 +39,7 @@ import org.apache.tamaya.inject.WithLoadPolicy;
 import org.apache.tamaya.inject.WithPropertyConverter;
 import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
 import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.PropertyConverter;
 import org.apache.tamaya.spi.ServiceContext;
 
 
@@ -174,7 +175,7 @@ final class InjectionUtils {
     private static String evaluteConfigValue(List<String> keys) {
         String configValue = null;
         for (String key : keys) {
-            configValue = Configuration.current().get(key);
+            configValue = ConfigurationProvider.getConfiguration().get(key);
             if (configValue != null) {
                 break;
             }
@@ -184,27 +185,28 @@ final class InjectionUtils {
 
 
     @SuppressWarnings("rawtypes")
-    public static <T> T adaptValue(AnnotatedElement element, Class<T> targetType,
String configValue) {
+    public static <T> T adaptValue(AnnotatedElement element, TypeLiteral<T> targetType,
String configValue) {
         // Check for adapter/filter
         T adaptedValue = null;
         WithPropertyConverter converterAnnot = element.getAnnotation(WithPropertyConverter.class);
         Class<? extends PropertyConverter<T>> converterType;
         if (converterAnnot != null) {
             converterType = (Class<? extends PropertyConverter<T>>) converterAnnot.value();
-            if (!converterType.equals(WithPropertyConverter.class)) {
+            if (!converterType.getName().equals(WithPropertyConverter.class.getName())) {
                 try {
                     // TODO cache here...
-                    PropertyConverter<T> codec = PropertyConverter.class.cast(converterType.newInstance());
-                    adaptedValue = (T) codec.convert(configValue);
+                    PropertyConverter<T> converter = PropertyConverter.class.cast(converterType.newInstance());
+                    adaptedValue = (T) converter.convert(configValue);
                 } catch (Exception e) {
-                    LOG.log(Level.SEVERE, "Failed to convert using explicit PropertyConverter
on " + element + ", trying default conversion.", e);
+                    LOG.log(Level.SEVERE, "Failed to convert using explicit PropertyConverter
on " + element +
+                            ", trying default conversion.", e);
                 }
             }
         }
         if (adaptedValue != null) {
             return adaptedValue;
         }
-        if (String.class.equals(targetType)) {
+        if (String.class == targetType.getType()) {
             return (T) configValue;
         } else {
             List<PropertyConverter<T>> converters = ServiceContext.getInstance().getService(ConfigurationContext.class).get()

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b9735e02/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
index 592fd0c..bdabc28 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ConfigResolver.java
@@ -19,6 +19,7 @@
 package org.apache.tamaya.resolver.internal;
 
 import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
 import org.apache.tamaya.resolver.spi.ExpressionResolver;
 
 import javax.annotation.Priority;
@@ -37,7 +38,7 @@ public final class ConfigResolver implements ExpressionResolver{
 
     @Override
     public String evaluate(String expression){
-        return Configuration.current().get(expression);
+        return ConfigurationProvider.getConfiguration().get(expression);
     }
 
 }


Mime
View raw message