/[schmitzm]/branches/2.4.x/src/skrueger/AbstractServerList.java
ViewVC logotype

Annotation of /branches/2.4.x/src/skrueger/AbstractServerList.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1295 - (hide annotations)
Mon Nov 22 15:09:59 2010 UTC (14 years, 3 months ago) by alfonx
Original Path: trunk/src/skrueger/AbstractServerList.java
File MIME type: text/plain
File size: 2013 byte(s)
Refactored ServerSettings and ServerList classes in schmitzm for more usablility ;-)
1 alfonx 1292 package skrueger;
2    
3 alfonx 1295 import java.net.MalformedURLException;
4 alfonx 1292 import java.util.ArrayList;
5 alfonx 1295 import java.util.regex.Pattern;
6 alfonx 1292
7 alfonx 1295 import org.jfree.util.Log;
8    
9     import skrueger.geotools.io.GtDbServerSettings;
10     import skrueger.geotools.io.ServerSettings;
11    
12     abstract public class AbstractServerList<T extends ServerSettings> extends
13     ArrayList<T> implements ServerList<T> {
14 alfonx 1292 /**
15     * Character used to separate the parameters when serializing settings to a
16     * String
17     */
18     public static final String DELIMITER = "@";
19    
20 alfonx 1295 public AbstractServerList(T... wfss) {
21     for (T wfs : wfss) {
22     add(wfs);
23     }
24     }
25    
26     public AbstractServerList(String propertiesString) {
27     parsePropertiesString(propertiesString);
28     }
29    
30     /**
31     * @return transforms the settings to a String that can be stored in a
32     * .properties line. @see #parsePropertiesString
33     * @throws MalformedURLException
34     */
35     @Override
36     public final boolean parsePropertiesString(String propString) {
37    
38     if (propString == null)
39     return false;
40    
41     String[] split = propString.split(Pattern.quote(DELIMITER));
42    
43     for (String s : split) {
44     try {
45     T dbServer = newInstance();
46     dbServer.parsePropertiesString(s);
47    
48     if (dbServer == null) {
49     Log.error("Could not import a "
50     + GtDbServerSettings.class.getSimpleName()
51     + ". Ignoring it.");
52     } else
53     add(dbServer);
54     } catch (Exception e) {
55     Log.error(
56     "Could not import a "
57     + GtDbServerSettings.class.getSimpleName()
58     + ". Ignoring it.", e);
59     return false;
60     }
61     }
62    
63     return true;
64     }
65    
66     protected abstract T newInstance();
67    
68     /**
69     * @return transforms the settings to a String that can be stored in a
70     * .properties line. @see #parsePropertiesString
71     */
72     public final String toPropertiesString() {
73    
74     StringBuffer serialized = new StringBuffer(100);
75    
76     for (T wfs : this) {
77     serialized.append(wfs.toPropertiesString());
78     serialized.append(DELIMITER);
79     }
80    
81     return serialized.toString();
82     }
83    
84     @Override
85     public boolean add(T e) {
86     return super.add(e);
87     }
88 alfonx 1292 }

Properties

Name Value
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26