Mercurial > dive4elements > framework
view artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultServiceFactory.java @ 70:ce488c1d3fc4
Serve services over artifact database.
artifacts/trunk@597 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 22 Jan 2010 11:08:40 +0000 |
parents | 498bb84334d0 |
children | 48d1a9a082c2 |
line wrap: on
line source
package de.intevation.artifactdatabase; import org.w3c.dom.Document; import org.w3c.dom.Node; import de.intevation.artifacts.ServiceFactory; import de.intevation.artifacts.Service; import org.apache.log4j.Logger; /** * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class DefaultServiceFactory implements ServiceFactory { private static Logger logger = Logger.getLogger(DefaultServiceFactory.class); public static final String XPATH_NAME = "@name"; public static final String XPATH_DESCRIPTION = "@description"; public static final String XPATH_SERVICE = "@service"; public static final String DEFAULT_DESCRIPTION = "No description available"; public static final String DEFAULT_SERVICE = "de.intevation.artifactdatabase.DefaultService"; protected String name; protected String description; protected Class serviceClass; public DefaultServiceFactory() { } public String getName() { return name; } public String getDescription() { return description; } public Service createService(Object globalContext) { try { Service service = (Service)serviceClass.newInstance(); service.setup(this, globalContext); return service; } catch (InstantiationException ie) { logger.error(ie.getLocalizedMessage(), ie); } catch (IllegalAccessException iae) { logger.error(iae.getLocalizedMessage(), iae); } catch (ClassCastException cce) { logger.error(cce.getLocalizedMessage(), cce); } return null; } public void setup(Document config, Node factoryNode) { description = Config.getStringXPath( factoryNode, XPATH_DESCRIPTION, DEFAULT_DESCRIPTION); name = Config.getStringXPath( factoryNode, XPATH_NAME, toString()); String service = Config.getStringXPath( factoryNode, XPATH_SERVICE, DEFAULT_SERVICE); try { serviceClass = Class.forName(service); } catch (ClassNotFoundException cnfe) { logger.error(cnfe.getLocalizedMessage(), cnfe); } if (serviceClass == null) { serviceClass = DefaultService.class; } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :