Mercurial > dive4elements > framework
view artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultArtifactFactory.java @ 11:af07d004d320
Fixed typo in xpath expression.
artifacts/trunk@26 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 06 Sep 2009 13:22:34 +0000 |
parents | e8626caac353 |
children | 5a6b6a3debc7 |
line wrap: on
line source
package de.intevation.artifactdatabase; import org.w3c.dom.Document; import org.w3c.dom.Node; import de.intevation.artifacts.ArtifactFactory; import de.intevation.artifacts.Artifact; public class DefaultArtifactFactory implements ArtifactFactory { 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) { try { Artifact artifact = (Artifact)artifactClass.newInstance(); artifact.setup(identifier, context); return artifact; } catch (InstantiationException ie) { ie.printStackTrace(System.err); } catch (IllegalAccessException iae) { iae.printStackTrace(System.err); } catch (ClassCastException cce) { cce.printStackTrace(System.err); } 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) { nfe.printStackTrace(System.err); } } 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) { cnfe.printStackTrace(System.err); } if (artifactClass == null) { artifactClass = DefaultArtifact.class; } } public Long timeToLiveUntouched(Artifact artifact, Object context) { return ttl; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: