|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| package org.objectledge.container; |
|
30 |
| |
|
31 |
| import java.io.IOException; |
|
32 |
| import java.net.URL; |
|
33 |
| |
|
34 |
| import org.jcontainer.dna.Configuration; |
|
35 |
| import org.jcontainer.dna.Logger; |
|
36 |
| import org.nanocontainer.integrationkit.ContainerBuilder; |
|
37 |
| import org.nanocontainer.integrationkit.PicoCompositionException; |
|
38 |
| import org.nanocontainer.reflection.StringToObjectConverter; |
|
39 |
| import org.objectledge.configuration.ConfigurationFactory; |
|
40 |
| import org.objectledge.configuration.CustomizedConfigurationProvider; |
|
41 |
| import org.objectledge.filesystem.FileSystem; |
|
42 |
| import org.objectledge.logging.LoggerFactory; |
|
43 |
| import org.objectledge.logging.LoggingConfigurator; |
|
44 |
| import org.objectledge.pico.LedgeStringToObjectConverter; |
|
45 |
| import org.objectledge.pico.customization.CustomizedComponentAdapter; |
|
46 |
| import org.objectledge.pico.customization.CustomizingConstructorComponentAdapterFactory; |
|
47 |
| import org.objectledge.pico.xml.LedgeContainerBuilder; |
|
48 |
| import org.objectledge.xml.XMLGrammarCache; |
|
49 |
| import org.objectledge.xml.XMLValidator; |
|
50 |
| import org.picocontainer.ComponentAdapter; |
|
51 |
| import org.picocontainer.MutablePicoContainer; |
|
52 |
| import org.picocontainer.Parameter; |
|
53 |
| import org.picocontainer.PicoContainer; |
|
54 |
| import org.picocontainer.defaults.CachingComponentAdapterFactory; |
|
55 |
| import org.picocontainer.defaults.ComponentAdapterFactory; |
|
56 |
| import org.picocontainer.defaults.ComponentParameter; |
|
57 |
| import org.picocontainer.defaults.ConstantParameter; |
|
58 |
| import org.picocontainer.defaults.ConstructorInjectionComponentAdapter; |
|
59 |
| import org.picocontainer.defaults.DefaultPicoContainer; |
|
60 |
| import org.picocontainer.defaults.ObjectReference; |
|
61 |
| import org.picocontainer.defaults.SimpleReference; |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| public class LedgeContainer |
|
75 |
| { |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| public static final String COMPOSITION_FILE = "/container.xml"; |
|
80 |
| |
|
81 |
| |
|
82 |
| public static final String FRONT_END_CLASS = |
|
83 |
| "org.objectledge.pico.xml.LedgeXMLContainerBuilder"; |
|
84 |
| |
|
85 |
| |
|
86 |
| public static final String CONFIG_BASE_KEY = "org.objectledge.ConfigBase"; |
|
87 |
| |
|
88 |
| |
|
89 |
| protected ObjectReference containerRef = new SimpleReference(); |
|
90 |
| |
|
91 |
| |
|
92 |
| protected ContainerBuilder containerBuilder; |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
172
| public LedgeContainer(FileSystem fs, String configBase, ClassLoader classLoader)
|
|
108 |
| throws IOException, ClassNotFoundException, PicoCompositionException |
|
109 |
| { |
|
110 |
172
| containerBuilder = new LedgeContainerBuilder(getCompositionFile(fs, configBase),
|
|
111 |
| classLoader); |
|
112 |
172
| ObjectReference parentRef = new SimpleReference();
|
|
113 |
172
| parentRef.set(getBootContainer(fs, configBase, classLoader));
|
|
114 |
172
| containerBuilder.buildContainer(containerRef, parentRef, null, true);
|
|
115 |
| } |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
172
| public MutablePicoContainer getContainer()
|
|
123 |
| { |
|
124 |
172
| return (MutablePicoContainer)containerRef.get();
|
|
125 |
| } |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
83
| public void killContainer()
|
|
131 |
| { |
|
132 |
83
| containerBuilder.killContainer(containerRef);
|
|
133 |
| } |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
172
| protected static URL getCompositionFile(FileSystem fs, String configBase)
|
|
146 |
| throws IOException, PicoCompositionException |
|
147 |
| { |
|
148 |
172
| return fs.getResource(configBase + COMPOSITION_FILE);
|
|
149 |
| } |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
172
| protected static PicoContainer getBootContainer(FileSystem fs, String configBase,
|
|
160 |
| ClassLoader classLoader) |
|
161 |
| { |
|
162 |
172
| MutablePicoContainer bootContainer = new DefaultPicoContainer();
|
|
163 |
172
| bootContainer.registerComponentInstance(FileSystem.class, fs);
|
|
164 |
172
| bootContainer.registerComponentInstance(ClassLoader.class, classLoader);
|
|
165 |
172
| bootContainer.registerComponentImplementation(XMLGrammarCache.class);
|
|
166 |
172
| bootContainer.registerComponentImplementation(XMLValidator.class);
|
|
167 |
172
| bootContainer.registerComponentImplementation(StringToObjectConverter.class,
|
|
168 |
| LedgeStringToObjectConverter.class); |
|
169 |
| |
|
170 |
172
| bootContainer.registerComponentImplementation(ConfigurationFactory.class,
|
|
171 |
| ConfigurationFactory.class, params(COMPONENT, COMPONENT, constant(configBase))); |
|
172 |
172
| bootContainer.registerComponentImplementation(CustomizedConfigurationProvider.class);
|
|
173 |
172
| ComponentAdapter adapter = new ConstructorInjectionComponentAdapter("anonymous",
|
|
174 |
| CustomizedComponentAdapter.class, params(constant(Configuration.class), |
|
175 |
| component(CustomizedConfigurationProvider.class))); |
|
176 |
172
| adapter = (ComponentAdapter)adapter.getComponentInstance(bootContainer);
|
|
177 |
172
| bootContainer.registerComponent(adapter);
|
|
178 |
| |
|
179 |
172
| bootContainer.registerComponentImplementation(LoggingConfigurator.class);
|
|
180 |
172
| bootContainer.registerComponentImplementation(LoggerFactory.class);
|
|
181 |
172
| adapter = new ConstructorInjectionComponentAdapter("anonymous",
|
|
182 |
| CustomizedComponentAdapter.class, params(constant(Logger.class), |
|
183 |
| component(LoggerFactory.class))); |
|
184 |
172
| adapter = (ComponentAdapter)adapter.getComponentInstance(bootContainer);
|
|
185 |
172
| bootContainer.registerComponent(adapter);
|
|
186 |
| |
|
187 |
172
| bootContainer.
|
|
188 |
| registerComponentImplementation(CustomizingConstructorComponentAdapterFactory.class); |
|
189 |
172
| bootContainer.registerComponentImplementation(ComponentAdapterFactory.class,
|
|
190 |
| CachingComponentAdapterFactory.class, |
|
191 |
| params(component(CustomizingConstructorComponentAdapterFactory.class))); |
|
192 |
172
| return bootContainer;
|
|
193 |
| } |
|
194 |
| |
|
195 |
| private static final Parameter COMPONENT = new ComponentParameter(); |
|
196 |
| |
|
197 |
| |
|
198 |
688
| private static Parameter[] params(Parameter... parameters)
|
|
199 |
| { |
|
200 |
688
| return parameters;
|
|
201 |
| } |
|
202 |
| |
|
203 |
516
| private static Parameter constant(Object value)
|
|
204 |
| { |
|
205 |
516
| return new ConstantParameter(value);
|
|
206 |
| } |
|
207 |
| |
|
208 |
516
| private static Parameter component(Object key)
|
|
209 |
| { |
|
210 |
516
| return new ComponentParameter(key);
|
|
211 |
| } |
|
212 |
| } |