| 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.XmlType; |
| 27 | |
import javax.xml.bind.annotation.XmlValue; |
| 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.HashMap; |
| 34 | |
import java.util.List; |
| 35 | |
import java.util.Map; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | 0 | public class MapStringStringAdapter extends XmlAdapter<MapStringStringAdapter.StringMapEntryList, Map<String, String>> { |
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public StringMapEntryList marshal(Map<String, String> map) throws Exception { |
| 56 | 0 | if (map == null) { |
| 57 | 0 | return null; |
| 58 | |
} |
| 59 | 0 | List<StringMapEntry> entries = new ArrayList<StringMapEntry>(); |
| 60 | 0 | for (Map.Entry<String, String> entry : map.entrySet()) { |
| 61 | 0 | entries.add(new StringMapEntry(entry)); |
| 62 | |
} |
| 63 | 0 | return new StringMapEntryList(entries); |
| 64 | |
} |
| 65 | |
|
| 66 | |
@Override |
| 67 | |
public Map<String, String> unmarshal(StringMapEntryList entryList) throws Exception { |
| 68 | 0 | if (entryList == null || entryList.getEntries() == null) { |
| 69 | 0 | return null; |
| 70 | |
} |
| 71 | 0 | List<StringMapEntry> entries = entryList.getEntries(); |
| 72 | 0 | Map<String, String> resultMap = new HashMap<String, String>(entries.size()); |
| 73 | 0 | for (StringMapEntry entry : entries) { |
| 74 | 0 | resultMap.put(entry.getKey(), entry.getValue()); |
| 75 | |
} |
| 76 | 0 | return Collections.unmodifiableMap(resultMap); |
| 77 | |
} |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 89 | |
@XmlType(name = "StringMapEntryType") |
| 90 | |
public static final class StringMapEntry implements Serializable { |
| 91 | |
|
| 92 | |
private static final long serialVersionUID = -9609663434312103L; |
| 93 | |
|
| 94 | |
@XmlAttribute(name = "key") |
| 95 | |
private final String key; |
| 96 | |
|
| 97 | |
@XmlValue |
| 98 | |
private final String value; |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
@SuppressWarnings("unused") |
| 104 | 0 | private StringMapEntry() { |
| 105 | 0 | this.key = null; |
| 106 | 0 | this.value = null; |
| 107 | 0 | } |
| 108 | |
|
| 109 | 0 | public StringMapEntry(String key, String value) { |
| 110 | 0 | this.key = key; |
| 111 | 0 | this.value = value; |
| 112 | 0 | } |
| 113 | |
|
| 114 | 0 | public StringMapEntry(Map.Entry<String, String> e) { |
| 115 | 0 | this.key = e.getKey(); |
| 116 | 0 | this.value = e.getValue(); |
| 117 | 0 | } |
| 118 | |
|
| 119 | |
public String getKey() { |
| 120 | 0 | return this.key; |
| 121 | |
} |
| 122 | |
|
| 123 | |
public String getValue() { |
| 124 | 0 | return this.value; |
| 125 | |
} |
| 126 | |
|
| 127 | |
} |
| 128 | |
|
| 129 | 0 | @XmlAccessorType(XmlAccessType.FIELD) |
| 130 | |
@XmlType(name = "StringMapEntryListType") |
| 131 | |
public static class StringMapEntryList extends AbstractDataTransferObject { |
| 132 | |
|
| 133 | |
private static final long serialVersionUID = 1L; |
| 134 | |
|
| 135 | |
@XmlElement(name = "entry") |
| 136 | |
private final List<StringMapEntry> entries; |
| 137 | |
|
| 138 | 0 | @SuppressWarnings("unused") |
| 139 | |
@XmlAnyElement |
| 140 | |
private final Collection<Element> _futureElements = null; |
| 141 | |
|
| 142 | |
@SuppressWarnings("unused") |
| 143 | 0 | private StringMapEntryList() { |
| 144 | 0 | this.entries = null; |
| 145 | 0 | } |
| 146 | |
|
| 147 | 0 | public StringMapEntryList(List<StringMapEntry> entries) { |
| 148 | 0 | this.entries = new ArrayList<StringMapEntry>(entries); |
| 149 | 0 | } |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
public List<StringMapEntry> getEntries() { |
| 155 | 0 | if (this.entries == null) { |
| 156 | 0 | return Collections.emptyList(); |
| 157 | |
} |
| 158 | 0 | return Collections.unmodifiableList(entries); |
| 159 | |
} |
| 160 | |
} |
| 161 | |
} |