# HG changeset patch # User Sascha L. Teichmann # Date 1264159677 0 # Node ID c99da6837be071636a42480675ab532e0e817b8d # Parent ce488c1d3fc450ac25377a4aaddb02993fbd0454 Load service factories and services during bootstrap. artifacts/trunk@598 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r ce488c1d3fc4 -r c99da6837be0 ChangeLog --- a/ChangeLog Fri Jan 22 11:08:40 2010 +0000 +++ b/ChangeLog Fri Jan 22 11:27:57 2010 +0000 @@ -1,3 +1,10 @@ +2010-01-22 Sascha L. Teichmann + + * artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java: + Load service factories while bootstrapping the server. + + * artifact-database/doc/example-conf/conf.xml: Added examples for trivial services. + 2010-01-22 Sascha L. Teichmann * artifacts/src/main/java/de/intevation/artifacts/ArtifactDatabase.java: diff -r ce488c1d3fc4 -r c99da6837be0 artifact-database/doc/example-conf/conf.xml --- a/artifact-database/doc/example-conf/conf.xml Fri Jan 22 11:08:40 2010 +0000 +++ b/artifact-database/doc/example-conf/conf.xml Fri Jan 22 11:27:57 2010 +0000 @@ -13,6 +13,16 @@ name="dummy-3" description="dummy description 3" artifact="de.intevation.artifactdatabase.DefaultArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory + + de.intevation.artifactdatabase.DefaultServiceFactory + de.intevation.artifactdatabase.DefaultServiceFactory + diff -r ce488c1d3fc4 -r c99da6837be0 artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java Fri Jan 22 11:08:40 2010 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java Fri Jan 22 11:27:57 2010 +0000 @@ -28,10 +28,15 @@ public static final String ARTIFACT_FACTORIES = "/artifact-database/factories/artifact-factories/artifact-factory"; + public static final String SERVICE_FACTORIES = + "/artifact-database/factories/service-factories/service-factory"; + protected Object context; protected ArtifactFactory [] artifactFactories; + protected ServiceFactory [] serviceFactories; + public FactoryBootstrap() { } @@ -69,6 +74,9 @@ } protected void loadArtifactFactories() { + + logger.info("loading artifact factories"); + ArrayList loadedFactories = new ArrayList(); NodeList nodes = Config.getNodeSetXPath(ARTIFACT_FACTORIES); @@ -80,7 +88,7 @@ Document config = Config.getConfig(); for (int i = 0, N = nodes != null ? nodes.getLength() : 0; i < N; ++i) { - String className = nodes.item(i).getTextContent(); + String className = nodes.item(i).getTextContent().trim(); ArtifactFactory factory = null; @@ -112,9 +120,57 @@ new ArtifactFactory[loadedFactories.size()]); } + protected void loadServiceFactories() { + + logger.info("loading service factories"); + + ArrayList loadedFactories = new ArrayList(); + + NodeList nodes = Config.getNodeSetXPath(SERVICE_FACTORIES); + + if (nodes == null) { + logger.warn("No factories found"); + } + + Document config = Config.getConfig(); + + for (int i = 0, N = nodes != null ? nodes.getLength() : 0; i < N; ++i) { + String className = nodes.item(i).getTextContent().trim(); + + ServiceFactory factory = null; + + try { + Class clazz = Class.forName(className); + factory = (ServiceFactory)clazz.newInstance(); + } + 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); + } + + if (factory != null) { + factory.setup(config, nodes.item(i)); + loadedFactories.add(factory); + logger.info("Registering '" + factory.getName() + "' as service factory."); + } + } + + serviceFactories = (ServiceFactory [])loadedFactories.toArray( + new ServiceFactory[loadedFactories.size()]); + } + public void boot() { buildContext(); loadArtifactFactories(); + loadServiceFactories(); } public ArtifactFactory [] getArtifactFactories() { @@ -122,8 +178,7 @@ } public ServiceFactory [] getServiceFactories() { - logger.warn("Service factories are not supported yet"); - return new ServiceFactory[0]; + return serviceFactories; } public Object getContext() {