You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by vg...@apache.org on 2005/03/04 04:38:15 UTC

cvs commit: xml-xindice/java/src/org/apache/xindice/core/query XPathQueryResolver.java

vgritsenko    2005/03/03 19:38:14

  Modified:    .        status.xml
               java/src/org/apache/xindice/core/query
                        XPathQueryResolver.java
  Log:
  Bug #33657: Added support for current Xalan CVS (post 2.6.0 release).
  
  Revision  Changes    Path
  1.51      +4 -1      xml-xindice/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/xml-xindice/status.xml,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -r1.50 -r1.51
  --- status.xml	29 Oct 2004 18:52:23 -0000	1.50
  +++ status.xml	4 Mar 2005 03:38:14 -0000	1.51
  @@ -73,7 +73,10 @@
       </todo>
   
       <changes>
  -        <release version="1.1b5-dev" date="October 29 2004">
  +        <release version="1.1b5-dev" date="March 3 2005">
  +            <action dev="VG" type="update" fixes-bug="33657" due-to="Dave Brosius">
  +                Added support for current Xalan CVS (post 2.6.0 release).
  +            </action>
               <action dev="VG" type="fix" due-to="Daniel Migowski">
                   Fixed memory leak in command line tool, addmultiple command.
               </action>
  
  
  
  1.32      +61 -12    xml-xindice/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
  
  Index: XPathQueryResolver.java
  ===================================================================
  RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/core/query/XPathQueryResolver.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- XPathQueryResolver.java	21 May 2004 12:45:19 -0000	1.31
  +++ XPathQueryResolver.java	4 Mar 2005 03:38:14 -0000	1.32
  @@ -18,6 +18,7 @@
   
   package org.apache.xindice.core.query;
   
  +import java.lang.reflect.Constructor;
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
  @@ -25,6 +26,7 @@
   import java.util.TreeSet;
   
   import javax.xml.transform.ErrorListener;
  +import javax.xml.transform.SourceLocator;
   import javax.xml.transform.TransformerException;
   
   import org.apache.commons.logging.Log;
  @@ -85,31 +87,64 @@
    *
    * @version CVS $Revision$, $Date$
    */
  -public final class XPathQueryResolver extends SimpleConfigurable implements QueryResolver {
  +public final class XPathQueryResolver extends SimpleConfigurable
  +                                      implements QueryResolver {
  +
       private static final Log log = LogFactory.getLog(XPathQueryResolver.class);
   
       private static final Key[] EMPTY_KEYS = new Key[0];
       private static final Key[][] EMPTY_KEYSET = new Key[0][0];
       private static final String WILDCARD = "*";
  -    // private static final String THISNODE = ".";
  -    // private static final String PARENTNODE = "..";
  -
  -    private static final String AUTOINDEX = "autoindex";
   
       public static final String STYLE_XPATH = "XPath";
   
       // Maps Xalan Comparisons To IndexQuery
  -    private static final int[] OpMap = {
  +    private static final int[] OPMAP = {
           IndexQuery.NEQ, IndexQuery.EQ, IndexQuery.LEQ, IndexQuery.LT, IndexQuery.GEQ, IndexQuery.GT
       };
   
  +
  +    // Flag set if Xalan Compiler constructor has 3 arguments
  +    private static final boolean XCOMPILER3;
  +    // Xalan Compiler constructor
  +    private static final Constructor XCOMPILER;
  +
  +    static {
  +        boolean c3;
  +        Constructor c;
  +        try {
  +            c = Compiler.class.getConstructor(
  +                    new Class[] { ErrorListener.class, SourceLocator.class, FunctionTable.class });
  +            c3 = true;
  +        } catch (NoSuchMethodException nsme) {
  +            try {
  +                c = Compiler.class.getConstructor(
  +                        new Class[] { ErrorListener.class, SourceLocator.class });
  +                c3 = false;
  +            } catch (NoSuchMethodException e) {
  +                // Should not happen
  +                throw new RuntimeException("Could not obtain org.apache.xpath.compiler.Compiler constructor. " +
  +                                           "Incompatible Xalan version?");
  +            }
  +        }
  +
  +        XCOMPILER3 = c3;
  +        XCOMPILER = c;
  +    }
  +
  +
       private DefaultErrorHandler errorListener = new DefaultErrorHandler();
  -    private boolean autoIndex = false;
  +    private FunctionTable functionTable;
  +    private boolean autoIndex;
   
   
       public void setConfig(Configuration config) throws XindiceException {
           super.setConfig(config);
  -        autoIndex = config.getBooleanAttribute(AUTOINDEX, autoIndex);
  +        this.autoIndex = config.getBooleanAttribute("autoindex", false);
  +
  +        if (XCOMPILER3) {
  +            functionTable = new FunctionTable();
  +        }
       }
   
       public String getQueryStyle() {
  @@ -131,6 +166,20 @@
           return xq.execute();
       }
   
  +    private Compiler createCompiler() {
  +        try {
  +            if (XCOMPILER3) {
  +                return (Compiler) XCOMPILER.newInstance(
  +                        new Object[] {errorListener, null, functionTable});
  +            } else {
  +                return (Compiler) XCOMPILER.newInstance(
  +                        new Object[] {errorListener, null});
  +            }
  +        } catch (Exception e) {
  +            throw new RuntimeException("Could not instantiate Compiler: " + e);
  +        }
  +    }
  +
   	/**
        * XPathQuery
        */
  @@ -159,8 +208,8 @@
                       pr = new PrefixResolverDefault(n);
                   }
   
  +                cmp = createCompiler();
                   XPathParser parser = new XPathParser(errorListener, null);
  -                cmp = new Compiler(errorListener, null);
                   parser.initXPath(cmp, query, pr);
                   ex = cmp.compile(0);
   
  @@ -1058,7 +1107,7 @@
            * @return The resulting Keys (if any)
            */
           private Object queryComparison(int op, String owner, Object left, Object right) {
  -            op = OpMap[op - OpCodes.OP_NOTEQUALS];
  +            op = OPMAP[op - OpCodes.OP_NOTEQUALS];
   
               if (left instanceof XObject) {
                   // Check if we have to switch the operation