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