Coverage Report - org.kuali.rice.kim.api.jaxb.NameAndNamespacePairToKimTypeIdAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
NameAndNamespacePairToKimTypeIdAdapter
0%
0/13
0%
0/8
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.kim.api.jaxb;
 17  
 
 18  
 import javax.xml.bind.MarshalException;
 19  
 import javax.xml.bind.UnmarshalException;
 20  
 import javax.xml.bind.annotation.adapters.NormalizedStringAdapter;
 21  
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.kuali.rice.core.util.jaxb.NameAndNamespacePair;
 25  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 26  
 import org.kuali.rice.kim.api.type.KimTypeContract;
 27  
 
 28  
 /**
 29  
  * An XML adapter that converts between a NameAndNamespacePair and a KIM type ID.
 30  
  * 
 31  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 32  
  */
 33  0
 public class NameAndNamespacePairToKimTypeIdAdapter extends XmlAdapter<NameAndNamespacePair,String> {
 34  
 
 35  
     /**
 36  
      * @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
 37  
      */
 38  
     @Override
 39  
     public String unmarshal(NameAndNamespacePair v) throws Exception {
 40  0
         if (v != null) {
 41  0
             KimTypeContract kimType = KimApiServiceLocator.getKimTypeInfoService().findKimTypeByNameAndNamespace(
 42  
                     v.getNamespaceCode(), new NormalizedStringAdapter().unmarshal(v.getName()));
 43  0
             if (kimType == null) {
 44  0
                 throw new UnmarshalException("Cannot find KIM Type with namespace \"" + v.getNamespaceCode() + "\" and name \"" + v.getName() + "\"");
 45  
             }
 46  0
             return kimType.getId();
 47  
         }
 48  0
         return null;
 49  
     }
 50  
 
 51  
     /**
 52  
      * @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
 53  
      */
 54  
     @Override
 55  
     public NameAndNamespacePair marshal(String v) throws Exception {
 56  0
         if (v != null) {
 57  0
             KimTypeContract kimType = KimApiServiceLocator.getKimTypeInfoService().getKimType(StringUtils.trim(v));
 58  0
             if (kimType == null) {
 59  0
                 throw new MarshalException("Cannot find KIM Type with ID \"" + v + "\"");
 60  
             }
 61  0
             return new NameAndNamespacePair(kimType.getNamespaceCode(), kimType.getName());
 62  
         }
 63  0
         return null;
 64  
     }
 65  
 
 66  
 }