Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 122   Methods: 12
NCLOC: 94   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
IdentityConstraintElement.java 61,1% 69% 66,7% 66,7%
 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.Iterator;
 14   
 import java.util.List;
 15   
 
 16   
 import org.jbind.xml.base.IAttribute;
 17   
 import org.jbind.xml.base.IBindingAttributes;
 18   
 import org.jbind.xml.base.IRef;
 19   
 import org.jbind.xml.base.ISymbolspace;
 20   
 import org.jbind.xml.base.ISymbolspaces;
 21   
 import org.jbind.xml.core.cmp.IComponent;
 22   
 import org.jbind.xml.core.cmp.IComponentStore;
 23   
 import org.jbind.xml.core.constraint.IIdentityConstraintComponent;
 24   
 import org.jbind.xml.core.type.IAnyType;
 25   
 import org.jbind.xml.msg.IConstraintViolations;
 26   
 import org.jbind.xml.msg.XmlException;
 27   
 import org.jbind.xml.msg.XmlMessages;
 28   
 import org.jbind.xml.schema.instantiation.IElemValHelper;
 29   
 import org.jbind.xml.schema.instantiation.IElementHelper;
 30   
 import org.jbind.xml.schema.instantiation.IJobRefs;
 31   
 
 32   
 public abstract class IdentityConstraintElement extends Named implements IIdentityConstraintElement {
 33   
 
 34   
   private ISelector mySelector = null;
 35   
   private boolean myRestrictedForm;
 36   
 
 37  63
   public IdentityConstraintElement(CreationParams aCPs, boolean aRestrictedForm) {
 38  63
     super(aCPs);
 39  63
     myRestrictedForm = aRestrictedForm;
 40   
   }
 41   
 
 42  133
   public IElement doCreateChild(CreationParams aCreationParams) throws XmlException {
 43  133
     IElement res = null;
 44  133
     String componentName = NameUtil.getSchemaComponentName(aCreationParams);
 45  133
     if ("selector".equals(componentName)) {
 46  63
       res = new Selector(aCreationParams, myRestrictedForm);
 47  70
     } else if ("field".equals(componentName)) {
 48  70
       res = new Field(aCreationParams, myRestrictedForm);
 49   
     } else {
 50  0
       res = super.doCreateChild(aCreationParams);
 51   
     }
 52  133
     return res;
 53   
   }
 54   
 
 55   
 
 56  0
   public ISelector getSelector() {
 57  0
     return mySelector;
 58   
   }
 59   
 
 60   
 
 61  0
   public Iterator iterFields() {
 62  0
     return iterChildrenByClass(IField.class);
 63   
   }
 64   
 
 65   
 
 66  0
   public ISymbolspace getSymbolSpace() {
 67  0
     return ISymbolspaces.IDENTITY_CONSTRAINT;
 68   
   }
 69   
 
 70  63
   public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
 71  63
     super.validateElement(aHelper, aViolations);
 72  63
     if (null == getName()) {
 73  0
       aViolations.add(XmlMessages.missingName(this));
 74   
     }
 75  63
     Iterator i = iterChildrenByClass(ISelector.class);
 76  63
     if (!i.hasNext()) {
 77  0
       aViolations.add(XmlMessages.missingSelector(this));
 78   
     }
 79  63
     mySelector = (ISelector)i.next();
 80  63
     if (i.hasNext()) {
 81  0
       aViolations.add(XmlMessages.moreThanOneSelector(this));
 82   
     }
 83  63
     i = iterChildrenByClass(IField.class);
 84  63
     if (!i.hasNext()) {
 85  0
       aViolations.add(XmlMessages.missingField(this));
 86   
     }
 87   
   }
 88   
 
 89  63
   public final void collectRefsForCreation(IJobRefs aJobRefs) {}
 90  122
   public final void collectRefsForCompletion(IElementHelper anElementHelper, IJobRefs aJobRefs) {
 91  122
     doCollectRefsForCompletion(anElementHelper, aJobRefs);
 92  122
     IAttribute a = getBindingAttribute(IBindingAttributes.REFERENCED_TYPE);
 93  122
     if (null != a) {
 94  0
       IRef ref = a.getRef();
 95  0
       aJobRefs.add(ref, false, this);
 96   
     }
 97   
   }
 98  0
   public final void collectRefsForValidation(IElementHelper anElementHelper, IJobRefs aJobRefs) {}
 99   
 
 100  80
   protected void doCollectRefsForCompletion(IElementHelper anElementHelper, IJobRefs aJobRefs) {}
 101   
 
 102  60
   public void completeComponent(IElementHelper anElementHelper, IComponent aComponent, IConstraintViolations aViolations) {
 103  60
     IIdentityConstraintComponent icc = (IIdentityConstraintComponent)aComponent;
 104  60
     IAttribute a = getBindingAttribute(IBindingAttributes.REFERENCED_TYPE);
 105  60
     if (null != a) {
 106  0
       IRef ref = a.getRef();
 107  0
       IAnyType t = (IAnyType)anElementHelper.getComponent(ref, false);
 108  0
       icc.setDataType(t);
 109   
     }
 110  60
     icc.setSelector(mySelector.getXPath());
 111  60
     List fields = new ArrayList();
 112  60
     for (Iterator i = iterChildrenByClass(IField.class); i.hasNext(); ) {
 113  67
       IField field = (IField)i.next();
 114  67
       fields.add(field.getXPath());
 115   
     }
 116  60
     icc.setFields(fields);
 117   
   }
 118   
 
 119  55
   public void addSchemaData(IComponentStore aComponentStore, IComponent aComponent, IConstraintViolations aViolations) {}
 120   
 
 121   
 }
 122