001/** 002 * Copyright 2005-2016 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.kew.framework.actionlist; 017 018import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 019import org.kuali.rice.kew.api.action.ActionItemCustomization; 020import org.w3c.dom.Element; 021 022import javax.xml.bind.annotation.XmlAnyElement; 023import javax.xml.bind.annotation.XmlAttribute; 024import javax.xml.bind.annotation.XmlElement; 025import javax.xml.bind.annotation.adapters.XmlAdapter; 026import java.util.Collection; 027import java.util.HashMap; 028import java.util.Map; 029 030/** 031 * Do jax-ws mapping of Map<String, ActionItemCustomization> for KIM service method parameters, etc. 032 * 033 * @author Kuali Rice Team (rice.collab@kuali.org) 034 * 035 */ 036public class MapStringActionItemCustomizationAdapter extends XmlAdapter<MapStringActionItemCustomizationAdapter.StringActionItemCustomizationMapEntry[], Map<String, ActionItemCustomization>> { 037 038 /** 039 * converts the map to an array 040 * 041 * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object) 042 */ 043 @Override 044 public StringActionItemCustomizationMapEntry[] marshal(Map<String, ActionItemCustomization> map) throws Exception { 045 if(null == map) return null; 046 StringActionItemCustomizationMapEntry[] entryArray = new StringActionItemCustomizationMapEntry[map.size()]; 047 int i = 0; 048 for (Map.Entry<String, ActionItemCustomization> e : map.entrySet()) { 049 entryArray[i] = new StringActionItemCustomizationMapEntry(e.getKey(), e.getValue()); 050 i++; 051 } 052 return entryArray; 053 } 054 055 /** 056 * converts the array back to a map 057 * 058 * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object) 059 */ 060 @Override 061 public Map<String, ActionItemCustomization> unmarshal(StringActionItemCustomizationMapEntry[] entryArray) throws Exception { 062 if (null == entryArray) return null; 063 Map<String, ActionItemCustomization> resultMap = new HashMap<String, ActionItemCustomization>(entryArray.length); 064 for (int i = 0; i < entryArray.length; i++) { 065 StringActionItemCustomizationMapEntry entry = entryArray[i]; 066 resultMap.put(entry.getKey(), entry.getValue()); 067 } 068 return resultMap; 069 } 070 071 public static class StringActionItemCustomizationMapEntry extends AbstractDataTransferObject { 072 073 private static final long serialVersionUID = 1L; 074 075 @XmlAttribute 076 private final String key; 077 078 @XmlElement(required=true) 079 private final ActionItemCustomization value; 080 081 @SuppressWarnings("unused") 082 @XmlAnyElement 083 private final Collection<Element> _futureElements = null; 084 085 /** 086 * constructor used by JAXB. 087 */ 088 public StringActionItemCustomizationMapEntry() { 089 key = null; 090 value = null; 091 } 092 093 public StringActionItemCustomizationMapEntry(String key, ActionItemCustomization value) { 094 super(); 095 096 this.key = key; 097 this.value = value; 098 } 099 100 public String getKey() { 101 return key; 102 } 103 104 public ActionItemCustomization getValue() { 105 return value; 106 } 107 } 108}