View Javadoc

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  import org.kuali.rice.kim.bo.entity.dto.KimEntityNameInfo;
24  
25  /**
26   * Do jax-ws mapping of Map<String, String> for KIM service method parameters, etc.
27   * 
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   *
30   */
31  public class StringToKimEntityNameInfoMapAdapter extends XmlAdapter<StringEntityNameInfoMapEntry[], Map<String, KimEntityNameInfo>> {
32  
33  	/**
34  	 * This overridden method ...
35  	 * 
36  	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
37  	 */
38  	@Override
39  	public StringEntityNameInfoMapEntry[] marshal(Map<String, KimEntityNameInfo> map) throws Exception {
40  		if(null == map) return null;
41  		StringEntityNameInfoMapEntry[] entryArray = new StringEntityNameInfoMapEntry[map.size()];
42  		int i = 0;
43  		for (Map.Entry<String, KimEntityNameInfo> e : map.entrySet()) {
44  			entryArray[i] = new StringEntityNameInfoMapEntry(e.getKey(), e.getValue());
45  			i++;
46  		}
47  		return entryArray;
48  	}
49  
50  	/**
51  	 * This overridden method ...
52  	 * 
53  	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
54  	 */
55  	@Override
56  	public Map<String, KimEntityNameInfo> unmarshal(StringEntityNameInfoMapEntry[] entryArray) throws Exception {
57  		if (null == entryArray) return null;
58  		Map<String, KimEntityNameInfo> resultMap = new HashMap<String, KimEntityNameInfo>(entryArray.length);
59  		for (int i = 0; i < entryArray.length; i++) {
60  			StringEntityNameInfoMapEntry entry = entryArray[i];
61  			resultMap.put(entry.key, entry.value);
62  		}
63  		return resultMap;
64  	}
65  }