Coverage Report - uk.co.badgersinfoil.asxsd.MappingCodeGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
MappingCodeGenerator
64% 
100% 
1.25
 
 1  
 /*
 2  
  * Copyright (c) 2006 David Holroyd
 3  
  */
 4  
 
 5  
 package uk.co.badgersinfoil.asxsd;
 6  
 
 7  
 
 8  
 import java.io.IOException;
 9  
 import java.util.Iterator;
 10  
 import java.util.List;
 11  
 import org.eclipse.xsd.XSDComplexTypeDefinition;
 12  
 import org.eclipse.xsd.XSDConcreteComponent;
 13  
 import org.eclipse.xsd.XSDSchema;
 14  
 import org.eclipse.xsd.XSDTypeDefinition;
 15  
 import uk.co.badgersinfoil.metaas.ActionScriptFactory;
 16  
 import uk.co.badgersinfoil.metaas.ActionScriptProject;
 17  
 
 18  
 
 19  
 public class MappingCodeGenerator {
 20  15
         private TypeNameGenerator nameGen = new TypeNameGenerator();
 21  
         private UnmarshalBuilder unmarshalerBuilder;
 22  
         private MarshalBuilder marshalerBuilder;
 23  
         private TypeBuilder typeBuilder;
 24  
         private CodegenContext context;
 25  
 
 26  15
         public MappingCodeGenerator(ActionScriptFactory factory, ActionScriptProject project) {
 27  15
                 MappingRegistry reg = MappingRegistryFactory.createMappingRegistry();
 28  15
                 BaseCodegenContext ctxt = new BaseCodegenContext(reg, factory, project);
 29  
 
 30  15
                 typeBuilder = new TypeBuilder(ctxt, nameGen);
 31  15
                 ctxt.setTypeBuilder(typeBuilder);
 32  
 
 33  15
                 unmarshalerBuilder = new UnmarshalBuilder(project, ctxt);
 34  15
                 ctxt.setUnmarshalBuilder(unmarshalerBuilder);
 35  
 
 36  15
                 marshalerBuilder = new MarshalBuilder(project, ctxt);
 37  15
                 ctxt.setMarshalBuilder(marshalerBuilder);
 38  15
                 context = ctxt;
 39  15
         }
 40  
 
 41  
         public void processSchema(XSDSchema schema) throws IOException {
 42  15
                 processSchemaCreateTypes(schema);
 43  15
                 unmarshalerBuilder.processSchema(schema);
 44  15
                 marshalerBuilder.processSchema(schema);
 45  15
         }
 46  
 
 47  
         private void processSchemaCreateTypes(XSDSchema schema) throws IOException {
 48  15
                 List types = schema.getTypeDefinitions();
 49  15
                 for (Iterator i = types.iterator(); i.hasNext(); ) {
 50  19
                         XSDTypeDefinition typeDef = (XSDTypeDefinition)i.next();
 51  19
                         if (typeDef instanceof XSDComplexTypeDefinition) {
 52  17
                                 context.typeDescriptorFor(typeDef);
 53  
                         }
 54  19
                 }
 55  15
         }
 56  
 
 57  
         public UnmarshalBuilder getUnmarshalerBuilder() {
 58  0
                 return unmarshalerBuilder;
 59  
         }
 60  
 
 61  
         public MarshalBuilder getMarshalerBuilder() {
 62  0
                 return marshalerBuilder;
 63  
         }
 64  
         
 65  
         public MappingFunction marshalMethodFor(XSDConcreteComponent component) {
 66  0
                 context.pushAttrScope();
 67  0
                 context.setCurrentRole(CodegenRole.MARSHAL);
 68  0
                 MappingFunction fn = context.functionFor(component);
 69  0
                 context.popAttrScope();
 70  0
                 return fn;
 71  
         }
 72  
         
 73  
         public MappingFunction unmarshalMethodFor(XSDConcreteComponent component) {
 74  0
                 context.pushAttrScope();
 75  0
                 context.setCurrentRole(CodegenRole.UNMARSHAL);
 76  0
                 MappingFunction fn = context.functionFor(component);
 77  0
                 context.popAttrScope();
 78  0
                 return fn;
 79  
         }
 80  
 
 81  
         public TypeDescriptor typeDescriptorFor(XSDConcreteComponent component) {
 82  0
                 return context.typeDescriptorFor(component);
 83  
         }
 84  
 }