Coverage Report - org.kuali.rice.kew.api.doctype.DocumentTypePolicyMapAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentTypePolicyMapAdapter
100%
14/14
70%
7/10
3.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.kew.api.doctype;
 17  
 
 18  
 import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter;
 19  
 
 20  
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 21  
 import java.util.ArrayList;
 22  
 import java.util.HashMap;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 /**
 27  
  * TODO...
 28  
  * 
 29  
  * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 30  
  *
 31  
  */
 32  5
 class DocumentTypePolicyMapAdapter extends XmlAdapter<MapStringStringAdapter.StringMapEntryList, Map<DocumentTypePolicy, String>> {
 33  
 
 34  
         @Override
 35  
         public MapStringStringAdapter.StringMapEntryList marshal(Map<DocumentTypePolicy, String> map) {
 36  1
             List<MapStringStringAdapter.StringMapEntry> entries = new ArrayList<MapStringStringAdapter.StringMapEntry>();
 37  1
             if (map != null) {
 38  1
                 for (DocumentTypePolicy policy : map.keySet()) {
 39  1
                     entries.add(new MapStringStringAdapter.StringMapEntry(policy.getCode(), map.get(policy)));
 40  
                 }
 41  
             }
 42  1
             return new MapStringStringAdapter.StringMapEntryList(entries);
 43  
         }
 44  
 
 45  
         @Override
 46  
         public Map<DocumentTypePolicy, String> unmarshal(MapStringStringAdapter.StringMapEntryList entryList) {
 47  2
             Map<DocumentTypePolicy, String> policies = new HashMap<DocumentTypePolicy, String>();
 48  2
             if (entryList != null) {
 49  2
                 for (MapStringStringAdapter.StringMapEntry entry : entryList.getEntries()) {
 50  2
                     DocumentTypePolicy policy = DocumentTypePolicy.fromCode(entry.getKey());
 51  
                     // if the policy value comes back as null, that means we recieved a policy that we
 52  
                     // don't understand...ignore it
 53  2
                     if (policy != null) {
 54  2
                         policies.put(policy, entry.getValue());
 55  
                     }
 56  2
                 }
 57  
             }
 58  2
             return policies;
 59  
         }
 60  
         
 61  
 }