Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 74   Methods: 4
NCLOC: 56   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
XPathConstraintElement.java 50% 65,2% 100% 65,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 org.jbind.xml.base.IAttribute;
 13   
 import org.jbind.xml.core.bridge.IXPath;
 14   
 import org.jbind.xml.core.constraint.IXPathConstraint;
 15   
 import org.jbind.xml.msg.IConstraintViolations;
 16   
 import org.jbind.xml.msg.XmlException;
 17   
 import org.jbind.xml.msg.XmlMessages;
 18   
 import org.jbind.xml.schema.constraint.XPathConstraint;
 19   
 import org.jbind.xml.schema.instantiation.IElemValHelper;
 20   
 import org.jbind.xml.schema.instantiation.IElementHelper;
 21   
 
 22   
 public class XPathConstraintElement extends Element implements IXPathConstraintElement {
 23   
 
 24   
   private String myContext = null;
 25   
   private String myTest = null;
 26   
 
 27   
   private IXPath myTestXPath = null;
 28   
   private IXPath mySelectXPath = null;
 29   
 
 30  2
   public XPathConstraintElement(CreationParams aCreationParams) {
 31  2
     super(aCreationParams);
 32   
   }
 33   
 
 34  2
   protected IAttribute doCreateAttribute(ACParams anACParams) throws XmlException {
 35  2
     IAttribute res = null;
 36  2
     String an = NameUtil.getSchemaAttributeName(anACParams);
 37  2
     if ("select".equals(an)) {
 38  0
       res = new Attribute(anACParams);
 39  0
       myContext = res.getStringValue();
 40  2
     } else if ("test".equals(an)) {
 41  2
       res = new Attribute(anACParams);
 42  2
       myTest = res.getStringValue();
 43   
     } else {
 44  0
       res = super.doCreateAttribute(anACParams);
 45   
     }
 46  2
     return res;
 47   
   }
 48   
 
 49  2
   public void validateElement(IElemValHelper aHelper, IConstraintViolations aViolations) {
 50  2
     super.validateElement(aHelper, aViolations);
 51  2
     if (null == myTest) {
 52  0
       aViolations.add(XmlMessages.missingAttribute("test", this));
 53   
     } else {
 54  2
       try {
 55  2
         myTestXPath = aHelper.createXPath(myTest, getPrefixToNamespaceMapping(), false);
 56   
       } catch (Exception e) {
 57  0
         aViolations.add(XmlMessages.invalidXPath(myTest, e, this));
 58   
       }
 59   
     }
 60  2
     if (null != myContext) {
 61  0
       try {
 62  0
         mySelectXPath = aHelper.createXPath(myContext, getPrefixToNamespaceMapping(), false);
 63   
       } catch (Exception e) {
 64  0
         aViolations.add(XmlMessages.invalidXPath(myContext, e, this));
 65   
       }
 66   
     }
 67   
   }
 68   
 
 69  2
   public IXPathConstraint createXPathConstraint(IElementHelper aHelper) throws XmlException {
 70  2
     IXPath context = null;
 71  2
     return new XPathConstraint(myTestXPath, mySelectXPath, this);
 72   
   }
 73   
 }
 74