m2u-upass-core / src / my / com / upass / util / MapAdapter.java @ 60:1cff9a56093f
History | View | Annotate | Download (750 Bytes)
1 | 40:29d3fc38fdee | hadi | 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 | 45:31b70565f532 | hadi | for (MapElement mapElement : elements)
|
24 | map.put(mapElement.key, mapElement.value); |
||
25 | 40:29d3fc38fdee | hadi | |
26 | return map;
|
||
27 | } |
||
28 | } |