tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [2/3] incubator-tamaya git commit: https://issues.apache.org/jira/browse/TAMAYA-3: Added missing features on SE.
Date Sat, 29 Nov 2014 07:23:37 GMT
https://issues.apache.org/jira/browse/TAMAYA-3: Added missing features on SE.


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

Branch: refs/heads/master
Commit: fc9caf6f6c4b8e510944b6eaec553b2f0c754ed0
Parents: a36cd97
Author: anatole <anatole@apache.org>
Authored: Sat Nov 29 08:23:16 2014 +0100
Committer: anatole <anatole@apache.org>
Committed: Sat Nov 29 08:23:16 2014 +0100

----------------------------------------------------------------------
 .../internal/inject/ConfigurationInjector.java  | 57 ++++++++++++++++++++
 .../core/internal/inject/ConfiguredType.java    | 11 ++++
 2 files changed, 68 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/fc9caf6f/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
new file mode 100644
index 0000000..29afec3
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/internal/inject/ConfigurationInjector.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal.inject;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Simple injector singleton that also registers instances configured using weak references.
+ */
+public final class ConfigurationInjector {
+
+    private static final ConfigurationInjector INSTANCE = new ConfigurationInjector();
+
+    private Map<Class, ConfiguredType> configuredTypes = new ConcurrentHashMap<>();
+
+    public static ConfiguredType registerType(Class<?> type){
+        if (!ConfiguredType.isConfigured(type)) {
+            return null;
+        }
+        return INSTANCE.configuredTypes.computeIfAbsent(type, (c) -> new ConfiguredType(c));
+    }
+
+    public static void configure(Object instance){
+        Class type = Objects.requireNonNull(instance).getClass();
+        if (!ConfiguredType.isConfigured(type)) {
+            throw new IllegalArgumentException("Not a configured type: " + type.getName());
+        }
+        ConfiguredType configType = registerType(type);
+        initializeConfiguredFields(configType, instance);
+    }
+
+    private static <T> void initializeConfiguredFields(final ConfiguredType configuredType,
Object instance) {
+        Objects.requireNonNull(configuredType).configure(instance);
+        ConfiguredInstancesManager.register(configuredType, instance);
+
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/fc9caf6f/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 798e5a6..b84a3d4 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
@@ -150,6 +150,17 @@ public class ConfiguredType {
                 return true;
             }
         }
+        for (Field field : type.getDeclaredFields()) {
+            if (field.isAnnotationPresent(ConfiguredProperty.class)) {
+                return true;
+            }
+        }
+        // if no class level annotation is there we might have method level annotations only
+        for (Method method : type.getDeclaredMethods()) {
+            if (method.isAnnotationPresent(ConfiguredProperty.class)) {
+                return true;
+            }
+        }
         return false;
     }
 


Mime
View raw message