Coverage Report - uk.co.badgersinfoil.asxsd.components.UnknownSimpleTypeComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
UnknownSimpleTypeComponent
56% 
100% 
1.75
 
 1  
 /*
 2  
  * Copyright (c) 2007 David Holroyd
 3  
  */
 4  
 
 5  
 package uk.co.badgersinfoil.asxsd.components;
 6  
 
 7  
 import org.eclipse.xsd.XSDConcreteComponent;
 8  
 import org.eclipse.xsd.XSDSimpleTypeDefinition;
 9  
 import org.eclipse.xsd.XSDVariety;
 10  
 import uk.co.badgersinfoil.asxsd.CodegenContext;
 11  
 import uk.co.badgersinfoil.asxsd.MappingFunction;
 12  
 import uk.co.badgersinfoil.asxsd.TypeDescriptor;
 13  
 import uk.co.badgersinfoil.metaas.dom.ASConstants;
 14  
 
 15  
 /**
 16  
  * Handles an unknown (by any other MappingComponent) simpleType by trying to
 17  
  * handle it as an instance of the type's base type.  Does not handle the
 18  
  * type if it doesn't have a distinct base-type.
 19  
  */
 20  16
 public class UnknownSimpleTypeComponent extends AbstractSimpleTypeComponent {
 21  
 
 22  
         protected TypeDescriptor typeDescriptorFor(CodegenContext context,
 23  
                                                       XSDSimpleTypeDefinition simpleType)
 24  
         {
 25  
                 try {
 26  235
                         return context.typeDescriptorFor(simpleType.getBaseTypeDefinition());
 27  0
                 } catch (RuntimeException e) {
 28  0
                         throw new RuntimeException("Exception handling "+simpleType+", looking for TypeDescriptor", e);
 29  
                 }
 30  
         }
 31  
 
 32  
         protected TypeDescriptor createTypeDescriptor(CodegenContext context,
 33  
                                                       XSDSimpleTypeDefinition simpleType)
 34  
         {
 35  0
                 String docs = "Value of type "+simpleType.getURI();
 36  0
                 return new TypeDescriptor(ASConstants.TYPE_STRING, false, docs, simpleType);
 37  
         }
 38  
 
 39  
         public MappingFunction functionFor(CodegenContext context, XSDConcreteComponent component) {
 40  174
                 XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition)component;
 41  174
                 return context.functionFor(simpleType.getBaseTypeDefinition());
 42  
         }
 43  
 
 44  
         protected boolean willAcceptType(XSDSimpleTypeDefinition simpleType) {
 45  607
                 return simpleType.getVariety() == XSDVariety.ATOMIC_LITERAL
 46  
                     && simpleType.getBaseTypeDefinition() != null
 47  
                     && simpleType.getBaseTypeDefinition() != simpleType;
 48  
         }
 49  
 }