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