Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 125   Methods: 15
NCLOC: 86   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
SimpleTypeDef.java 71,4% 88,2% 86,7% 84,1%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.schema.element;
 11   
 
 12   
 import java.util.Set;
 13   
 
 14   
 import org.jbind.xml.base.IRef;
 15   
 import org.jbind.xml.core.cmp.IComponent;
 16   
 import org.jbind.xml.core.cmp.IComponentStore;
 17   
 import org.jbind.xml.core.type.IAnyType;
 18   
 import org.jbind.xml.msg.IConstraintViolations;
 19   
 import org.jbind.xml.msg.XmlException;
 20   
 import org.jbind.xml.msg.XmlMessages;
 21   
 import org.jbind.xml.schema.instantiation.IElemValHelper;
 22   
 import org.jbind.xml.schema.instantiation.IElementHelper;
 23   
 import org.jbind.xml.schema.instantiation.IJobRefs;
 24   
 import org.jbind.xml.schema.instantiation.ITopLevelElement;
 25   
 
 26   
 public class SimpleTypeDef extends TypeDef implements ISimpleTypeDef {
 27   
 
 28   
   private IVariety myVariety = null;
 29   
 
 30   
 
 31  291
   public SimpleTypeDef(CreationParams aCreationParams, String aRole) {
 32  291
     super(aCreationParams, aRole);
 33   
   }
 34   
 
 35   
 
 36  417
   public IElement doCreateChild(CreationParams aCreationParams) throws XmlException {
 37  417
     IElement res = null;
 38  417
     String componentName = NameUtil.getSchemaComponentName(aCreationParams);
 39  417
     if ("list".equals(componentName)) {
 40  39
       res = new ListVariety(aCreationParams);
 41  378
     } else if ("union".equals(componentName)) {
 42  31
       res = new UnionVariety(aCreationParams);
 43  347
     } else if ("restriction".equals(componentName)) {
 44  230
       res = new RestrictionVariety(aCreationParams);
 45   
     } else {
 46  117
       res = super.doCreateChild(aCreationParams);
 47   
     }
 48  414
     return res;
 49   
   }
 50   
 
 51   
 
 52  797
   public IVariety getVariety() {
 53  797
     return myVariety;
 54   
   }
 55   
 
 56   
 
 57  291
   public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
 58  291
     super.validateElement(aHelper, aViolations);
 59  291
     myVariety = (IVariety)getSubElement(IVariety.class, "variety", aViolations);
 60  291
     if (null == myVariety) {
 61  0
       aViolations.add(XmlMessages.missingVariety(this));
 62   
     }
 63   
   }
 64   
 
 65   
 
 66   
   //
 67   
   // implementation of IComponentJobHelper
 68   
   //
 69   
 
 70  269
   public void collectRefsForCreation(IJobRefs aJobRefs) {
 71  269
     getVariety().collectRefsForCreation(aJobRefs);
 72   
   }
 73   
 
 74  504
   public void collectRefsForCompletion(IElementHelper anElementHelper, IJobRefs aJobRefs) {}
 75   
 
 76  0
   public void collectRefsForValidation(IElementHelper anElementHelper, IJobRefs aJobRefs) {}
 77   
 
 78   
 
 79  250
   public IComponent createComponent(IElementHelper anElementHelper, IConstraintViolations aViolations) {
 80  250
     Set finalTypes = getFinalTypes();
 81  250
     if (null == finalTypes) {
 82  250
       finalTypes = getSchemaElement().getDefaultFinalTypes();
 83   
     }
 84  250
     IAnyType res = (IAnyType)getVariety().createComponent(anElementHelper, this, getTargetNamespace(), getName(), getRole(), finalTypes, aViolations);
 85  250
     res.setConstraints(res.getBaseType().getConstraints().shallowCopy());
 86  250
     return res;
 87   
   }
 88   
 
 89  250
   public void completeComponent(IElementHelper anElementHelper, IComponent aComponent, IConstraintViolations aViolations) {}
 90   
 
 91  250
   public void addSchemaData(IComponentStore aComponentStore, IComponent aComponent, IConstraintViolations aViolations) {
 92  250
     getVariety().addSchemaData(aComponentStore, aComponent, aViolations);
 93   
   }
 94   
 
 95  14
   public IRef getBaseRef() {
 96  14
     return getVariety().getBaseRef();
 97   
   }
 98   
 
 99  14
   public void collectConstraints(IAnyType aType, IConstraintViolations aViolations) {
 100  14
     getVariety().collectConstraints(aType, aViolations);
 101   
   }
 102   
 
 103  3
   public void redefine(ITopLevelElement aRedefinedElement, IConstraintViolations aViolations) {
 104  3
     if (myVariety instanceof IRestrictionVariety) {
 105  3
       IRestrictionVariety rv = (IRestrictionVariety)myVariety;
 106  3
       if (getGlobalRef().equals(rv.getBaseAttribute())) {
 107  3
         rv.setBaseAttribute(aRedefinedElement.getGlobalRef());
 108   
       } else {
 109  0
         aViolations.add(XmlMessages.baseTypeOfRedefinitionMustBeItself(getGlobalRef(), rv.getBaseAttribute(), this));
 110   
       }
 111   
     } else {
 112  0
       aViolations.add(XmlMessages.simpleTypeRedefinitionMustBeRestriction(this));
 113   
     }
 114   
   }
 115   
 
 116   
   private IRef myRedefinedRef = null;
 117  0
   public IRef getRedefinedRef() {
 118  0
     return myRedefinedRef;
 119   
   }
 120  3
   public void setRedefinedRef(IRef aRef) {
 121  3
     myRedefinedRef = aRef;
 122   
   }
 123   
 
 124   
 }
 125