Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 143   Methods: 11
NCLOC: 112   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
UnionVariety.java 68,2% 82,2% 81,8% 78,2%
 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.ArrayList;
 13   
 import java.util.Enumeration;
 14   
 import java.util.Iterator;
 15   
 import java.util.List;
 16   
 import java.util.Set;
 17   
 import java.util.StringTokenizer;
 18   
 
 19   
 import org.jbind.xml.base.IAttribute;
 20   
 import org.jbind.xml.base.IQName;
 21   
 import org.jbind.xml.base.IRef;
 22   
 import org.jbind.xml.base.ISymbolspaces;
 23   
 import org.jbind.xml.base.QName;
 24   
 import org.jbind.xml.core.cmp.IComponent;
 25   
 import org.jbind.xml.core.cmp.IComponentStore;
 26   
 import org.jbind.xml.core.cmp.ISourceInfo;
 27   
 import org.jbind.xml.core.type.IAnyType;
 28   
 import org.jbind.xml.core.type.ISimpleType;
 29   
 import org.jbind.xml.msg.IConstraintViolations;
 30   
 import org.jbind.xml.msg.XmlException;
 31   
 import org.jbind.xml.msg.XmlMessages;
 32   
 import org.jbind.xml.schema.cmp.UnionType;
 33   
 import org.jbind.xml.schema.cmp.W3CTypes;
 34   
 import org.jbind.xml.schema.instantiation.IComponentSetter;
 35   
 import org.jbind.xml.schema.instantiation.IElementHelper;
 36   
 import org.jbind.xml.schema.instantiation.IJobRefs;
 37   
 
 38   
 public class UnionVariety extends Variety implements IUnionVariety {
 39   
 
 40   
   private List myRefMemberTypes = new ArrayList();
 41   
   private int myAnonymousMemberCounter = 0;
 42   
 
 43  31
   public UnionVariety(CreationParams aCreationParams) {
 44  31
     super(aCreationParams);
 45   
   }
 46   
 
 47   
 
 48  47
   public Iterator iterMemberTypes() {
 49  47
     return myRefMemberTypes.iterator();
 50   
   }
 51   
 
 52   
 
 53  23
   public Iterator iterSimpleTypeDefs() {
 54  23
     return iterChildrenByClass(ISimpleTypeDef.class);
 55   
   }
 56   
 
 57  21
   protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
 58  21
     IAttribute res = null;
 59  21
     String an = NameUtil.getSchemaAttributeName(anACParams);
 60  21
     if ("memberTypes".equals(an)) {
 61  21
       res = new Attribute(anACParams);
 62  21
       for (Enumeration e = new StringTokenizer(res.getStringValue(), " ");
 63  46
               e.hasMoreElements(); ) {
 64  25
         String s = (String)e.nextElement();
 65  25
         IQName qn = QName.create(s, anACParams.prefixMappings);
 66  25
         if (null == qn) {
 67  0
           throw new XmlException(XmlMessages.invalidQNameForMemberType(s, this));
 68   
         }
 69  25
         IRef ref = createGlobalRef(qn, ISymbolspaces.TYPE);
 70  25
         if (null == ref) {
 71  0
           throw new XmlException(XmlMessages.unknownNamespacePrefixInQName(s, this));
 72   
         }
 73  25
         myRefMemberTypes.add(ref);
 74   
       }
 75   
 
 76   
     } else {
 77  0
       res = super.doCreateAttribute(anACParams);
 78   
     }
 79  21
     return res;
 80   
   }
 81   
 
 82  28
   protected IElement doCreateChild(CreationParams aCreationParams) throws XmlException {
 83  28
     IElement res = null;
 84  28
     String componentName = NameUtil.getSchemaComponentName(aCreationParams);
 85  28
     if ("simpleType".equals(componentName)) {
 86  28
       res = new SimpleTypeDef(aCreationParams, "Member" + myAnonymousMemberCounter++);
 87   
     } else {
 88  0
       res = super.doCreateChild(aCreationParams);
 89   
     }
 90  28
     return res;
 91   
   }
 92   
 
 93   
 
 94  24
   public void collectRefsForCreation(IJobRefs aJobRefs) {
 95  24
     for (Iterator i = iterMemberTypes(); i.hasNext(); ) {
 96  18
       aJobRefs.add((IRef)i.next(), true, this);
 97   
     }
 98   
   }
 99   
 
 100  23
   public IComponent createComponent(IElementHelper anElementHelper, ISourceInfo aSourceInfo, String aNamespace, String aName, String aRole, Set aFinalTypes, IConstraintViolations aViolations) {
 101  23
     final UnionType res = new UnionType(aSourceInfo, aNamespace, aName, aRole, aFinalTypes);
 102  23
     for (Iterator i = iterMemberTypes(); i.hasNext(); ) {
 103  16
       IRef globalRef = (IRef)i.next();
 104  16
       IComponent c = anElementHelper.getComponent(globalRef, true);
 105  16
       if (c instanceof ISimpleType) {
 106  16
         ISimpleType t = (ISimpleType)c;
 107  16
         if (t == W3CTypes.notation) {
 108  0
           aViolations.add(XmlMessages.notationTypeMustNotBeUsedDirectly(this));
 109   
         } else {
 110  16
           res.addMemberType(t, aViolations);
 111   
         }
 112   
       } else {
 113  0
         aViolations.add(XmlMessages.referencedMemberTypeMustBeSimple(globalRef, this));
 114   
       }
 115   
     }
 116  23
     int idx = 0;
 117  23
     for (Iterator i = iterSimpleTypeDefs(); i.hasNext(); ) {
 118   
       // TODO the sequence of the inlined member types should be preserved when
 119   
       // they are added as memeber types.
 120  28
       ISimpleTypeDef std = (ISimpleTypeDef)i.next();
 121  28
       anElementHelper.addSubJob(std, new IComponentSetter() {
 122  28
         public void set(IComponent aComponent, IConstraintViolations aVls) {
 123  28
           if (aComponent instanceof ISimpleType) {
 124  28
             res.addMemberType((ISimpleType)aComponent, aVls);
 125   
           } else {
 126  0
             aVls.add(XmlMessages.inlinedMemberTypeMustBeSimple(aComponent));
 127   
           }
 128   
         }
 129   
       });
 130   
     }
 131  23
     return res;
 132   
   }
 133   
 
 134  23
   public void addSchemaData(IComponentStore aComponentStore, IComponent aComponent, IConstraintViolations aViolations) {}
 135   
 
 136  0
   public IRef getBaseRef() {
 137  0
     return W3CTypes.anySimpleType.getGlobalRef();
 138   
   }
 139   
 
 140  0
   public void collectConstraints(IAnyType aType, IConstraintViolations aViolations) {}
 141   
 
 142   
 }
 143