Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 86   Methods: 8
NCLOC: 64   Classes: 2
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
JaxenXPathFactory.java 100% 81% 100% 87,1%
 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.instance.impl;
 11   
 
 12   
 import java.util.Iterator;
 13   
 import java.util.List;
 14   
 import java.util.Map;
 15   
 
 16   
 import org.jaxen.BaseXPath;
 17   
 import org.jaxen.JaxenException;
 18   
 import org.jaxen.NamespaceContext;
 19   
 import org.jbind.xml.core.bridge.IDataImpl;
 20   
 import org.jbind.xml.core.bridge.IXPath;
 21   
 import org.jbind.xml.core.bridge.IXPathFactory;
 22   
 import org.jbind.xml.core.bridge.XPath;
 23   
 import org.jbind.xml.msg.XmlException;
 24   
 import org.jbind.xml.msg.XmlMessages;
 25   
 
 26   
 public class JaxenXPathFactory implements IXPathFactory {
 27   
 
 28  3
   public JaxenXPathFactory() {}
 29   
 
 30  147
   public IXPath createXPath(String anXPath, Map aPrefixMapping, boolean aRestrictedForm) throws Exception {
 31  147
     return new JaxenXPath(anXPath, aPrefixMapping);
 32   
   }
 33   
 
 34   
   private static class JaxenXPath extends XPath implements IXPath {
 35   
 
 36   
     private BaseXPath myXPath;
 37  147
     public JaxenXPath(String anXPath, final Map aPrefixMapping) throws Exception {
 38  147
       super(anXPath);
 39  147
       myXPath = new BaseXPath(anXPath, ImplNavigator.ourImplNavigator);
 40  147
       NamespaceContext namespaceContext = new NamespaceContext() {
 41  5788
         public String translateNamespacePrefixToUri(String prefix) {
 42  5788
           if ("".equals(prefix)) {
 43  40
             return null;
 44   
           }
 45  5748
           return (String)aPrefixMapping.get(prefix);
 46   
         }
 47   
       };
 48  147
       myXPath.setNamespaceContext(namespaceContext);
 49   
     }
 50   
 
 51  377
     public Iterator select(IDataImpl aData) throws XmlException {
 52  377
       try {
 53  377
         List l = myXPath.selectNodes(aData);
 54  377
         return l.iterator();
 55   
       } catch (JaxenException e) {
 56  0
         throw new XmlException(XmlMessages.xPathException(getXPath(), e, aData));
 57   
       }
 58   
     }
 59   
 
 60  23
     public boolean test(IDataImpl aData) throws XmlException {
 61  23
       try {
 62  23
         return myXPath.booleanValueOf(aData);
 63   
       } catch (JaxenException e) {
 64  0
         throw new XmlException(XmlMessages.xPathException(getXPath(), e, aData));
 65   
       }
 66   
     }
 67   
 
 68  1
     public double number(IDataImpl aData) throws XmlException {
 69  1
       try {
 70  1
         return myXPath.numberValueOf(aData).doubleValue();
 71   
       } catch (JaxenException e) {
 72  0
         throw new XmlException(XmlMessages.xPathException(getXPath(), e, aData));
 73   
       }
 74   
     }
 75   
 
 76  1
     public String string(IDataImpl aData) throws XmlException {
 77  1
       try {
 78  1
         return myXPath.stringValueOf(aData);
 79   
       } catch (JaxenException e) {
 80  0
         throw new XmlException(XmlMessages.xPathException(getXPath(), e, aData));
 81   
       }
 82   
     }
 83   
 
 84   
   }
 85   
 }
 86