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 |
|
|
|
47 |
alfonx |
1296 |
if (!dbServer.parsePropertiesString(s)) { |
48 |
alfonx |
1295 |
Log.error("Could not import a " |
49 |
|
|
+ GtDbServerSettings.class.getSimpleName() |
50 |
|
|
+ ". Ignoring it."); |
51 |
|
|
} else |
52 |
|
|
add(dbServer); |
53 |
|
|
} catch (Exception e) { |
54 |
|
|
Log.error( |
55 |
|
|
"Could not import a " |
56 |
|
|
+ GtDbServerSettings.class.getSimpleName() |
57 |
|
|
+ ". Ignoring it.", e); |
58 |
|
|
return false; |
59 |
|
|
} |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
return true; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
protected abstract T newInstance(); |
66 |
|
|
|
67 |
|
|
/** |
68 |
|
|
* @return transforms the settings to a String that can be stored in a |
69 |
|
|
* .properties line. @see #parsePropertiesString |
70 |
|
|
*/ |
71 |
|
|
public final String toPropertiesString() { |
72 |
|
|
|
73 |
|
|
StringBuffer serialized = new StringBuffer(100); |
74 |
|
|
|
75 |
|
|
for (T wfs : this) { |
76 |
|
|
serialized.append(wfs.toPropertiesString()); |
77 |
|
|
serialized.append(DELIMITER); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
return serialized.toString(); |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
@Override |
84 |
|
|
public boolean add(T e) { |
85 |
|
|
return super.add(e); |
86 |
|
|
} |
87 |
alfonx |
1292 |
} |