[PATCH 2 of 2] Simplified code to be more readable

Wald Commits scm-commit at wald.intevation.org
Wed Apr 30 17:03:16 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1398870190 -7200
# Node ID 863f1fa669814fd73053e733ada79f62a3a924b5
# Parent  7bdc45945e5d052006caa7dcbd73709ec4d8038e
Simplified code to be more readable.

diff -r 7bdc45945e5d -r 863f1fa66981 artifact-database/src/main/java/org/dive4elements/artifactdatabase/DefaultArtifactFactory.java
--- 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);
         }


More information about the Dive4Elements-commits mailing list