| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MultiValuedStringMapAdapter |
|
| 2.5;2.5 |
| 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.api.util.jaxb; | |
| 17 | ||
| 18 | import javax.xml.bind.annotation.adapters.XmlAdapter; | |
| 19 | import java.util.ArrayList; | |
| 20 | import java.util.List; | |
| 21 | import java.util.Map; | |
| 22 | ||
| 23 | /** | |
| 24 | * Do JAXB mapping of Map<String, String> to a format like the following for a | |
| 25 | * map containing { key1:value1, key2:value2 }: | |
| 26 | * | |
| 27 | * <pre> | |
| 28 | * {@code | |
| 29 | * <...> | |
| 30 | * <entry key="key1">value1</entry> | |
| 31 | * <entry key="key2">value2</entry> | |
| 32 | * </...> | |
| 33 | * } | |
| 34 | * | |
| 35 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 36 | * | |
| 37 | */ | |
| 38 | 0 | public class MultiValuedStringMapAdapter extends XmlAdapter<MultiValuedStringMapEntryList, Map<String, List<String>>> { |
| 39 | ||
| 40 | @Override | |
| 41 | public MultiValuedStringMapEntryList marshal(Map<String, List<String>> map) throws Exception { | |
| 42 | 0 | if (map == null) { |
| 43 | 0 | return null; |
| 44 | } | |
| 45 | 0 | List<MultiValuedStringMapEntry> entries = new ArrayList<MultiValuedStringMapEntry>(); |
| 46 | 0 | for (Map.Entry<String, List<String>> entry : map.entrySet()) { |
| 47 | 0 | entries.add(new MultiValuedStringMapEntry(entry)); |
| 48 | } | |
| 49 | 0 | return new MultiValuedStringMapEntryList(entries); |
| 50 | } | |
| 51 | ||
| 52 | @Override | |
| 53 | public Map<String, List<String>> unmarshal(MultiValuedStringMapEntryList multiValuedStringMapEntryList) throws Exception { | |
| 54 | 0 | return null; //To change body of implemented methods use File | Settings | File Templates. |
| 55 | } | |
| 56 | ||
| 57 | // @Override | |
| 58 | // public Map<String, List<String>> unmarshal(MultiValuedStringMapEntryList entryList) throws Exception { | |
| 59 | // if (entryList == null || entryList.getEntries() == null) { | |
| 60 | // return null; | |
| 61 | // } | |
| 62 | // List<MultiValuedStringMapEntry> entries = entryList.getEntries(); | |
| 63 | // Map<String, List<String>> resultMap = new HashMap<String, List<String>>(entries.size()); | |
| 64 | // for (MultiValuedStringMapEntry entry : entries) { | |
| 65 | // resultMap.put(entry.getKey(), entry.getValues()); | |
| 66 | // } | |
| 67 | // return Collections.unmodifiableMap(resultMap); | |
| 68 | // } | |
| 69 | ||
| 70 | } |