changeset 1575:0f2b94408bd1

Added further methods to DataFactory to create concrete Data instances. flys-client/trunk@3841 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 31 Jan 2012 15:20:17 +0000
parents 465f72f68cee
children 8e5c5c70c586
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleArrayData.java flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerData.java flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerOptionsData.java flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java flys-client/src/main/java/de/intevation/flys/client/shared/model/StringData.java
diffstat 8 files changed, 235 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Jan 31 14:25:51 2012 +0000
+++ b/flys-client/ChangeLog	Tue Jan 31 15:20:17 2012 +0000
@@ -1,3 +1,19 @@
+2012-01-31  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/DoubleArrayData.java,
+	  src/main/java/de/intevation/flys/client/shared/model/StringData.java,
+	  src/main/java/de/intevation/flys/client/shared/model/IntegerData.java:
+	  New. Subclasses of DefaultData. They are currently used to distinguish
+	  them during UI creation.
+
+	* src/main/java/de/intevation/flys/client/shared/model/IntegerOptionsData.java,
+	  src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java,
+	  src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java:
+	  Added a static TYPE field.
+
+	* src/main/java/de/intevation/flys/client/server/DataFactory.java: Added
+	further methods to create concrete Data instances for specific data types.
+
 2012-01-31  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java	Tue Jan 31 14:25:51 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java	Tue Jan 31 15:20:17 2012 +0000
