xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ce...@apache.org
Subject svn commit: r1363158 - in /xmlbeans/trunk: build.xml src/store/org/apache/xmlbeans/impl/store/Path.java src/store/org/apache/xmlbeans/impl/store/Query.java
Date Wed, 18 Jul 2012 22:26:10 GMT
Author: cezar
Date: Wed Jul 18 22:26:09 2012
New Revision: 1363158

URL: http://svn.apache.org/viewvc?rev=1363158&view=rev
Log:
Add another xpath and xquery interface implementation.


Modified:
    xmlbeans/trunk/build.xml
    xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java
    xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Query.java

Modified: xmlbeans/trunk/build.xml
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/build.xml?rev=1363158&r1=1363157&r2=1363158&view=diff
==============================================================================
--- xmlbeans/trunk/build.xml (original)
+++ xmlbeans/trunk/build.xml Wed Jul 18 22:26:09 2012
@@ -19,7 +19,7 @@
     <property name="javac.source" value="1.4"/>
     <property name="javac.target" value="1.4"/>
 
-    <property name="version.base" value="2.6.0"/>
+    <property name="version.base" value="2.6.0-RC1"/>
     <property name="version.rc" value=""/>
 
     <!-- manifest entries -->

Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java?rev=1363158&r1=1363157&r2=1363158&view=diff
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Path.java Wed Jul 18 22:26:09
2012
@@ -37,6 +37,7 @@ public abstract class Path
 {
     public static final String PATH_DELEGATE_INTERFACE = "PATH_DELEGATE_INTERFACE";
     public static String _useDelegateForXpath = "use delegate for xpath";
+    public static String _useXdkForXpath = "use xdk for xpath";
     public static String _useXqrlForXpath = "use xqrl for xpath";
     public static String _useXbeanForXpath = "use xbean for xpath";
     public static String _forceXqrl2002ForXpathXQuery = "use xqrl-2002 for xpath";
@@ -45,14 +46,18 @@ public abstract class Path
     private static final int USE_XQRL     = 0x02;
     private static final int USE_DELEGATE = 0x04;
     private static final int USE_XQRL2002 = 0x08;
+    private static final int USE_XDK      = 0x10;
 
     private static Map _xbeanPathCache = new WeakHashMap();
+    private static Map _xdkPathCache = new WeakHashMap();
     private static Map _xqrlPathCache = new WeakHashMap();
     private static Map _xqrl2002PathCache = new WeakHashMap();
 
+    private static Method _xdkCompilePath;
     private static Method _xqrlCompilePath;
     private static Method _xqrl2002CompilePath;
 
+    private static boolean _xdkAvailable = true;
     private static boolean _xqrlAvailable = true;
     private static boolean _xqrl2002Available = true;
 
@@ -120,9 +125,10 @@ public abstract class Path
         int force =
                 options.hasOption(_useDelegateForXpath) ? USE_DELEGATE
                 : options.hasOption(_useXqrlForXpath) ? USE_XQRL
+                : options.hasOption(_useXdkForXpath) ? USE_XDK
                 : options.hasOption(_useXbeanForXpath) ? USE_XBEAN
                 : options.hasOption(_forceXqrl2002ForXpathXQuery) ? USE_XQRL2002
-                : USE_XBEAN|USE_XQRL|USE_DELEGATE; //set all bits except XQRL2002
+                : USE_XBEAN|USE_XQRL|USE_XDK|USE_DELEGATE; //set all bits except XQRL2002
         String delIntfName = 
             options.hasOption(PATH_DELEGATE_INTERFACE) ? 
                 (String)options.get(PATH_DELEGATE_INTERFACE) : _delIntfName;
@@ -141,6 +147,8 @@ public abstract class Path
             pathWeakRef = (WeakReference)_xbeanPathCache.get(pathExpr);
         if (pathWeakRef == null && (force & USE_XQRL) != 0)
             pathWeakRef = (WeakReference)_xqrlPathCache.get(pathExpr);
+        if (pathWeakRef == null && (force & USE_XDK) != 0)
+            pathWeakRef = (WeakReference)_xdkPathCache.get(pathExpr);
         if (pathWeakRef == null && (force & USE_XQRL2002) != 0)
             pathWeakRef = (WeakReference)_xqrl2002PathCache.get(pathExpr);
 
@@ -153,6 +161,8 @@ public abstract class Path
             path = getCompiledPathXbean(pathExpr, currentVar, namespaces);
         if (path == null && (force & USE_XQRL) != 0)
             path = getCompiledPathXqrl(pathExpr, currentVar);
+        if (path == null && (force & USE_XDK) != 0)
+            path = getCompiledPathXdk(pathExpr, currentVar);
         if (path == null && (force & USE_DELEGATE) != 0)
             path = getCompiledPathDelegate(pathExpr, currentVar, namespaces, delIntfName);
         if (path == null && (force & USE_XQRL2002) != 0)
@@ -165,6 +175,8 @@ public abstract class Path
                 errMessage.append(" Trying XBeans path engine...");
             if ((force & USE_XQRL) != 0)
                 errMessage.append(" Trying XQRL...");
+            if ((force & USE_XDK) != 0)
+                errMessage.append(" Trying XDK...");
             if ((force & USE_DELEGATE) != 0)
                 errMessage.append(" Trying delegated path engine...");
             if ((force & USE_XQRL2002) != 0)
@@ -176,6 +188,15 @@ public abstract class Path
         return path;
     }
 
