You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2020/08/20 22:25:58 UTC

svn commit: r1881037 [7/7] - in /xmlbeans/trunk/src/main/java/org/apache/xmlbeans: ./ impl/common/ impl/config/ impl/regex/ impl/schema/ impl/store/

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Path.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Path.java?rev=1881037&r1=1881036&r2=1881037&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Path.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Path.java Thu Aug 20 22:25:57 2020
@@ -15,30 +15,29 @@
 
 package org.apache.xmlbeans.impl.store;
 
-import java.io.*;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.ref.WeakReference;
-import java.math.BigDecimal;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
+import org.apache.xmlbeans.*;
 import org.apache.xmlbeans.impl.common.DefaultClassLoaderResourceLoader;
 import org.apache.xmlbeans.impl.common.XPath;
+import org.apache.xmlbeans.impl.common.XPathExecutionContext;
 import org.apache.xmlbeans.impl.common.XPath.XPathCompileException;
-import org.apache.xmlbeans.impl.common.XPath.ExecutionContext;
-
-import org.apache.xmlbeans.*;
 import org.w3c.dom.Node;
 
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
 
 // TODO - This class handled query *and* path ... rename it?
 
-public abstract class Path
-{
+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";
@@ -46,16 +45,16 @@ public abstract class Path
     public static String _useXbeanForXpath = "use xbean for xpath";
     public static String _forceXqrl2002ForXpathXQuery = "use xqrl-2002 for xpath";
 
-    private static final int USE_XBEAN    = 0x01;
-    private static final int USE_XQRL     = 0x02;
+    private static final int USE_XBEAN = 0x01;
+    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 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 final Map<String,WeakReference<Path>> _xbeanPathCache = new WeakHashMap<>();
+    private static final Map<String,WeakReference<Path>> _xdkPathCache = new WeakHashMap<>();
+    private static final Map<String,WeakReference<Path>> _xqrlPathCache = new WeakHashMap<>();
+    private static final Map<String,WeakReference<Path>> _xqrl2002PathCache = new WeakHashMap<>();
 
     private static Method _xdkCompilePath;
     private static Method _xqrlCompilePath;
@@ -68,13 +67,12 @@ public abstract class Path
     private static final String _delIntfName;
     private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
 
-    static
-    {
+    static {
         String id = "META-INF/services/org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface";
         InputStream in = new DefaultClassLoaderResourceLoader().getResourceAsStream(id);
 
         String name = null;
-        if(in != null) {
+        if (in != null) {
             try {
                 BufferedReader br = new BufferedReader(new InputStreamReader(in));
                 name = br.readLine().trim();
@@ -89,14 +87,12 @@ public abstract class Path
 
     protected final String _pathKey;
 
-    Path(String key)
-    {
+    Path(String key) {
         _pathKey = key;
     }
 
 
-    interface PathEngine
-    {
+    interface PathEngine {
         void release();
 
         boolean next(Cur c);
@@ -108,8 +104,7 @@ public abstract class Path
     //
     //
 
-    static String getCurrentNodeVar(XmlOptions options)
-    {
+    static String getCurrentNodeVar(XmlOptions options) {
         String currentNodeVar = "this";
 
         options = XmlOptions.maskNull(options);
@@ -125,171 +120,179 @@ public abstract class Path
         return currentNodeVar;
     }
 
-    public static Path getCompiledPath(String pathExpr, XmlOptions options)
-    {
+    public static Path getCompiledPath(String pathExpr, XmlOptions options) {
         options = XmlOptions.maskNull(options);
 
         int force =
-                options.hasOption(_useDelegateForXpath) ? USE_DELEGATE
+            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_XDK|USE_DELEGATE; //set all bits except XQRL2002
-        String delIntfName = 
-            options.hasOption(PATH_DELEGATE_INTERFACE) ? 
-                (String)options.get(PATH_DELEGATE_INTERFACE) : _delIntfName;
+                : 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;
 
         return getCompiledPath(pathExpr, force, getCurrentNodeVar(options), delIntfName);
     }
 
     static Path getCompiledPath(String pathExpr, int force,
-        String currentVar, String delIntfName)
-    {
+                                String currentVar, String delIntfName) {
         Path path = null;
-        WeakReference pathWeakRef = null;
-        Map namespaces = (force & USE_DELEGATE) != 0 ? new HashMap() : null;
+        WeakReference<Path> pathWeakRef = null;
+        Map<String,String> namespaces = (force & USE_DELEGATE) != 0 ? new HashMap<>() : null;
         lock.readLock().lock();
         try {
-        if ((force & USE_XBEAN) != 0)
-            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);
-
-        if (pathWeakRef!=null)
-            path = (Path)pathWeakRef.get();
-        if (path != null)
-            return path;
+            if ((force & USE_XBEAN) != 0) {
+                pathWeakRef = _xbeanPathCache.get(pathExpr);
+            }
+            if (pathWeakRef == null && (force & USE_XQRL) != 0) {
+                pathWeakRef = _xqrlPathCache.get(pathExpr);
+            }
+            if (pathWeakRef == null && (force & USE_XDK) != 0) {
+                pathWeakRef = _xdkPathCache.get(pathExpr);
+            }
+            if (pathWeakRef == null && (force & USE_XQRL2002) != 0) {
+                pathWeakRef = _xqrl2002PathCache.get(pathExpr);
+            }
+
+            if (pathWeakRef != null) {
+                path = pathWeakRef.get();
+            }
+            if (path != null) {
+                return path;
+            }
         } finally {
             lock.readLock().unlock();
         }
         lock.writeLock().lock();
         try {
-        if ((force & USE_XBEAN) != 0) {
-            pathWeakRef = (WeakReference)_xbeanPathCache.get(pathExpr);
-            if (pathWeakRef != null)
-                path = (Path)pathWeakRef.get();
-            if (path==null)
-            path = getCompiledPathXbean(pathExpr, currentVar, namespaces);
-        }
-        if (path == null && (force & USE_XQRL) != 0) {
-            pathWeakRef = (WeakReference)_xqrlPathCache.get(pathExpr);
-            if (pathWeakRef != null)
-                path = (Path)pathWeakRef.get();
-            if (path==null)
-            path = getCompiledPathXqrl(pathExpr, currentVar);
-        }
-        if (path == null && (force & USE_XDK) != 0) {
-            pathWeakRef = (WeakReference)_xdkPathCache.get(pathExpr);
-            if (pathWeakRef != null)
-                path = (Path)pathWeakRef.get();
-            if (path==null)
-            path = getCompiledPathXdk(pathExpr, currentVar);
-        }
-        if (path == null && (force & USE_DELEGATE) != 0) {
-            path = getCompiledPathDelegate(pathExpr, currentVar, namespaces, delIntfName);
-        }
-        if (path == null && (force & USE_XQRL2002) != 0) {
-            pathWeakRef = (WeakReference)_xqrl2002PathCache.get(pathExpr);
-            if (pathWeakRef != null)
-                path = (Path)pathWeakRef.get();
-            if (path==null)
-            path = getCompiledPathXqrl2002(pathExpr, currentVar);
-        }
-        if (path == null)
-        {
-            StringBuilder errMessage = new StringBuilder();
-            if ((force & USE_XBEAN) != 0)
-                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)
-                errMessage.append(" Trying XQRL2002...");
+            if ((force & USE_XBEAN) != 0) {
+                pathWeakRef = _xbeanPathCache.get(pathExpr);
+                if (pathWeakRef != null) {
+                    path = pathWeakRef.get();
+                }
+                if (path == null) {
+                    path = getCompiledPathXbean(pathExpr, currentVar, namespaces);
+                }
+            }
+            if (path == null && (force & USE_XQRL) != 0) {
+                pathWeakRef = _xqrlPathCache.get(pathExpr);
+                if (pathWeakRef != null) {
+                    path = pathWeakRef.get();
+                }
+                if (path == null) {
+                    path = getCompiledPathXqrl(pathExpr, currentVar);
+                }
+            }
+            if (path == null && (force & USE_XDK) != 0) {
+                pathWeakRef = _xdkPathCache.get(pathExpr);
+                if (pathWeakRef != null) {
+                    path = pathWeakRef.get();
+                }
+                if (path == null) {
+                    path = getCompiledPathXdk(pathExpr, currentVar);
+                }
+            }
+            if (path == null && (force & USE_DELEGATE) != 0) {
+                path = getCompiledPathDelegate(pathExpr, currentVar, namespaces, delIntfName);
+            }
+            if (path == null && (force & USE_XQRL2002) != 0) {
+                pathWeakRef = _xqrl2002PathCache.get(pathExpr);
+                if (pathWeakRef != null) {
+                    path = pathWeakRef.get();
+                }
+                if (path == null) {
+                    path = getCompiledPathXqrl2002(pathExpr, currentVar);
+                }
+            }
+            if (path == null) {
+                StringBuilder errMessage = new StringBuilder();
+                if ((force & USE_XBEAN) != 0) {
+                    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) {
+                    errMessage.append(" Trying XQRL2002...");
+                }
 
-            throw new RuntimeException(errMessage.toString() + " FAILED on " + pathExpr);
-        }
+                throw new RuntimeException(errMessage.toString() + " FAILED on " + pathExpr);
+            }
         } finally {
             lock.writeLock().unlock();
         }
         return path;
     }
 
-    static private Path getCompiledPathXdk(String pathExpr, String currentVar)
-    {
+    static private Path getCompiledPathXdk(String pathExpr, String currentVar) {
         Path path = createXdkCompiledPath(pathExpr, currentVar);
-        if (path != null)
-            _xdkPathCache.put(path._pathKey, new WeakReference(path));
+        if (path != null) {
+            _xdkPathCache.put(path._pathKey, new WeakReference<>(path));
+        }
 
         return path;
     }
 
-    static private Path getCompiledPathXqrl(String pathExpr, String currentVar)
-    {
+    static private Path getCompiledPathXqrl(String pathExpr, String currentVar) {
         Path path = createXqrlCompiledPath(pathExpr, currentVar);
-        if (path != null)
-            _xqrlPathCache.put(path._pathKey, new WeakReference(path));
+        if (path != null) {
+            _xqrlPathCache.put(path._pathKey, new WeakReference<>(path));
+        }
 
         return path;
     }
 
-    static private Path getCompiledPathXqrl2002(String pathExpr, String currentVar)
-    {
+    static private Path getCompiledPathXqrl2002(String pathExpr, String currentVar) {
         Path path = createXqrl2002CompiledPath(pathExpr, currentVar);
-        if (path != null)
-            _xqrl2002PathCache.put(path._pathKey, new WeakReference(path));
+        if (path != null) {
+            _xqrl2002PathCache.put(path._pathKey, new WeakReference<>(path));
+        }
 
         return path;
     }
 
     static private Path getCompiledPathXbean(String pathExpr,
-        String currentVar, Map namespaces)
-    {
+                                             String currentVar, Map<String,String> namespaces) {
         Path path = XbeanPath.create(pathExpr, currentVar, namespaces);
-        if (path != null)
-            _xbeanPathCache.put(path._pathKey, new WeakReference(path));
+        if (path != null) {
+            _xbeanPathCache.put(path._pathKey, new WeakReference<>(path));
+        }
 
         return path;
     }
 
-    static private Path getCompiledPathDelegate(String pathExpr, String currentVar, Map namespaces, String delIntfName)
-    {
-        Path path = null;
-        if ( namespaces == null )
-            namespaces = new HashMap();
+    static private Path getCompiledPathDelegate(String pathExpr, String currentVar, Map<String,String> namespaces, String delIntfName) {
+        if (namespaces == null) {
+            namespaces = new HashMap<>();
+        }
 
-        try
-        {
+        try {
             XPath.compileXPath(pathExpr, currentVar, namespaces);
-        }
-        catch (XPath.XPathCompileException e)
-        {
+        } catch (XPath.XPathCompileException e) {
             //do nothing, this function is only called to populate the namespaces map
         }
 
-        int offset =
-            namespaces.get(XPath._NS_BOUNDARY) == null ?
-            0 :
-            ((Integer) namespaces.get(XPath._NS_BOUNDARY)).intValue();
+
+        int offset = Integer.parseInt(namespaces.getOrDefault(XPath._NS_BOUNDARY, "0"));
         namespaces.remove(XPath._NS_BOUNDARY);
-        path = DelegatePathImpl.create(delIntfName,
+
+        return DelegatePathImpl.create(delIntfName,
             pathExpr.substring(offset),
             currentVar,
             namespaces);
-
-        return path;
     }
 
 
-    public static String compilePath(String pathExpr, XmlOptions options)
-    {
+    public static String compilePath(String pathExpr, XmlOptions options) {
         return getCompiledPath(pathExpr, options)._pathKey;
     }
 
@@ -297,42 +300,35 @@ public abstract class Path
     // Xbean store specific implementation of compiled path
     //
 
-    private static final class XbeanPath extends Path
-    {
-        static Path create(String pathExpr, String currentVar, Map namespaces)
-        {
-            try
-            {
+    private static final class XbeanPath extends Path {
+        static Path create(String pathExpr, String currentVar, Map<String,String> namespaces) {
+            try {
                 return new XbeanPath(pathExpr, currentVar,
-                                XPath.compileXPath(pathExpr, currentVar, namespaces));
-            }
-            catch (XPathCompileException e) {
+                    XPath.compileXPath(pathExpr, currentVar, namespaces));
+            } catch (XPathCompileException e) {
                 return null;
             }
         }
 
-        private XbeanPath(String pathExpr, String currentVar, XPath xpath)
-        {
+        private XbeanPath(String pathExpr, String currentVar, XPath xpath) {
             super(pathExpr);
 
             _currentVar = currentVar;
             _compiledPath = xpath;
         }
 
-        PathEngine execute(Cur c, XmlOptions options)
-        {
+        PathEngine execute(Cur c, XmlOptions options) {
             options = XmlOptions.maskNull(options);
-            String delIntfName = 
-                options.hasOption(PATH_DELEGATE_INTERFACE) ? 
-                    (String)options.get(PATH_DELEGATE_INTERFACE) : _delIntfName;
+            String delIntfName =
+                options.hasOption(PATH_DELEGATE_INTERFACE) ?
+                    (String) options.get(PATH_DELEGATE_INTERFACE) : _delIntfName;
 
             // The builtin XPath engine works only on containers.  Delegate to
             // xqrl otherwise.  Also, if the path had a //. at the end, the
             // simple xpath engine can't do the generate case, it only handles
             // attrs and elements.
 
-            if (!c.isContainer() || _compiledPath.sawDeepDot())
-            {
+            if (!c.isContainer() || _compiledPath.sawDeepDot()) {
                 int force = USE_DELEGATE | USE_XQRL | USE_XDK;
                 return getCompiledPath(_pathKey, force, _currentVar, delIntfName).execute(c, options);
             }
@@ -341,141 +337,112 @@ public abstract class Path
 
         private final String _currentVar;
         private final XPath _compiledPath;
-        public Map namespaces;
+        public Map<String,String> namespaces;
     }
 
-    private static Path createXdkCompiledPath(String pathExpr, String currentVar)
-    {
-        if (!_xdkAvailable)
+    private static Path createXdkCompiledPath(String pathExpr, String currentVar) {
+        if (!_xdkAvailable) {
             return null;
+        }
 
-        if (_xdkCompilePath == null)
-        {
-            try
-            {
+        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)
-            {
+            } catch (ClassNotFoundException e) {
                 _xdkAvailable = false;
                 return null;
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 _xdkAvailable = false;
                 throw new RuntimeException(e.getMessage(), e);
             }
         }
 
-        Object[] args = new Object[]{pathExpr, currentVar, new Boolean(true)};
+        Object[] args = new Object[]{pathExpr, currentVar, Boolean.TRUE};
 
         try {
             return (Path) _xdkCompilePath.invoke(null, args);
-        }
-        catch (InvocationTargetException e) {
+        } catch (InvocationTargetException e) {
             Throwable t = e.getCause();
             throw new RuntimeException(t.getMessage(), t);
-        }
-        catch (IllegalAccessException e) {
+        } catch (IllegalAccessException e) {
             throw new RuntimeException(e.getMessage(), e);
         }
     }
 
-    private static Path createXqrlCompiledPath(String pathExpr, String currentVar)
-    {
-        if (!_xqrlAvailable)
+    private static Path createXqrlCompiledPath(String pathExpr, String currentVar) {
+        if (!_xqrlAvailable) {
             return null;
+        }
 
-        if (_xqrlCompilePath == null)
-        {
-            try
-            {
+        if (_xqrlCompilePath == null) {
+            try {
                 Class xqrlImpl = Class.forName("org.apache.xmlbeans.impl.store.XqrlImpl");
 
                 _xqrlCompilePath =
-                        xqrlImpl.getDeclaredMethod("compilePath",
-                                new Class[]{String.class, String.class, Boolean.class});
-            }
-            catch (ClassNotFoundException e)
-            {
+                    xqrlImpl.getDeclaredMethod("compilePath",
+                        new Class[]{String.class, String.class, Boolean.class});
+            } catch (ClassNotFoundException e) {
                 _xqrlAvailable = false;
                 return null;
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 _xqrlAvailable = false;
                 throw new RuntimeException(e.getMessage(), e);
             }
         }
 
-        Object[] args = new Object[]{pathExpr, currentVar, new Boolean(true)};
+        Object[] args = new Object[]{pathExpr, currentVar, Boolean.TRUE};
 
         try {
             return (Path) _xqrlCompilePath.invoke(null, args);
-        }
-        catch (InvocationTargetException e) {
+        } catch (InvocationTargetException e) {
             Throwable t = e.getCause();
             throw new RuntimeException(t.getMessage(), t);
-        }
-        catch (IllegalAccessException e) {
+        } catch (IllegalAccessException e) {
             throw new RuntimeException(e.getMessage(), e);
         }
     }
 
-    private static Path createXqrl2002CompiledPath(String pathExpr, String currentVar)
-    {
-        if (!_xqrl2002Available)
+    private static Path createXqrl2002CompiledPath(String pathExpr, String currentVar) {
+        if (!_xqrl2002Available) {
             return null;
+        }
 
-        if (_xqrl2002CompilePath == null)
-        {
-            try
-            {
+        if (_xqrl2002CompilePath == null) {
+            try {
                 Class xqrlImpl = Class.forName("org.apache.xmlbeans.impl.store.Xqrl2002Impl");
 
                 _xqrl2002CompilePath =
                     xqrlImpl.getDeclaredMethod("compilePath",
                         new Class[]{String.class, String.class, Boolean.class});
-            }
-            catch (ClassNotFoundException e)
-            {
+            } catch (ClassNotFoundException e) {
                 _xqrl2002Available = false;
                 return null;
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 _xqrl2002Available = false;
                 throw new RuntimeException(e.getMessage(), e);
             }
         }
 
-        Object[] args = new Object[]{pathExpr, currentVar, new Boolean(true)};
+        Object[] args = new Object[]{pathExpr, currentVar, Boolean.TRUE};
 
-        try
-        {
+        try {
             return (Path) _xqrl2002CompilePath.invoke(null, args);
-        }
-        catch (InvocationTargetException e)
-        {
+        } catch (InvocationTargetException e) {
             Throwable t = e.getCause();
             throw new RuntimeException(t.getMessage(), t);
-        }
-        catch (IllegalAccessException e)
-        {
+        } catch (IllegalAccessException e) {
             throw new RuntimeException(e.getMessage(), e);
         }
     }
 
     private static final class XbeanPathEngine
-        extends ExecutionContext
-        implements PathEngine
-    {
-        XbeanPathEngine(XPath xpath, Cur c)
-        {
+        extends XPathExecutionContext
+        implements PathEngine {
+        XbeanPathEngine(XPath xpath, Cur c) {
             assert c.isContainer();
 
             _version = c._locale.version();
@@ -487,62 +454,57 @@ public abstract class Path
 
             int ret = start();
 
-            if ((ret & HIT) != 0)
+            if ((ret & HIT) != 0) {
                 c.addToSelection();
+            }
 
             doAttrs(ret, c);
 
-            if ((ret & DESCEND) == 0 || !Locale.toFirstChildElement(_cur))
+            if ((ret & DESCEND) == 0 || !Locale.toFirstChildElement(_cur)) {
                 release();
+            }
         }
 
-        private void advance(Cur c)
-        {
+        private void advance(Cur c) {
             assert _cur != null;
 
-            if (_cur.isFinish())
-            {
-                if (_cur.isAtEndOfLastPush())
+            if (_cur.isFinish()) {
+                if (_cur.isAtEndOfLastPush()) {
                     release();
-                else {
+                } else {
                     end();
                     _cur.next();
                 }
-            }
-            else if (_cur.isElem())
-            {
+            } else if (_cur.isElem()) {
                 int ret = element(_cur.getName());
 
-                if ((ret & HIT) != 0)
+                if ((ret & HIT) != 0) {
                     c.addToSelection(_cur);
+                }
 
                 doAttrs(ret, c);
 
-                if ((ret & DESCEND) == 0 || !Locale.toFirstChildElement(_cur))
-                {
+                if ((ret & DESCEND) == 0 || !Locale.toFirstChildElement(_cur)) {
                     end();
                     _cur.skip();
                 }
-            }
-            else
-            {
-                do
-                {
+            } else {
+                do {
                     _cur.next();
                 }
-                while(!_cur.isContainerOrFinish());
+                while (!_cur.isContainerOrFinish());
             }
         }
 
-        private void doAttrs(int ret, Cur c)
-        {
+        private void doAttrs(int ret, Cur c) {
             assert _cur.isContainer();
 
             if ((ret & ATTRS) != 0) {
                 if (_cur.toFirstAttr()) {
                     do {
-                        if (attr(_cur.getName()))
+                        if (attr(_cur.getName())) {
                             c.addToSelection(_cur);
+                        }
                     }
                     while (_cur.toNextAttr());
 
@@ -551,25 +513,25 @@ public abstract class Path
             }
         }
 
-        public boolean next(Cur c)
-        {
-            if (_cur != null && _version != _cur._locale.version())
+        public boolean next(Cur c) {
+            if (_cur != null && _version != _cur._locale.version()) {
                 throw new ConcurrentModificationException("Document changed during select");
+            }
 
             int startCount = c.selectionCount();
 
             while (_cur != null) {
                 advance(c);
 
-                if (startCount != c.selectionCount())
+                if (startCount != c.selectionCount()) {
                     return true;
+                }
             }
 
             return false;
         }
 
-        public void release()
-        {
+        public void release() {
             if (_cur != null) {
                 _cur.release();
                 _cur = null;
@@ -581,64 +543,59 @@ public abstract class Path
     }
 
     private static final class DelegatePathImpl
-        extends Path
-    {
+        extends Path {
         private PathDelegate.SelectPathInterface _xpathImpl;
 
-        static Path create(String implClassName, String pathExpr, String currentNodeVar, Map namespaceMap)
-        {
+        static Path create(String implClassName, String pathExpr, String currentNodeVar, Map namespaceMap) {
             assert !currentNodeVar.startsWith("$"); // cezar review with ericvas
 
             PathDelegate.SelectPathInterface impl =
-                    PathDelegate.createInstance(implClassName, pathExpr, currentNodeVar, namespaceMap);
-            if (impl == null)
+                PathDelegate.createInstance(implClassName, pathExpr, currentNodeVar, namespaceMap);
+            if (impl == null) {
                 return null;
+            }
 
             return new DelegatePathImpl(impl, pathExpr);
         }
 
 
         private DelegatePathImpl(PathDelegate.SelectPathInterface xpathImpl,
-                              String pathExpr)
-        {
+                                 String pathExpr) {
             super(pathExpr);
             _xpathImpl = xpathImpl;
         }
 
-        protected PathEngine execute(Cur c, XmlOptions options)
-        {
+        protected PathEngine execute(Cur c, XmlOptions options) {
             return new DelegatePathEngine(_xpathImpl, c);
         }
 
         private static class DelegatePathEngine
-                extends XPath.ExecutionContext
-                implements PathEngine
-        {
+            extends XPathExecutionContext
+            implements PathEngine {
             // full datetime format: yyyy-MM-dd'T'HH:mm:ss'Z'
             private final DateFormat xmlDateFormat = new SimpleDateFormat("yyyy-MM-dd");
 
             DelegatePathEngine(PathDelegate.SelectPathInterface xpathImpl,
-                               Cur c)
-            {
+                               Cur c) {
                 _engine = xpathImpl;
                 _version = c._locale.version();
                 _cur = c.weakCur(this);
             }
 
-            public boolean next(Cur c)
-            {
-                if (!_firstCall)
+            public boolean next(Cur c) {
+                if (!_firstCall) {
                     return false;
+                }
 
                 _firstCall = false;
 
-                if (_cur != null && _version != _cur._locale.version())
+                if (_cur != null && _version != _cur._locale.version()) {
                     throw new ConcurrentModificationException("Document changed during select");
+                }
 
                 List resultsList;
-                Object context_node;
 
-                context_node = _cur.getDom();
+                Object context_node = _cur.getDom();
                 resultsList = _engine.selectPath(context_node);
 
                 int i;
@@ -652,7 +609,7 @@ public abstract class Path
                         if (obj instanceof Date) {
                             value = xmlDateFormat.format((Date) obj);
                         } else if (obj instanceof BigDecimal) {
-                            value = ((BigDecimal)obj).toPlainString();
+                            value = ((BigDecimal) obj).toPlainString();
                         } else {
                             value = obj.toString();
                         }
@@ -663,19 +620,17 @@ public abstract class Path
                         Locale l = c._locale;
                         try {
                             pos = l.load("<xml-fragment/>").tempCur();
-                            pos.setValue(value);     
+                            pos.setValue(value);
                             SchemaType type = getType(node);
                             Locale.autoTypeDocument(pos, type, null);
                             //move the cur to the actual text
                             pos.next();
-                        }
-                        catch (Exception e) {
+                        } catch (Exception e) {
                             throw new RuntimeException(e);
                         }
-                    }
-                    else {
-                        assert (node instanceof DomImpl.Dom):
-                                "New object created in XPATH!";
+                    } else {
+                        assert (node instanceof DomImpl.Dom) :
+                            "New object created in XPATH!";
                         pos = ((DomImpl.Dom) node).tempCur();
 
                     }
@@ -687,32 +642,31 @@ public abstract class Path
                 return true;
             }
 
-            private SchemaType getType(Object node)
-            {
+            private SchemaType getType(Object node) {
                 SchemaType type;
-                if (node instanceof Integer)
+                if (node instanceof Integer) {
                     type = XmlInteger.type;
-                else if (node instanceof Double)
+                } else if (node instanceof Double) {
                     type = XmlDouble.type;
-                else if (node instanceof Long)
+                } else if (node instanceof Long) {
                     type = XmlLong.type;
-                else if (node instanceof Float)
+                } else if (node instanceof Float) {
                     type = XmlFloat.type;
-                else if (node instanceof BigDecimal)
+                } else if (node instanceof BigDecimal) {
                     type = XmlDecimal.type;
-                else if (node instanceof Boolean)
+                } else if (node instanceof Boolean) {
                     type = XmlBoolean.type;
-                else if (node instanceof String)
+                } else if (node instanceof String) {
                     type = XmlString.type;
-                else if (node instanceof Date)
+                } else if (node instanceof Date) {
                     type = XmlDate.type;
-                else
+                } else {
                     type = XmlAnySimpleType.type;
+                }
                 return type;
             }
 
-            public void release()
-            {
+            public void release() {
                 if (_cur != null) {
                     _cur.release();
                     _cur = null;

Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Query.java
URL: http://svn.apache.org/viewvc/xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Query.java?rev=1881037&r1=1881036&r2=1881037&view=diff
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Query.java (original)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Query.java Thu Aug 20 22:25:57 2020
@@ -18,20 +18,21 @@ package org.apache.xmlbeans.impl.store;
 import org.apache.xmlbeans.*;
 import org.apache.xmlbeans.impl.common.DefaultClassLoaderResourceLoader;
 import org.apache.xmlbeans.impl.common.XPath;
-import org.w3c.dom.*;
+import org.w3c.dom.Node;
 
 import javax.xml.namespace.QName;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Date;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
-import java.math.BigDecimal;
 
-public abstract class Query
-{
+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";
@@ -48,21 +49,17 @@ public abstract class Query
     private static boolean _xqrlAvailable = true;  // at the beginning assume is available
 
     private static HashMap _xqrl2002QueryCache = new HashMap();
-    private static Method  _xqrl2002CompileQuery;
+    private static Method _xqrl2002CompileQuery;
     private static boolean _xqrl2002Available = true;  // at the beginning assume is available
 
-    static
-    {
+    static {
         String id = "META-INF/services/org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface";
         InputStream in = new DefaultClassLoaderResourceLoader().getResourceAsStream(id);
-        try
-        {
+        try {
             BufferedReader br = new BufferedReader(new InputStreamReader(in));
             _delIntfName = br.readLine().trim();
             br.close();
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             _delIntfName = null;
         }
     }
@@ -75,36 +72,31 @@ public abstract class Query
     // Xqrl store specific implementation of compiled path/query
     //
 
-    static XmlObject[] objectExecQuery(Cur c, String queryExpr, XmlOptions options)
-    {
+    static XmlObject[] objectExecQuery(Cur c, String queryExpr, XmlOptions options) {
         return getCompiledQuery(queryExpr, options).objectExecute(c, options);
     }
 
-    static XmlCursor cursorExecQuery(Cur c, String queryExpr, XmlOptions options)
-    {
+    static XmlCursor cursorExecQuery(Cur c, String queryExpr, XmlOptions options) {
         return getCompiledQuery(queryExpr, options).cursorExecute(c, options);
     }
 
-    public static synchronized Query getCompiledQuery(String queryExpr, XmlOptions options)
-    {
+    public static synchronized Query getCompiledQuery(String queryExpr, XmlOptions options) {
         return getCompiledQuery(queryExpr, Path.getCurrentNodeVar(options), options);
     }
 
-    static synchronized Query getCompiledQuery(String queryExpr, String currentVar, XmlOptions options)
-    {
+    static synchronized Query getCompiledQuery(String queryExpr, String currentVar, XmlOptions options) {
         assert queryExpr != null;
         options = XmlOptions.maskNull(options);
         Query query;
 
-        if (options.hasOption(Path._forceXqrl2002ForXpathXQuery))
-        {
-            query = (Query)_xqrl2002QueryCache.get(queryExpr);
-            if (query!=null)
+        if (options.hasOption(Path._forceXqrl2002ForXpathXQuery)) {
+            query = (Query) _xqrl2002QueryCache.get(queryExpr);
+            if (query != null) {
                 return query;
+            }
 
             query = getXqrl2002CompiledQuery(queryExpr, currentVar);
-            if (query!=null)
-            {
+            if (query != null) {
                 _xqrl2002QueryCache.put(queryExpr, query);
                 return query;
             }
@@ -113,66 +105,57 @@ public abstract class Query
 
         //Parse the query via XBeans: need to figure out end of prolog
         //in order to bind $this...not good but...
-        Map boundary = new HashMap();
-        int boundaryVal = 0;
-        try
-        {
+        Map<String, String> boundary = new HashMap<>();
+        int boundaryVal;
+        try {
             XPath.compileXPath(queryExpr, currentVar, boundary);
-        }
-        catch (XPath.XPathCompileException e)
-        {
+        } catch (XPath.XPathCompileException e) {
             //don't care if it fails, just care about boundary
-        }
-        finally
-        {
-            boundaryVal = boundary.get(XPath._NS_BOUNDARY) == null ? 0 :
-                ((Integer) boundary.get(XPath._NS_BOUNDARY)).intValue();
+        } finally {
+            boundaryVal = Integer.parseInt(boundary.getOrDefault(XPath._NS_BOUNDARY, "0"));
         }
 
-        if (options.hasOption(_useXdkForXQuery))
-        {
+        if (options.hasOption(_useXdkForXQuery)) {
             //try XDK
             query = (Query) _xdkQueryCache.get(queryExpr);
-            if (query != null)
+            if (query != null) {
                 return query;
+            }
 
             query = createXdkCompiledQuery(queryExpr, currentVar);
-            if (query != null)
-            {
+            if (query != null) {
                 _xdkQueryCache.put(queryExpr, query);
                 return query;
             }
         }
 
-        if (!options.hasOption(_useDelegateForXQuery))
-        {
-        //try XQRL
-        query = (Query) _xqrlQueryCache.get(queryExpr);
-        if (query != null)
-            return query;
+        if (!options.hasOption(_useDelegateForXQuery)) {
+            //try XQRL
+            query = (Query) _xqrlQueryCache.get(queryExpr);
+            if (query != null) {
+                return query;
+            }
 
-        query = createXqrlCompiledQuery(queryExpr, currentVar);
-        if (query != null)
-        {
-            _xqrlQueryCache.put(queryExpr, query);
-            return query;
-        }
+            query = createXqrlCompiledQuery(queryExpr, currentVar);
+            if (query != null) {
+                _xqrlQueryCache.put(queryExpr, query);
+                return query;
+            }
         }
 
-        //otherwise (if _useDelegateForXQuery option is set), 
+        //otherwise (if _useDelegateForXQuery option is set),
         //or if xqrl is not found, try delegate
         //query = (Query) _delegateQueryCache.get(queryExpr);
 
         //if (query != null)
         //    return query;
 
-        String delIntfName = 
-            options.hasOption(QUERY_DELEGATE_INTERFACE) ? 
-                (String)options.get(QUERY_DELEGATE_INTERFACE) : _delIntfName;
+        String delIntfName =
+            options.hasOption(QUERY_DELEGATE_INTERFACE) ?
+                (String) options.get(QUERY_DELEGATE_INTERFACE) : _delIntfName;
         query = DelegateQueryImpl.createDelegateCompiledQuery(delIntfName, queryExpr, currentVar, boundaryVal, options);
 
-        if (query != null)
-        {
+        if (query != null) {
             //_delegateQueryCache.put(queryExpr, query);
             return query;
         }
@@ -180,33 +163,27 @@ public abstract class Query
         throw new RuntimeException("No query engine found");
     }
 
-    public static synchronized String compileQuery(String queryExpr, XmlOptions options)
-    {
+    public static synchronized String compileQuery(String queryExpr, XmlOptions options) {
         getCompiledQuery(queryExpr, options);
         return queryExpr;
     }
 
-    private static Query createXdkCompiledQuery(String queryExpr, String currentVar)
-    {
+    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
-            {
+        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)
-            {
+            } catch (ClassNotFoundException e) {
                 _xdkAvailable = false;
                 return null;
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 _xdkAvailable = false;
                 throw new RuntimeException(e.getMessage(), e);
             }
@@ -214,42 +191,32 @@ public abstract class Query
 
         Object[] args = new Object[]{queryExpr, currentVar, new Boolean(true)};
 
-        try
-        {
+        try {
             return (Query) _xdkCompileQuery.invoke(null, args);
-        }
-        catch (InvocationTargetException e)
-        {
+        } catch (InvocationTargetException e) {
             Throwable t = e.getCause();
             throw new RuntimeException(t.getMessage(), t);
-        }
-        catch (IllegalAccessException e)
-        {
+        } catch (IllegalAccessException e) {
             throw new RuntimeException(e.getMessage(), e);
         }
     }
 
-    private static Query createXqrlCompiledQuery(String queryExpr, String currentVar)
-    {
+    private static Query createXqrlCompiledQuery(String queryExpr, String currentVar) {
         //if the XQRL engine has been determined unavailable, return null
-        if ( !_xqrlAvailable ) return null;
-        if ( _xqrlCompileQuery == null)
-        {
-            try
-            {
+        if (!_xqrlAvailable) {
+            return null;
+        }
+        if (_xqrlCompileQuery == null) {
+            try {
                 Class xqrlImpl = Class.forName("org.apache.xmlbeans.impl.store.XqrlImpl");
 
                 _xqrlCompileQuery =
-                        xqrlImpl.getDeclaredMethod("compileQuery",
-                                new Class[]{String.class, String.class, Boolean.class});
-            }
-            catch (ClassNotFoundException e)
-            {
+                    xqrlImpl.getDeclaredMethod("compileQuery",
+                        new Class[]{String.class, String.class, Boolean.class});
+            } catch (ClassNotFoundException e) {
                 _xqrlAvailable = false;
                 return null;
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 _xqrlAvailable = false;
                 throw new RuntimeException(e.getMessage(), e);
             }
@@ -257,40 +224,28 @@ public abstract class Query
 
         Object[] args = new Object[]{queryExpr, currentVar, new Boolean(true)};
 
-        try
-        {
+        try {
             return (Query) _xqrlCompileQuery.invoke(null, args);
-        }
-        catch (InvocationTargetException e)
-        {
+        } catch (InvocationTargetException e) {
             Throwable t = e.getCause();
             throw new RuntimeException(t.getMessage(), t);
-        }
-        catch (IllegalAccessException e)
-        {
+        } catch (IllegalAccessException e) {
             throw new RuntimeException(e.getMessage(), e);
         }
     }
 
-    private static Query getXqrl2002CompiledQuery(String queryExpr, String currentVar)
-    {
-        if (_xqrl2002Available && _xqrl2002CompileQuery == null)
-        {
-            try
-            {
+    private static Query getXqrl2002CompiledQuery(String queryExpr, String currentVar) {
+        if (_xqrl2002Available && _xqrl2002CompileQuery == null) {
+            try {
                 Class xqrlImpl = Class.forName("org.apache.xmlbeans.impl.store.Xqrl2002Impl");
 
                 _xqrl2002CompileQuery =
-                        xqrlImpl.getDeclaredMethod("compileQuery",
-                                new Class[]{String.class, String.class, Boolean.class});
-            }
-            catch (ClassNotFoundException e)
-            {
+                    xqrlImpl.getDeclaredMethod("compileQuery",
+                        new Class[]{String.class, String.class, Boolean.class});
+            } catch (ClassNotFoundException e) {
                 _xqrl2002Available = false;
                 return null;
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 _xqrl2002Available = false;
                 throw new RuntimeException(e.getMessage(), e);
             }
@@ -298,25 +253,18 @@ public abstract class Query
 
         Object[] args = new Object[]{queryExpr, currentVar, new Boolean(true)};
 
-        try
-        {
+        try {
             return (Query) _xqrl2002CompileQuery.invoke(null, args);
-        }
-        catch (InvocationTargetException e)
-        {
+        } catch (InvocationTargetException e) {
             Throwable t = e.getCause();
             throw new RuntimeException(t.getMessage(), t);
-        }
-        catch (IllegalAccessException e)
-        {
+        } catch (IllegalAccessException e) {
             throw new RuntimeException(e.getMessage(), e);
         }
     }
 
-    private static final class DelegateQueryImpl extends Query
-    {
-        private DelegateQueryImpl(QueryDelegate.QueryInterface xqueryImpl)
-        {
+    private static final class DelegateQueryImpl extends Query {
+        private DelegateQueryImpl(QueryDelegate.QueryInterface xqueryImpl) {
             _xqueryImpl = xqueryImpl;
         }
 
@@ -324,34 +272,30 @@ public abstract class Query
                                                  String queryExpr,
                                                  String currentVar,
                                                  int boundary,
-                                                 XmlOptions xmlOptions)
-        {
+                                                 XmlOptions xmlOptions) {
             assert !(currentVar.startsWith(".") || currentVar.startsWith(".."));
             QueryDelegate.QueryInterface impl =
                 QueryDelegate.createInstance(delIntfName, queryExpr,
-                                             currentVar, boundary, xmlOptions);
-            if (impl == null)
+                    currentVar, boundary, xmlOptions);
+            if (impl == null) {
                 return null;
+            }
 
             return new DelegateQueryImpl(impl);
         }
 
-        XmlObject[] objectExecute(Cur c, XmlOptions options)
-        {
+        XmlObject[] objectExecute(Cur c, XmlOptions options) {
             return new DelegateQueryEngine(_xqueryImpl, c, options).objectExecute();
         }
 
-        XmlCursor cursorExecute(Cur c, XmlOptions options)
-        {
+        XmlCursor cursorExecute(Cur c, XmlOptions options) {
             return new DelegateQueryEngine(_xqueryImpl, c, options).cursorExecute();
         }
 
 
-        private static class DelegateQueryEngine
-        {
+        private static class DelegateQueryEngine {
             public DelegateQueryEngine(QueryDelegate.QueryInterface xqImpl,
-                                    Cur c, XmlOptions opt)
-            {
+                                       Cur c, XmlOptions opt) {
 
                 _engine = xqImpl;
                 _version = c._locale.version();
@@ -360,12 +304,13 @@ public abstract class Query
 
             }
 
-            public XmlObject[] objectExecute()
-            {
+            public XmlObject[] objectExecute() {
                 if (_cur != null && _version != _cur._locale.version())
                 //throw new ConcurrentModificationException
                 // ("Document changed during select")
+                {
                     ;
+                }
 
                 Map bindings = (Map) XmlOptions.maskNull(_options).
                     get(XmlOptions.XQUERY_VARIABLE_MAP);
@@ -379,7 +324,7 @@ public abstract class Query
                 for (i = 0; i < resultsList.size(); i++) {
                     //copy objects into the locale
                     Locale l = Locale.getLocale(_cur._locale._schemaTypeLoader,
-                            _options);
+                        _options);
 
                     l.enter();
                     Object node = resultsList.get(i);
@@ -392,18 +337,16 @@ public abstract class Query
                             //superclass???
                             res = l.load("<xml-fragment/>").tempCur();
                             res.setValue(node.toString());
-                            SchemaType type=getType(node);
+                            SchemaType type = getType(node);
                             Locale.autoTypeDocument(res, type, null);
                             result[i] = res.getObject();
-                        }
-                        else
+                        } else {
                             res = loadNode(l, (Node) node);
+                        }
                         result[i] = res.getObject();
-                    }
-                    catch (XmlException e) {
+                    } catch (XmlException e) {
                         throw new RuntimeException(e);
-                    }
-                    finally {
+                    } finally {
                         l.exit();
                     }
                     res.release();
@@ -412,35 +355,38 @@ public abstract class Query
                 _engine = null;
                 return result;
             }
-            private SchemaType getType(Object node)
-            {
+
+            private SchemaType getType(Object node) {
                 SchemaType type;
-                if (node instanceof Integer)
+                if (node instanceof Integer) {
                     type = XmlInteger.type;
-                else if (node instanceof Double)
+                } else if (node instanceof Double) {
                     type = XmlDouble.type;
-                else if (node instanceof Long)
+                } else if (node instanceof Long) {
                     type = XmlLong.type;
-                else if (node instanceof Float)
+                } else if (node instanceof Float) {
                     type = XmlFloat.type;
-                else if (node instanceof BigDecimal)
+                } else if (node instanceof BigDecimal) {
                     type = XmlDecimal.type;
-                else if (node instanceof Boolean)
+                } else if (node instanceof Boolean) {
                     type = XmlBoolean.type;
-                else if (node instanceof String)
+                } else if (node instanceof String) {
                     type = XmlString.type;
-                else if (node instanceof Date)
+                } else if (node instanceof Date) {
                     type = XmlDate.type;
-                else
+                } else {
                     type = XmlAnySimpleType.type;
+                }
                 return type;
             }
-            public XmlCursor cursorExecute()
-            {
+
+            public XmlCursor cursorExecute() {
                 if (_cur != null && _version != _cur._locale.version())
                 //throw new ConcurrentModificationException
                 // ("Document changed during select")
+                {
                     ;
+                }
 
                 Map bindings = (Map) XmlOptions.maskNull(_options).
                     get(XmlOptions.XQUERY_VARIABLE_MAP);
@@ -464,10 +410,8 @@ public abstract class Query
                     Locale.associateSourceName(c, _options);
                     Locale.autoTypeDocument(c, null, _options);
                     resultCur = new Cursor(c);
-                }
-                catch (Exception e) {
-                }
-                finally {
+                } catch (Exception e) {
+                } finally {
                     locale.exit();
                 }
                 release();
@@ -475,8 +419,7 @@ public abstract class Query
             }
 
 
-            public void release()
-            {
+            public void release() {
                 if (_cur != null) {
                     _cur.release();
                     _cur = null;
@@ -484,8 +427,7 @@ public abstract class Query
             }
 
 
-            private Cur loadNode(Locale locale, Node node)
-            {
+            private Cur loadNode(Locale locale, Node node) {
                 Locale.LoadContext context = new Cur.CurLoadContext(locale, _options);
 
                 try {
@@ -494,22 +436,20 @@ public abstract class Query
                     Locale.associateSourceName(c, _options);
                     Locale.autoTypeDocument(c, null, _options);
                     return c;
-                }
-                catch (Exception e) {
+                } catch (Exception e) {
                     throw new XmlRuntimeException(e.getMessage(), e);
                 }
             }
 
-            private void loadNodeHelper(Locale locale, Node node, Locale.LoadContext context)
-            {
+            private void loadNodeHelper(Locale locale, Node node, Locale.LoadContext context) {
                 if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
-                        QName attName = new QName(node.getNamespaceURI(),
-                            node.getLocalName(),
-                            node.getPrefix());
-                        context.attr(attName, node.getNodeValue());
-                        }
-                else
-                        locale.loadNode(node, context);
+                    QName attName = new QName(node.getNamespaceURI(),
+                        node.getLocalName(),
+                        node.getPrefix());
+                    context.attr(attName, node.getNodeValue());
+                } else {
+                    locale.loadNode(node, context);
+                }
 
             }
 



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