[Schmitzm-commits] r1292 - in trunk: src/skrueger src/skrueger/geotools/io src_junit/skrueger/geotools/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Nov 22 11:39:29 CET 2010


Author: alfonx
Date: 2010-11-22 11:39:13 +0100 (Mon, 22 Nov 2010)
New Revision: 1292

Added:
   trunk/src/skrueger/AbstractSeverList.java
   trunk/src/skrueger/ServerList.java
Modified:
   trunk/src/skrueger/geotools/io/DbServerList.java
   trunk/src/skrueger/geotools/io/DbServerSettings.java
   trunk/src/skrueger/geotools/io/GsServerSettings.java
   trunk/src/skrueger/geotools/io/ServerSettings.java
   trunk/src/skrueger/geotools/io/WfsServerSettings.java
   trunk/src_junit/skrueger/geotools/io/DbServerListTest.java
   trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java
Log:
Reorgnaized ServerList classes in schmitzm a bit

Added: trunk/src/skrueger/AbstractSeverList.java
===================================================================
--- trunk/src/skrueger/AbstractSeverList.java	2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src/skrueger/AbstractSeverList.java	2010-11-22 10:39:13 UTC (rev 1292)
@@ -0,0 +1,12 @@
+package skrueger;
+
+import java.util.ArrayList;
+
+abstract public class AbstractSeverList<T> extends ArrayList<T> implements ServerList{
+	/**
+	 * Character used to separate the parameters when serializing settings to a
+	 * String
+	 */
+	public static final String DELIMITER = "@";
+
+}


Property changes on: trunk/src/skrueger/AbstractSeverList.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/src/skrueger/ServerList.java
===================================================================
--- trunk/src/skrueger/ServerList.java	2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src/skrueger/ServerList.java	2010-11-22 10:39:13 UTC (rev 1292)
@@ -0,0 +1,10 @@
+package skrueger;
+
+
+public interface ServerList {
+
+	String toPropertiesString();
+
+	boolean parsePropertiesString(String propString);
+
+}


Property changes on: trunk/src/skrueger/ServerList.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/src/skrueger/geotools/io/DbServerList.java
===================================================================
--- trunk/src/skrueger/geotools/io/DbServerList.java	2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src/skrueger/geotools/io/DbServerList.java	2010-11-22 10:39:13 UTC (rev 1292)
@@ -1,20 +1,16 @@
 package skrueger.geotools.io;
 
 import java.net.MalformedURLException;
-import java.util.ArrayList;
 import java.util.regex.Pattern;
 
 import org.jfree.util.Log;
 
+import skrueger.AbstractSeverList;
+
 /**
  * A list of {@link DbServerSettings}.
  */
-public class DbServerList extends ArrayList<DbServerSettings> {
-	/**
-	 * Character used to separate the parameters when serializing settings to a
-	 * String
-	 */
-	private static final String DELIMITER = "@";
+public class DbServerList extends AbstractSeverList<DbServerSettings> {
 
 	public DbServerList(DbServerSettings... wfss) {
 		for (DbServerSettings wfs : wfss) {
@@ -22,10 +18,15 @@
 		}
 	}
 
+	public DbServerList(String propertiesString) {
+		parsePropertiesString(propertiesString);
+	}
+
 	/**
 	 * @return transforms the settings to a String that can be stored in a
 	 *         .properties line. @see #parsePropertiesString
 	 */
+	@Override
 	public String toPropertiesString() {
 
 		StringBuffer serialized = new StringBuffer(100);
@@ -43,11 +44,12 @@
 	 *         .properties line. @see #parsePropertiesString
 	 * @throws MalformedURLException
 	 */
-	public static DbServerList parsePropertiesString(String propString) {
-		DbServerList wfsServerList = new DbServerList();
+	@Override
+	public boolean parsePropertiesString(String propString) {
+		// DbServerList wfsServerList = new DbServerList();
 
 		if (propString == null)
-			return wfsServerList;
+			return false;
 
 		String[] split = propString.split(Pattern.quote(DELIMITER));
 
@@ -55,20 +57,22 @@
 			try {
 				DbServerSettings dbServer = new DbServerSettings(s);
 				if (dbServer == null) {
-					Log.error(
-							"Could not import a "
-									+ DbServerSettings.class.getSimpleName()
-									+ ". Ignoring it.");
+					Log.error("Could not import a "
+							+ DbServerSettings.class.getSimpleName()
+							+ ". Ignoring it.");
 				} else
-					wfsServerList.add(dbServer);
+					add(dbServer);
 			} catch (Exception e) {
 				Log.error(
 						"Could not import a "
 								+ DbServerSettings.class.getSimpleName()
 								+ ". Ignoring it.", e);
+				return false;
 			}
 		}
 
-		return wfsServerList;
+		return true;
+
+		// return wfsServerList;
 	}
 }

Modified: trunk/src/skrueger/geotools/io/DbServerSettings.java
===================================================================
--- trunk/src/skrueger/geotools/io/DbServerSettings.java	2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src/skrueger/geotools/io/DbServerSettings.java	2010-11-22 10:39:13 UTC (rev 1292)
@@ -8,8 +8,6 @@
 import java.util.HashMap;
 import java.util.regex.Pattern;
 
-import javax.management.RuntimeErrorException;
-
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
@@ -151,7 +149,7 @@
 	 * @throws MalformedURLException
 	 */
 	@Override
-	public DbServerSettings parsePropertiesString(String propString)
+	public boolean parsePropertiesString(String propString)
 			throws MalformedURLException {
 
 		if (propString == null || propString.isEmpty())
@@ -161,22 +159,24 @@
 			String[] split = propString.split(Pattern.quote(DELIMITER));
 
 			int i = 0;
-			DbServerSettings dbServer = new DbServerSettings(
-					DbType.valueOf(split[i++]));
+			setDbType(	DbType.valueOf(split[i++]));
+//			DbServerSettings dbServer = new DbServerSettings(
+//					DbType.valueOf(split[i++])
+//					);
 
-			dbServer.setTitle(split[i++]);
-			dbServer.setHost(split[i++]);
-			dbServer.setPort(java.lang.Integer.valueOf(split[i++]));
-			dbServer.setUsername(StringUtils.stripToNull(split[i++]));
-			dbServer.setPassword(split[i++]);
-			dbServer.setDatabase(split[i++]);
-			dbServer.setExposePrimaryKey(Boolean.valueOf(split[i++]));
-			dbServer.setSchema(stringOrNull(split[i++]));
+			setTitle(split[i++]);
+			setHost(split[i++]);
+			setPort(java.lang.Integer.valueOf(split[i++]));
+			setUsername(StringUtils.stripToNull(split[i++]));
+			setPassword(split[i++]);
+			setDatabase(split[i++]);
+			setExposePrimaryKey(Boolean.valueOf(split[i++]));
+			setSchema(stringOrNull(split[i++]));
 
-			return dbServer;
+			return true;
 		} catch (Exception e) {
 			Log.warn("couldn't parse " + propString, e);
-			return null;
+			return false;
 		}
 	}
 

Modified: trunk/src/skrueger/geotools/io/GsServerSettings.java
===================================================================
--- trunk/src/skrueger/geotools/io/GsServerSettings.java	2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src/skrueger/geotools/io/GsServerSettings.java	2010-11-22 10:39:13 UTC (rev 1292)
@@ -21,10 +21,10 @@
 	}
 
 	@Override
-	public ServerSettings parsePropertiesString(String propString)
+	public boolean parsePropertiesString(String propString)
 			throws MalformedURLException {
 		// TODO Auto-generated method stub
-		return null;
+		return false;
 	}
 
 	

Modified: trunk/src/skrueger/geotools/io/ServerSettings.java
===================================================================
--- trunk/src/skrueger/geotools/io/ServerSettings.java	2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src/skrueger/geotools/io/ServerSettings.java	2010-11-22 10:39:13 UTC (rev 1292)
@@ -49,7 +49,7 @@
 		return title;
 	}
 
-	abstract public ServerSettings parsePropertiesString(String propString)
+	abstract public boolean parsePropertiesString(String propString)
 			throws MalformedURLException ;
 
 }

Modified: trunk/src/skrueger/geotools/io/WfsServerSettings.java
===================================================================
--- trunk/src/skrueger/geotools/io/WfsServerSettings.java	2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src/skrueger/geotools/io/WfsServerSettings.java	2010-11-22 10:39:13 UTC (rev 1292)
@@ -199,31 +199,31 @@
 	 * @throws MalformedURLException
 	 */
 	@Override
-	public WfsServerSettings parsePropertiesString(String propString)
+	public boolean parsePropertiesString(String propString)
 			throws MalformedURLException {
 
 		try {
 			String[] split = propString.split(Pattern.quote(DELIMITER));
 
-			WfsServerSettings wfs = new WfsServerSettings();
+//			WfsServerSettings wfs = new WfsServerSettings();
 
 			int i = 0;
-			wfs.setTitle(split[i++]);
-			wfs.setBaseUrl(new URL(split[i++]));
-			wfs.setVersion(WfsProtocollVersion.valueOf(split[i++]));
-			wfs.setMaxFeatures(intOrNull(split[i++]));
-			wfs.setTimeout(intOrNull(split[i++]));
-			wfs.setLenient(java.lang.Boolean.valueOf(split[i++]));
-			wfs.setHttpProtocol(HttpProtocol.parse(split[i++]));
+			setTitle(split[i++]);
+			setBaseUrl(new URL(split[i++]));
+			setVersion(WfsProtocollVersion.valueOf(split[i++]));
+			setMaxFeatures(intOrNull(split[i++]));
+			setTimeout(intOrNull(split[i++]));
+			setLenient(java.lang.Boolean.valueOf(split[i++]));
+			setHttpProtocol(HttpProtocol.parse(split[i++]));
 
-			wfs.setUsername(stringOrNull(split[i++]));
+			setUsername(stringOrNull(split[i++]));
 
-			wfs.setPassword(stringOrNull(split[i++]));
+			setPassword(stringOrNull(split[i++]));
 
-			return wfs;
+			return true;
 		} catch (Exception e) {
 			Log.warn("couldn't parse " + propString, e);
-			return null;
+			return false;
 		}
 
 	}

Modified: trunk/src_junit/skrueger/geotools/io/DbServerListTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/DbServerListTest.java	2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src_junit/skrueger/geotools/io/DbServerListTest.java	2010-11-22 10:39:13 UTC (rev 1292)
@@ -17,7 +17,7 @@
 
 		DbServerList list1 = new DbServerList(dbDs1, dbDs2);
 
-		DbServerList list2 = DbServerList.parsePropertiesString(list1
+		DbServerList list2 = new DbServerList(list1
 				.toPropertiesString());
 
 		assertEquals(list1.size(), list2.size());
@@ -27,7 +27,7 @@
 
 	@Test
 	public void testParseEmpty() {
-		assertEquals(0, DbServerList.parsePropertiesString(null).size());
-		assertEquals(0, DbServerList.parsePropertiesString("").size());
+		assertEquals(0, new DbServerList( (String) null).size());
+		assertEquals(0, new DbServerList("").size());
 	}
 }

Modified: trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java	2010-11-22 01:18:13 UTC (rev 1291)
+++ trunk/src_junit/skrueger/geotools/io/DbServerSettingsTest.java	2010-11-22 10:39:13 UTC (rev 1292)
@@ -3,8 +3,6 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.net.MalformedURLException;
-
 import org.junit.Test;
 
 import skrueger.geotools.io.DbServerSettings.DbType;



More information about the Schmitzm-commits mailing list