View Javadoc

1   /**
2    * Copyright 2005-2013 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.identity.principal;
17  
18  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
19  import org.w3c.dom.Element;
20  
21  import javax.xml.bind.annotation.XmlAnyElement;
22  import javax.xml.bind.annotation.XmlAttribute;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.adapters.XmlAdapter;
25  import java.util.Collection;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  /**
30   * Do jax-ws mapping of Map<String, String> for KIM service method parameters, etc.
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   *
34   */
35  public class StringToKimEntityNamePrincipalInfoMapAdapter extends XmlAdapter<StringToKimEntityNamePrincipalInfoMapAdapter.StringEntNmPrncpInfoMapEntry[], Map<String, EntityNamePrincipalName>> {
36  
37  	/**
38  	 * This overridden method ...
39  	 * 
40  	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
41  	 */
42  	@Override
43  	public StringEntNmPrncpInfoMapEntry[] marshal(Map<String, EntityNamePrincipalName> map) throws Exception {
44  		if(null == map) return null;
45  		StringEntNmPrncpInfoMapEntry[] entryArray = new StringEntNmPrncpInfoMapEntry[map.size()];
46  		int i = 0;
47  		for (Map.Entry<String, EntityNamePrincipalName> e : map.entrySet()) {
48  			entryArray[i] = new StringEntNmPrncpInfoMapEntry(e.getKey(), e.getValue());
49  			i++;
50  		}
51  		return entryArray;
52  	}
53  
54  	/**
55  	 * This overridden method ...
56  	 * 
57  	 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
58  	 */
59  	@Override
60  	public Map<String, EntityNamePrincipalName> unmarshal(StringEntNmPrncpInfoMapEntry[] entryArray) throws Exception {
61  		if (null == entryArray) return null;
62  		Map<String, EntityNamePrincipalName> resultMap = new HashMap<String, EntityNamePrincipalName>(entryArray.length);
63  		for (int i = 0; i < entryArray.length; i++) {
64  			StringEntNmPrncpInfoMapEntry entry = entryArray[i];
65  			resultMap.put(entry.getKey(), entry.getValue());
66  		}
67  		return resultMap;
68  	}
69  
70      public static class StringEntNmPrncpInfoMapEntry extends AbstractDataTransferObject {
71  
72          private static final long serialVersionUID = 1L;
73  
74          @XmlAttribute
75          private final String key;
76  
77          @XmlElement(required=true)
78          private final EntityNamePrincipalName value;
79  
80          @SuppressWarnings("unused")
81          @XmlAnyElement
82          private final Collection<Element> _futureElements = null;
83  
84          /**
85           * Private constructor used only by JAXB.
86           */
87          private StringEntNmPrncpInfoMapEntry() {
88              key = null;
89              value = null;
90          }
91  
92          public StringEntNmPrncpInfoMapEntry(String key, EntityNamePrincipalName value) {
93              super();
94  
95              this.key = key;
96              this.value = value;
97          }
98  
99          public String getKey() {
100             return key;
101         }
102 
103         public EntityNamePrincipalName getValue() {
104             return value;
105         }
106     }
107 }