001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kim.api.identity.principal;
017
018 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
019 import org.w3c.dom.Element;
020
021 import javax.xml.bind.annotation.XmlAnyElement;
022 import javax.xml.bind.annotation.XmlAttribute;
023 import javax.xml.bind.annotation.XmlElement;
024 import javax.xml.bind.annotation.adapters.XmlAdapter;
025 import java.util.Collection;
026 import java.util.HashMap;
027 import java.util.Map;
028
029 /**
030 * Do jax-ws mapping of Map<String, String> for KIM service method parameters, etc.
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 *
034 */
035 public class StringToKimEntityNamePrincipalInfoMapAdapter extends XmlAdapter<StringToKimEntityNamePrincipalInfoMapAdapter.StringEntNmPrncpInfoMapEntry[], Map<String, EntityNamePrincipalName>> {
036
037 /**
038 * This overridden method ...
039 *
040 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
041 */
042 @Override
043 public StringEntNmPrncpInfoMapEntry[] marshal(Map<String, EntityNamePrincipalName> map) throws Exception {
044 if(null == map) return null;
045 StringEntNmPrncpInfoMapEntry[] entryArray = new StringEntNmPrncpInfoMapEntry[map.size()];
046 int i = 0;
047 for (Map.Entry<String, EntityNamePrincipalName> e : map.entrySet()) {
048 entryArray[i] = new StringEntNmPrncpInfoMapEntry(e.getKey(), e.getValue());
049 i++;
050 }
051 return entryArray;
052 }
053
054 /**
055 * This overridden method ...
056 *
057 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
058 */
059 @Override
060 public Map<String, EntityNamePrincipalName> unmarshal(StringEntNmPrncpInfoMapEntry[] entryArray) throws Exception {
061 if (null == entryArray) return null;
062 Map<String, EntityNamePrincipalName> resultMap = new HashMap<String, EntityNamePrincipalName>(entryArray.length);
063 for (int i = 0; i < entryArray.length; i++) {
064 StringEntNmPrncpInfoMapEntry entry = entryArray[i];
065 resultMap.put(entry.getKey(), entry.getValue());
066 }
067 return resultMap;
068 }
069
070 public static class StringEntNmPrncpInfoMapEntry extends AbstractDataTransferObject {
071
072 private static final long serialVersionUID = 1L;
073
074 @XmlAttribute
075 private final String key;
076
077 @XmlElement(required=true)
078 private final EntityNamePrincipalName value;
079
080 @SuppressWarnings("unused")
081 @XmlAnyElement
082 private final Collection<Element> _futureElements = null;
083
084 /**
085 * Private constructor used only by JAXB.
086 */
087 private StringEntNmPrncpInfoMapEntry() {
088 key = null;
089 value = null;
090 }
091
092 public StringEntNmPrncpInfoMapEntry(String key, EntityNamePrincipalName value) {
093 super();
094
095 this.key = key;
096 this.value = value;
097 }
098
099 public String getKey() {
100 return key;
101 }
102
103 public EntityNamePrincipalName getValue() {
104 return value;
105 }
106 }
107 }