Mercurial > dive4elements > framework
changeset 517:863f1fa66981
Simplified code to be more readable.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Wed, 30 Apr 2014 17:03:10 +0200 |
parents | 7bdc45945e5d |
children | d364086a01bc |
files | artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java |
diffstat | 1 files changed, 22 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java Wed Apr 30 16:46:32 2014 +0200 +++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java Wed Apr 30 17:03:10 2014 +0200 @@ -27,6 +27,7 @@ import org.apache.log4j.Logger; import org.w3c.dom.Document; +import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -141,9 +142,9 @@ try { Artifact artifact = (Artifact)artifactClass.newInstance(); + String oldName = artifact.getName(); - if (artifact.getName() == null || - artifact.getName().length() == 0) { + if (oldName == null || oldName.length() == 0) { artifact.setName(artifactName); } artifact.setup( @@ -170,6 +171,8 @@ } public void setup(Document document, Node factoryNode) { + boolean debug = logger.isDebugEnabled(); + String ttlString = Config.getStringXPath(factoryNode, XPATH_TTL); if (ttlString != null) { try { @@ -185,14 +188,20 @@ name = Config.getStringXPath( factoryNode, XPATH_NAME, toString()); - logger.debug("setting up " + name); + + if (debug) { + logger.debug("setting up " + name); + } String artifact = Config.getStringXPath( factoryNode, XPATH_ARTIFACT, DEFAULT_ARTIFACT); artifactName = Config.getStringXPath( document, XPATH_ARTIFACT_NAME, "default"); - logger.debug(artifactName); + + if (debug) { + logger.debug("artifact name: " + artifactName); + } Map<String, String> variables = new HashMap<String, String>(); variables.put("name", name); NodeList facets = (NodeList) XMLUtils.xpath( @@ -202,10 +211,14 @@ null, variables); - for (int i = 0; i < facets.getLength(); i++) { - logger.debug(facets.item(i).getAttributes().getNamedItem("class").getNodeValue()); - String className = - facets.item(i).getAttributes().getNamedItem("class").getNodeValue(); + for (int i = 0, F = facets.getLength(); i < F; i++) { + Element element = (Element)facets.item(i); + String className = element.getAttribute("class"); + + if (debug) { + logger.debug("load facet class: " + className); + } + try { facetClasses.add(Class.forName(className)); } @@ -213,6 +226,7 @@ logger.error(cnfe.getLocalizedMessage(), cnfe); } } + try { artifactClass = Class.forName(artifact); }