Mercurial > dive4elements > framework
comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.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 | 084d68974d4a |
children | a367a0d011af |
comparison
equal
deleted
inserted
replaced
291:f8c4fa292c9c | 292:39c0ff00d188 |
---|---|
21 import de.intevation.artifacts.ArtifactNamespaceContext; | 21 import de.intevation.artifacts.ArtifactNamespaceContext; |
22 import de.intevation.artifacts.ArtifactSerializer; | 22 import de.intevation.artifacts.ArtifactSerializer; |
23 import de.intevation.artifacts.CallContext; | 23 import de.intevation.artifacts.CallContext; |
24 import de.intevation.artifacts.CallMeta; | 24 import de.intevation.artifacts.CallMeta; |
25 import de.intevation.artifacts.CollectionItem; | 25 import de.intevation.artifacts.CollectionItem; |
26 import de.intevation.artifacts.Hook; | |
26 import de.intevation.artifacts.Service; | 27 import de.intevation.artifacts.Service; |
27 import de.intevation.artifacts.ServiceFactory; | 28 import de.intevation.artifacts.ServiceFactory; |
28 import de.intevation.artifacts.User; | 29 import de.intevation.artifacts.User; |
29 import de.intevation.artifacts.UserFactory; | 30 import de.intevation.artifacts.UserFactory; |
30 | 31 |
36 | 37 |
37 import java.util.Arrays; | 38 import java.util.Arrays; |
38 import java.util.Date; | 39 import java.util.Date; |
39 import java.util.HashMap; | 40 import java.util.HashMap; |
40 import java.util.HashSet; | 41 import java.util.HashSet; |
42 import java.util.List; | |
41 import java.util.Set; | 43 import java.util.Set; |
42 | 44 |
43 import javax.xml.xpath.XPathConstants; | 45 import javax.xml.xpath.XPathConstants; |
44 | 46 |
45 import org.apache.commons.codec.binary.Base64; | 47 import org.apache.commons.codec.binary.Base64; |
416 protected HashSet<Integer> backgroundIds; | 418 protected HashSet<Integer> backgroundIds; |
417 | 419 |
418 protected CallContext.Listener callContextListener; | 420 protected CallContext.Listener callContextListener; |
419 | 421 |
420 /** | 422 /** |
423 * Hooks that are executed after an artifact has been fed. | |
424 */ | |
425 protected List<Hook> postFeedHooks; | |
426 | |
427 /** | |
428 * Hooks that are executed after an artifact has advanced. | |
429 */ | |
430 protected List<Hook> postAdvanceHooks; | |
431 | |
432 /** | |
421 * Default constructor. | 433 * Default constructor. |
422 */ | 434 */ |
423 public ArtifactDatabaseImpl() { | 435 public ArtifactDatabaseImpl() { |
424 } | 436 } |
425 | 437 |
447 setupArtifactCollectionFactory(bootstrap); | 459 setupArtifactCollectionFactory(bootstrap); |
448 setupArtifactFactories(bootstrap); | 460 setupArtifactFactories(bootstrap); |
449 setupServices(bootstrap); | 461 setupServices(bootstrap); |
450 setupUserFactory(bootstrap); | 462 setupUserFactory(bootstrap); |
451 setupCallContextListener(bootstrap); | 463 setupCallContextListener(bootstrap); |
464 setupHooks(bootstrap); | |
452 | 465 |
453 context = bootstrap.getContext(); | 466 context = bootstrap.getContext(); |
454 exportSecret = bootstrap.getExportSecret(); | 467 exportSecret = bootstrap.getExportSecret(); |
455 | 468 |
456 wireWithBackend(backend); | 469 wireWithBackend(backend); |
464 CallContext.Listener callContextListener | 477 CallContext.Listener callContextListener |
465 ) { | 478 ) { |
466 this.callContextListener = callContextListener; | 479 this.callContextListener = callContextListener; |
467 } | 480 } |
468 | 481 |
482 | |
483 public void setPostFeedHook(List<Hook> postFeedHooks) { | |
484 this.postFeedHooks = postFeedHooks; | |
485 } | |
486 | |
487 public void setPostAdvanceHook(List<Hook> postAdvanceHooks) { | |
488 this.postAdvanceHooks = postAdvanceHooks; | |
489 } | |
490 | |
469 /** | 491 /** |
470 * Used to extract the artifact collection factory from bootstrap. | 492 * Used to extract the artifact collection factory from bootstrap. |
471 * | 493 * |
472 * @param bootstrap The bootstrap parameters. | 494 * @param bootstrap The bootstrap parameters. |
473 */ | 495 */ |
505 * | 527 * |
506 * @param bootstrap The bootstrap parameters. | 528 * @param bootstrap The bootstrap parameters. |
507 */ | 529 */ |
508 protected void setupCallContextListener(FactoryBootstrap bootstrap) { | 530 protected void setupCallContextListener(FactoryBootstrap bootstrap) { |
509 setCallContextListener(bootstrap.getCallContextListener()); | 531 setCallContextListener(bootstrap.getCallContextListener()); |
532 } | |
533 | |
534 | |
535 protected void setupHooks(FactoryBootstrap bootstrap) { | |
536 setPostFeedHook(bootstrap.getPostFeedHooks()); | |
537 setPostAdvanceHook(bootstrap.getPostAdvanceHooks()); | |
510 } | 538 } |
511 | 539 |
512 /** | 540 /** |
513 * Used to extract the user factory from the bootstrap. | 541 * Used to extract the user factory from the bootstrap. |
514 */ | 542 */ |
732 CallContext.STORE, | 760 CallContext.STORE, |
733 callMeta, | 761 callMeta, |
734 artifact); | 762 artifact); |
735 | 763 |
736 try { | 764 try { |
737 return artifact.getArtifact().advance(target, cc); | 765 Artifact art = artifact.getArtifact(); |
766 Document res = art.advance(target, cc); | |
767 | |
768 if (postAdvanceHooks != null) { | |
769 for (Hook hook: postAdvanceHooks) { | |
770 hook.execute(art, cc); | |
771 } | |
772 } | |
773 | |
774 return res; | |
738 } | 775 } |
739 finally { | 776 finally { |
740 cc.postCall(); | 777 cc.postCall(); |
741 } | 778 } |
742 } | 779 } |
756 CallContext.STORE, | 793 CallContext.STORE, |
757 callMeta, | 794 callMeta, |
758 artifact); | 795 artifact); |
759 | 796 |
760 try { | 797 try { |
761 return artifact.getArtifact().feed(data, cc); | 798 Artifact art = artifact.getArtifact(); |
799 Document res = art.feed(data, cc); | |
800 | |
801 if (postFeedHooks != null) { | |
802 for (Hook hook: postFeedHooks) { | |
803 hook.execute(art, cc); | |
804 } | |
805 } | |
806 | |
807 return res; | |
762 } | 808 } |
763 finally { | 809 finally { |
764 cc.postCall(); | 810 cc.postCall(); |
765 } | 811 } |
766 } | 812 } |