Coverage Report - org.kuali.rice.core.api.util.jaxb.MultiValuedStringMapAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
MultiValuedStringMapAdapter
0%
0/9
0%
0/4
1.5
MultiValuedStringMapAdapter$MultiValuedStringMapEntry
0%
0/14
N/A
1.5
MultiValuedStringMapAdapter$MultiValuedStringMapEntryList
0%
0/10
0%
0/2
1.5
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.core.api.util.jaxb;
 17  
 
 18  
 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
 19  
 import org.w3c.dom.Element;
 20  
 
 21  
 import javax.xml.bind.annotation.XmlAccessType;
 22  
 import javax.xml.bind.annotation.XmlAccessorType;
 23  
 import javax.xml.bind.annotation.XmlAnyElement;
 24  
 import javax.xml.bind.annotation.XmlAttribute;
 25  
 import javax.xml.bind.annotation.XmlElement;
 26  
 import javax.xml.bind.annotation.XmlElementWrapper;
 27  
 import javax.xml.bind.annotation.XmlType;
 28  
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 29  
 import java.io.Serializable;
 30  
 import java.util.ArrayList;
 31  
 import java.util.Collection;
 32  
 import java.util.Collections;
 33  
 import java.util.List;
 34  
 import java.util.Map;
 35  
 
 36  
 /**
 37  
  * Do JAXB mapping of Map<String, String> to a format like the following for a
 38  
  * map containing { key1:value1, key2:value2 }:
 39  
  * 
 40  
  * <pre>
 41  
  * {@code
 42  
  * <...>
 43  
  *   <entry key="key1">value1</entry>
 44  
  *   <entry key="key2">value2</entry>
 45  
  * </...>
 46  
  * }
 47  
  * 
 48  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 49  
  *
 50  
  */
 51  0
 public class MultiValuedStringMapAdapter extends XmlAdapter<MultiValuedStringMapAdapter.MultiValuedStringMapEntryList, Map<String, List<String>>> {
 52  
 
 53  
         @Override
 54  
         public MultiValuedStringMapEntryList marshal(Map<String, List<String>> map) throws Exception {
 55  0
                 if (map == null) {
 56  0
                         return null;
 57  
                 }
 58  0
                 List<MultiValuedStringMapEntry> entries = new ArrayList<MultiValuedStringMapEntry>();
 59  0
                 for (Map.Entry<String, List<String>> entry : map.entrySet()) {
 60  0
                         entries.add(new MultiValuedStringMapEntry(entry));
 61  
                 }
 62  0
                 return new MultiValuedStringMapEntryList(entries);
 63  
         }
 64  
 
 65  
     @Override
 66  
     public Map<String, List<String>> unmarshal(MultiValuedStringMapEntryList multiValuedStringMapEntryList) throws Exception {
 67  0
         return null;  //To change body of implemented methods use File | Settings | File Templates.
 68  
     }
 69  
 
 70  
 //    @Override
 71  
 //        public Map<String, List<String>> unmarshal(MultiValuedStringMapEntryList entryList) throws Exception {
 72  
 //                if (entryList == null || entryList.getEntries() == null) {
 73  
 //                        return null;
 74  
 //                }
 75  
 //                List<MultiValuedStringMapEntry> entries = entryList.getEntries();
 76  
 //                Map<String, List<String>> resultMap = new HashMap<String, List<String>>(entries.size());
 77  
 //                for (MultiValuedStringMapEntry entry : entries) {
 78  
 //                        resultMap.put(entry.getKey(), entry.getValues());
 79  
 //                }
 80  
 //                return Collections.unmodifiableMap(resultMap);
 81  
 //        }
 82  
 
 83  
     /**
 84  
     * Created by IntelliJ IDEA.
 85  
     * User: ewestfal
 86  
     * Date: 7/29/11
 87  
     * Time: 2:49 PM
 88  
     * To change this template use File | Settings | File Templates.
 89  
     */
 90  
     @XmlAccessorType(XmlAccessType.NONE)
 91  
     @XmlType(name = "MultiValuedStringMapEntryType")
 92  
     public static final class MultiValuedStringMapEntry implements Serializable {
 93  
 
 94  
         private static final long serialVersionUID = -9609663434312103L;
 95  
 
 96  
         @XmlAttribute(name = "key")
 97  
         private final String key;
 98  
 
 99  
         @XmlElementWrapper(name = "values")
 100  
         @XmlElement(name = "value")
 101  
         private final List<String> values;
 102  
 
 103  
         /**
 104  
          * Used only by JAXB.
 105  
          */
 106  
         @SuppressWarnings("unused")
 107  0
         MultiValuedStringMapEntry() {
 108  0
             this.key = null;
 109  0
             this.values = null;
 110  0
         }
 111  
 
 112  0
         public MultiValuedStringMapEntry(String key, List<String> values) {
 113  0
             this.key = key;
 114  0
             this.values = values;
 115  0
         }
 116  
 
 117  0
         public MultiValuedStringMapEntry(Map.Entry<String, List<String>> entry) {
 118  0
             this.key = entry.getKey();
 119  0
             this.values = new ArrayList<String>(entry.getValue());
 120  0
         }
 121  
 
 122  
         public String getKey() {
 123  0
             return this.key;
 124  
         }
 125  
 
 126  
         public List<String> getValues() {
 127  0
             return this.values;
 128  
         }
 129  
 
 130  
     }
 131  
 
 132  
     /**
 133  
     * Created by IntelliJ IDEA.
 134  
     * User: ewestfal
 135  
     * Date: 7/29/11
 136  
     * Time: 2:49 PM
 137  
     * To change this template use File | Settings | File Templates.
 138  
     */
 139  0
     @XmlAccessorType(XmlAccessType.FIELD)
 140  
     @XmlType(name = "MultiValuedStringMapEntryListType")
 141  
     public static class MultiValuedStringMapEntryList extends AbstractDataTransferObject {
 142  
 
 143  
         private static final long serialVersionUID = 1L;
 144  
 
 145  
         @XmlElement(name = "entry")
 146  
         private final List<MultiValuedStringMapEntry> entries;
 147  
 
 148  0
         @SuppressWarnings("unused") @XmlAnyElement
 149  
         private final Collection<Element> _futureElements = null;
 150  
 
 151  
         @SuppressWarnings("unused")
 152  0
         MultiValuedStringMapEntryList() {
 153  0
             this.entries = null;
 154  0
         }
 155  
 
 156  0
         public MultiValuedStringMapEntryList(List<MultiValuedStringMapEntry> entries) {
 157  0
             this.entries = new ArrayList<MultiValuedStringMapEntry>(entries);
 158  0
         }
 159  
 
 160  
         /**
 161  
          * @return the attribute
 162  
          */
 163  
         public List<MultiValuedStringMapEntry> getEntries() {
 164  0
             if (this.entries == null) {
 165  0
                 return Collections.emptyList();
 166  
             }
 167  0
             return Collections.unmodifiableList(entries);
 168  
         }
 169  
     }
 170  
 }