Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java @ 292:39c0ff00d188
Introduced a hook concept - currently used for 'post-feed' and 'post-advance'.
artifacts/trunk@2327 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 13 Jul 2011 13:12:08 +0000 |
parents | d52947ce8629 |
children | a367a0d011af |
comparison
equal
deleted
inserted
replaced
291:f8c4fa292c9c | 292:39c0ff00d188 |
---|---|
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.CallContext; |
17 import de.intevation.artifacts.Hook; | |
17 import de.intevation.artifacts.ServiceFactory; | 18 import de.intevation.artifacts.ServiceFactory; |
18 import de.intevation.artifacts.UserFactory; | 19 import de.intevation.artifacts.UserFactory; |
19 | 20 |
20 | 21 |
21 import de.intevation.artifactdatabase.rest.HTTPServer; | 22 import de.intevation.artifactdatabase.rest.HTTPServer; |
22 | 23 |
23 import java.util.ArrayList; | 24 import java.util.ArrayList; |
25 import java.util.List; | |
24 | 26 |
25 import org.apache.log4j.Logger; | 27 import org.apache.log4j.Logger; |
26 | 28 |
27 import org.w3c.dom.Document; | 29 import org.w3c.dom.Document; |
28 import org.w3c.dom.Node; | 30 import org.w3c.dom.Node; |
102 * XPAth that points to a configuration node for a CallContext.Listener. | 104 * XPAth that points to a configuration node for a CallContext.Listener. |
103 */ | 105 */ |
104 public static final String CALLCONTEXT_LISTENER = | 106 public static final String CALLCONTEXT_LISTENER = |
105 "/artifact-database/callcontext-listener"; | 107 "/artifact-database/callcontext-listener"; |
106 | 108 |
109 /** | |
110 * XPath that points to configuration nodes for hooks. | |
111 */ | |
112 public static final String HOOKS = | |
113 "/artifact-database/hooks/hook"; | |
107 | 114 |
108 public static final String HTTP_SERVER = | 115 public static final String HTTP_SERVER = |
109 "/artifact-database/rest-server/http-server/text()"; | 116 "/artifact-database/rest-server/http-server/text()"; |
110 | 117 |
111 public static final String DEFAULT_HTTP_SERVER = | 118 public static final String DEFAULT_HTTP_SERVER = |
148 | 155 |
149 /** | 156 /** |
150 * The CallContext.Listener. | 157 * The CallContext.Listener. |
151 */ | 158 */ |
152 protected CallContext.Listener callContextListener; | 159 protected CallContext.Listener callContextListener; |
160 | |
161 protected List<Hook> postFeedHooks; | |
162 | |
163 protected List<Hook> postAdvanceHooks; | |
153 | 164 |
154 /** | 165 /** |
155 * byte array holding the export signing secret. | 166 * byte array holding the export signing secret. |
156 */ | 167 */ |
157 protected byte [] exportSecret; | 168 protected byte [] exportSecret; |
424 logger.error(cce.getLocalizedMessage(), cce); | 435 logger.error(cce.getLocalizedMessage(), cce); |
425 } | 436 } |
426 catch (IllegalAccessException iae) { | 437 catch (IllegalAccessException iae) { |
427 logger.error(iae.getLocalizedMessage(), iae); | 438 logger.error(iae.getLocalizedMessage(), iae); |
428 } | 439 } |
440 } | |
441 | |
442 protected void loadHooks() { | |
443 logger.info("loading hooks"); | |
444 | |
445 postFeedHooks = new ArrayList<Hook>(); | |
446 postAdvanceHooks = new ArrayList<Hook>(); | |
447 | |
448 NodeList nodes = Config.getNodeSetXPath(HOOKS); | |
449 | |
450 for (int i = 0, len = nodes.getLength(); i < len; i++) { | |
451 Node cfg = nodes.item(i); | |
452 String applies = Config.getStringXPath(cfg, "@applies"); | |
453 | |
454 if (applies == null || applies.length() == 0) { | |
455 continue; | |
456 } | |
457 | |
458 Hook hook = loadHook(cfg); | |
459 String[] apply = applies.split(","); | |
460 | |
461 for (String a: apply) { | |
462 a = a.trim().toLowerCase(); | |
463 | |
464 if (a.equals("post-feed")) { | |
465 postFeedHooks.add(hook); | |
466 } | |
467 else if (a.equals("post-advance")) { | |
468 postAdvanceHooks.add(hook); | |
469 } | |
470 } | |
471 } | |
472 } | |
473 | |
474 protected Hook loadHook(Node hookCfg) { | |
475 if (hookCfg == null) { | |
476 return null; | |
477 } | |
478 | |
479 Hook hook = null; | |
480 | |
481 String className = Config.getStringXPath(hookCfg, "@class"); | |
482 | |
483 try { | |
484 Class clazz = Class.forName(className); | |
485 hook = (Hook) clazz.newInstance(); | |
486 | |
487 hook.setup(hookCfg); | |
488 } | |
489 catch (ClassNotFoundException cnfe) { | |
490 logger.error(cnfe.getLocalizedMessage(), cnfe); | |
491 } | |
492 catch (InstantiationException ie) { | |
493 logger.error(ie.getLocalizedMessage(), ie); | |
494 } | |
495 catch (ClassCastException cce) { | |
496 logger.error(cce.getLocalizedMessage(), cce); | |
497 } | |
498 catch (IllegalAccessException iae) { | |
499 logger.error(iae.getLocalizedMessage(), iae); | |
500 } | |
501 | |
502 return hook; | |
429 } | 503 } |
430 | 504 |
431 /** | 505 /** |
432 * Fetches the export signing secret from the global configuration. | 506 * Fetches the export signing secret from the global configuration. |
433 * If none is found if defaults to the DEFAULT_EXORT_SECRET which | 507 * If none is found if defaults to the DEFAULT_EXORT_SECRET which |
454 loadArtifactFactories(); | 528 loadArtifactFactories(); |
455 loadServiceFactories(); | 529 loadServiceFactories(); |
456 loadUserFactory(); | 530 loadUserFactory(); |
457 loadCallContextListener(); | 531 loadCallContextListener(); |
458 loadHTTPServer(); | 532 loadHTTPServer(); |
533 loadHooks(); | |
459 } | 534 } |
460 | 535 |
461 /** | 536 /** |
462 * Returns the artifact collection factory. | 537 * Returns the artifact collection factory. |
463 * | 538 * |
516 */ | 591 */ |
517 public CallContext.Listener getCallContextListener() { | 592 public CallContext.Listener getCallContextListener() { |
518 return callContextListener; | 593 return callContextListener; |
519 } | 594 } |
520 | 595 |
596 public List<Hook> getPostFeedHooks() { | |
597 return postFeedHooks; | |
598 } | |
599 | |
600 public List<Hook> getPostAdvanceHooks() { | |
601 return postAdvanceHooks; | |
602 } | |
603 | |
521 public HTTPServer getHTTPServer() { | 604 public HTTPServer getHTTPServer() { |
522 return httpServer; | 605 return httpServer; |
523 } | 606 } |
524 } | 607 } |
525 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 608 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |