package skrueger; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.regex.Pattern; import org.jfree.util.Log; import skrueger.geotools.io.GtDbServerSettings; import skrueger.geotools.io.ServerSettings; abstract public class AbstractServerList extends ArrayList implements ServerList { /** * Character used to separate the parameters when serializing settings to a * String */ public static final String DELIMITER = "@"; public AbstractServerList(T... wfss) { for (T wfs : wfss) { add(wfs); } } public AbstractServerList(String propertiesString) { parsePropertiesString(propertiesString); } /** * @return transforms the settings to a String that can be stored in a * .properties line. @see #parsePropertiesString * @throws MalformedURLException */ @Override public final boolean parsePropertiesString(String propString) { if (propString == null) return false; String[] split = propString.split(Pattern.quote(DELIMITER)); for (String s : split) { try { T dbServer = newInstance(); if (!dbServer.parsePropertiesString(s)) { Log.error("Could not import a " + GtDbServerSettings.class.getSimpleName() + ". Ignoring it."); } else add(dbServer); } catch (Exception e) { Log.error( "Could not import a " + GtDbServerSettings.class.getSimpleName() + ". Ignoring it.", e); return false; } } return true; } protected abstract T newInstance(); /** * @return transforms the settings to a String that can be stored in a * .properties line. @see #parsePropertiesString */ public final String toPropertiesString() { StringBuffer serialized = new StringBuffer(100); for (T wfs : this) { serialized.append(wfs.toPropertiesString()); serialized.append(DELIMITER); } return serialized.toString(); } @Override public boolean add(T e) { return super.add(e); } }