wt.util.xml.xpath.xalan2
Class XPathXalan2Impl

java.lang.Object
  extended bywt.util.xml.xpath.xalan2.XPathXalan2Impl
All Implemented Interfaces:
XPath, XPathNI

public final class XPathXalan2Impl
extends Object
implements XPathNI


Field Summary
private static org.apache.xalan210.xalan.extensions.ExtensionsTable xalanExtensionsTable
           
private  org.apache.xalan210.xpath.XPath xpath
          XPath expression string
 
Constructor Summary
XPathXalan2Impl(String xpathExprStr)
           
 
Method Summary
 Object evaluate(Node node)
          Evaluates the xpath relative to the specified node and returns the result as the most appropriate object.
 void evaluate(Node node, XPathCallback callback)
          Evaluates the xpath relative to the specified node and invokes the callback method most appropriate for the located object.
 Object evaluateAllowingIterResult(Node node)
          Same as XPath.evaluate(Node) except that org.w3c.dom.traversal.NodeIterator objects will be returned in place of NodeLists when the result is a node set.
private  org.apache.xalan210.xpath.objects.XObject getXObjectResult(Node node)
          Internal implementation of evaluate() methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xpath

private org.apache.xalan210.xpath.XPath xpath
XPath expression string


xalanExtensionsTable

private static final org.apache.xalan210.xalan.extensions.ExtensionsTable xalanExtensionsTable
Constructor Detail

XPathXalan2Impl

public XPathXalan2Impl(String xpathExprStr)
                throws XPathException
Method Detail

evaluate

public void evaluate(Node node,
                     XPathCallback callback)
              throws XPathException
Description copied from interface: XPath
Evaluates the xpath relative to the specified node and invokes the callback method most appropriate for the located object.

You must supply an XPathCallback object to use this method to evaluate an XPath against a document. The XPath implementation is responsble for switching to the appropriate callback handler based on the XML nodes referenced by the XPath. This necessitates a style of programming that uses inner or anonymous class to handle the results of the XPath.

The motivation to implement XPath support this was largely to discourage styles of programming that use switches or cascading if-else-ifs where the type of the result is checked via the instanceof operator. To see how to effectively use this means of evaluation, look at the following example code.

Example

The following example evaluates the expression on the document and returns true if the xpath evaluates to a resulta and false if no result is located.
    public class SomeUtilityClass
    {
       private XPathFactory factory_ = ...;
        
       public static boolean doesXPathPointToSomething(
                Document doc_to_search,
                String x_path_expression)
          throws XPathException
       {
          // this inner class is the callback for the evaluated xpath
          class WasExpressionFoundCallback
             extends AbstractXPathCallback
          {
             private boolean wasFound = true;
             public void processNotFound() { wasFound = false; }
          };
           
          XPath x_path = factory_.newXPath(x_path_expression);
          WasExpressionFoundCallback callback = new WasExpressionFoundCallback();
          x_path.evaluate(doc_to_search, callback);
           
          return callback.wasFound;
       }
    }
 


Supported API: false

Specified by:
evaluate in interface XPath
Parameters:
node - node to search relative to
callback - interface bearing methods for each type of located object
Throws:
XPathException - implementations should rethrow all failures as XPathExceptions
See Also:
XPathCallback

evaluateAllowingIterResult

public Object evaluateAllowingIterResult(Node node)
                                  throws XPathException
Description copied from interface: XPathNI
Same as XPath.evaluate(Node) except that org.w3c.dom.traversal.NodeIterator objects will be returned in place of NodeLists when the result is a node set. This can be advantageous in that it may be more efficient in some XPath implementations.

Specified by:
evaluateAllowingIterResult in interface XPathNI
Throws:
XPathException

evaluate

public Object evaluate(Node node)
                throws XPathException
Description copied from interface: XPath
Evaluates the xpath relative to the specified node and returns the result as the most appropriate object. This will be a Double, String, Boolean, NodeList, DocumentFragment, null, or, where none of these are appropriate, an implementation specific object.

One should not use this method as an excuse to implement poor code consisting of switches or cascading if-else-ifs where the type of the result is checked via the instanceof operator. This method should only be used when a single result type is demanded.

Supported API: true

Specified by:
evaluate in interface XPath
Parameters:
node -
Returns:
Object
Throws:
XPathException

getXObjectResult

private org.apache.xalan210.xpath.objects.XObject getXObjectResult(Node node)
                                                            throws XPathException
Internal implementation of evaluate() methods.

Throws:
XPathException