X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=system%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fadapters%2FClassConfiguration.java;h=31e09f9286aa2b31bcb0e44f6efcceedfc7f7189;hb=94ddca39fadbe7931a17c179424afd123bd2863a;hp=3756bd3b7923fa52c00af73b3ebcfc97c0f27f94;hpb=7273d083a2f03cd3d2061d3c6628a46b679e718b;p=utils
diff --git a/system/general/src/main/java/org/wamblee/system/adapters/ClassConfiguration.java b/system/general/src/main/java/org/wamblee/system/adapters/ClassConfiguration.java
index 3756bd3b..31e09f92 100644
--- a/system/general/src/main/java/org/wamblee/system/adapters/ClassConfiguration.java
+++ b/system/general/src/main/java/org/wamblee/system/adapters/ClassConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -12,77 +12,87 @@
* 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.wamblee.system.adapters;
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.wamblee.collections.CollectionFilter;
-import org.wamblee.conditions.Condition;
import org.wamblee.system.core.DefaultProvidedInterface;
-import org.wamblee.system.core.DefaultRequiredInterface;
import org.wamblee.system.core.ProvidedInterface;
import org.wamblee.system.core.RequiredInterface;
import org.wamblee.system.core.Scope;
-import org.wamblee.system.core.SystemAssemblyException;
+
+import java.util.ArrayList;
+import java.util.List;
/**
- * The class configuration encapsulates the knowledge of how to wrap a class as a component.
- * In particular, it provides:
- *
- * - Selection of a constructor using explicit selection
- * {@link #select(Class...)} or using the most greedy constructor
- * {@link #greedy()}.
- *
- * -
- * Selection of methods to invoke to inject other objects into the object.
- *
- * - Selection of fields to set.
- *
- *
+ * The class configuration encapsulates the knowledge of how to wrap a class as
+ * a component.
*
* @author Erik Brakkee
- *
*/
public class ClassConfiguration {
+ private Class clazz;
+
+ private ConstructorConfiguration constructorConfig;
+
+ private ObjectConfiguration objectConfig;
+
+ /**
+ * Constructs the configuration. By default no constructor is selected and
+ * one of {@link #select(Class...)} or {@link #greedy()} must be called.
+ *
+ * @param aClass
+ * Class to construct.
+ */
+ public ClassConfiguration(Class aClass) {
+ clazz = aClass;
+ constructorConfig = new ConstructorConfiguration(aClass);
+ objectConfig = new ObjectConfiguration(aClass);
+ }
+
+ public ConstructorConfiguration getConstructorConfig() {
+ return constructorConfig;
+ }
+
+ public ObjectConfiguration getObjectConfig() {
+ return objectConfig;
+ }
+
+ /**
+ * Creates the object in the given scope.
+ *
+ * @param aScope
+ * Scope containing required interfaces for this object.
+ *
+ * @return object.
+ */
+ public Object create(Scope aScope) {
+ return constructorConfig.create(aScope);
+ }
+
+ /**
+ * Injects required interfaces through the setters
+ *
+ * @param aScope
+ * Scope in which injection takes place.
+ * @param aObject
+ * Object to inject into.
+ */
+ public void inject(Scope aScope, Object aObject) {
+ objectConfig.inject(aScope, aObject);
+ }
+
+ public List getProvidedInterfaces() {
+ List result = new ArrayList();
+ result.add(new DefaultProvidedInterface("provided", clazz));
+
+ return result;
+ }
- private Class _class;
- private ConstructorConfiguration _constructorConfig;
-
- /**
- * Constructs the configuration. By default no constructor is selected and
- * one of {@link #select(Class...)} or
- * {@link #greedy()} must be called.
- * @param aClass Class to construct.
- */
- public ClassConfiguration(Class aClass) {
- _class = aClass;
- _constructorConfig = new ConstructorConfiguration(aClass);
- }
-
- public ConstructorConfiguration getConstructorConfig() {
- return _constructorConfig;
- }
+ public List getRequiredInterfaces() {
+ List result = new ArrayList();
+ result.addAll(constructorConfig.getRequiredInterfaces());
+ result.addAll(objectConfig.getRequiredInterfaces());
- /**
- * Creates the object in the given scope.
- * @param aScope Scope containing required interfaces for this object.
- * @return object.
- */
- public Object create(Scope aScope) {
- return _constructorConfig.create(aScope);
- }
-
- public ProvidedInterface[] getProvidedInterfaces() {
- return new ProvidedInterface[] {
- new DefaultProvidedInterface("provided", _class)
- };
- }
-
- public RequiredInterface[] getRequiredInterface() {
- return _constructorConfig.getRequiredInterfaces().toArray(new RequiredInterface[0]);
- }
+ return result;
+ }
}