+    static private synchronized Path getCompiledPathXdk(String pathExpr, String currentVar)
+    {
+        Path path = createXdkCompiledPath(pathExpr, currentVar);
+        if (path != null)
+            _xdkPathCache.put(path._pathKey, new WeakReference(path));
+
+        return path;
+    }
+
     static private synchronized Path getCompiledPathXqrl(String pathExpr, String currentVar)
     {
         Path path = createXqrlCompiledPath(pathExpr, currentVar);
@@ -278,7 +299,7 @@ public abstract class Path
 
             if (!c.isContainer() || _compiledPath.sawDeepDot())
             {
-                int force = USE_DELEGATE | USE_XQRL;
+                int force = USE_DELEGATE | USE_XQRL | USE_XDK;
                 return getCompiledPath(_pathKey, force, _currentVar, delIntfName).execute(c,
options);
             }
             return new XbeanPathEngine(_compiledPath, c);
@@ -289,6 +310,47 @@ public abstract class Path
         public Map namespaces;
     }
 
+    private static Path createXdkCompiledPath(String pathExpr, String currentVar)
+    {
+        if (!_xdkAvailable)
+            return null;
+
+        if (_xdkCompilePath == null)
+        {
+            try
+            {
+                Class xdkImpl = Class.forName("org.apache.xmlbeans.impl.store.OXQXBXqrlImpl");
+
+                _xdkCompilePath =
+                    xdkImpl.getDeclaredMethod("compilePath",
+                        new Class[]{String.class, String.class, Boolean.class});
+            }
+            catch (ClassNotFoundException e)
+            {
+                _xdkAvailable = false;
+                return null;
+            }
+            catch (Exception e)
+            {
+                _xdkAvailable = false;
+                throw new RuntimeException(e.getMessage(), e);
+            }
+        }
+
+        Object[] args = new Object[]{pathExpr, currentVar, new Boolean(true)};
+
+        try {
+            return (Path) _xdkCompilePath.invoke(null, args);
+        }
+        catch (InvocationTargetException e) {
+            Throwable t = e.getCause();
+            throw new RuntimeException(t.getMessage(), t);
+        }
+        catch (IllegalAccessException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
     private static Path createXqrlCompiledPath(String pathExpr, String currentVar)
     {
         if (!_xqrlAvailable)

Modified: xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Query.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Query.java?rev=1363158&r1=1363157&r2=1363158&view=diff
==============================================================================
--- xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Query.java (original)
+++ xmlbeans/trunk/src/store/org/apache/xmlbeans/impl/store/Query.java Wed Jul 18 22:26:09
2012
@@ -33,10 +33,15 @@ public abstract class Query
 {
     public static final String QUERY_DELEGATE_INTERFACE = "QUERY_DELEGATE_INTERFACE";
     public static String _useDelegateForXQuery = "use delegate for xquery";
+    public static String _useXdkForXQuery = "use xdk for xquery";
 
     private static String _delIntfName;
     //private static HashMap _delegateQueryCache = new HashMap();
 
+    private static HashMap _xdkQueryCache = new HashMap();
+    private static Method _xdkCompileQuery;
+    private static boolean _xdkAvailable = true;  // at the beginning assume is available
+
     private static HashMap _xqrlQueryCache = new HashMap(); //todo check for memory leaks
     private static Method _xqrlCompileQuery;
     private static boolean _xqrlAvailable = true;  // at the beginning assume is available
@@ -124,6 +129,21 @@ public abstract class Query
                 ((Integer) boundary.get(XPath._NS_BOUNDARY)).intValue();
         }
 
+        if (options.hasOption(_useXdkForXQuery))
+        {
+            //try XDK
+            query = (Query) _xdkQueryCache.get(queryExpr);
+            if (query != null)
+                return query;
+
+            query = createXdkCompiledQuery(queryExpr, currentVar);
+            if (query != null)
+            {
+                _xdkQueryCache.put(queryExpr, query);
+                return query;
+            }
+        }
+
         if (!options.hasOption(_useDelegateForXQuery))
         {
         //try XQRL
@@ -166,6 +186,49 @@ public abstract class Query
         return queryExpr;
     }
 
+    private static Query createXdkCompiledQuery(String queryExpr, String currentVar)
+    {
+        //if the XDK engine has been determined unavailable, return null
+        if ( !_xdkAvailable ) return null;
+        if ( _xdkCompileQuery == null)
+        {
+            try
+            {
+                Class xdkImpl = Class.forName("org.apache.xmlbeans.impl.store.OXQXBXqrlImpl");
+
+                _xdkCompileQuery =
+                    xdkImpl.getDeclaredMethod("compileQuery",
+                        new Class[]{String.class, String.class, Boolean.class});
+            }
+            catch (ClassNotFoundException e)
+            {
+                _xdkAvailable = false;
+                return null;
+            }
+            catch (Exception e)
+            {
+                _xdkAvailable = false;
+                throw new RuntimeException(e.getMessage(), e);
+            }
+        }
+
+        Object[] args = new Object[]{queryExpr, currentVar, new Boolean(true)};
+
+        try
+        {
+            return (Query) _xdkCompileQuery.invoke(null, args);
+        }
+        catch (InvocationTargetException e)
+        {
+            Throwable t = e.getCause();
+            throw new RuntimeException(t.getMessage(), t);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
     private static Query createXqrlCompiledQuery(String queryExpr, String currentVar)
     {
         //if the XQRL engine has been determined unavailable, return null



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


Mime
View raw message