You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by ce...@apache.org on 2003/11/10 01:02:03 UTC

cvs commit: xml-xmlbeans/v2/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen XBeansXPathAdv.java XBeansXPath.java

cezar       2003/11/09 16:02:03

  Modified:    v2       build.xml
               v2/src/xmlstore/org/apache/xmlbeans/impl/store Path.java
               v2/test/src/drt/drtcases JaxenXPathTests.java
               v2/test/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen
                        TestXPath.java XPathPerf.java
               v2/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen
                        XBeansXPath.java
  Added:       v2/src/xmlstore/org/apache/xmlbeans/impl/store
                        JaxenXBeansDelegate.java
               v2/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen
                        XBeansXPathAdv.java
  Log:
  Integrating the new xpath implementation in XmlCursor.selectPath().
  
  In order to use this implementation one has to have build/private/lib/xbean_xpath.jar and build/lib/jaxen.jar on the classpath.
  
  CR: David Bau
  
  Revision  Changes    Path
  1.19      +1 -1      xml-xmlbeans/v2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/build.xml,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- build.xml	7 Nov 2003 23:48:46 -0000	1.18
  +++ build.xml	10 Nov 2003 00:02:03 -0000	1.19
  @@ -1019,7 +1019,7 @@
          source="1.4"
          debug="on">
         <classpath id="xpath.compile.path">
  -          <pathelement location="build/lib/xmlpublic.jar"/>
  +          <pathelement location="build/lib/xbean.jar"/>
             <pathelement location="build/lib/jaxen.jar"/>
         </classpath>
       </javac>
  
  
  
  1.2       +96 -8     xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Path.java
  
  Index: Path.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/Path.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Path.java	26 Sep 2003 21:23:37 -0000	1.1
  +++ Path.java	10 Nov 2003 00:02:03 -0000	1.2
  @@ -56,17 +56,15 @@
   
   package org.apache.xmlbeans.impl.store;
   
  -import java.util.ArrayList;
  -import java.util.HashMap;
  -import org.apache.xmlbeans.impl.store.Splay.CursorGoober;
  -import org.apache.xmlbeans.impl.store.Cursor.Selections;
  -import org.apache.xmlbeans.impl.store.Cursor.PathEngine;
  -import org.apache.xmlbeans.XmlOptions;
   import org.apache.xmlbeans.XmlCursor;
  -import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlObject;
  +import org.apache.xmlbeans.XmlOptions;
   import org.apache.xmlbeans.impl.common.XPath;
  -import org.apache.xmlbeans.impl.values.TypeStore;
  +import org.apache.xmlbeans.impl.store.Cursor.PathEngine;
  +import org.apache.xmlbeans.impl.store.Cursor.Selections;
  +
  +import java.util.HashMap;
  +import java.util.List;
   
   /**
    * Represents a precompiled path expression
  @@ -111,7 +109,9 @@
           synchronized ( _xbeanPathCache )
           {
               if (!xqrl)
  +            {
                   path = _xbeanPathCache.get( pathExpr );
  +            }
   
               if (path == null)
                   path = _xqrlPathCache.get( pathExpr );
  @@ -179,6 +179,13 @@
                       if (path != null)
                           _xbeanPathCache.put( path.getPathExpr(), path );
                   }
  +                if (path == null)
  +                {
  +                    path = JaxenPathImpl.create( pathExpr, currentNodeVar );
  +
  +                    if (path != null)
  +                        _xbeanPathCache.put( path.getPathExpr(), path );
  +                }
               }
   
               if (path == null)
  @@ -500,6 +507,87 @@
           private String _pathExpr;
           private XPath  _xpath;
           private String _currentNodeVar;
  +    }
  +
  +
  +    private static final class JaxenPathImpl extends Path
  +    {
  +        private String _pathExpr;
  +        private JaxenXBeansDelegate.SelectPathInterface _xpathImpl;
  +
  +        private JaxenPathImpl (
  +            JaxenXBeansDelegate.SelectPathInterface xpathImpl, String pathExpr )
  +        {
  +            _xpathImpl = xpathImpl;
  +            _pathExpr = pathExpr;
  +        }
  +
  +        static Path create ( String pathExpr, String currentNodeVar )
  +        {
  +            assert !currentNodeVar.startsWith( "$" ); // cezar review with ericvas
  +
  +            JaxenXBeansDelegate.SelectPathInterface impl = JaxenXBeansDelegate.createInstance( pathExpr );
  +            if (impl == null)
  +                return null;
  +
  +            return new JaxenPathImpl( impl , pathExpr );
  +        }
  +
  +        protected String getPathExpr ( ) { return _pathExpr; }
  +
  +        protected PathEngine execute ( Root r, Splay s, int p, XmlOptions options )
  +        {
  +            return new JaxenPathEngine( _xpathImpl, r, s, p);
  +        }
  +
  +        private static class JaxenPathEngine
  +            extends XPath.ExecutionContext implements PathEngine
  +        {
  +            JaxenPathEngine( JaxenXBeansDelegate.SelectPathInterface xpathImpl, Root r, Splay s, int p )
  +            {
  +                _jaxenXpathImpl = xpathImpl;
  +                _root = r;
  +                _splay = s;
  +                _p = p;
  +                _version = r.getVersion();
  +            }
  +
  +            public boolean next ( Selections selections )
  +            {
  +                if (!_firstCall)
  +                    return false;
  +
  +                _firstCall = false;
  +
  +                if (_root.getVersion() != _version)
  +                    throw new IllegalStateException( "Document changed" );
  +
  +                List resultsList;
  +                Cursor cur = new Cursor(_root, _splay, _p);
  +                resultsList = _jaxenXpathImpl.selectPath(cur);
  +
  +                int i;
  +                for (i = 0; i<resultsList.size(); i++)
  +                {
  +                    XmlCursor.XmlBookmark b = (XmlCursor.XmlBookmark)resultsList.get(i);
  +                    Splay.Annotation ann = ((Splay.Annotation)b._currentMark);
  +                    selections.add(_root, ann.getSplay(), ann.getPos());
  +                }
  +                cur.dispose();
  +                _root = null;
  +                _splay = null;
  +                _jaxenXpathImpl = null;
  +
  +                return false;
  +            }
  +
  +            private JaxenXBeansDelegate.SelectPathInterface _jaxenXpathImpl;
  +            private Root  _root;
  +            private Splay _splay;
  +            private int _p;
  +            private long  _version;
  +            private boolean _firstCall = true;
  +        }
       }
   
       private static HashMap _xqrlPathCache = new HashMap();
  
  
  
  1.1                  xml-xmlbeans/v2/src/xmlstore/org/apache/xmlbeans/impl/store/JaxenXBeansDelegate.java
  
  Index: JaxenXBeansDelegate.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.store;
  
  import java.lang.reflect.Constructor;
  import java.util.List;
  
  /**
   * Author: Cezar Andrei (cezar.andrei at bea.com)
   * Date: Nov 6, 2003
   *
   * Help class to decouple from xbean_xpath.jar and jaxen.jar (version v1.1 beta2)
   */
  public final class JaxenXBeansDelegate
  {
      private JaxenXBeansDelegate()
      {}
  
      static SelectPathInterface createInstance(String xpath)
      {
          if (_constructor==null)
              return null;
  
          try
          {
              return (JaxenXBeansDelegate.SelectPathInterface)_constructor.newInstance(new Object[] {xpath});
          }
          catch (Exception e)
          {
              throw new RuntimeException(e);
          }
      }
  
  
      // Loose coupling functionality with xqrl.jar
  
      private static Constructor _constructor;
  
      static
      {
          boolean hasTheJars = false;
          Class jaxenXPathImpl = null;
          try
          {
              // from jaxen.jar
              Class.forName( "org.jaxen.BaseXPath" );
              // from xbean_xpath.jar
              jaxenXPathImpl = Class.forName( "org.apache.xmlbeans.impl.xpath.jaxen.XBeansXPathAdv" );
  
              hasTheJars = true;
          }
          catch ( ClassNotFoundException e )
          {
              hasTheJars = false;
          }
          catch ( NoClassDefFoundError e )
          {
              hasTheJars = false;
          }
  
          if (hasTheJars)
          {
              try
              {
                  _constructor =
                      jaxenXPathImpl.getConstructor( new Class[] { String.class } );
              }
              catch ( Exception e )
              {
                  throw new RuntimeException( e );
              }
          }
      }
  
      public static interface SelectPathInterface
      {
          public List selectPath(Object node);
      }
  }
  
  
  
  1.2       +44 -26    xml-xmlbeans/v2/test/src/drt/drtcases/JaxenXPathTests.java
  
  Index: JaxenXPathTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/JaxenXPathTests.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JaxenXPathTests.java	4 Nov 2003 17:08:19 -0000	1.1
  +++ JaxenXPathTests.java	10 Nov 2003 00:02:03 -0000	1.2
  @@ -63,13 +63,13 @@
   import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlCursor;
   import org.apache.xmlbeans.XmlException;
  -import org.apache.xmlbeans.impl.xpath.jaxen.XBeansXPath;
  -import org.jaxen.XPathSyntaxException;
  -import org.jaxen.JaxenException;
  -import org.jaxen.XPath;
  -
  -import java.util.List;
  -import java.util.Iterator;
  +//import org.apache.xmlbeans.impl.xpath.jaxen.XBeansXPath;
  +//import org.jaxen.XPathSyntaxException;
  +//import org.jaxen.JaxenException;
  +//import org.jaxen.XPath;
  +//
  +//import java.util.List;
  +//import java.util.Iterator;
   import java.io.FileNotFoundException;
   import java.io.FileWriter;
   import java.io.IOException;
  @@ -118,42 +118,60 @@
   
               runAll(doc, xpath);
           }
  -        catch (XPathSyntaxException e)
  -        {
  -            System.err.println( e.getMultilineMessage() );
  -            throw new RuntimeException(e);
  -        }
  -        catch (JaxenException e)
  -        {
  -            throw new RuntimeException(e);
  -        }
           catch (Exception e)
           {
               throw new RuntimeException(e);
           }
       }
   
  -    private static void runAll(XmlObject doc, String[] xpathes) throws JaxenException
  +    private static void runAll(XmlObject doc, String[] xpathes)
       {
           for (int i=0; i<xpathes.length; i++)
           {
  -            runXpath(doc, xpathes[i], i);
  +            runXpath2(doc, xpathes[i], i);
           }
       }
   
  -    private static void runXpath(XmlObject doc, String xpathStr, int i)
  -        throws JaxenException
  +//    private static void runXpath(XmlObject doc, String xpathStr, int i)
  +//    {
  +//        try
  +//        {
  +//            XmlCursor xc = doc.newCursor();
  +//            XPath xpath = new XBeansXPath(xpathStr);
  +//            List results = xpath.selectNodes( xc );
  +//
  +//            Iterator resultIter = results.iterator();
  +//
  +//            int j = 0;
  +//            while ( resultIter.hasNext() )
  +//            {
  +//                xc = (XmlCursor)resultIter.next();  //it's the same object as previous xc
  +//                // generateExpected(i, j, xc.toString());
  +//                check(i, j, xc);
  +//                j++;
  +//            }
  +//
  +//            xc.dispose();
  +//        }
  +//        catch (XPathSyntaxException e)
  +//        {
  +//            System.err.println( e.getMultilineMessage() );
  +//            throw new RuntimeException(e);
  +//        }
  +//        catch (JaxenException e)
  +//        {
  +//            throw new RuntimeException(e);
  +//        }
  +//    }
  +
  +    private static void runXpath2(XmlObject doc, String xpathStr, int i)
       {
  -        XPath xpath = new XBeansXPath(xpathStr);
           XmlCursor xc = doc.newCursor();
  -		List results = xpath.selectNodes( xc );
  -
  -        Iterator resultIter = results.iterator();
  +		xc.selectPath( xpathStr );
   
           int j = 0;
  -        while ( resultIter.hasNext() )
  +        while ( xc.toNextSelection() )
           {
  -            xc = (XmlCursor)resultIter.next();  //it's the same object as previous xc
               // generateExpected(i, j, xc.toString());
               check(i, j, xc);
               j++;
  
  
  
  1.2       +21 -3     xml-xmlbeans/v2/test/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen/TestXPath.java
  
  Index: TestXPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen/TestXPath.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestXPath.java	4 Nov 2003 17:08:19 -0000	1.1
  +++ TestXPath.java	10 Nov 2003 00:02:03 -0000	1.2
  @@ -136,11 +136,11 @@
       {
           for (int i=0; i<xpathes.length; i++)
           {
  -            runXpath(doc, xpathes[i], i);
  +            runXpath2(doc, xpathes[i], i);
           }
       }
   
  -    private static void runXpath(XmlObject doc, String xpathStr, int i)
  +    private static void runXpath1(XmlObject doc, String xpathStr, int i)
           throws JaxenException
       {
           System.out.println("\n>>>================= " + i + " " + xpathStr + " ========================<<<");
  @@ -155,7 +155,25 @@
           int j = 0;
           while ( resultIter.hasNext() )
           {
  -            xc = (XmlCursor)resultIter.next();  //it's the same object as previous xc
  +            xc = (XmlCursor)resultIter.next();
  +            System.out.println("> " + (j++) + " >--------------------------------------< " + xc.currentTokenType());
  +            System.out.println( xc );
  +        }
  +        System.out.println("\n>>>Results: " + j + "    " + xpathStr + " ==========================<<<");
  +		xc.dispose();
  +    }
  +
  +    private static void runXpath2(XmlObject doc, String xpathStr, int i)
  +    {
  +        System.out.println("\n>>>================= " + i + " " + xpathStr + " ========================<<<");
  +
  +        XmlCursor xc = doc.newCursor();
  +		xc.selectPath(xpathStr);
  +
  +        //System.out.println("Document :: \n" + doc );
  +        int j = 0;
  +        while ( xc.toNextSelection() )
  +        {
               System.out.println("> " + (j++) + " >--------------------------------------< " + xc.currentTokenType());
               System.out.println( xc );
           }
  
  
  
  1.2       +35 -2     xml-xmlbeans/v2/test/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen/XPathPerf.java
  
  Index: XPathPerf.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen/XPathPerf.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XPathPerf.java	4 Nov 2003 17:08:19 -0000	1.1
  +++ XPathPerf.java	10 Nov 2003 00:02:03 -0000	1.2
  @@ -94,8 +94,9 @@
               }
   
               //test1(xpathStr, file);
  -            test2(xpathStr, file);
  +            //test2(xpathStr, file);
   
  +            test3t(xpathStr, file);
               test3(xpathStr, file);
               test4(file);
           }
  @@ -211,11 +212,43 @@
   
                       count += (speaker == null ? 0 : 1);
                   }
  -                //System.out.println((j*100) + "                \t" + (System.currentTimeMillis()-start2));
  +                System.out.println((j*100) + "                \t" + (System.currentTimeMillis()-start2));
               }
   
               long end = System.currentTimeMillis();
               System.out.println(">>> " + count + " selections in " + (end - start) + " ms");
  +        }
  +        catch (XmlException e)
  +        {
  +            e.printStackTrace();
  +        }
  +        catch (IOException e)
  +        {
  +            e.printStackTrace();
  +        }
  +    }
  +
  +    private static void test3t(String xpathStr, File file)
  +    {
  +        System.out.println("\n ----- test3:   XmlCursor.selectPath(cpath)  -----");
  +
  +        try
  +        {
  +            String cpath = XmlBeans.compilePath( xpathStr );
  +            XmlObject doc = XmlObject.Factory.parse(file);
  +            XmlCursor speaker = doc.newCursor();
  +
  +            int count = 0;
  +            speaker.toStartDoc();
  +            speaker.selectPath(cpath);
  +            //speaker.getSelectionCount();
  +            while ( speaker.toNextSelection() )
  +            {
  +                System.out.println(speaker);
  +                count += (speaker == null ? 0 : 1);
  +            }
  +
  +            System.out.println(">>> " + count + " selections");
           }
           catch (XmlException e)
           {
  
  
  
  1.3       +1 -1      xml-xmlbeans/v2/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen/XBeansXPath.java
  
  Index: XBeansXPath.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen/XBeansXPath.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XBeansXPath.java	4 Nov 2003 17:08:17 -0000	1.2
  +++ XBeansXPath.java	10 Nov 2003 00:02:03 -0000	1.3
  @@ -113,7 +113,7 @@
               xc = ((XmlCursor)node).newCursor();
           }
           else
  -            throw new IllegalArgumentException("node must be an XmlObject or an XmlCursor.");
  +            throw new IllegalArgumentException("node must be an XmlObject or an XmlCursor, found: " + node.getClass());
   
           ((XBeansNavigator)getNavigator()).setCursor(xc);
           return new ListImpl(super.selectNodes( XBeansNavigator.getBookmarkInThisPlace(xc) ));
  
  
  
  1.1                  xml-xmlbeans/v2/src/xpath/org/apache/xmlbeans/impl/xpath/jaxen/XBeansXPathAdv.java
  
  Index: XBeansXPathAdv.java
  ===================================================================
  /*
  * The Apache Software License, Version 1.1
  *
  *
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution,
  *    if any, must include the following acknowledgment:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowledgment may appear in the software itself,
  *    if and wherever such third-party acknowledgments normally appear.
  *
  * 4. The names "Apache" and "Apache Software Foundation" must
  *    not be used to endorse or promote products derived from this
  *    software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache
  *    XMLBeans", nor may "Apache" appear in their name, without prior
  *    written permission of the Apache Software Foundation.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation and was
  * originally based on software copyright (c) 2000-2003 BEA Systems
  * Inc., <http://www.bea.com/>. For more information on the Apache Software
  * Foundation, please see <http://www.apache.org/>.
  */
  
  package org.apache.xmlbeans.impl.xpath.jaxen;
  
  import org.jaxen.BaseXPath;
  import org.jaxen.JaxenException;
  import org.apache.xmlbeans.XmlCursor;
  import org.apache.xmlbeans.impl.store.JaxenXBeansDelegate;
  
  import java.util.List;
  
  /**
   * Author: Cezar Andrei (cezar.andrei at bea.com)
   * Date: Oct 10, 2003
   */
  public class XBeansXPathAdv
      extends BaseXPath
      implements JaxenXBeansDelegate.SelectPathInterface
  {
      /** Construct given an XPath expression string.
       *
       *  @param xpathExpr The XPath expression.
       *
       *  @throws org.jaxen.JaxenException if there is a syntax error while
       *          parsing the expression.
       */
      public XBeansXPathAdv(String xpathExpr) throws JaxenException
      {
          super( xpathExpr, XBeansNavigator.getInstance() );
      }
  
      /** Select all nodes that are selectable by this XPath
       *  expression. If multiple nodes match, multiple nodes
       *  will be returned.
       *
       *  <p>
       *  <b>NOTE:</b> In most cases, nodes will be returned
       *  in document-order, as defined by the XML Canonicalization
       *  specification.  The exception occurs when using XPath
       *  expressions involving the <code>union</code> operator
       *  (denoted with the pipe '|' character).
       *  </p>
       *
       *  <p>
       *  <b>NOTE:</b> Param node must be an XmlCursor, which will be used during the xpath
       *  execution and iteration through the results. A call of node.dispose() must be done
       *  after reading all results.
       *  </p>
       *
       *  @param node The node, nodeset or Context object for evaluation. This value can be null.
       *
       *  @return The <code>node-set</code> of all items selected
       *          by this XPath expression.
       *
       *  @see #selectSingleNode
       */
      public List selectNodes(Object node) throws JaxenException
      {
          XmlCursor xc;
          xc = ((XmlCursor)node);
  
          ((XBeansNavigator)getNavigator()).setCursor(xc);
          return super.selectNodes( XBeansNavigator.getBookmarkInThisPlace(xc) );
      }
  
      public List selectPath(Object node)
      {
          try
          {
              return selectNodes(node);
          }
          catch (JaxenException e)
          {
              throw new RuntimeException(e);
          }
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org