comparison artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java @ 249:c47a640cfdae

Enhanced the bootstrap - the CallContext.Listener is initialized (if configured). artifacts/trunk@1692 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 14 Apr 2011 13:08:49 +0000
parents b2115f484edb
children c0fb96f88ad1
comparison
equal deleted inserted replaced
248:eafe59ecfb7e 249:c47a640cfdae
11 import de.intevation.artifacts.common.utils.Config; 11 import de.intevation.artifacts.common.utils.Config;
12 12
13 import de.intevation.artifacts.ArtifactCollectionFactory; 13 import de.intevation.artifacts.ArtifactCollectionFactory;
14 import de.intevation.artifacts.ArtifactContextFactory; 14 import de.intevation.artifacts.ArtifactContextFactory;
15 import de.intevation.artifacts.ArtifactFactory; 15 import de.intevation.artifacts.ArtifactFactory;
16 import de.intevation.artifacts.CallContext;
16 import de.intevation.artifacts.ServiceFactory; 17 import de.intevation.artifacts.ServiceFactory;
17 import de.intevation.artifacts.UserFactory; 18 import de.intevation.artifacts.UserFactory;
18 19
19 import java.util.ArrayList; 20 import java.util.ArrayList;
20 21
93 */ 94 */
94 public static final String EXPORT_SECRET = 95 public static final String EXPORT_SECRET =
95 "/artifact-database/export-secret/text()"; 96 "/artifact-database/export-secret/text()";
96 97
97 /** 98 /**
99 * XPAth that points to a configuration node for a CallContext.Listener.
100 */
101 public static final String CALLCONTEXT_LISTENER =
102 "/artifact-database/callcontext-listener";
103
104 /**
98 * Default export signing secret. 105 * Default export signing secret.
99 * <strong>PLEASE CHANGE THE SECRET VIA THE XPATH EXPORT_SECRET 106 * <strong>PLEASE CHANGE THE SECRET VIA THE XPATH EXPORT_SECRET
100 * IN THE CONFIGURATION.</strong>. 107 * IN THE CONFIGURATION.</strong>.
101 */ 108 */
102 public static final String DEFAULT_EXPORT_SECRET = 109 public static final String DEFAULT_EXPORT_SECRET =
126 133
127 /** 134 /**
128 * The factory that is used to create new artifact collections. 135 * The factory that is used to create new artifact collections.
129 */ 136 */
130 protected ArtifactCollectionFactory collectionFactory; 137 protected ArtifactCollectionFactory collectionFactory;
138
139 /**
140 * The CallContext.Listener.
141 */
142 protected CallContext.Listener callContextListener;
131 143
132 /** 144 /**
133 * byte array holding the export signing secret. 145 * byte array holding the export signing secret.
134 */ 146 */
135 protected byte [] exportSecret; 147 protected byte [] exportSecret;
327 try { 339 try {
328 Class clazz = Class.forName(className); 340 Class clazz = Class.forName(className);
329 userFactory = (UserFactory) clazz.newInstance(); 341 userFactory = (UserFactory) clazz.newInstance();
330 342
331 userFactory.setup(Config.getConfig(), factory); 343 userFactory.setup(Config.getConfig(), factory);
344 }
345 catch (ClassNotFoundException cnfe) {
346 logger.error(cnfe.getLocalizedMessage(), cnfe);
347 }
348 catch (InstantiationException ie) {
349 logger.error(ie.getLocalizedMessage(), ie);
350 }
351 catch (ClassCastException cce) {
352 logger.error(cce.getLocalizedMessage(), cce);
353 }
354 catch (IllegalAccessException iae) {
355 logger.error(iae.getLocalizedMessage(), iae);
356 }
357 }
358
359
360 protected void loadCallContextListener() {
361 logger.info("loading CallContext.Listener");
362
363 Node listener = Config.getNodeXPath(CALLCONTEXT_LISTENER);
364
365 if (listener == null) {
366 return;
367 }
368
369 String className = Config.getStringXPath(listener, "text()");
370
371 try {
372 Class clazz = Class.forName(className);
373 callContextListener = (CallContext.Listener) clazz.newInstance();
374
375 callContextListener.setup(Config.getConfig(), listener);
332 } 376 }
333 catch (ClassNotFoundException cnfe) { 377 catch (ClassNotFoundException cnfe) {
334 logger.error(cnfe.getLocalizedMessage(), cnfe); 378 logger.error(cnfe.getLocalizedMessage(), cnfe);
335 } 379 }
336 catch (InstantiationException ie) { 380 catch (InstantiationException ie) {
368 buildContext(); 412 buildContext();
369 loadCollectionFactory(); 413 loadCollectionFactory();
370 loadArtifactFactories(); 414 loadArtifactFactories();
371 loadServiceFactories(); 415 loadServiceFactories();
372 loadUserFactory(); 416 loadUserFactory();
417 loadCallContextListener();
373 } 418 }
374 419
375 /** 420 /**
376 * Returns the artifact collection factory. 421 * Returns the artifact collection factory.
377 * 422 *
420 * @return the byte array containg the signing secret. 465 * @return the byte array containg the signing secret.
421 */ 466 */
422 public byte [] getExportSecret() { 467 public byte [] getExportSecret() {
423 return exportSecret; 468 return exportSecret;
424 } 469 }
470
471 /**
472 * Returns a CallContext.Listener if configured or null.
473 *
474 * @return a CallContext.Listener.
475 */
476 public CallContext.Listener getCallContextListener() {
477 return callContextListener;
478 }
425 } 479 }
426 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 480 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org