Coverage Report - org.kuali.student.common.dictionary.service.jaxws.ObjStructXmlTypeAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
ObjStructXmlTypeAdapter
0%
0/18
0%
0/12
3.333
 
 1  
 package org.kuali.student.common.dictionary.service.jaxws;
 2  
 
 3  
 import java.util.HashMap;
 4  
 import java.util.Map;
 5  
 
 6  
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 7  
 
 8  
 import org.kuali.student.common.dictionary.dto.DataType;
 9  
 import org.kuali.student.common.dictionary.dto.FieldDefinition;
 10  
 import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
 11  
 
 12  0
 public class ObjStructXmlTypeAdapter extends XmlAdapter<ObjectStructureDefinitionWrapper, ObjectStructureDefinition> {
 13  
 
 14  
         @Override
 15  
         public ObjectStructureDefinitionWrapper marshal(ObjectStructureDefinition objStruct)
 16  
                         throws Exception {
 17  0
                 ObjectStructureDefinitionWrapper wrapper = new ObjectStructureDefinitionWrapper();
 18  
                 
 19  0
                 wrapper.setRootDefinitionName(objStruct.getName());
 20  
                 
 21  0
                 Map<String,ObjectStructureDefinition> objStructDefMap = parseNestedDefinitions(objStruct, new HashMap<String,ObjectStructureDefinition>());
 22  
                 
 23  0
                 wrapper.getDefinitions().addAll(objStructDefMap.values());
 24  
                 
 25  0
                 return wrapper;
 26  
         }
 27  
 
 28  
 
 29  
         @Override
 30  
         public ObjectStructureDefinition unmarshal(
 31  
                         ObjectStructureDefinitionWrapper wrapper) throws Exception {
 32  0
                 String rootDefinitionName = wrapper.getRootDefinitionName();
 33  0
                 if(rootDefinitionName!=null){
 34  0
                         for(ObjectStructureDefinition objStruct : wrapper.getDefinitions()){
 35  0
                                 if(rootDefinitionName.equals(objStruct.getName())){
 36  0
                                         return objStruct;
 37  
                                 }
 38  
                         }
 39  
                 }
 40  0
                 return null;
 41  
         }
 42  
 
 43  
         private Map<String,ObjectStructureDefinition> parseNestedDefinitions(ObjectStructureDefinition objStruct, Map<String, ObjectStructureDefinition> objStructDefMap) {
 44  
                 //See if this type was already parsed, if not, add to the list of nested structures and recurse
 45  0
                 if(!objStructDefMap.containsKey(objStruct.getName())){
 46  0
                         objStructDefMap.put(objStruct.getName(), objStruct);
 47  
                         
 48  
                         //Loop through all field definitions and check for complex types
 49  0
                         for(FieldDefinition fd:objStruct.getAttributes()){
 50  0
                                 if(DataType.COMPLEX.equals(fd.getDataType())){
 51  0
                                         parseNestedDefinitions(fd.getDataObjectStructure(), objStructDefMap);
 52  
                                 }
 53  
                         }
 54  
                 }
 55  0
                 return objStructDefMap;
 56  
         }
 57  
 
 58  
 }