Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 128   Methods: 14
NCLOC: 96   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
ModelGroupDeclaration.java 75% 82,1% 78,6% 79,5%
 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.Iterator;
 13   
 
 14   
 import org.jbind.xml.base.IRef;
 15   
 import org.jbind.xml.base.ISymbolspace;
 16   
 import org.jbind.xml.base.ISymbolspaces;
 17   
 import org.jbind.xml.core.cmp.IComponent;
 18   
 import org.jbind.xml.core.cmp.IComponentStore;
 19   
 import org.jbind.xml.msg.IConstraintViolations;
 20   
 import org.jbind.xml.msg.XmlException;
 21   
 import org.jbind.xml.msg.XmlMessages;
 22   
 import org.jbind.xml.schema.instantiation.IElemValHelper;
 23   
 import org.jbind.xml.schema.instantiation.IElementHelper;
 24   
 import org.jbind.xml.schema.instantiation.IJobRefs;
 25   
 import org.jbind.xml.schema.instantiation.ITopLevelElement;
 26   
 
 27   
 public class ModelGroupDeclaration extends GroupDeclaration implements IModelGroupDeclaration {
 28   
 
 29   
   private IModelGroup myModelGroup = null;
 30   
 
 31  36
   public ModelGroupDeclaration(CreationParams aCreationParams) {
 32  36
     super(aCreationParams);
 33   
   }
 34   
 
 35  46
   protected IElement doCreateChild(CreationParams aCreationParams) throws XmlException {
 36  46
     IElement res = null;
 37  46
     String componentName = NameUtil.getSchemaComponentName(aCreationParams);
 38  46
     if ("all".equals(componentName)) {
 39  0
       res = new AllModelGroup(aCreationParams);
 40  46
     } else if ("choice".equals(componentName)) {
 41  20
       res = new ChoiceModelGroup(aCreationParams);
 42  26
     } else if ("sequence".equals(componentName)) {
 43  16
       res = new SequenceModelGroup(aCreationParams);
 44   
     } else {
 45  10
       res = super.doCreateChild(aCreationParams);
 46   
     }
 47  46
     return res;
 48   
   }
 49   
 
 50  0
   public IModelGroup getModelGroup() {
 51  0
     return myModelGroup;
 52   
   }
 53   
 
 54  60
   public ISymbolspace getSymbolSpace() {
 55  60
     return ISymbolspaces.ELEMENT_GROUP;
 56   
   }
 57   
 
 58  36
   public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
 59  36
     super.validateElement(aHelper, aViolations);
 60  36
     Iterator i = iterChildrenByClass(IModelGroup.class);
 61  36
     if (i.hasNext()) {
 62  36
       myModelGroup = (IModelGroup)i.next();
 63  36
       if (i.hasNext()) {
 64  0
         aViolations.add(XmlMessages.moreThanOneModelGroup(this));
 65   
       }
 66   
     } else {
 67  0
       aViolations.add(XmlMessages.missingModelGroup(this));
 68   
     }
 69   
   }
 70   
 
 71   
   //
 72   
   // Implementation of IComponentJobHelper
 73   
   //
 74   
 
 75  36
   public void collectRefsForCreation(IJobRefs aJobRefs) {
 76  36
     myModelGroup.collectRefsForCreation(aJobRefs);
 77   
   }
 78   
 
 79  72
   public void collectRefsForCompletion(IElementHelper anElementHelper, IJobRefs aJobRefs) {
 80  72
     myModelGroup.collectRefsForCompletion(anElementHelper, aJobRefs);
 81   
   }
 82   
 
 83  0
   public void collectRefsForValidation(IElementHelper anElementHelper, IJobRefs aJobRefs) {
 84  0
     myModelGroup.collectRefsForValidation(anElementHelper, aJobRefs);
 85   
   }
 86   
 
 87  36
   public IComponent createComponent(IElementHelper anElementHelper, IConstraintViolations aViolations) {
 88  36
     return myModelGroup.createComponent(anElementHelper, aViolations, getSchemaElement().getTargetNamespace(), getName());
 89   
   }
 90   
 
 91  36
   public void completeComponent(IElementHelper aHelper, IComponent aComponent, IConstraintViolations aViolations) {
 92  36
     myModelGroup.completeComponent(aHelper, aComponent, aViolations);
 93  36
     if (null != myRedefinedRef) {
 94   
       // TODO validate that it is a valid redefinition
 95   
     }
 96   
   }
 97   
 
 98  35
   public void addSchemaData(IComponentStore aStore, IComponent aComponent, IConstraintViolations aViolations) {
 99  35
     myModelGroup.addSchemaData(aStore, aComponent, aViolations);
 100   
   }
 101   
 
 102  3
   public void redefine(ITopLevelElement aRedefinedElement, IConstraintViolations aViolations) {
 103  3
     boolean replaced = false;
 104  3
     for (Iterator i = myModelGroup.iterParticles(); i.hasNext(); ) {
 105  9
       Object o = i.next();
 106  9
       if (o instanceof IModelGroupRef) {
 107  3
         IModelGroupRef gr = (IModelGroupRef)o;
 108  3
         if (gr.getRef().equals(getGlobalRef())) {
 109  3
           if (!replaced) {
 110  3
             gr.setRef(aRedefinedElement.getGlobalRef());
 111  3
             replaced = true;
 112   
           } else {
 113  0
             aViolations.add(XmlMessages.redefinedGroupCanOnlyBeReferencedOnce(this));
 114   
           }
 115   
         }
 116   
       }
 117   
     }
 118   
   }
 119   
 
 120   
   private IRef myRedefinedRef = null;
 121  0
   public IRef getRedefinedRef() {
 122  0
     return myRedefinedRef;
 123   
   }
 124  3
   public void setRedefinedRef(IRef aRef) {
 125  3
     myRedefinedRef = aRef;
 126   
   }
 127   
 }
 128