You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by ot...@apache.org on 2014/12/19 01:30:24 UTC

incubator-tamaya git commit: refactor in ConfiguredType

Repository: incubator-tamaya
Updated Branches:
  refs/heads/master eb59d86b7 -> d98932c72


refactor in ConfiguredType


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/d98932c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/d98932c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/d98932c7

Branch: refs/heads/master
Commit: d98932c72fd9588f01f55ac59866305aac798209
Parents: eb59d86
Author: otaviojava <ot...@people.apache.org>
Authored: Thu Dec 18 22:30:09 2014 -0200
Committer: otaviojava <ot...@people.apache.org>
Committed: Thu Dec 18 22:30:09 2014 -0200

----------------------------------------------------------------------
 .../core/internal/inject/ConfiguredType.java    | 60 +++++++++++---------
 .../samples/annotations/ConfiguredTest.java     |  9 ++-
 2 files changed, 38 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d98932c7/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
index b199c23..643873f 100644
--- a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfiguredType.java
@@ -40,31 +40,12 @@ public class ConfiguredType {
 
     public ConfiguredType(Class type) {
         this.type = Objects.requireNonNull(type);
-        for (Field f : type.getDeclaredFields()) {
-            ConfiguredProperties propertiesAnnot = f.getAnnotation(ConfiguredProperties.class);
-            if (propertiesAnnot != null) {
-                try {
-                    ConfiguredField configuredField = new ConfiguredField(f);
-                    configuredFields.add(configuredField);
-                } catch (Exception e) {
-                    throw new ConfigException("Failed to initialized configured field: " +
-                            f.getDeclaringClass().getName() + '.' + f.getName(), e);
-                }
-            }
-            else{
-                ConfiguredProperty propertyAnnot = f.getAnnotation(ConfiguredProperty.class);
-                if (propertyAnnot != null) {
-                    try {
-                        ConfiguredField configuredField = new ConfiguredField(f);
-                        configuredFields.add(configuredField);
-                    } catch (Exception e) {
-                        throw new ConfigException("Failed to initialized configured field: " +
-                                f.getDeclaringClass().getName() + '.' + f.getName(), e);
-                    }
-                }
-            }
-        }
-        for (Method m : type.getDeclaredMethods()) {
+        configureFields(type);
+        configureMethod(type);
+    }
+
+	private void configureMethod(Class type) {
+		for (Method m : type.getDeclaredMethods()) {
             ObservesConfigChange mAnnot = m.getAnnotation(ObservesConfigChange.class);
             if(mAnnot!=null) {
                 if (m.getParameterTypes().length != 1) {
@@ -108,7 +89,34 @@ public class ConfiguredType {
                 }
             }
         }
-    }
+	}
+
+	private void configureFields(Class type) {
+		for (Field f : type.getDeclaredFields()) {
+            ConfiguredProperties propertiesAnnot = f.getAnnotation(ConfiguredProperties.class);
+            if (propertiesAnnot != null) {
+                try {
+                    ConfiguredField configuredField = new ConfiguredField(f);
+                    configuredFields.add(configuredField);
+                } catch (Exception e) {
+                    throw new ConfigException("Failed to initialized configured field: " +
+                            f.getDeclaringClass().getName() + '.' + f.getName(), e);
+                }
+            }
+            else{
+                ConfiguredProperty propertyAnnot = f.getAnnotation(ConfiguredProperty.class);
+                if (propertyAnnot != null) {
+                    try {
+                        ConfiguredField configuredField = new ConfiguredField(f);
+                        configuredFields.add(configuredField);
+                    } catch (Exception e) {
+                        throw new ConfigException("Failed to initialized configured field: " +
+                                f.getDeclaringClass().getName() + '.' + f.getName(), e);
+                    }
+                }
+            }
+        }
+	}
 
     public Object getConfiguredValue(Method method, Object[] args) {
         ConfiguredMethod m = this.configuredMethods.get(method);

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/d98932c7/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java b/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java
index 208fa4d..a71a58d 100644
--- a/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java
+++ b/core/src/test/java/org/apache/tamaya/samples/annotations/ConfiguredTest.java
@@ -18,13 +18,12 @@
  */
 package org.apache.tamaya.samples.annotations;
 
-import org.apache.tamaya.Configuration;
-import org.junit.Assume;
-import org.junit.Test;
-
 import static junit.framework.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assume.*;
+import static org.junit.Assume.assumeTrue;
+
+import org.apache.tamaya.Configuration;
+import org.junit.Test;
 
 /**
  * Created by Anatole on 08.09.2014.