1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.api.util.jaxb; |
17 | |
|
18 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
19 | |
import org.w3c.dom.Element; |
20 | |
|
21 | |
import javax.xml.bind.annotation.XmlAccessType; |
22 | |
import javax.xml.bind.annotation.XmlAccessorType; |
23 | |
import javax.xml.bind.annotation.XmlAnyElement; |
24 | |
import javax.xml.bind.annotation.XmlAttribute; |
25 | |
import javax.xml.bind.annotation.XmlElement; |
26 | |
import javax.xml.bind.annotation.XmlElementWrapper; |
27 | |
import javax.xml.bind.annotation.XmlType; |
28 | |
import javax.xml.bind.annotation.adapters.XmlAdapter; |
29 | |
import java.io.Serializable; |
30 | |
import java.util.ArrayList; |
31 | |
import java.util.Collection; |
32 | |
import java.util.Collections; |
33 | |
import java.util.List; |
34 | |
import java.util.Map; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public class MultiValuedStringMapAdapter extends XmlAdapter<MultiValuedStringMapAdapter.MultiValuedStringMapEntryList, Map<String, List<String>>> { |
52 | |
|
53 | |
@Override |
54 | |
public MultiValuedStringMapEntryList marshal(Map<String, List<String>> map) throws Exception { |
55 | 0 | if (map == null) { |
56 | 0 | return null; |
57 | |
} |
58 | 0 | List<MultiValuedStringMapEntry> entries = new ArrayList<MultiValuedStringMapEntry>(); |
59 | 0 | for (Map.Entry<String, List<String>> entry : map.entrySet()) { |
60 | 0 | entries.add(new MultiValuedStringMapEntry(entry)); |
61 | |
} |
62 | 0 | return new MultiValuedStringMapEntryList(entries); |
63 | |
} |
64 | |
|
65 | |
@Override |
66 | |
public Map<String, List<String>> unmarshal(MultiValuedStringMapEntryList multiValuedStringMapEntryList) throws Exception { |
67 | 0 | return null; |
68 | |
} |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
@XmlAccessorType(XmlAccessType.NONE) |
91 | |
@XmlType(name = "MultiValuedStringMapEntryType") |
92 | |
public static final class MultiValuedStringMapEntry implements Serializable { |
93 | |
|
94 | |
private static final long serialVersionUID = -9609663434312103L; |
95 | |
|
96 | |
@XmlAttribute(name = "key") |
97 | |
private final String key; |
98 | |
|
99 | |
@XmlElementWrapper(name = "values") |
100 | |
@XmlElement(name = "value") |
101 | |
private final List<String> values; |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
@SuppressWarnings("unused") |
107 | 0 | MultiValuedStringMapEntry() { |
108 | 0 | this.key = null; |
109 | 0 | this.values = null; |
110 | 0 | } |
111 | |
|
112 | 0 | public MultiValuedStringMapEntry(String key, List<String> values) { |
113 | 0 | this.key = key; |
114 | 0 | this.values = values; |
115 | 0 | } |
116 | |
|
117 | 0 | public MultiValuedStringMapEntry(Map.Entry<String, List<String>> entry) { |
118 | 0 | this.key = entry.getKey(); |
119 | 0 | this.values = new ArrayList<String>(entry.getValue()); |
120 | 0 | } |
121 | |
|
122 | |
public String getKey() { |
123 | 0 | return this.key; |
124 | |
} |
125 | |
|
126 | |
public List<String> getValues() { |
127 | 0 | return this.values; |
128 | |
} |
129 | |
|
130 | |
} |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | 0 | @XmlAccessorType(XmlAccessType.FIELD) |
140 | |
@XmlType(name = "MultiValuedStringMapEntryListType") |
141 | |
public static class MultiValuedStringMapEntryList extends AbstractDataTransferObject { |
142 | |
|
143 | |
private static final long serialVersionUID = 1L; |
144 | |
|
145 | |
@XmlElement(name = "entry") |
146 | |
private final List<MultiValuedStringMapEntry> entries; |
147 | |
|
148 | 0 | @SuppressWarnings("unused") @XmlAnyElement |
149 | |
private final Collection<Element> _futureElements = null; |
150 | |
|
151 | |
@SuppressWarnings("unused") |
152 | 0 | MultiValuedStringMapEntryList() { |
153 | 0 | this.entries = null; |
154 | 0 | } |
155 | |
|
156 | 0 | public MultiValuedStringMapEntryList(List<MultiValuedStringMapEntry> entries) { |
157 | 0 | this.entries = new ArrayList<MultiValuedStringMapEntry>(entries); |
158 | 0 | } |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public List<MultiValuedStringMapEntry> getEntries() { |
164 | 0 | if (this.entries == null) { |
165 | 0 | return Collections.emptyList(); |
166 | |
} |
167 | 0 | return Collections.unmodifiableList(entries); |
168 | |
} |
169 | |
} |
170 | |
} |