MentaContainer

Rev

Rev 92 | Rev 94 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 92 Rev 93
Line 11... Line 11...
11
import org.mentacontainer.ConfigurableFactory;
11
import org.mentacontainer.ConfigurableFactory;
12
import org.mentacontainer.Container;
12
import org.mentacontainer.Container;
13
import org.mentacontainer.util.FindMethod;
13
import org.mentacontainer.util.FindMethod;
14
14
15
/**
15
/**
16
 * A simple implementation of the Component interface.
16
 * The implementation of the Configurable Factory.
17
 *
17
 *
18
 * @author sergio.oliveira.jr@gmail.com
18
 * @author sergio.oliveira.jr@gmail.com
19
 */
19
 */
20
public class ClassFactory implements ConfigurableFactory {
20
class ClassFactory implements ConfigurableFactory {
21
       
21
       
22
                private final Container container;
22
                private final Container container;
23
       
23
       
24
            private final Class<? extends Object> klass;
24
            private final Class<? extends Object> klass;
25
           
25
           
Line 30... Line 30...
30
            private List<Class<? extends Object>> initTypes = null;
30
            private List<Class<? extends Object>> initTypes = null;
31
           
31
           
32
            private Constructor<? extends Object> constructor = null;
32
            private Constructor<? extends Object> constructor = null;
33
           
33
           
34
            private Map<String, Method> cache = null;
34
            private Map<String, Method> cache = null;
35
           
-
 
36
            public ClassFactory(Class<? extends Object> klass) {
-
 
37
               
-
 
38
                this(null, klass);
-
 
39
            }
-
 
40
           
35
           
41
            public ClassFactory(Container container, Class<? extends Object> klass) {
36
            public ClassFactory(Container container, Class<? extends Object> klass) {
42
               
37
               
43
                this.container = container;
38
                this.container = container;
44
               
39
               
Line 60... Line 55...
60
                return this;
55
                return this;
61
            }
56
            }
62
           
57
           
63
            @Override
58
            @Override
64
            public ConfigurableFactory addPropertyDependency(String property, String key) {
59
            public ConfigurableFactory addPropertyDependency(String property, String key) {
65
               
-
 
66
                if (container == null) throw new IllegalStateException("Cannot set property dependency because factory does not have container!");
-
 
67
               
60
               
68
                return addPropertyValue(property, new DependencyKey(key));
61
                return addPropertyValue(property, new DependencyKey(key));
69
            }
62
            }
70
           
63
           
71
            @Override
64
            @Override
72
            public ConfigurableFactory addInitDependency(String key) {
65
            public ConfigurableFactory addInitDependency(String key) {
73
               
-
 
74
                if (container == null) throw new IllegalStateException("Cannot set constructor dependency because factory does not have container!");
-
 
75
               
66
               
76
                return addInitValue(new DependencyKey(key), container.getType(key));
67
                return addInitValue(new DependencyKey(key), container.getType(key));
77
            }
68
            }
78
           
69
           
79
            private ConfigurableFactory addInitValue(Object value, Class<? extends Object> type) {
70
            private ConfigurableFactory addInitValue(Object value, Class<? extends Object> type) {