1 /*
2 * Copyright 2007-2009 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 jax-ws mapping of Map<String, String> for KIM service method parameters, etc.
25 *
26 * @author Kuali Rice Team (kuali-rice@googlegroups.com)
27 *
28 */
29 public class JaxbStringMapAdapter extends XmlAdapter<StringMapEntryList, Map<String, String>> {
30
31 /**
32 * This overridden method ...
33 *
34 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
35 */
36 @Override
37 public StringMapEntryList marshal(Map<String, String> map) throws Exception {
38 if(null == map) return null;
39 StringMapEntryList entryList = new StringMapEntryList();
40 for (Map.Entry<String, String> e : map.entrySet()) {
41 entryList.getEntries().add(
42 new StringMapEntry(e.getKey(), e.getValue()));
43 }
44 return entryList;
45 }
46
47 /**
48 * This overridden method ...
49 *
50 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
51 */
52 @Override
53 public Map<String, String> unmarshal(StringMapEntryList entryList) throws Exception {
54 if (null == entryList) return null;
55 Map<String, String> resultMap = new HashMap<String, String>();
56 for (StringMapEntry entry : entryList.getEntries()) {
57 resultMap.put(entry.key, entry.value);
58 }
59 return resultMap;
60 }
61 }