Mercurial > dive4elements > framework
changeset 155:f797093c60bd
Made a (single one) artifact collection factory configurable.
artifacts/trunk@1380 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 03 Mar 2011 09:51:09 +0000 |
parents | 1a72f08ce8d7 |
children | a76de72ad6d1 |
files | ChangeLog artifact-database/doc/example-conf/conf.xml artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java |
diffstat | 4 files changed, 95 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Mar 03 09:36:03 2011 +0000 +++ b/ChangeLog Thu Mar 03 09:51:09 2011 +0000 @@ -1,3 +1,15 @@ +2011-03-03 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/doc/example-conf/conf.xml: Added a node that + configures a default artifact collection factory. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java: + The artifact collection factory (currently just a single one) is read + from configuration and setup with its parameters. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java: + Fetch the configured artifact collection factory from bootstrap. + 2011-03-03 Sascha L. Teichmann <sascha.teichmann@intevation.de> * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java,
--- a/artifact-database/doc/example-conf/conf.xml Thu Mar 03 09:36:03 2011 +0000 +++ b/artifact-database/doc/example-conf/conf.xml Thu Mar 03 09:51:09 2011 +0000 @@ -4,6 +4,9 @@ <export-secret>dMFhRZP4CYePgb1BSuVAhTnnh4kGGeENfe2YFyaq</export-secret> <factories> <context-factory>de.intevation.artifactdatabase.DefaultArtifactContextFactory</context-factory> + <collection-factory + name="dummy-1" description="dummy description 1" ttl="60000" + collection="de.intevation.artifactdatabase.DefaultCollection">de.intevation.artifactdatabase.DefaultArtifactCollectionFactory</collection-factory> <artifact-factories> <artifact-factory name="dummy-1" description="dummy description 1" ttl="60000"
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Thu Mar 03 09:36:03 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Thu Mar 03 09:51:09 2011 +0000 @@ -11,6 +11,7 @@ import de.intevation.artifactdatabase.Backend.PersistentArtifact; import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactCollectionFactory; import de.intevation.artifacts.ArtifactDatabase; import de.intevation.artifacts.ArtifactDatabaseException; import de.intevation.artifacts.ArtifactFactory; @@ -386,6 +387,11 @@ protected HashMap name2service; /** + * The factory that is used to create new artifact collections. + */ + protected ArtifactCollectionFactory collectionFactory; + + /** * The factory that is used to create and list users. */ protected UserFactory userFactory; @@ -438,6 +444,7 @@ backgroundIds = new HashSet(); + setupArtifactCollectionFactory(bootstrap); setupArtifactFactories(bootstrap); setupServices(bootstrap); setupUserFactory(bootstrap); @@ -449,6 +456,15 @@ } /** + * Used to extract the artifact collection factory from bootstrap. + * + * @param bootstrap The bootstrap parameters. + */ + protected void setupArtifactCollectionFactory(FactoryBootstrap bootstrap) { + collectionFactory = bootstrap.getArtifactCollectionFactory(); + } + + /** * Used to extract the artifact factories from the bootstrap * parameters and building the internal lookup tables. * @param bootstrap The bootstrap parameters.
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java Thu Mar 03 09:36:03 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java Thu Mar 03 09:51:09 2011 +0000 @@ -8,6 +8,7 @@ package de.intevation.artifactdatabase; +import de.intevation.artifacts.ArtifactCollectionFactory; import de.intevation.artifacts.ArtifactContextFactory; import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.ServiceFactory; @@ -63,7 +64,7 @@ * configuration. */ public static final String USER_FACTORY = - "/artfifact-database/factories/user-factory"; + "/artifact-database/factories/user-factory"; /** * The name of the default user factory. @@ -72,6 +73,19 @@ "de.intevation.artifactdatabase.DefaultUserFactory"; /** + * XPath to figure out the class name of the collection factory from global + * configuration. + */ + public static final String COLLECTION_FACTORY = + "/artifact-database/factories/collection-factory"; + + /** + * The name of the default user factory. + */ + public static final String DEFAULT_COLLECTION_FACTORY = + "de.intevation.artifactdatabase.DefaultArtifactCollectionFactory"; + + /** * XPath to figure out the secret used to sign the artifact exports * made by the artfifact database server. */ @@ -109,6 +123,11 @@ protected UserFactory userFactory; /** + * The factory that is used to create new artifact collections. + */ + protected ArtifactCollectionFactory collectionFactory; + + /** * byte array holding the export signing secret. */ protected byte [] exportSecret; @@ -153,6 +172,40 @@ context = factory.createArtifactContext(Config.getConfig()); } + + /** + * Scans the global configuration to load the configured collection factory + * and sets it up. + */ + protected void loadCollectionFactory() { + + logger.info("loading collection factory."); + + Node factory = Config.getNodeXPath(COLLECTION_FACTORY); + + String className = Config.getStringXPath( + factory, "text()", DEFAULT_COLLECTION_FACTORY); + + try { + Class clazz = Class.forName(className); + collectionFactory = (ArtifactCollectionFactory) clazz.newInstance(); + + collectionFactory.setup(Config.getConfig(), factory); + } + catch (ClassNotFoundException cnfe) { + logger.error(cnfe.getLocalizedMessage(), cnfe); + } + catch (InstantiationException ie) { + logger.error(ie.getLocalizedMessage(), ie); + } + catch (ClassCastException cce) { + logger.error(cce.getLocalizedMessage(), cce); + } + catch (IllegalAccessException iae) { + logger.error(iae.getLocalizedMessage(), iae); + } + } + /** * Scans the global configuration to load the configured * artifact factories and sets them up. @@ -311,12 +364,22 @@ public void boot() { setupExportSecret(); buildContext(); + loadCollectionFactory(); loadArtifactFactories(); loadServiceFactories(); loadUserFactory(); } /** + * Returns the artifact collection factory. + * + * @return the artifact collection factory. + */ + public ArtifactCollectionFactory getArtifactCollectionFactory() { + return collectionFactory; + } + + /** * Returns the list of ready to use artifact factories. * @return The list of artifact factories. */