diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactFactoryUtilities.java @ 657:af3f56758f59

merged gnv-artifacts/0.5
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:53 +0200
parents 7fb9441dd8af
children 9a828e5a2390
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactFactoryUtilities.java	Fri Sep 28 12:13:53 2012 +0200
@@ -0,0 +1,55 @@
+/**
+ *
+ */
+package de.intevation.gnv.utils;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import de.intevation.artifacts.ArtifactFactory;
+
+/**
+ * @author Tim Englich <tim.englich@intevation.de>
+ * 
+ */
+public class ArtifactFactoryUtilities {
+    /**
+     * the logger, used to log exceptions and additonaly information
+     */
+    private static Logger log = Logger
+            .getLogger(ArtifactFactoryUtilities.class);
+
+    /**
+     * Constructor
+     */
+    public ArtifactFactoryUtilities() {
+    }
+
+    public ArtifactFactory createArtitfactFactor(Document config,
+                                                 Node artifactFactoryNode) {
+        String className = artifactFactoryNode.getTextContent();
+
+        ArtifactFactory factory = null;
+
+        try {
+            Class clazz = Class.forName(className);
+            factory = (ArtifactFactory) clazz.newInstance();
+        } catch (ClassNotFoundException cnfe) {
+            log.error(cnfe.getLocalizedMessage(), cnfe);
+        } catch (InstantiationException ie) {
+            log.error(ie.getLocalizedMessage(), ie);
+        } catch (ClassCastException cce) {
+            log.error(cce.getLocalizedMessage(), cce);
+        } catch (IllegalAccessException iae) {
+            log.error(iae.getLocalizedMessage(), iae);
+        }
+
+        if (factory != null) {
+            factory.setup(config, artifactFactoryNode);
+            log.info("Registering '" + factory.getName()
+                     + "' as artifact factory.");
+        }
+        return factory;
+    }
+}

http://dive4elements.wald.intevation.org