Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 132   Methods: 12
NCLOC: 103   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
PartDeclaration.java 90,9% 97,9% 100% 96,3%
 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 org.jbind.xml.base.IAttribute;
 13   
 import org.jbind.xml.base.IBindingAttributes;
 14   
 import org.jbind.xml.base.IRef;
 15   
 import org.jbind.xml.base.ISymbolspaces;
 16   
 import org.jbind.xml.core.cmp.IComponent;
 17   
 import org.jbind.xml.core.cmp.IComponentStore;
 18   
 import org.jbind.xml.core.content.IDataRefOrDecl;
 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.cmp.W3CTypes;
 23   
 import org.jbind.xml.schema.instantiation.IElemValHelper;
 24   
 import org.jbind.xml.schema.instantiation.IElementHelper;
 25   
 
 26   
 public abstract class PartDeclaration extends Declaration implements IPartDeclaration {
 27   
 
 28   
   private IRef myRef = null;
 29   
   private IRef myType = null;
 30   
   private FormType myForm = null;
 31   
 
 32   
   private String myDefault = null;
 33   
   private String myFixed = null;
 34   
 
 35   
   private boolean myIsLocal;
 36   
 
 37   
   private IDataRefOrDecl myReferencedDecl = null;
 38   
 
 39  1674
   public PartDeclaration(CreationParams aCreationParams, boolean anIsLocal) {
 40  1674
     super(aCreationParams);
 41  1674
     myIsLocal = anIsLocal;
 42   
   }
 43   
 
 44  198
   protected boolean getIsLocal() {
 45  198
     return myIsLocal;
 46   
   }
 47   
 
 48  970
   public FormType getFormType() {
 49  970
     return myForm;
 50   
   }
 51   
 
 52  13765
   public IRef getType() {
 53  13765
     return myType;
 54   
   }
 55   
 
 56  3038
   public String getDefault() {
 57  3038
     return myDefault;
 58   
   }
 59   
 
 60  3038
   public String getFixed() {
 61  3038
     return myFixed;
 62   
   }
 63   
 
 64  8939
   public IRef getRef() {
 65  8939
     return myRef;
 66   
   }
 67   
 
 68  2867
   protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
 69  2867
     IAttribute res = null;
 70  2867
     String an = NameUtil.getSchemaAttributeName(anACParams);
 71  2867
     String upan = NameUtil.getBindingAttributeName(anACParams);
 72  2867
     if ("type".equals(an)) {
 73  948
       res = new RefAttribute(anACParams, ISymbolspaces.TYPE);
 74  948
       myType = res.getRef();
 75  1919
     } else if ("ref".equals(an)) {
 76  261
       res = new RefAttribute(anACParams, getSymbolSpace());
 77  261
       myRef = res.getRef();
 78  1658
     } else if ("form".equals(an)) {
 79  10
       if (isTopLevelComponent()) {
 80  2
         throw new XmlException(XmlMessages.formAttributeNotAllowedFAtTopLevelDeclarations(this));
 81   
       }
 82  8
       res = new Attribute(anACParams);
 83  8
       myForm = ConstantResolver.getFormType(res.getStringValue(), this);
 84  1648
     } else if ("default".equals(an)) {
 85  77
       res = new Attribute(anACParams);
 86  77
       myDefault = res.getStringValue();
 87  1571
     } else if ("fixed".equals(an)) {
 88  50
       res = new Attribute(anACParams);
 89  50
       myFixed = res.getStringValue();
 90   
     } else {
 91  1521
       res = super.doCreateAttribute(anACParams);
 92   
     }
 93  2865
     return res;
 94   
   }
 95   
 
 96  1674
   public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
 97  1674
     super.validateElement(aHelper, aViolations);
 98  1674
     if ((null != myDefault) && (null != myFixed)) {
 99  1
       aViolations.add(XmlMessages.fixedAndDefaultPresent(this));
 100   
     }
 101  1674
     if (isTopLevelComponent() && (null != myRef)) {
 102  1
       aViolations.add(XmlMessages.topLevelDeclarationMustNotRef(this));
 103   
     }
 104   
   }
 105   
 
 106  1519
   public void addSchemaData(IComponentStore aComponentStore, IComponent aComponent, IConstraintViolations aViolations) {
 107  1519
     IDataRefOrDecl item = (IDataRefOrDecl)aComponent;
 108  1519
     String def = getDefault();
 109  1519
     String fix = getFixed();
 110  1519
     item.addValueConstraints(getDefault(), getFixed(), aViolations);
 111   
   }
 112   
 
 113  239
   protected String getBoundName() {
 114  239
     String res = getStringBindingAttribute(IBindingAttributes.NAME);
 115  239
     if (null == res) {
 116  239
       res = getName();
 117   
     }
 118  239
     return res;
 119   
   }
 120   
 
 121  1583
   public void completeComponent(IElementHelper anElementHelper, IComponent aComponent, IConstraintViolations aViolations) {
 122  1583
     if (aComponent.isReference()) {
 123  247
       return;
 124   
     }
 125  1336
     IDataRefOrDecl decl = (IDataRefOrDecl)aComponent;
 126  1336
     if (decl.getType() == W3CTypes.notation) {
 127  0
       aViolations.add(XmlMessages.notationTypeMustNotBeUsedDirectly(this));
 128   
     }
 129   
   }
 130   
 
 131   
 }
 132