Mercurial > dive4elements > framework
view artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultServiceFactory.java @ 87:0f48188a6e02
Added some javadoc to the artifactdatabase module. Not done yet.
artifacts/trunk@839 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 26 Mar 2010 11:40:28 +0000 |
parents | 48d1a9a082c2 |
children | d348fe1fd822 |
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 <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> */ 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 :