[Schmitzm-commits] r468 - in trunk/src: schmitzm/geotools/gui schmitzm/geotools/styling skrueger/geotools/labelsearch

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 14 12:57:12 CEST 2009


Author: alfonx
Date: 2009-10-14 12:57:11 +0200 (Wed, 14 Oct 2009)
New Revision: 468

Modified:
   trunk/src/schmitzm/geotools/gui/JMapPane.java
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src/skrueger/geotools/labelsearch/LabelSearch.java
Log:
* Added three missing Iterator<Feature> close statement.

Modified: trunk/src/schmitzm/geotools/gui/JMapPane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-10-14 08:31:11 UTC (rev 467)
+++ trunk/src/schmitzm/geotools/gui/JMapPane.java	2009-10-14 10:57:11 UTC (rev 468)
@@ -1277,6 +1277,8 @@
 							Double nearestDist = 0.0;
 
 							Iterator<Feature> fcIt = fc.iterator();
+							try {
+								
 							while (fcIt.hasNext()) {
 								Feature f = fcIt.next();
 								Object obj = f.getAttribute(0);
@@ -1300,7 +1302,9 @@
 								}
 
 							}
-							fc.close(fcIt);
+							} finally {
+								fc.close(fcIt);
+							}
 
 							fcOne = new MemoryFeatureCollection(fc
 									.getFeatureType());

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-10-14 08:31:11 UTC (rev 467)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2009-10-14 10:57:11 UTC (rev 468)
@@ -1142,6 +1142,8 @@
 			 * .filterSLDVisibleOnly(FeatureUtil.java:216) *
 			 * 
 			 */
+		} finally {
+			fc.close(fcIt);
 		}
 
 		// LOGGER.info("filterSLDVisibleOnly removed "+ (fc.size() -

Modified: trunk/src/skrueger/geotools/labelsearch/LabelSearch.java
===================================================================
--- trunk/src/skrueger/geotools/labelsearch/LabelSearch.java	2009-10-14 08:31:11 UTC (rev 467)
+++ trunk/src/skrueger/geotools/labelsearch/LabelSearch.java	2009-10-14 10:57:11 UTC (rev 468)
@@ -63,14 +63,11 @@
  */
 public class LabelSearch {
 	final static private Logger LOGGER = Logger.getLogger(LabelSearch.class);
-	
+
 	public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
-	.extendPackagePath(LabelSearch.class,
-			"labelsearch"), Locale.ENGLISH);
-	
-	
-			
-			
+			.extendPackagePath(LabelSearch.class, "labelsearch"),
+			Locale.ENGLISH);
+
 	public static String R(String key, Object... values) {
 		return RESOURCE.getString(key, values);
 	}
@@ -113,8 +110,8 @@
 				if (!ml.isVisible())
 					continue;
 
-				final List<TextSymbolizer> allTS = StylingUtil.getTextSymbolizers(ml
-						.getStyle());
+				final List<TextSymbolizer> allTS = StylingUtil
+						.getTextSymbolizers(ml.getStyle());
 				if (allTS.size() == 0) {
 					// A layer without any TextSymbolizer doesn't have to be
 					// searched any more.
@@ -131,8 +128,9 @@
 				// new DefaultQuery(typeName, ff.like(labelExp,
 				// "*"+searchMe+"*"), properties));
 
-				final FeatureCollection features = ml.getFeatureSource().getFeatures(
-						new DefaultQuery(typeName, Filter.INCLUDE));
+				final FeatureCollection features = ml
+						.getFeatureSource()
+						.getFeatures(new DefaultQuery(typeName, Filter.INCLUDE));
 
 				// new MemoryDataStore().getFeatureSource(typeName)
 
@@ -142,54 +140,62 @@
 				 * function.
 				 */
 				final Iterator<Feature> fi = features.iterator();
-				while (fi.hasNext()) {
-					final Feature f = fi.next();
+				try {
+					while (fi.hasNext()) {
+						final Feature f = fi.next();
 
-					final TextSymbolizer ts = StylingUtil.getTextSymbolizer(ml
-							.getStyle(), f);
-					if (ts == null)
-						continue;
+						final TextSymbolizer ts = StylingUtil
+								.getTextSymbolizer(ml.getStyle(), f);
+						if (ts == null)
+							continue;
 
-					final AttributeType labelAttribute = getLabelAttribute(ts, ml
-							.getFeatureSource().getSchema());
+						final AttributeType labelAttribute = getLabelAttribute(
+								ts, ml.getFeatureSource().getSchema());
 
-					if (labelAttribute == null) {
-						continue;
-					}
+						if (labelAttribute == null) {
+							continue;
+						}
 
-					// System.out.println("labelAttrib local name" +
-					// labelAttribute.getLocalName());
+						// System.out.println("labelAttrib local name" +
+						// labelAttribute.getLocalName());
 
-					final Object value = f
-							.getAttribute(labelAttribute.getLocalName());
+						final Object value = f.getAttribute(labelAttribute
+								.getLocalName());
 
-					// System.out.println("labelAttrib value " + value);
+						// System.out.println("labelAttrib value " + value);
 
-					if (value == null) {
-						LOGGER.info("Skipping f: getLocalName() is null for feature="+f);
-						continue;
-					}
+						if (value == null) {
+							LOGGER
+									.info("Skipping f: getLocalName() is null for feature="
+											+ f);
+							continue;
+						}
 
-					/**
-					 * LabelString ist z.B. "IMPETUS pluviograph". Suchwort
-					 * "plu" soll treffen. Also wird nach spaces zerlegt und
-					 * dann gesucht
-					 */
-					final String labelString = value.toString().toLowerCase();
-					if (labelString.startsWith(searchMe)) {
-						hits.add(createSearchResult(f, value.toString(), ml
-								.getTitle(),ml));
-					} else {
-						final String[] parts = labelString.trim().split(" ");
-						for (final String part : parts) {
-							if (part.startsWith(searchMe)) {
-								hits.add(createSearchResult(f, value.toString(), ml
-										.getTitle(), ml));
-								break;
+						/**
+						 * LabelString ist z.B. "IMPETUS pluviograph". Suchwort
+						 * "plu" soll treffen. Also wird nach spaces zerlegt und
+						 * dann gesucht
+						 */
+						final String labelString = value.toString()
+								.toLowerCase();
+						if (labelString.startsWith(searchMe)) {
+							hits.add(createSearchResult(f, value.toString(), ml
+									.getTitle(), ml));
+						} else {
+							final String[] parts = labelString.trim()
+									.split(" ");
+							for (final String part : parts) {
+								if (part.startsWith(searchMe)) {
+									hits.add(createSearchResult(f, value
+											.toString(), ml.getTitle(), ml));
+									break;
+								}
 							}
 						}
+
 					}
-
+				} finally {
+					features.close(fi);
 				}
 
 			} catch (final IOException e) {
@@ -204,8 +210,8 @@
 		return hits;
 	}
 
-	protected SearchResult createSearchResult(final Feature f, final String title,
-			final String inTitle, MapLayer ml) {
+	protected SearchResult createSearchResult(final Feature f,
+			final String title, final String inTitle, MapLayer ml) {
 		return new SearchResultFeature(f, title, inTitle, mapPane, ml);
 	}
 



More information about the Schmitzm-commits mailing list