comparison artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java @ 89:d348fe1fd822

More javadoc (fixes small glitches, too). artifacts/trunk@845 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 26 Mar 2010 16:16:32 +0000
parents f69e5b87f05f
children 5332d956729c
comparison
equal deleted inserted replaced
88:69c84cf7c5d7 89:d348fe1fd822
18 */ 18 */
19 public class FactoryBootstrap 19 public class FactoryBootstrap
20 { 20 {
21 private static Logger logger = Logger.getLogger(FactoryBootstrap.class); 21 private static Logger logger = Logger.getLogger(FactoryBootstrap.class);
22 22
23 /**
24 * XPath to figure out the class name of the context factory from
25 * the global configuration.
26 */
23 public static final String CONTEXT_FACTORY = 27 public static final String CONTEXT_FACTORY =
24 "/artifact-database/factories/context-factory/text()"; 28 "/artifact-database/factories/context-factory/text()";
25 29
30 /**
31 * The name of the default context factory.
32 */
26 public static final String DEFAULT_CONTEXT_FACTORY = 33 public static final String DEFAULT_CONTEXT_FACTORY =
27 "de.intevation.artifactdatabase.DefaultArtifactContextFactory"; 34 "de.intevation.artifactdatabase.DefaultArtifactContextFactory";
28 35
36 /**
37 * XPath to figure out the names of the artifact factories from
38 * the global configuration to be exposed by the artifact database.
39 */
29 public static final String ARTIFACT_FACTORIES = 40 public static final String ARTIFACT_FACTORIES =
30 "/artifact-database/factories/artifact-factories/artifact-factory"; 41 "/artifact-database/factories/artifact-factories/artifact-factory";
31 42
43 /**
44 * XPath to figure out the names of the service factories from
45 * the global configuration to build the services offered by the
46 * artifact database.
47 */
32 public static final String SERVICE_FACTORIES = 48 public static final String SERVICE_FACTORIES =
33 "/artifact-database/factories/service-factories/service-factory"; 49 "/artifact-database/factories/service-factories/service-factory";
34 50
51 /**
52 * XPath to figure out the secret used to sign the artifact exports
53 * made by the artfifact database server.
54 */
35 public static final String EXPORT_SECRET = 55 public static final String EXPORT_SECRET =
36 "/artifact-database/export-secret/text()"; 56 "/artifact-database/export-secret/text()";
37 57
38 public static final String DEFAULT_EXORT_SECRET = 58 /**
59 * Default export signing secret.
60 * <strong>PLEASE CHANGE THE SECRET VIA THE XPATH EXPORT_SECRET
61 * IN THE CONFIGURATION.</strong>.
62 */
63 public static final String DEFAULT_EXPORT_SECRET =
39 "!!!CHANGE ME! I'M NO SECRET!!!"; 64 "!!!CHANGE ME! I'M NO SECRET!!!";
40 65
66 /**
67 * Reference to the global context build by the global context factory.
68 */
41 protected Object context; 69 protected Object context;
42 70
71 /**
72 * List of the artifact factories to be exposed by the
73 * artifact database.
74 */
43 protected ArtifactFactory [] artifactFactories; 75 protected ArtifactFactory [] artifactFactories;
44 76
77 /**
78 * List of service factories which creates services that are
79 * exposed by the artifact database.
80 */
45 protected ServiceFactory [] serviceFactories; 81 protected ServiceFactory [] serviceFactories;
46 82
83 /**
84 * byte array holding the export signing secret.
85 */
47 protected byte [] exportSecret; 86 protected byte [] exportSecret;
48 87
49 88
89 /**
90 * Default constructor
91 */
50 public FactoryBootstrap() { 92 public FactoryBootstrap() {
51 } 93 }
52 94
53 void buildContext() { 95 void buildContext() {
54 String className = Config.getStringXPath( 96 String className = Config.getStringXPath(
81 + "' for context creation."); 123 + "' for context creation.");
82 124
83 context = factory.createArtifactContext(Config.getConfig()); 125 context = factory.createArtifactContext(Config.getConfig());
84 } 126 }
85 127
128 /**
129 * Scans the global configuration to load the configured
130 * artifact factories and sets them up.
131 */
86 protected void loadArtifactFactories() { 132 protected void loadArtifactFactories() {
87 133
88 logger.info("loading artifact factories"); 134 logger.info("loading artifact factories");
89 135
90 ArrayList loadedFactories = new ArrayList(); 136 ArrayList loadedFactories = new ArrayList();
120 } 166 }
121 167
122 if (factory != null) { 168 if (factory != null) {
123 factory.setup(config, nodes.item(i)); 169 factory.setup(config, nodes.item(i));
124 loadedFactories.add(factory); 170 loadedFactories.add(factory);
125 logger.info("Registering '" + factory.getName() + "' as artifact factory."); 171 logger.info("Registering '"
172 + factory.getName() + "' as artifact factory.");
126 } 173 }
127 } 174 }
128 175
129 artifactFactories = (ArtifactFactory [])loadedFactories.toArray( 176 artifactFactories = (ArtifactFactory [])loadedFactories.toArray(
130 new ArtifactFactory[loadedFactories.size()]); 177 new ArtifactFactory[loadedFactories.size()]);
131 } 178 }
132 179
180 /**
181 * Scans the global configuration for the configured service factories
182 * and sets them up.
183 */
133 protected void loadServiceFactories() { 184 protected void loadServiceFactories() {
134 185
135 logger.info("loading service factories"); 186 logger.info("loading service factories");
136 187
137 ArrayList loadedFactories = new ArrayList(); 188 ArrayList loadedFactories = new ArrayList();
175 226
176 serviceFactories = (ServiceFactory [])loadedFactories.toArray( 227 serviceFactories = (ServiceFactory [])loadedFactories.toArray(
177 new ServiceFactory[loadedFactories.size()]); 228 new ServiceFactory[loadedFactories.size()]);
178 } 229 }
179 230
231 /**
232 * Fetches the export signing secret from the global configuration.
233 * If none is found if defaults to the DEFAULT_EXORT_SECRET which
234 * is insecure.
235 */
180 protected void setupExportSecret() { 236 protected void setupExportSecret() {
181 String secret = Config.getStringXPath(EXPORT_SECRET); 237 String secret = Config.getStringXPath(EXPORT_SECRET);
182 238
183 if (secret == null) { 239 if (secret == null) {
184 logger.warn("NO EXPORT SECRET SET! USING INSECURE DEFAULT!"); 240 logger.warn("NO EXPORT SECRET SET! USING INSECURE DEFAULT!");
185 secret = DEFAULT_EXORT_SECRET; 241 secret = DEFAULT_EXPORT_SECRET;
186 } 242 }
187 243
188 exportSecret = StringUtils.getUTF8Bytes(secret); 244 exportSecret = StringUtils.getUTF8Bytes(secret);
189 } 245 }
190 246
247 /**
248 * Loads all the dynamic classes configured by the global configuration.
249 */
191 public void boot() { 250 public void boot() {
192 setupExportSecret(); 251 setupExportSecret();
193 buildContext(); 252 buildContext();
194 loadArtifactFactories(); 253 loadArtifactFactories();
195 loadServiceFactories(); 254 loadServiceFactories();
196 } 255 }
197 256
257 /**
258 * Returns the list of ready to use artifact factories.
259 * @return The list of artifact factories.
260 */
198 public ArtifactFactory [] getArtifactFactories() { 261 public ArtifactFactory [] getArtifactFactories() {
199 return artifactFactories; 262 return artifactFactories;
200 } 263 }
201 264
265 /**
266 * Returns the ready to use service factories.
267 * @return The list of service factories.
268 */
202 public ServiceFactory [] getServiceFactories() { 269 public ServiceFactory [] getServiceFactories() {
203 return serviceFactories; 270 return serviceFactories;
204 } 271 }
205 272
273 /**
274 * Returns the global context created by the global context factory.
275 * @return The global context.
276 */
206 public Object getContext() { 277 public Object getContext() {
207 return context; 278 return context;
208 } 279 }
209 280
281 /**
282 * Returns the signing secret to be used when ex- and importing
283 * artifacts from and into the artifact database.
284 * @return the byte array containg the signing secret.
285 */
210 public byte [] getExportSecret() { 286 public byte [] getExportSecret() {
211 return exportSecret; 287 return exportSecret;
212 } 288 }
213 } 289 }
214 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 290 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org