svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / tools / coerce / SimpleAttributesSerializer.java @ 38581
History | View | Annotate | Download (1.25 KB)
1 |
package org.gvsig.fmap.mapcontext.tools.coerce; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.Iterator; |
5 |
import java.util.Map; |
6 |
import java.util.Map.Entry; |
7 |
|
8 |
public class SimpleAttributesSerializer { |
9 |
Map values = null; |
10 |
String name = null; |
11 |
|
12 |
public SimpleAttributesSerializer(String name) { |
13 |
this.name = name;
|
14 |
this.values = new HashMap(); |
15 |
} |
16 |
|
17 |
public void put(String name, Object value) { |
18 |
this.values.put(name, value);
|
19 |
} |
20 |
|
21 |
public Object get(String name) { |
22 |
return this.get(name); |
23 |
} |
24 |
|
25 |
public String toString() { |
26 |
StringBuffer buffer = null; |
27 |
Iterator it = this.values.entrySet().iterator(); |
28 |
while( it.hasNext() ) {
|
29 |
Entry entry = (Entry)(it.next()); |
30 |
if( buffer==null ) { |
31 |
buffer = new StringBuffer(); |
32 |
buffer.append(this.name).append(":"); |
33 |
} else {
|
34 |
buffer.append(";");
|
35 |
} |
36 |
buffer.append(entry.getKey()) |
37 |
.append("=")
|
38 |
.append(entry.getValue()) |
39 |
.append(";");
|
40 |
} |
41 |
return buffer.toString();
|
42 |
} |
43 |
|
44 |
public void load(String buffer) { |
45 |
if( ! buffer.startsWith(this.name+":") ) { |
46 |
return;
|
47 |
} |
48 |
|
49 |
String[] pairs = buffer.substring(this.name.length()) .split(";"); |
50 |
for( int i=0; i<pairs.length; i++ ) { |
51 |
String[] pair = pairs[i].split("="); |
52 |
if( pair.length==2 ) { |
53 |
this.values.put(pair[0].trim(), pair[1].trim()); |
54 |
} |
55 |
} |
56 |
} |
57 |
} |