svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / fmap / mapcontext / tools / coerce / SimpleAttributesSerializer.java @ 40559
History | View | Annotate | Download (2.19 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.mapcontext.tools.coerce; |
25 |
|
26 |
import java.util.HashMap; |
27 |
import java.util.Iterator; |
28 |
import java.util.Map; |
29 |
import java.util.Map.Entry; |
30 |
|
31 |
public class SimpleAttributesSerializer { |
32 |
Map values = null; |
33 |
String name = null; |
34 |
|
35 |
public SimpleAttributesSerializer(String name) { |
36 |
this.name = name;
|
37 |
this.values = new HashMap(); |
38 |
} |
39 |
|
40 |
public void put(String name, Object value) { |
41 |
this.values.put(name, value);
|
42 |
} |
43 |
|
44 |
public Object get(String name) { |
45 |
return this.get(name); |
46 |
} |
47 |
|
48 |
public String toString() { |
49 |
StringBuffer buffer = null; |
50 |
Iterator it = this.values.entrySet().iterator(); |
51 |
while( it.hasNext() ) {
|
52 |
Entry entry = (Entry)(it.next()); |
53 |
if( buffer==null ) { |
54 |
buffer = new StringBuffer(); |
55 |
buffer.append(this.name).append(":"); |
56 |
} else {
|
57 |
buffer.append(";");
|
58 |
} |
59 |
buffer.append(entry.getKey()) |
60 |
.append("=")
|
61 |
.append(entry.getValue()) |
62 |
.append(";");
|
63 |
} |
64 |
return buffer.toString();
|
65 |
} |
66 |
|
67 |
public void load(String buffer) { |
68 |
if( ! buffer.startsWith(this.name+":") ) { |
69 |
return;
|
70 |
} |
71 |
|
72 |
String[] pairs = buffer.substring(this.name.length()) .split(";"); |
73 |
for( int i=0; i<pairs.length; i++ ) { |
74 |
String[] pair = pairs[i].split("="); |
75 |
if( pair.length==2 ) { |
76 |
this.values.put(pair[0].trim(), pair[1].trim()); |
77 |
} |
78 |
} |
79 |
} |
80 |
} |