001/**
002 * Copyright 2005-2014 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 */
016package org.kuali.rice.kim.api.identity.name;
017
018import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
019import org.w3c.dom.Element;
020
021import javax.xml.bind.annotation.XmlAnyElement;
022import javax.xml.bind.annotation.XmlAttribute;
023import javax.xml.bind.annotation.XmlElement;
024import javax.xml.bind.annotation.adapters.XmlAdapter;
025import java.util.Collection;
026import java.util.HashMap;
027import 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 */
035public class StringToKimEntityNameInfoMapAdapter extends XmlAdapter<StringToKimEntityNameInfoMapAdapter.StringEntityNameInfoMapEntry[], Map<String, EntityName>> {
036
037        /**
038         * This overridden method ...
039         * 
040         * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
041         */
042        @Override
043        public StringEntityNameInfoMapEntry[] marshal(Map<String, EntityName> map) throws Exception {
044                if(null == map) return null;
045                StringEntityNameInfoMapEntry[] entryArray = new StringEntityNameInfoMapEntry[map.size()];
046                int i = 0;
047                for (Map.Entry<String, EntityName> e : map.entrySet()) {
048                        entryArray[i] = new StringEntityNameInfoMapEntry(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, EntityName> unmarshal(StringEntityNameInfoMapEntry[] entryArray) throws Exception {
061                if (null == entryArray) return null;
062                Map<String, EntityName> resultMap = new HashMap<String, EntityName>(entryArray.length);
063                for (int i = 0; i < entryArray.length; i++) {
064                        StringEntityNameInfoMapEntry entry = entryArray[i];
065                        resultMap.put(entry.getKey(), entry.getValue());
066                }
067                return resultMap;
068        }
069
070    public static class StringEntityNameInfoMapEntry 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 EntityName 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        public StringEntityNameInfoMapEntry() {
088            key = null;
089            value = null;
090        }
091
092        public StringEntityNameInfoMapEntry(String key, EntityName 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 EntityName getValue() {
104            return value;
105        }
106    }
107}