@@ -14,6 +14,12 @@
 import de.intevation.flys.client.shared.model.DataItem;
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
+import de.intevation.flys.client.shared.model.DoubleArrayData;
+import de.intevation.flys.client.shared.model.IntegerArrayData;
+import de.intevation.flys.client.shared.model.IntegerData;
+import de.intevation.flys.client.shared.model.IntegerOptionsData;
+import de.intevation.flys.client.shared.model.IntegerRangeData;
+import de.intevation.flys.client.shared.model.StringData;
 
 
 /**
@@ -39,14 +45,42 @@
         String name = element.getAttributeNS(NS_URI, "name");
         String type = element.getAttributeNS(NS_URI, "type");
 
-        logger.debug("Create new Data instance for: " + name + " | " + type);
+        try {
+            logger.debug("Create Data instance for: " + name + " | " + type);
 
-        if (type == null || type.length() == 0) {
-            return createDefaultData(element, name);
+            if (type == null || type.length() == 0) {
+                return createDefaultData(element, name);
+            }
+
+            type = type.toLowerCase();
+
+            if (type.equals(StringData.TYPE)) {
+                return createStringData(element, name);
+            }
+            else if (type.equals(IntegerData.TYPE)) {
+                return createIntegerData(element, name);
+            }
+            else if (type.equals(IntegerOptionsData.TYPE)) {
+                return createIntegerOptionsData(element, name);
+            }
+            else if (type.equals(IntegerRangeData.TYPE)) {
+                return createIntegerRangeData(element, name);
+            }
+            else if (type.equals(IntegerArrayData.TYPE)) {
+                return createIntegerArrayData(element, name);
+            }
+            else if (type.equals(DoubleArrayData.TYPE)) {
+                return createDoubleArrayData(element, name);
+            }
+            else {
+                return createDefaultData(element, name);
+            }
         }
-        else {
-            return createDefaultData(element, name);
+        catch (Exception e) {
+            logger.error("Error while data creation for: " + name);
         }
+
+        return null;
     }
 
 
@@ -66,6 +100,114 @@
 
 
     /**
+     * This method creates a new instance of StringData which has a type
+     * "string" set.
+     *
+     * @param ele The Data element.
+     * @param name The name of the Data instance.
+     *
+     * @return an instance of StringData.
+     */
+    protected static Data createStringData(Element ele, String name) {
+        return new StringData(name, name, extractDataItems(ele));
+    }
+
+
+    /**
+     * This method creates a new instance of DefaultData which has a type
+     * "integer" set.
+     *
+     * @param ele The Data element.
+     * @param name The name of the Data instance.
+     *
+     * @return an instance of IntegerData.
+     */
+    protected static Data createIntegerData(Element ele, String name) {
+        return new IntegerData(name, name, extractDataItems(ele));
+    }
+
+
+    /**
+     * This method creates a new instance of DefaultData which has a type
+     * "intoptions" set.
+     *
+     * @param ele The Data element.
+     * @param name The name of the Data instance.
+     *
+     * @return an instance of IntegerOptionsData.
+     */
+    protected static Data createIntegerOptionsData(Element ele, String name) {
+        return new IntegerOptionsData(name, name, extractDataItems(ele));
+    }
+
+
+    /**
+     * This method creates a new instance of DefaultData which has a type
+     * "intrange" set.
+     *
+     * @param ele The Data element.
+     * @param name The name of the Data instance.
+     *
+     * @return an instance of IntegerRangeData.
+     */
+    protected static Data createIntegerRangeData(Element ele, String name) {
+        DataItem[] items    = extractDataItems(ele);
+        String     rawValue = items[0].getStringValue();
+
+        String[] minmax = rawValue.split(";");
+
+        return new IntegerRangeData(
+            name,
+            name,
+            Integer.valueOf(minmax[0]),
+            Integer.valueOf(minmax[1]));
+    }
+
+
+    /**
+     * This method creates a new instance of DefaultData which has a type
+     * "integerarray" set.
+     *
+     * @param ele The Data element.
+     * @param name The name of the Data instance.
+     *
+     * @return an instance of IntegerArrayData.
+     */
+    protected static Data createIntegerArrayData(Element ele, String name) {
+        DataItem[] items    = extractDataItems(ele);
+        String     rawValue = items[0].getStringValue();
+
+        String[] values   = rawValue.split(";");
+        int[]    integers = new int[values.length];
+
+        for (int i = 0; i < values.length; i++) {
+            try {
+                integers[i] = Integer.valueOf(values[i]);
+            }
+            catch (NumberFormatException nfe) {
+                logger.warn("Error while parsing IntegerArrayData: " + nfe);
+            }
+        }
+
+        return new IntegerArrayData(name, name, integers);
+    }
+
+
+    /**
+     * This method creates a new instance of DefaultData which has a type
+     * "doublearray" set.
+     *
+     * @param ele The Data element.
+     * @param name The name of the Data instance.
+     *
+     * @return an instance of DoubleArrayData.
+     */
+    protected static Data createDoubleArrayData(Element ele, String name) {
+        return new DoubleArrayData(name, name, extractDataItems(ele));
+    }
+
+
+    /**
      * This method extracts the art:item elements placed under <i>elements</i>.
      *
      * @param element A data node that contains items.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/DoubleArrayData.java	Tue Jan 31 15:20:17 2012 +0000
@@ -0,0 +1,21 @@
+package de.intevation.flys.client.shared.model;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class DoubleArrayData extends DefaultData {
+
+    public static final String TYPE = "doublearray";
+
+
+    public DoubleArrayData() {
+        super();
+    }
+
+
+    public DoubleArrayData(String name, String description, DataItem[] items) {
+        super(name, description, TYPE, items);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java	Tue Jan 31 14:25:51 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerArrayData.java	Tue Jan 31 15:20:17 2012 +0000
@@ -3,6 +3,9 @@
 
 public class IntegerArrayData implements Data {
 
+    public static final String TYPE = "intarray";
+
+
     protected String label;
     protected String description;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerData.java	Tue Jan 31 15:20:17 2012 +0000
@@ -0,0 +1,21 @@
+package de.intevation.flys.client.shared.model;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class IntegerData extends DefaultData {
+
+    public static final String TYPE = "integer";
+
+
+    public IntegerData() {
+        super();
+    }
+
+
+    public IntegerData(String name, String description, DataItem[] items) {
+        super(name, description, TYPE, items);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerOptionsData.java	Tue Jan 31 14:25:51 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerOptionsData.java	Tue Jan 31 15:20:17 2012 +0000
@@ -3,6 +3,8 @@
 
 public class IntegerOptionsData implements Data {
 
+    public static final String TYPE = "intoptions";
+
     protected String label;
     protected String description;
 
@@ -46,7 +48,7 @@
      * @return the type.
      */
     public String getType() {
-        return "intoptions";
+        return TYPE;
     }
 
 
--- a/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java	Tue Jan 31 14:25:51 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java	Tue Jan 31 15:20:17 2012 +0000
@@ -6,6 +6,9 @@
  */
 public class IntegerRangeData implements RangeData {
 
+    public static final String TYPE = "intrange";
+
+
     protected String label;
     protected String description;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/StringData.java	Tue Jan 31 15:20:17 2012 +0000
@@ -0,0 +1,21 @@
+package de.intevation.flys.client.shared.model;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class StringData extends DefaultData {
+
+    public static final String TYPE = "string";
+
+
+    public StringData() {
+        super();
+    }
+
+
+    public StringData(String name, String description, DataItem[] items) {
+        super(name, description, TYPE, items);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org