m2u-upass-core / src / my / com / upass / util / MapAdapter.java @ 44:7a7fb8fcfd6e
History | View | Annotate | Download (750 Bytes)
1 |
package my.com.upass.util; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.Map; |
5 |
|
6 |
import javax.xml.bind.annotation.adapters.XmlAdapter; |
7 |
|
8 |
public class MapAdapter extends XmlAdapter<MapElement[], Map<String, String>> { |
9 |
|
10 |
public MapElement[] marshal(Map<String, String> map) throws Exception { |
11 |
|
12 |
MapElement[] elements = new MapElement[map.size()]; |
13 |
int i = 0; |
14 |
for (Map.Entry<String, String> entry : map.entrySet()) |
15 |
elements[i++] = new MapElement(entry.getKey(), entry.getValue());
|
16 |
|
17 |
return elements;
|
18 |
} |
19 |
|
20 |
public Map<String, String> unmarshal(MapElement[] elements) throws Exception { |
21 |
|
22 |
Map<String, String> map = new HashMap<String, String>(); |
23 |
for (MapElement mapelement : elements)
|
24 |
map.put(mapelement.key, mapelement.value); |
25 |
|
26 |
return map;
|
27 |
} |
28 |
} |