changeset 2058:f97cf2e350c9

Some refactoring done: all Sections subclass TypeSection now to be able to use the convinience methods for string, integer, double and boolean attributes. flys-artifacts/trunk@3550 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 27 Dec 2011 11:37:23 +0000
parents 49b7c2b1a6a7
children 522826b41ffa
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/LegendSection.java
diffstat 4 files changed, 33 insertions(+), 132 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Dec 27 11:19:44 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Dec 27 11:37:23 2011 +0000
@@ -1,3 +1,11 @@
+2011-12-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/AxisSection.java,
+	  src/main/java/de/intevation/flys/exports/LegendSection.java,
+	  src/main/java/de/intevation/flys/exports/ChartSection.java: Subclasses
+	  TypeSection to be able to use convinience methods for string, integer,
+	  double and boolean values.
+
 2011-12-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartGenerator.java: The
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java	Tue Dec 27 11:19:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java	Tue Dec 27 11:37:23 2011 +0000
@@ -12,7 +12,7 @@
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class AxisSection extends DefaultSection {
+public class AxisSection extends TypeSection {
 
     public static final String IDENTIFIER_ATTR = "id";
     public static final String LABEL_ATTR      = "label";
@@ -28,47 +28,22 @@
 
 
     public void setIdentifier(String identifier) {
-        if (identifier == null || identifier.length() == 0) {
-            return;
-        }
-
-        Attribute attr = getAttribute(IDENTIFIER_ATTR);
-        if (attr == null) {
-            attr = new StringAttribute(IDENTIFIER_ATTR, identifier, false);
-            addAttribute(IDENTIFIER_ATTR, attr);
-        }
-        else {
-            attr.setValue(identifier);
-        }
+        setStringValue(IDENTIFIER_ATTR, identifier);
     }
 
 
     public String getIdentifier() {
-        StringAttribute attr = (StringAttribute) getAttribute(IDENTIFIER_ATTR);
-
-        return attr != null ? (String) attr.getValue() : null;
+        return getStringValue(IDENTIFIER_ATTR);
     }
 
 
     public void setLabel(String label) {
-        if (label == null) {
-            return;
-        }
-
-        Attribute attr = getAttribute(LABEL_ATTR);
-        if (attr == null) {
-            attr = new StringAttribute(LABEL_ATTR, label, true);
-            addAttribute(LABEL_ATTR, attr);
-        }
-        else {
-            attr.setValue(label);
-        }
+        setStringValue(LABEL_ATTR, label);
     }
 
 
     public String getLabel() {
-        StringAttribute attr = (StringAttribute) getAttribute(LABEL_ATTR);
-        return attr != null ? (String) attr.getValue() : null;
+        return getStringValue(LABEL_ATTR);
     }
 
 
@@ -77,76 +52,42 @@
             return;
         }
 
-        Attribute attr = getAttribute(FONTSIZE_ATTR);
-        if (attr == null) {
-            attr = new IntegerAttribute(FONTSIZE_ATTR, fontSize, true);
-            addAttribute(FONTSIZE_ATTR, attr);
-        }
-        else {
-            attr.setValue(fontSize);
-        }
+        setIntegerValue(FONTSIZE_ATTR, fontSize);
     }
 
 
     public Integer getFontSize() {
-        IntegerAttribute attr = (IntegerAttribute) getAttribute(FONTSIZE_ATTR);
-        return attr != null ? (Integer) attr.getValue() : null;
+        return getIntegerValue(FONTSIZE_ATTR);
     }
 
 
     public void setFixed(boolean fixed) {
-        Attribute attr = getAttribute(FIXATION_ATTR);
-        if (attr == null) {
-            attr = new BooleanAttribute(FIXATION_ATTR, fixed, true);
-            addAttribute(FIXATION_ATTR, attr);
-        }
-        else {
-            attr.setValue(fixed);
-        }
+        setBooleanValue(FIXATION_ATTR, fixed);
     }
 
 
     public Boolean isFixed() {
-        BooleanAttribute attr = (BooleanAttribute) getAttribute(FIXATION_ATTR);
-        return attr != null ? (Boolean) attr.getValue() : null;
+        return getBooleanValue(FIXATION_ATTR);
     }
 
 
     public void setUpperRange(double upperRange) {
-        Attribute attr = getAttribute(UPPERRANGE_ATTR);
-        if (attr == null) {
-            attr = new DoubleAttribute(UPPERRANGE_ATTR, upperRange, true);
-            addAttribute(UPPERRANGE_ATTR, attr);
-        }
-        else {
-            attr.setValue(upperRange);
-        }
+        setDoubleValue(UPPERRANGE_ATTR, upperRange);
     }
 
 
     public Double getUpperRange() {
-        DoubleAttribute attr = (DoubleAttribute) getAttribute(UPPERRANGE_ATTR);
-
-        return attr != null ? (Double) attr.getValue() : null;
+        return getDoubleValue(UPPERRANGE_ATTR);
     }
 
 
     public void setLowerRange(double lowerRange) {
-        Attribute attr = getAttribute(LOWERRANGE_ATTR);
-        if (attr == null) {
-            attr = new DoubleAttribute(LOWERRANGE_ATTR, lowerRange, true);
-            addAttribute(LOWERRANGE_ATTR, attr);
-        }
-        else {
-            attr.setValue(lowerRange);
-        }
+        setDoubleValue(LOWERRANGE_ATTR, lowerRange);
     }
 
 
     public Double getLowerRange() {
-        DoubleAttribute attr = (DoubleAttribute) getAttribute(LOWERRANGE_ATTR);
-
-        return attr != null ? (Double) attr.getValue() : null;
+        return getDoubleValue(LOWERRANGE_ATTR);
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSection.java	Tue Dec 27 11:19:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartSection.java	Tue Dec 27 11:37:23 2011 +0000
@@ -7,7 +7,7 @@
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class ChartSection extends DefaultSection {
+public class ChartSection extends TypeSection {
 
     public static final String TITLE_ATTR       = "title";
     public static final String SUBTITLE_ATTR    = "subtitle";
@@ -20,64 +20,32 @@
 
 
     public void setTitle(String title) {
-        if (title == null || title.length() == 0) {
-            return;
-        }
-
-        Attribute attr = getAttribute(TITLE_ATTR);
-        if (attr == null) {
-            attr = new StringAttribute(TITLE_ATTR, title, true);
-            addAttribute(TITLE_ATTR, attr);
-        }
-        else {
-            attr.setValue(title);
-        }
+        setStringValue(TITLE_ATTR, title);
     }
 
 
     public String getTitle() {
-        StringAttribute attr = (StringAttribute) getAttribute(TITLE_ATTR);
-        return attr != null ? (String) attr.getValue() : null;
+        return getStringValue(TITLE_ATTR);
     }
 
 
     public void setSubtitle(String subtitle) {
-        if (subtitle == null || subtitle.length() == 0) {
-            return;
-        }
-
-        Attribute attr = getAttribute(SUBTITLE_ATTR);
-        if (attr == null) {
-            attr = new StringAttribute(SUBTITLE_ATTR, subtitle, true);
-            addAttribute(SUBTITLE_ATTR, attr);
-        }
-        else {
-            attr.setValue(subtitle);
-        }
+        setStringValue(SUBTITLE_ATTR, subtitle);
     }
 
 
     public String getSubtitle() {
-        StringAttribute attr = (StringAttribute) getAttribute(SUBTITLE_ATTR);
-        return attr != null ? (String) attr.getValue() : null;
+        return getStringValue(SUBTITLE_ATTR);
     }
 
 
     public void setDisplayGird(boolean displayGrid) {
-        Attribute attr = getAttribute(DISPLAYGRID_ATTR);
-        if (attr == null) {
-            attr = new BooleanAttribute(DISPLAYGRID_ATTR, displayGrid, true);
-            addAttribute(DISPLAYGRID_ATTR, attr);
-        }
-        else {
-            attr.setValue(displayGrid);
-        }
+        setBooleanValue(DISPLAYGRID_ATTR, displayGrid);
     }
 
 
     public Boolean getDisplayGrid() {
-        BooleanAttribute ba = (BooleanAttribute) getAttribute(DISPLAYGRID_ATTR);
-        return ba != null ? (Boolean) ba.getValue() : null;
+        return getBooleanValue(DISPLAYGRID_ATTR);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LegendSection.java	Tue Dec 27 11:19:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LegendSection.java	Tue Dec 27 11:37:23 2011 +0000
@@ -7,7 +7,7 @@
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class LegendSection extends DefaultSection {
+public class LegendSection extends TypeSection {
 
     public static final String VISIBILITY_ATTR = "visibility";
     public static final String FONTSIZE_ATTR   = "font-size";
@@ -23,38 +23,22 @@
             return;
         }
 
-        Attribute attr = getAttribute(FONTSIZE_ATTR);
-        if (attr == null) {
-            attr = new IntegerAttribute(FONTSIZE_ATTR, fontSize, true);
-            addAttribute(FONTSIZE_ATTR, attr);
-        }
-        else {
-            attr.setValue(fontSize);
-        }
+        setIntegerValue(FONTSIZE_ATTR, fontSize);
     }
 
 
     public Integer getFontSize() {
-        IntegerAttribute ia = (IntegerAttribute) getAttribute(FONTSIZE_ATTR);
-        return ia != null ? (Integer) ia.getValue() : null;
+        return getIntegerValue(FONTSIZE_ATTR);
     }
 
 
     public void setVisibility(boolean visibility) {
-        Attribute attr = getAttribute(VISIBILITY_ATTR);
-        if (attr == null) {
-            attr = new BooleanAttribute(VISIBILITY_ATTR, visibility, true);
-            addAttribute(VISIBILITY_ATTR, attr);
-        }
-        else {
-            attr.setValue(visibility);
-        }
+        setBooleanValue(VISIBILITY_ATTR, visibility);
     }
 
 
     public Boolean getVisibility() {
-        BooleanAttribute ba = (BooleanAttribute) getAttribute(VISIBILITY_ATTR);
-        return ba != null ? (Boolean ) ba.getValue() : null;
+        return getBooleanValue(VISIBILITY_ATTR);
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org