| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MapStringStringAdapter |
|
| 4.0;4 |
| 1 | /* | |
| 2 | * Copyright 2007-2010 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl2.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.core.jaxb; | |
| 17 | ||
| 18 | import java.util.HashMap; | |
| 19 | import java.util.Map; | |
| 20 | ||
| 21 | import javax.xml.bind.annotation.adapters.XmlAdapter; | |
| 22 | ||
| 23 | /** | |
| 24 | * Do JAXB mapping of Map<String, String> to a format like the following: | |
| 25 | * | |
| 26 | * <pre> | |
| 27 | * {@code | |
| 28 | * | |
| 29 | * } | |
| 30 | * | |
| 31 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 32 | * | |
| 33 | */ | |
| 34 | 0 | public class MapStringStringAdapter extends XmlAdapter<StringMapEntry[], Map<String, String>> { |
| 35 | ||
| 36 | @Override | |
| 37 | public StringMapEntry[] marshal(Map<String, String> map) throws Exception { | |
| 38 | 0 | if(null == map) return null; |
| 39 | 0 | StringMapEntry[] entryArray = new StringMapEntry[map.size()]; |
| 40 | 0 | int i = 0; |
| 41 | 0 | for (Map.Entry<String, String> e : map.entrySet()) { |
| 42 | 0 | entryArray[i] = new StringMapEntry(e); |
| 43 | 0 | i++; |
| 44 | } | |
| 45 | 0 | return entryArray; |
| 46 | } | |
| 47 | ||
| 48 | /** | |
| 49 | * This overridden method ... | |
| 50 | * | |
| 51 | * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object) | |
| 52 | */ | |
| 53 | @Override | |
| 54 | public Map<String, String> unmarshal(StringMapEntry[] entryArray) throws Exception { | |
| 55 | 0 | if (null == entryArray) return null; |
| 56 | 0 | Map<String, String> resultMap = new HashMap<String, String>(entryArray.length); |
| 57 | 0 | for (int i = 0; i < entryArray.length; i++) { |
| 58 | 0 | StringMapEntry stringMapEntry = entryArray[i]; |
| 59 | 0 | resultMap.put(stringMapEntry.getKey(), stringMapEntry.getValue()); |
| 60 | } | |
| 61 | 0 | return resultMap; |
| 62 | } | |
| 63 | } |