changeset 1099:af73f196eccc

Refactored to use new FLYSUtils, moved getRiver-functionality inside. flys-artifacts/trunk@2602 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 29 Aug 2011 09:01:40 +0000 (2011-08-29)
parents 1ea7eb72aaa6
children 29c67a76ad5d
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java
diffstat 3 files changed, 36 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Aug 29 08:58:03 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Aug 29 09:01:40 2011 +0000
@@ -1,3 +1,16 @@
+2011-08-29  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Refactored to use new Helper class FLYSUtils, moved getRiver-functionality
+	in there.
+
+	* src/main/java/de/intevation/flys/utils/FLYSUtils.java (getRiver):
+	  New function to retrieve river of an artifact, slightly modified from
+	  WINFOArtifact.
+
+	* src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Removed implementations of getRiver, update calls to use FLYSUtils.
+
 2011-08-29  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	Minor cosmetics.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java	Mon Aug 29 08:58:03 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java	Mon Aug 29 09:01:40 2011 +0000
@@ -28,18 +28,17 @@
 import de.intevation.artifacts.common.utils.XMLUtils;
 
 import de.intevation.flys.artifacts.states.DefaultState;
+import de.intevation.flys.artifacts.cache.CacheFactory;
 import de.intevation.flys.artifacts.context.FLYSContext;
+import de.intevation.flys.artifacts.model.AnnotationsFactory;
+import de.intevation.flys.artifacts.model.RiverFactory;
 
 import de.intevation.flys.backend.SessionHolder;
 
-import de.intevation.flys.artifacts.cache.CacheFactory;
-
 import de.intevation.flys.model.Annotation;
-import de.intevation.flys.artifacts.model.AnnotationsFactory;
-
 import de.intevation.flys.model.River;
 
-import de.intevation.flys.artifacts.model.RiverFactory;
+import de.intevation.flys.utils.FLYSUtils;
 
 /**
  * Artifact to access names of Points Of Interest along a segment of a river.
@@ -232,13 +231,6 @@
         }
     } 
 
-    public River getRiver() {
-        StateData dRiver = getData("river");
-
-        return dRiver != null
-            ? RiverFactory.getRiver((String) dRiver.getValue())
-            : null;
-    }
 
     /**
      * Get Annotations for Points (opposed to segments) in river in range.
@@ -246,7 +238,7 @@
      * @return list of Annotations.
      */
     public List<Annotation> getAnnotations() {
-        String river = getRiver().getName();
+        String river = FLYSUtils.getRiver(this).getName();
         logger.debug("Search annotations for river: " /*+ river*/);
         //Cache cache = CacheFactory.getCache(CACHE_NAME);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Mon Aug 29 08:58:03 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Mon Aug 29 09:01:40 2011 +0000
@@ -3,7 +3,8 @@
 import gnu.trove.TDoubleArrayList;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
-
+import de.intevation.flys.artifacts.model.RiverFactory;
+import de.intevation.flys.model.River;
 
 public class FLYSUtils {
 
@@ -15,7 +16,7 @@
 
 
     public static KM_MODE getKmRangeMode(FLYSArtifact flys) {
-        String mode  = flys.getDataAsString("ld_mode");
+        String mode = flys.getDataAsString("ld_mode");
 
         if (mode == null || mode.length() == 0) {
             return KM_MODE.NONE;
@@ -99,4 +100,19 @@
 
         return locations.toNativeArray();
     }
+
+
+    /**
+     * Returns the selected River object based on the 'river' data that might
+     * have been inserted by the user.
+     *
+     * @return the selected River or null if no river has been chosen yet.
+     */
+    public static River getRiver(FLYSArtifact flys) {
+        String sRiver = flys.getDataAsString("river");
+
+        return (sRiver != null)
+            ? RiverFactory.getRiver(sRiver)
+            : null;
+    }
 }

http://dive4elements.wald.intevation.org