Mercurial > dive4elements > framework
view artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java @ 75:d4c4c23847f5
Extended the Artifact-Interface-Method setup to be able to put the XML-Document which can contain further Data
to the Artifact-Implementation.
artifacts/trunk@649 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 01 Feb 2010 13:54:05 +0000 |
parents | 5e4bc24ea438 |
children | 48d1a9a082c2 |
line wrap: on
line source
package de.intevation.artifactdatabase; import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Node; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.ArtifactSerializer; /** * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class DefaultArtifactFactory implements ArtifactFactory { private static Logger logger = Logger.getLogger(DefaultArtifactFactory.class); public static final String XPATH_TTL = "@ttl"; public static final String XPATH_NAME = "@name"; public static final String XPATH_DESCRIPTION = "@description"; public static final String XPATH_ARTIFACT = "@artifact"; public static final String DEFAULT_DESCRIPTION = "No description available"; public static final String DEFAULT_ARTIFACT = "de.intevation.artifactdatabase.DefaultArtifact"; protected Long ttl; protected String name; protected String description; protected Class artifactClass; public DefaultArtifactFactory() { } public String getName() { return name; } public String getDescription() { return description; } public Artifact createArtifact(String identifier, Object context, Document data) { try { Artifact artifact = (Artifact)artifactClass.newInstance(); artifact.setup(identifier, this, context, data); return artifact; } 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 document, Node factoryNode) { String ttlString = Config.getStringXPath(factoryNode, XPATH_TTL); if (ttlString != null) { try { ttl = Long.valueOf(ttlString); } catch (NumberFormatException nfe) { logger.warn("'" + ttlString + "' is not an integer."); } } description = Config.getStringXPath( factoryNode, XPATH_DESCRIPTION, DEFAULT_DESCRIPTION); name = Config.getStringXPath( factoryNode, XPATH_NAME, toString()); String artifact = Config.getStringXPath( factoryNode, XPATH_ARTIFACT, DEFAULT_ARTIFACT); try { artifactClass = Class.forName(artifact); } catch (ClassNotFoundException cnfe) { logger.error(cnfe.getLocalizedMessage(), cnfe); } if (artifactClass == null) { artifactClass = DefaultArtifact.class; } } public Long timeToLiveUntouched(Artifact artifact, Object context) { return ttl; } public ArtifactSerializer getSerializer() { return DefaultArtifactSerializer.INSTANCE; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: