View Javadoc

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