You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by er...@apache.org on 2004/08/04 23:15:07 UTC

cvs commit: xml-xmlbeans/v2/test/src/xmlcursor/xpath/jaxen/checkin JaxenXPathTests.java

ericvas     2004/08/04 14:15:07

  Modified:    v2/src/newstore2/org/apache/xmlbeans/impl/newstore2
                        Cursor.java Locale.java Path.java Xobj.java
               v2/src/typeimpl/org/apache/xmlbeans/impl/values
                        JavaQNameHolder.java
               v2/src/xmlstore/org/apache/xmlbeans/impl/store Path.java
               v2/test/src/xmlcursor/xpath/jaxen/checkin
                        JaxenXPathTests.java
  Added:       v2/src/newstore2/org/apache/xmlbeans/impl/newstore2
                        Query.java
  Log:
  xquery/path integration in newstore
  
  Revision  Changes    Path
  1.24      +1 -0      xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Cursor.java
  
  Index: Cursor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Cursor.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Cursor.java	26 Jul 2004 18:24:13 -0000	1.23
  +++ Cursor.java	4 Aug 2004 21:15:06 -0000	1.24
  @@ -680,6 +680,7 @@
       public void _selectPath ( String pathExpr, XmlOptions options )
       {
           _cur.clearSelection();
  +        
           _pathEngine = Path.getCompiledPath( pathExpr, options ).execute( _cur );
       }
       
  
  
  
  1.22      +2 -2      xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Locale.java
  
  Index: Locale.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Locale.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- Locale.java	26 Jul 2004 18:24:13 -0000	1.21
  +++ Locale.java	4 Aug 2004 21:15:06 -0000	1.22
  @@ -221,7 +221,7 @@
       //
       //
       
  -    private static void associateSourceName ( Cur c, XmlOptions options )
  +    static void associateSourceName ( Cur c, XmlOptions options )
       {
           String sourceName = (String) XmlOptions.safeGet( options, XmlOptions.DOCUMENT_SOURCE_NAME );
   
  @@ -233,7 +233,7 @@
       //
       //
       
  -    private void autoTypeDocument ( Cur c, SchemaType requestedType, XmlOptions options )
  +    void autoTypeDocument ( Cur c, SchemaType requestedType, XmlOptions options )
           throws XmlException
       {
           assert c.isRoot();
  
  
  
  1.4       +127 -51   xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Path.java
  
  Index: Path.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Path.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Path.java	27 May 2004 23:36:19 -0000	1.3
  +++ Path.java	4 Aug 2004 21:15:06 -0000	1.4
  @@ -15,15 +15,20 @@
   
   package org.apache.xmlbeans.impl.newstore2;
   
  +import java.util.ConcurrentModificationException;
  +import java.util.HashMap;
  +
  +import java.lang.reflect.Method;
  +import java.lang.reflect.InvocationTargetException;
  +
  +import org.apache.xmlbeans.XmlRuntimeException;
  +
   import org.apache.xmlbeans.impl.common.XPath;
   import org.apache.xmlbeans.impl.common.XPath.XPathCompileException;
   import org.apache.xmlbeans.impl.common.XPath.ExecutionContext;
   
   import org.apache.xmlbeans.XmlOptions;
   
  -import java.util.ConcurrentModificationException;
  -import java.util.HashMap;
  -
   // TODO - This class handled query *and* path ... rename it?
   
   public abstract class Path
  @@ -34,10 +39,9 @@
       }
   
       public static String _useXqrlForXpath = "use xqrl for xpath";
  -
       public static String _useXbeanForXpath = "use xbean for xpath";
   
  -    static interface PathEngine
  +    interface PathEngine
       {
           void release ( );
           boolean next ( Cur c );
  @@ -45,6 +49,35 @@
   
       abstract PathEngine execute ( Cur c );
   
  +    //
  +    //
  +    //
  +
  +    static String getCurrentNodeVar ( XmlOptions options )
  +    {
  +        String currentNodeVar = "this";
  +
  +        options = XmlOptions.maskNull( options );
  +        
  +        if (options.hasOption( XmlOptions.XQUERY_CURRENT_NODE_VAR ))
  +        {
  +            currentNodeVar = (String) options.get( XmlOptions.XQUERY_CURRENT_NODE_VAR );
  +
  +            if (currentNodeVar.startsWith( "$" ))
  +            {
  +                throw
  +                    new IllegalArgumentException(
  +                        "Omit the '$' prefix for the current node variable" );
  +            }
  +        }
  +
  +        return currentNodeVar;
  +    }
  +
  +    private static final int FORCE_XQRL    = 0;
  +    private static final int FORCE_XBEAN   = 1;
  +    private static final int FORCE_NEITHER = 2;
  +
       static Path getCompiledPath ( String pathExpr, XmlOptions options )
       {
           options = XmlOptions.maskNull( options );
  @@ -59,40 +92,67 @@
           return getCompiledPath( pathExpr, force, getCurrentNodeVar( options ) );
       }
   
  -    private static final int FORCE_XQRL    = 0;
  -    private static final int FORCE_XBEAN   = 1;
  -    private static final int FORCE_NEITHER = 2;
  -
  -
  -    // TODO - This is a global lock ... make it not be a global lock?
       static synchronized Path getCompiledPath ( String pathExpr, int force, String currentVar )
       {
  -        Path path = null;
  -
  -        // TODO - remove this when integrate xqrl
           if (force == FORCE_XQRL)
  -            throw new RuntimeException( "Not XQRL support yet" );
  +        {
  +            Path path = (Path) _xqrlPathCache.get( pathExpr );
   
  -        // TODO - when integrate xqrl, add this back
  -//        if (force != FORCE_XQRL)
  -            path = (Path) _xbeanPathCache.get( pathExpr );
  +            if (path == null)
  +            {
  +                path = createXqrlCompiledPath( pathExpr, currentVar );
  +
  +                if (path == null)
  +                    throw new RuntimeException( "Can't force XQRL: Can't find xqrl" );
   
  -        // Check for other engine caches here .. make sure to check  force
  +                _xqrlPathCache.put( path._pathKey, path );
  +            }
   
  -        // Could not find the path in the caches, try to compile it
  +            return path;
  +        }
  +
  +        if (force == FORCE_XBEAN)
  +        {
  +            Path path = (Path) _xbeanPathCache.get( pathExpr );
               
  -        if (path == null && force != FORCE_XQRL)
  +            if (path == null)
  +            {
  +                path = XbeanPath.create( pathExpr, currentVar );
  +
  +                if (path == null)
  +                    throw new XmlRuntimeException( "Path too complex for XBean path engine" );
  +
  +                _xbeanPathCache.put( path._pathKey, path );
  +            }
  +
  +            return path;
  +        }
  +
  +        assert force == FORCE_NEITHER;
  +
  +        Path path = (Path) _xbeanPathCache.get( pathExpr );
  +
  +        if (path == null)
  +            path = (Path) _xqrlPathCache.get( pathExpr );
  +
  +        if (path == null)
           {
               path = XbeanPath.create( pathExpr, currentVar );
   
               if (path != null)
  -                _xbeanPathCache.put( pathExpr, path );
  +                _xbeanPathCache.put( path._pathKey, path );
  +            else
  +            {
  +                path = createXqrlCompiledPath( pathExpr, currentVar );
  +
  +                if (path == null)
  +                    throw new RuntimeException( "Path too complex for xmlbeans" );
  +
  +                _xqrlPathCache.put( path._pathKey, path );
  +            }
           }
   
  -        // TODO - for xqrl integ, check for null and try to compile
  -        
  -        if (path == null)
  -            throw new RuntimeException( "XQRL no integrated yet, path too complex or invalid" );
  +        assert path != null;
   
           return path;
      }
  @@ -147,6 +207,44 @@
           private final XPath  _compiledPath;
       }
   
  +    private static Path createXqrlCompiledPath ( String pathExpr, String currentVar )
  +    {
  +        if (_xqrlCompilePath == null)
  +        {
  +            try
  +            {
  +                Class xqrlImpl = Class.forName( "org.apache.xmlbeans.impl.newstore2.XqrlImpl" );
  +
  +                _xqrlCompilePath =
  +                    xqrlImpl.getDeclaredMethod(
  +                        "compilePath", new Class[] { String.class, String.class, Boolean.class } );
  +            }
  +            catch ( ClassNotFoundException e )
  +            {
  +                return null;
  +            }
  +            catch ( Exception e )
  +            {
  +                throw new RuntimeException( e.getMessage(), e );
  +            }
  +        }
  +
  +        Object[] args = new Object[] { pathExpr, currentVar, new Boolean( true ) };
  +
  +        try
  +        {
  +            return (Path) _xqrlCompilePath.invoke( null, args );
  +        }
  +        catch ( InvocationTargetException e )
  +        {
  +            throw new RuntimeException( e.getMessage(), e );
  +        }
  +        catch ( IllegalAccessException e )
  +        {
  +            throw new RuntimeException( e.getMessage(), e );
  +        }
  +    }
  +
       private static final class XbeanPathEngine extends ExecutionContext implements PathEngine
       {
           XbeanPathEngine ( XPath xpath, Cur c )
  @@ -255,33 +353,11 @@
       //
       //
       //
  -
  -    private static String getCurrentNodeVar ( XmlOptions options )
  -    {
  -        String currentNodeVar = "this";
  -
  -        options = XmlOptions.maskNull( options );
  -        
  -        if (options.hasOption( XmlOptions.XQUERY_CURRENT_NODE_VAR ))
  -        {
  -            currentNodeVar = (String) options.get( XmlOptions.XQUERY_CURRENT_NODE_VAR );
  -
  -            if (currentNodeVar.startsWith( "$" ))
  -            {
  -                throw
  -                    new IllegalArgumentException(
  -                        "Omit the '$' prefix for the current node variable" );
  -            }
  -        }
  -
  -        return currentNodeVar;
  -    }
  -
  -    //
  -    //
  -    //
       
       protected final String _pathKey;
       
       private static HashMap _xbeanPathCache = new HashMap();
  +    private static HashMap _xqrlPathCache  = new HashMap();
  +    
  +    private static Method _xqrlCompilePath;
   } 
  
  
  
  1.4       +16 -1     xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Xobj.java
  
  Index: Xobj.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Xobj.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Xobj.java	26 Jul 2004 18:24:13 -0000	1.3
  +++ Xobj.java	4 Aug 2004 21:15:06 -0000	1.4
  @@ -2250,7 +2250,22 @@
   
       public XmlObject[] exec_query ( String queryExpr, XmlOptions options ) throws XmlException
       {
  -        throw new RuntimeException( "Not implemeneted" );
  +        _locale.enter();
  +
  +        try
  +        {
  +            Cur c = tempCur();
  +            
  +            XmlObject[] result = Query.execQuery( c, queryExpr, options );
  +            
  +            c.release();
  +
  +            return result;
  +        }
  +        finally
  +        {
  +            _locale.exit();
  +        }
       }
   
       public String find_prefix_for_nsuri ( String nsuri, String suggested_prefix )
  
  
  
  1.1                  xml-xmlbeans/v2/src/newstore2/org/apache/xmlbeans/impl/newstore2/Query.java
  
  Index: Query.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.xmlbeans.impl.newstore2;
  
  import org.apache.xmlbeans.XmlOptions;
  import org.apache.xmlbeans.XmlObject;
  
  import java.util.HashMap;
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationTargetException;
  
  public abstract class Query
  {
      abstract XmlObject[] execute ( Cur c, XmlOptions options );
      
      //
      // Xqrl store specific implementation of compiled path/query
      //
  
      static XmlObject[] execQuery ( Cur c, String queryExpr, XmlOptions options )
      {
          return getCompiledQuery( queryExpr, options ).execute( c, options );
      }
  
      static synchronized Query getCompiledQuery ( String queryExpr, XmlOptions options )
      {
          return getCompiledQuery( queryExpr, Path.getCurrentNodeVar( options ) );
      }
      
      static synchronized Query getCompiledQuery ( String queryExpr, String currentVar )
      {
          assert queryExpr != null;
          
          Query query = (Query) _xqrlQueryCache.get( queryExpr );
  
          if (query != null)
              return query;
  
          // TODO - may want to add other query engines here: xqrl v2, saxon?
          
          query = createXqrlCompiledQuery( queryExpr, currentVar );
  
          if (query == null)
              throw new RuntimeException( "No query engine found" );
  
          _xqrlQueryCache.put( queryExpr, query );
  
          return query;
      }
      
      private static Query createXqrlCompiledQuery ( String queryExpr, String currentVar )
      {
          if (_xqrlCompileQuery == null)
          {
              try
              {
                  Class xqrlImpl = Class.forName( "org.apache.xmlbeans.impl.newstore2.XqrlImpl" );
  
                  _xqrlCompileQuery =
                      xqrlImpl.getDeclaredMethod(
                          "compileQuery", new Class[] { String.class, String.class, Boolean.class } );
              }
              catch ( ClassNotFoundException e )
              {
                  return null;
              }
              catch ( Exception e )
              {
                  throw new RuntimeException( e.getMessage(), e );
              }
          }
  
          Object[] args = new Object[] { queryExpr, currentVar, new Boolean( true ) };
  
          try
          {
              return (Query) _xqrlCompileQuery.invoke( null, args );
          }
          catch ( InvocationTargetException e )
          {
              throw new RuntimeException( e.getMessage(), e );
          }
          catch ( IllegalAccessException e )
          {
              throw new RuntimeException( e.getMessage(), e );
          }
      }
  
      //
      //
      //
  
      private static HashMap _xqrlQueryCache = new HashMap();
      
      private static Method _xqrlCompileQuery;
  }
  
  
  
  1.3       +2 -2      xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/values/JavaQNameHolder.java
  
  Index: JavaQNameHolder.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/typeimpl/org/apache/xmlbeans/impl/values/JavaQNameHolder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JavaQNameHolder.java	12 Feb 2004 20:06:22 -0000	1.2
  +++ JavaQNameHolder.java	4 Aug 2004 21:15:07 -0000	1.3
  @@ -46,11 +46,11 @@
       {
           public String find_prefix_for_nsuri(String nsuri, String suggested_prefix)
           {
  -            return QNameHelper.suggestPrefix(suggested_prefix);
  +            return QNameHelper.suggestPrefix(nsuri);
           }
           public String getNamespaceForPrefix(String prefix)
           {
  -            return prefix;
  +            throw new RuntimeException( "Should not be called" );
           }
       }
   
  
  
  
  1.5       +1 -1      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Path.java	23 Mar 2004 02:42:45 -0000	1.4
  +++ Path.java	4 Aug 2004 21:15:07 -0000	1.5
  @@ -219,7 +219,7 @@
                   query = XqrlDelegate.compileQuery( queryExpr, currentNodeVar );
   
                   if (query != null)
  -                    _xqrlQueryCache.put( query.getQueryExpr(), query );
  +                    _xqrlQueryCache.put( query.getQueryExpr(), query);
               }
           }
   
  
  
  
  1.3       +3 -0      xml-xmlbeans/v2/test/src/xmlcursor/xpath/jaxen/checkin/JaxenXPathTests.java
  
  Index: JaxenXPathTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xmlcursor/xpath/jaxen/checkin/JaxenXPathTests.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JaxenXPathTests.java	17 Jun 2004 16:29:41 -0000	1.2
  +++ JaxenXPathTests.java	4 Aug 2004 21:15:07 -0000	1.3
  @@ -51,11 +51,14 @@
       }
   
       public void testConformance() throws Exception {
  +// EricVas: I'm not implementing Jaxen in V2's newstore ... need to find a replacement for Jaxen
  +// NEWSTORE START
           XmlObject doc = null;
   
           doc = XmlObject.Factory.parse(sXml);
   
           runAll(doc, xpath);
  +// NEWSTORE END
       }
   
       private void runAll(XmlObject doc, String[] xpathes)
  
  
  

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