You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by dm...@apache.org on 2003/01/20 00:59:25 UTC

cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler CoreOperationAdd.java CoreOperationAnd.java CoreOperationCompare.java CoreOperationDivide.java CoreOperationEqual.java CoreOperationGreaterThan.java CoreOperationGreaterThanOrEqual.java CoreOperationLessThan.java CoreOperationLessThanOrEqual.java CoreOperationMod.java CoreOperationMultiply.java CoreOperationNegate.java CoreOperationNotEqual.java CoreOperationOr.java CoreOperationSubtract.java CoreOperationUnion.java Constant.java CoreFunction.java CoreOperation.java Expression.java ExpressionPath.java ExtensionFunction.java LocationPath.java NameAttributeTest.java NodeNameTest.java NodeTypeTest.java Operation.java Path.java ProcessingInstructionTest.java Step.java TreeCompiler.java VariableReference.java

dmitri      2003/01/19 15:59:25

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri/compiler
                        Constant.java CoreFunction.java CoreOperation.java
                        Expression.java ExpressionPath.java
                        ExtensionFunction.java LocationPath.java
                        NameAttributeTest.java NodeNameTest.java
                        NodeTypeTest.java Operation.java Path.java
                        ProcessingInstructionTest.java Step.java
                        TreeCompiler.java VariableReference.java
  Added:       jxpath/src/java/org/apache/commons/jxpath/ri/compiler
                        CoreOperationAdd.java CoreOperationAnd.java
                        CoreOperationCompare.java CoreOperationDivide.java
                        CoreOperationEqual.java
                        CoreOperationGreaterThan.java
                        CoreOperationGreaterThanOrEqual.java
                        CoreOperationLessThan.java
                        CoreOperationLessThanOrEqual.java
                        CoreOperationMod.java CoreOperationMultiply.java
                        CoreOperationNegate.java CoreOperationNotEqual.java
                        CoreOperationOr.java CoreOperationSubtract.java
                        CoreOperationUnion.java
  Log:
  Refactoring of CoreOperation and expression.toString()
  
  Revision  Changes    Path
  1.5       +13 -3     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Constant.java
  
  Index: Constant.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Constant.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Constant.java	11 Jan 2003 05:41:23 -0000	1.4
  +++ Constant.java	19 Jan 2003 23:59:23 -0000	1.5
  @@ -74,12 +74,10 @@
       private Object value;
   
       public Constant(Number number) {
  -        super(Expression.OP_CONSTANT);
           this.value = number;
       }
   
       public Constant(String string) {
  -        super(Expression.OP_CONSTANT);
           this.value = string;
       }
   
  @@ -109,6 +107,18 @@
       }
   
       public String toString() {
  -        return "(CONST " + value + ")";
  +        if (value instanceof Number) {
  +            double doubleValue = ((Number) value).doubleValue();
  +            long longValue = ((Number) value).longValue();
  +            if (doubleValue == longValue) {
  +                return String.valueOf(longValue);
  +            }
  +            else {
  +                return String.valueOf(doubleValue);
  +            }
  +        }
  +        else {
  +            return "'" + value + "'";
  +        }
       }
   }
  
  
  
  1.10      +78 -90    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java
  
  Index: CoreFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreFunction.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CoreFunction.java	11 Jan 2003 05:41:23 -0000	1.9
  +++ CoreFunction.java	19 Jan 2003 23:59:23 -0000	1.10
  @@ -83,13 +83,75 @@
       private int functionCode;
   
       public CoreFunction(int functionCode, Expression args[]) {
  -        super(Expression.OP_CORE_FUNCTION, args);
  +        super(args);
           this.functionCode = functionCode;
       }
   
       public int getFunctionCode() {
           return functionCode;
       }
  +    
  +    protected String getFunctionName() {
  +        switch (functionCode) {
  +            case Compiler.FUNCTION_LAST :
  +                return "last";
  +            case Compiler.FUNCTION_POSITION :
  +                return "position";
  +            case Compiler.FUNCTION_COUNT :
  +                return "count";
  +            case Compiler.FUNCTION_ID :
  +                return "id";
  +            case Compiler.FUNCTION_LOCAL_NAME :
  +                return "local-name";
  +            case Compiler.FUNCTION_NAMESPACE_URI :
  +                return "namespace-uri";
  +            case Compiler.FUNCTION_NAME :
  +                return "name";
  +            case Compiler.FUNCTION_STRING :
  +                return "string";
  +            case Compiler.FUNCTION_CONCAT :
  +                return "concat";
  +            case Compiler.FUNCTION_STARTS_WITH :
  +                return "starts-with";
  +            case Compiler.FUNCTION_CONTAINS :
  +                return "contains";
  +            case Compiler.FUNCTION_SUBSTRING_BEFORE :
  +                return "substring-before";
  +            case Compiler.FUNCTION_SUBSTRING_AFTER :
  +                return "substring-after";
  +            case Compiler.FUNCTION_SUBSTRING :
  +                return "substring";
  +            case Compiler.FUNCTION_STRING_LENGTH :
  +                return "string-length";
  +            case Compiler.FUNCTION_NORMALIZE_SPACE :
  +                return "normalize-space";
  +            case Compiler.FUNCTION_TRANSLATE :
  +                return "translate";
  +            case Compiler.FUNCTION_BOOLEAN :
  +                return "boolean";
  +            case Compiler.FUNCTION_NOT :
  +                return "not";
  +            case Compiler.FUNCTION_TRUE :
  +                return "true";
  +            case Compiler.FUNCTION_FALSE :
  +                return "false";
  +            case Compiler.FUNCTION_LANG :
  +                return "lang";
  +            case Compiler.FUNCTION_NUMBER :
  +                return "number";
  +            case Compiler.FUNCTION_SUM :
  +                return "sum";
  +            case Compiler.FUNCTION_FLOOR :
  +                return "floor";
  +            case Compiler.FUNCTION_CEILING :
  +                return "ceiling";
  +            case Compiler.FUNCTION_ROUND :
  +                return "round";
  +            case Compiler.FUNCTION_KEY :
  +                return "key";
  +        }
  +        return "unknownFunction" + functionCode + "()";
  +    }
   
       public Expression getArg1() {
           return args[0];
  @@ -157,96 +219,22 @@
   
           return false;
       }
  -
  -    protected String opCodeToString() {
  -        String function = null;
  -        switch (functionCode) {
  -            case Compiler.FUNCTION_LAST :
  -                function = "last";
  -                break;
  -            case Compiler.FUNCTION_POSITION :
  -                function = "position";
  -                break;
  -            case Compiler.FUNCTION_COUNT :
  -                function = "count";
  -                break;
  -            case Compiler.FUNCTION_ID :
  -                function = "id";
  -                break;
  -            case Compiler.FUNCTION_LOCAL_NAME :
  -                function = "local-name";
  -                break;
  -            case Compiler.FUNCTION_NAMESPACE_URI :
  -                function = "namespace-uri";
  -                break;
  -            case Compiler.FUNCTION_NAME :
  -                function = "name";
  -                break;
  -            case Compiler.FUNCTION_STRING :
  -                function = "string";
  -                break;
  -            case Compiler.FUNCTION_CONCAT :
  -                function = "concat";
  -                break;
  -            case Compiler.FUNCTION_STARTS_WITH :
  -                function = "starts-with";
  -                break;
  -            case Compiler.FUNCTION_CONTAINS :
  -                function = "contains";
  -                break;
  -            case Compiler.FUNCTION_SUBSTRING_BEFORE :
  -                function = "substring-before";
  -                break;
  -            case Compiler.FUNCTION_SUBSTRING_AFTER :
  -                function = "substring-after";
  -                break;
  -            case Compiler.FUNCTION_SUBSTRING :
  -                function = "substring";
  -                break;
  -            case Compiler.FUNCTION_STRING_LENGTH :
  -                function = "string-length";
  -                break;
  -            case Compiler.FUNCTION_NORMALIZE_SPACE :
  -                function = "normalize-space";
  -                break;
  -            case Compiler.FUNCTION_TRANSLATE :
  -                function = "translate";
  -                break;
  -            case Compiler.FUNCTION_BOOLEAN :
  -                function = "boolean";
  -                break;
  -            case Compiler.FUNCTION_NOT :
  -                function = "not";
  -                break;
  -            case Compiler.FUNCTION_TRUE :
  -                function = "true";
  -                break;
  -            case Compiler.FUNCTION_FALSE :
  -                function = "false";
  -                break;
  -            case Compiler.FUNCTION_LANG :
  -                function = "lang";
  -                break;
  -            case Compiler.FUNCTION_NUMBER :
  -                function = "number";
  -                break;
  -            case Compiler.FUNCTION_SUM :
  -                function = "sum";
  -                break;
  -            case Compiler.FUNCTION_FLOOR :
  -                function = "floor";
  -                break;
  -            case Compiler.FUNCTION_CEILING :
  -                function = "ceiling";
  -                break;
  -            case Compiler.FUNCTION_ROUND :
  -                function = "round";
  -                break;
  -            case Compiler.FUNCTION_KEY :
  -                function = "key";
  -                break;
  +    
  +    public String toString() {
  +        StringBuffer buffer = new StringBuffer();
  +        buffer.append(getFunctionName());
  +        buffer.append('(');
  +        Expression args[] = getArguments();
  +        if (args != null) {
  +            for (int i = 0; i < args.length; i++) {
  +                if (i > 0) {
  +                    buffer.append(", ");
  +                }
  +                buffer.append(args[i]);
  +            }
           }
  -        return super.opCodeToString() + ':' + function;
  +        buffer.append(')');
  +        return buffer.toString();
       }
   
       public Object compute(EvalContext context) {
  
  
  
  1.10      +53 -431   jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperation.java
  
  Index: CoreOperation.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperation.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CoreOperation.java	12 Jan 2003 01:52:57 -0000	1.9
  +++ CoreOperation.java	19 Jan 2003 23:59:23 -0000	1.10
  @@ -61,465 +61,87 @@
    */
   package org.apache.commons.jxpath.ri.compiler;
   
  -import java.util.HashSet;
  -import java.util.Iterator;
  -
  -import org.apache.commons.jxpath.Pointer;
   import org.apache.commons.jxpath.ri.EvalContext;
  -import org.apache.commons.jxpath.ri.InfoSetUtil;
  -import org.apache.commons.jxpath.ri.axes.InitialContext;
  -import org.apache.commons.jxpath.ri.axes.SelfContext;
  -import org.apache.commons.jxpath.ri.axes.UnionContext;
  -import org.apache.commons.jxpath.util.ValueUtils;
   
   /**
  - * A compile tree element representing one of the core operations like "+",
  - * "-", "*" etc.
  + * The common subclass for tree elements representing core operations like "+",
  + * "- ", "*" etc.
    *
    * @author Dmitri Plotnikov
    * @version $Revision$ $Date$
    */
  -public class CoreOperation extends Operation {
  -    public CoreOperation(int code, Expression args[]) {
  -        super(code, args);
  -    }
  -
  -    public CoreOperation(int code, Expression arg) {
  -        super(code, new Expression[]{arg});
  -    }
  -
  -    public CoreOperation(int code, Expression arg1, Expression arg2) {
  -        super(code, new Expression[]{arg1, arg2});
  -    }
  -
  -    public Expression getArg1() {
  -        return args[0];
  -    }
  -
  -    public Expression getArg2() {
  -        return args[1];
  +public abstract class CoreOperation extends Operation {
  +        
  +    public CoreOperation(Expression args[]) {
  +        super(args);
       }
   
       public Object compute(EvalContext context) {
           return computeValue(context);
       }
   
  -    public Object computeValue(EvalContext context) {
  -        switch (getExpressionTypeCode()) {
  -            case Expression.OP_UNION:
  -                return union(context, args[0], args[1]);
  -
  -            case Expression.OP_UNARY_MINUS:
  -                return minus(context, args[0]);
  -
  -            case Expression.OP_SUM:
  -                return sum(context, args);
  -
  -            case Expression.OP_MINUS:
  -                return minus(context, args[0], args[1]);
  -
  -            case Expression.OP_MULT:
  -                return mult(context, args[0], args[1]);
  -
  -            case Expression.OP_DIV:
  -                return div(context, args[0], args[1]);
  -
  -            case Expression.OP_MOD:
  -                return mod(context, args[0], args[1]);
  -
  -            case Expression.OP_LT:
  -                return lt(context, args[0], args[1]);
  -
  -            case Expression.OP_GT:
  -                return gt(context, args[0], args[1]);
  -
  -            case Expression.OP_LTE:
  -                return lte(context, args[0], args[1]);
  -
  -            case Expression.OP_GTE:
  -                return gte(context, args[0], args[1]);
  -
  -            case Expression.OP_EQ:
  -                return eq(context, args[0], args[1]);
  -
  -            case Expression.OP_NE:
  -                return ne(context, args[0], args[1]);
  -
  -            case Expression.OP_AND:
  -                return and(context, args);
  -
  -            case Expression.OP_OR:
  -                return or(context, args);
  -        }
  -        return null; // Should never happen
  -    }
  -
  -    /**
  -     * Computes <code>"left | right"<code>
  -     */
  -    protected Object union(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        Object l = left.compute(context);
  -        Object r = right.compute(context);
  -        EvalContext lctx;
  -        if (l instanceof EvalContext) {
  -            lctx = (EvalContext) l;
  -        }
  -        else {
  -            lctx = context.getRootContext().getConstantContext(l);
  -        }
  -        EvalContext rctx;
  -        if (r instanceof EvalContext) {
  -            rctx = (EvalContext) r;
  -        }
  -        else {
  -            rctx = context.getRootContext().getConstantContext(r);
  -        }
  -        return new UnionContext(
  -            context.getRootContext(),
  -            new EvalContext[] { lctx, rctx });
  -    }
  -
  -    /**
  -     * Computes <code>"-arg"<code>
  -     */
  -    protected Object minus(EvalContext context, Expression arg) {
  -        double a = InfoSetUtil.doubleValue(arg.computeValue(context));
  -        return new Double(-a);
  -    }
  -
  -    /**
  -     * Computes <code>"a + b + c + d"<code>
  -     */
  -    protected Object sum(EvalContext context, Expression[] arguments) {
  -        double s = 0.0;
  -        for (int i = 0; i < arguments.length; i++) {
  -            s += InfoSetUtil.doubleValue(arguments[i].computeValue(context));
  -        }
  -        return new Double(s);
  -    }
  -
  -    /**
  -     * Computes <code>"left - right"<code>
  -     */
  -    protected Object minus(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        double l = InfoSetUtil.doubleValue(left.computeValue(context));
  -        double r = InfoSetUtil.doubleValue(right.computeValue(context));
  -        return new Double(l - r);
  -    }
  -
  -    /**
  -     * Computes <code>"left div right"<code>
  -     */
  -    protected Object div(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        double l = InfoSetUtil.doubleValue(left.computeValue(context));
  -        double r = InfoSetUtil.doubleValue(right.computeValue(context));
  -        return new Double(l / r);
  -    }
  -
  -    /**
  -     * Computes <code>"left * right"<code>
  -     */
  -    protected Object mult(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        double l = InfoSetUtil.doubleValue(left.computeValue(context));
  -        double r = InfoSetUtil.doubleValue(right.computeValue(context));
  -        return new Double(l * r);
  -    }
  -
  -    /**
  -     * Computes <code>"left mod right"<code>
  -     */
  -    protected Object mod(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        long l = (long) InfoSetUtil.doubleValue(left.computeValue(context));
  -        long r = (long) InfoSetUtil.doubleValue(right.computeValue(context));
  -        return new Double(l % r);
  -    }
  -
  -    /**
  -     * Computes <code>"left &lt; right"<code>
  -     */
  -    protected Object lt(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        return test(context, left, right, LT_TEST)
  -            ? Boolean.TRUE
  -            : Boolean.FALSE;
  -    }
  -
  -    /**
  -     * Computes <code>"left &gt; right"<code>
  -     */
  -    protected Object gt(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        return test(context, left, right, GT_TEST)
  -            ? Boolean.TRUE
  -            : Boolean.FALSE;
  -    }
  -
  -    /**
  -     * Computes <code>"left &lt;= right"<code>
  -     */
  -    protected Object lte(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        return test(context, left, right, LTE_TEST)
  -            ? Boolean.TRUE
  -            : Boolean.FALSE;
  -    }
  -
  -    /**
  -     * Computes <code>"left &gt;= right"<code>
  -     */
  -    protected Object gte(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        return test(context, left, right, GTE_TEST)
  -            ? Boolean.TRUE
  -            : Boolean.FALSE;
  -    }
  -
  +    public abstract Object computeValue(EvalContext context);
  +    
       /**
  -     * Computes <code>"left = right"<code>
  +     * Returns the XPath symbol for this operation, e.g. "+", "div", etc.
        */
  -    protected Object eq(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        return test(context, left, right, EQUAL_TEST)
  -            ? Boolean.TRUE
  -            : Boolean.FALSE;
  -    }
  -
  +    public abstract String getSymbol();
  +    
       /**
  -     * Computes <code>"left != right"<code>
  +     * Returns true if the operation is not sensitive to the order of arguments,
  +     * e.g. "=", "and" etc, and false if it is, e.g. "&lt;=", "div".
        */
  -    protected Object ne(
  -        EvalContext context,
  -        Expression left,
  -        Expression right) 
  -    {
  -        return test(context, left, right, EQUAL_TEST)
  -            ? Boolean.FALSE
  -            : Boolean.TRUE;
  -    }
  +    protected abstract boolean isSymmetric();
       
       /**
  -     * When the left and/or right side of a comparisons like =, &lt;, &gt;, 
  -     * &lt;= and &gt;= is a NodeSet (i.e. a collection), we are supposed to
  -     * perform a search for a pair of matching nodes. That's exactly what this
  -     * method does.  It takes a "PairTest" static object that implements the
  -     * comparison of two nodes.
  +     * Computes the precedence of the operation.
        */
  -    protected boolean test(EvalContext context,
  -            Expression left,
  -            Expression right,
  -            NodeComparator pairTest)
  -    {
  -        Object l = left.compute(context);
  -        Object r = right.compute(context);
  -
  -//        System.err.println("COMPARING: " +
  -//            (l == null ? "null" : l.getClass().getName()) + " " +
  -//            (r == null ? "null" : r.getClass().getName()));
  -
  -        if (l instanceof InitialContext || l instanceof SelfContext) {
  -            l = ((EvalContext) l).getSingleNodePointer().getValue();
  -        }
  -
  -        if (r instanceof InitialContext || r instanceof SelfContext) {
  -            r = ((EvalContext) r).getSingleNodePointer().getValue();
  -        }
  -
  -        if (ValueUtils.isCollection(l)) {
  -            l = ValueUtils.iterate(l);
  -        }
  -
  -        if (ValueUtils.isCollection(r)) {
  -            r = ValueUtils.iterate(r);
  -        }
  -
  -        if ((l instanceof Iterator) && !(r instanceof Iterator)) {
  -            return contains((Iterator) l, r, pairTest);
  +    protected abstract int getPrecedence();
  +    
  +    public String toString() {
  +        if (args.length == 1) {
  +            return getSymbol() + parenthesize(args[0], false);
           }
  -        else if (!(l instanceof Iterator) && (r instanceof Iterator)) {
  -            Iterator it = (Iterator) r;
  -            while (it.hasNext()) {
  -                Object element = it.next();
  -                if (pairTest.isTrue(element, l)) {
  -                    return true;
  +        else {
  +            StringBuffer buffer = new StringBuffer();
  +            for (int i = 0; i < args.length; i++) {
  +                if (i > 0) {
  +                    buffer.append(' ');
  +                    buffer.append(getSymbol());
  +                    buffer.append(' ');
                   }
  +                buffer.append(parenthesize(args[i], i == 0));
               }
  -            return false;
  -        }
  -        else if (l instanceof Iterator && r instanceof Iterator) {
  -            return findMatch((Iterator) l, (Iterator) r, pairTest);
  -        }
  -
  -        return pairTest.isTrue(l, r);
  -    }
  -
  -    protected boolean contains(
  -        Iterator it,
  -        Object value,
  -        NodeComparator pairTest) 
  -    {
  -        while (it.hasNext()) {
  -            Object element = it.next();
  -            if (pairTest.isTrue(element, value)) {
  -                return true;
  -            }
  +            return buffer.toString();
           }
  -        return false;
       }
  -
  -    protected boolean findMatch(Iterator lit, Iterator rit, NodeComparator pairTest) {
  -        HashSet left = new HashSet();
  -        while (lit.hasNext()) {
  -            left.add(lit.next());
  -        }
  -        while (rit.hasNext()) {
  -            if (contains(left.iterator(), rit.next(), pairTest)) {
  -                return true;
  -            }
  +    
  +    private String parenthesize(Expression expression, boolean left) {
  +        if (!(expression instanceof CoreOperation)) {
  +            return expression.toString();
           }
  -        return false;
  -    }
  -
  -    private static abstract class NodeComparator {
  -        abstract boolean compare(Object left, Object right);
  -
  -        boolean isTrue(Object left, Object right){
  -            if (left instanceof Pointer) {
  -                left = ((Pointer) left).getValue();
  -            }
  +        CoreOperation op = (CoreOperation) expression;
  +        int myPrecedence = getPrecedence();
  +        int thePrecedence = op.getPrecedence();
   
  -            if (right instanceof Pointer) {
  -                right = ((Pointer) right).getValue();
  -            }
  -            return compare(left, right);
  +        boolean needParens = true;
  +        if (myPrecedence < thePrecedence) {
  +            needParens = false;
           }
  -    }
  -    
  -    private static final NodeComparator EQUAL_TEST = new NodeComparator() {
  -        public boolean isTrue(Object l, Object r) {
  -            if (l instanceof Pointer && r instanceof Pointer) {
  -                if (l.equals(r)) {
  -                    return true;
  -                }
  -            }
  -
  -            if (l instanceof Pointer) {
  -                l = ((Pointer) l).getValue();
  -            }
  -
  -            if (r instanceof Pointer) {
  -                r = ((Pointer) r).getValue();
  +        else if (myPrecedence == thePrecedence) {
  +            if (isSymmetric()){
  +                needParens = false;
               }
  -
  -            if (l == r) {
  -                return true;
  -            }
  -
  -            if (l instanceof Boolean || r instanceof Boolean) {
  -                return (
  -                    InfoSetUtil.booleanValue(l) == InfoSetUtil.booleanValue(r));
  -            }
  -            else if (l instanceof Number || r instanceof Number) {
  -                return (
  -                    InfoSetUtil.doubleValue(l) == InfoSetUtil.doubleValue(r));
  -            }
  -            else if (l instanceof String || r instanceof String) {
  -                return (
  -                    InfoSetUtil.stringValue(l).equals(
  -                        InfoSetUtil.stringValue(r)));
  +            else {
  +                needParens = !left;
               }
  -            else if (l == null) {
  -                return r == null;
  -            }
  -            return l.equals(r);
  -        }
  -        
  -        boolean compare(Object left, Object right){
  -            // Not used
  -            return false;
  -        }
  -    };
  -
  -    private static final NodeComparator LT_TEST = new NodeComparator() {
  -        public boolean compare(Object l, Object r) {
  -            return InfoSetUtil.doubleValue(l) < InfoSetUtil.doubleValue(r);
  -        }
  -    };
  -    
  -    private static final NodeComparator GT_TEST = new NodeComparator() {
  -        public boolean compare(Object l, Object r) {
  -            return InfoSetUtil.doubleValue(l) > InfoSetUtil.doubleValue(r);
  -        }
  -    };
  -    
  -    private static final NodeComparator LTE_TEST = new NodeComparator() {
  -        public boolean compare(Object l, Object r) {
  -            return InfoSetUtil.doubleValue(l) <= InfoSetUtil.doubleValue(r);
           }
  -    };
   
  -    private static final NodeComparator GTE_TEST = new NodeComparator() {
  -        public boolean compare(Object l, Object r) {
  -            return InfoSetUtil.doubleValue(l) >= InfoSetUtil.doubleValue(r);
  -        }
  -    };
  -
  -    /**
  -     * Computes <code>"left and right"<code>
  -     */
  -    protected Object and(EvalContext context, Expression[] arguments) {
  -        for (int i = 0; i < arguments.length; i++) {
  -            if (!InfoSetUtil.booleanValue(arguments[i].computeValue(context))) {
  -                return Boolean.FALSE;
  -            }
  +        if (needParens) {
  +            return "(" + expression.toString() + ")";
           }
  -        return Boolean.TRUE;
  -    }
  -
  -    /**
  -     * Computes <code>"left or right"<code>
  -     */
  -    protected Object or(EvalContext context, Expression[] arguments) {
  -        for (int i = 0; i < arguments.length; i++) {
  -            if (InfoSetUtil.booleanValue(arguments[i].computeValue(context))) {
  -                return Boolean.TRUE;
  -            }
  +        else {
  +            return expression.toString();
           }
  -        return Boolean.FALSE;
  -    }
  -    
  +    }    
   }
  
  
  
  1.5       +0 -93     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Expression.java
  
  Index: Expression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Expression.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Expression.java	11 Jan 2003 05:41:23 -0000	1.4
  +++ Expression.java	19 Jan 2003 23:59:24 -0000	1.5
  @@ -83,60 +83,13 @@
    */
   public abstract class Expression {
   
  -    public static final int OP_SUM = 1;
  -    public static final int OP_MINUS = 2;
  -    public static final int OP_MULT = 3;
  -    public static final int OP_DIV = 4;
  -
  -    public static final int OP_CONSTANT = 5;
  -    public static final int OP_STEP = 6;
  -
  -    public static final int OP_AND = 7;
  -    public static final int OP_OR = 8;
  -
  -    public static final int OP_UNARY_MINUS = 9;
  -    public static final int OP_MOD = 10;
  -
  -    public static final int OP_LT = 11;
  -    public static final int OP_GT = 12;
  -    public static final int OP_LTE = 13;
  -    public static final int OP_GTE = 14;
  -    public static final int OP_EQ = 15;
  -    public static final int OP_NE = 16;
  -
  -    public static final int OP_VAR = 17;
  -
  -    public static final int OP_FUNCTION = 18;
  -
  -    public static final int OP_UNION = 19;
  -    public static final int OP_LOCATION_PATH = 20;
  -    public static final int OP_EXPRESSION_PATH = 21;
  -
  -    public static final int OP_CORE_FUNCTION = 22;
  -
  -    public static final int OP_KEY_LOOKUP = 23;
  -
       protected static final Double ZERO = new Double(0);
       protected static final Double ONE = new Double(1);
       protected static final Double NOT_A_NUMBER = new Double(Double.NaN);
   
  -    private int typeCode;
  -
       private boolean contextDependencyKnown = false;
       private boolean contextDependent;
   
  -    protected Expression(int typeCode) {
  -        this.typeCode = typeCode;
  -    }
  -
  -    public int getExpressionTypeCode() {
  -        return typeCode;
  -    }
  -
  -    protected Expression[] getArguments() {
  -        return null;
  -    }
  -
       /**
        * Returns true if this expression should be re-evaluated
        * each time the current position in the context changes.
  @@ -153,52 +106,6 @@
        * Implemented by subclasses and result is cached by isContextDependent()
        */
       public abstract boolean computeContextDependent();
  -
  -    public String toString() {
  -        StringBuffer buffer = new StringBuffer();
  -        buffer.append('(');
  -        buffer.append(opCodeToString());
  -        Expression args[] = getArguments();
  -        if (args != null) {
  -            buffer.append(' ');
  -            for (int i = 0; i < args.length; i++) {
  -                if (i > 0) {
  -                    buffer.append(", ");
  -                }
  -                buffer.append(args[i]);
  -            }
  -        }
  -        buffer.append(')');
  -        return buffer.toString();
  -    }
  -
  -    protected String opCodeToString() {
  -        switch(typeCode) {
  -            case OP_CONSTANT: return "CONST";
  -            case OP_STEP: return "STEP";
  -            case OP_SUM: return "SUM";
  -            case OP_UNION: return "UNION";
  -            case OP_MINUS: return "MINUS";
  -            case OP_UNARY_MINUS: return "UNARY_MINUS";
  -            case OP_MULT: return "MULT";
  -            case OP_DIV: return "DIV";
  -            case OP_MOD: return "MOD";
  -            case OP_AND: return "AND";
  -            case OP_OR: return "OR";
  -            case OP_LT: return "LT";
  -            case OP_GT: return "GT";
  -            case OP_LTE: return "LTE";
  -            case OP_GTE: return "GTE";
  -            case OP_EQ: return "EQ";
  -            case OP_NE: return "NE";
  -            case OP_VAR: return "VAR";
  -            case OP_FUNCTION: return "FUNCTION";
  -            case OP_LOCATION_PATH: return "LOCATION_PATH";
  -            case OP_EXPRESSION_PATH: return "EXPRESSION_PATH";
  -            case OP_CORE_FUNCTION: return "CORE_FUNCTION";
  -        }
  -        return "UNKNOWN";
  -    }
   
       /**
        * Evaluates the expression. If the result is a node set, returns
  
  
  
  1.7       +12 -10    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/ExpressionPath.java
  
  Index: ExpressionPath.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/ExpressionPath.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ExpressionPath.java	11 Jan 2003 05:41:23 -0000	1.6
  +++ ExpressionPath.java	19 Jan 2003 23:59:24 -0000	1.7
  @@ -89,7 +89,7 @@
           Expression[] predicates,
           Step[] steps) 
       {
  -        super(Expression.OP_EXPRESSION_PATH, steps);
  +        super(steps);
           this.expression = expression;
           this.predicates = predicates;
       }
  @@ -138,11 +138,17 @@
   
       public String toString() {
           StringBuffer buffer = new StringBuffer();
  -        buffer.append("(EXPRESSION-PATH ");
  -        buffer.append(expression);
  -
  +        if (expression instanceof CoreOperation
  +            || expression instanceof ExpressionPath
  +            || expression instanceof LocationPath) {
  +            buffer.append('(');
  +            buffer.append(expression);
  +            buffer.append(')');
  +        }
  +        else {
  +            buffer.append(expression);
  +        }
           if (predicates != null) {
  -            buffer.append(' ');
               for (int i = 0; i < predicates.length; i++) {
                   buffer.append('[');
                   buffer.append(predicates[i]);
  @@ -152,15 +158,11 @@
   
           Step steps[] = getSteps();
           if (steps != null) {
  -            buffer.append(' ');
               for (int i = 0; i < steps.length; i++) {
  -                if (i > 0) {
  -                    buffer.append(", ");
  -                }
  +                buffer.append("/");
                   buffer.append(steps[i]);
               }
           }
  -        buffer.append(')');
           return buffer.toString();
       }
   
  
  
  
  1.7       +17 -4     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunction.java
  
  Index: ExtensionFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/ExtensionFunction.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ExtensionFunction.java	11 Jan 2003 05:41:23 -0000	1.6
  +++ ExtensionFunction.java	19 Jan 2003 23:59:24 -0000	1.7
  @@ -80,7 +80,7 @@
       private QName functionName;
   
       public ExtensionFunction(QName functionName, Expression args[]) {
  -        super(Expression.OP_FUNCTION, args);
  +        super(args);
           this.functionName = functionName;
       }
   
  @@ -96,10 +96,23 @@
           return true;
       }
   
  -    public String opCodeToString() {
  -        return super.opCodeToString() + ':' + functionName;
  +    public String toString() {
  +        StringBuffer buffer = new StringBuffer();
  +        buffer.append(functionName);
  +        buffer.append('(');
  +        Expression args[] = getArguments();
  +        if (args != null) {
  +            for (int i = 0; i < args.length; i++) {
  +                if (i > 0) {
  +                    buffer.append(", ");
  +                }
  +                buffer.append(args[i]);
  +            }
  +        }
  +        buffer.append(')');
  +        return buffer.toString();
       }
  -
  +    
       public Object compute(EvalContext context) {
           return computeValue(context);
       }
  
  
  
  1.7       +7 -16     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/LocationPath.java
  
  Index: LocationPath.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/LocationPath.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LocationPath.java	11 Jan 2003 05:41:23 -0000	1.6
  +++ LocationPath.java	19 Jan 2003 23:59:24 -0000	1.7
  @@ -73,7 +73,7 @@
       private boolean absolute;
   
       public LocationPath(boolean absolute, Step[] steps) {
  -        super(Expression.OP_LOCATION_PATH, steps);
  +        super(steps);
           this.absolute = absolute;
       }
   
  @@ -91,24 +91,15 @@
   
       public String toString() {
           StringBuffer buffer = new StringBuffer();
  -        buffer.append("(PATH");
  -        if (absolute) {
  -            buffer.append("[absolute] ");
  -        }
  -        else {
  -            buffer.append("[relative] ");
  -        }
  -        Step args[] = getSteps();
  -        if (args != null) {
  -            buffer.append(' ');
  -            for (int i = 0; i < args.length; i++) {
  -                if (i > 0) {
  -                    buffer.append(", ");
  +        Step steps[] = getSteps();
  +        if (steps != null) {
  +            for (int i = 0; i < steps.length; i++) {
  +                if (i > 0 || absolute) {
  +                    buffer.append('/');
                   }
  -                buffer.append(args[i]);
  +                buffer.append(steps[i]);
               }
           }
  -        buffer.append(')');
           return buffer.toString();
       }
   
  
  
  
  1.4       +3 -3      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/NameAttributeTest.java
  
  Index: NameAttributeTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/NameAttributeTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NameAttributeTest.java	11 Jan 2003 05:41:23 -0000	1.3
  +++ NameAttributeTest.java	19 Jan 2003 23:59:24 -0000	1.4
  @@ -9,14 +9,14 @@
    * @author Dmitri Plotnikov
    * @version $Revision$ $Date$
    */
  -public class NameAttributeTest extends CoreOperation {
  +public class NameAttributeTest extends CoreOperationEqual {
   
       public NameAttributeTest(Expression namePath, Expression nameValue) {
  -        super(OP_EQ, namePath, nameValue);
  +        super(namePath, nameValue);
       }
   
       public Expression getNameTestExpression() {
  -        return getArg2();
  +        return args[1];
       }
   
       /**
  
  
  
  1.6       +0 -0      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/NodeNameTest.java
  
  Index: NodeNameTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/NodeNameTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  
  
  
  1.5       +0 -0      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/NodeTypeTest.java
  
  Index: NodeTypeTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/NodeTypeTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  
  
  
  1.5       +1 -2      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Operation.java
  
  Index: Operation.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Operation.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Operation.java	11 Jan 2003 05:41:23 -0000	1.4
  +++ Operation.java	19 Jan 2003 23:59:24 -0000	1.5
  @@ -69,8 +69,7 @@
   
       protected Expression args[];
   
  -    public Operation(int code, Expression args[]) {
  -        super(code);
  +    public Operation(Expression args[]) {
           this.args = args;
       }
   
  
  
  
  1.8       +1 -2      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Path.java
  
  Index: Path.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Path.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Path.java	11 Jan 2003 05:41:23 -0000	1.7
  +++ Path.java	19 Jan 2003 23:59:24 -0000	1.8
  @@ -86,8 +86,7 @@
       private boolean basicKnown = false;
       private boolean basic;
   
  -    public Path(int typeCode, Step[] steps) {
  -        super(typeCode);
  +    public Path(Step[] steps) {
           this.steps = steps;
       }
   
  
  
  
  1.5       +1 -1      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/ProcessingInstructionTest.java
  
  Index: ProcessingInstructionTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/ProcessingInstructionTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProcessingInstructionTest.java	11 Jan 2003 05:41:23 -0000	1.4
  +++ ProcessingInstructionTest.java	19 Jan 2003 23:59:24 -0000	1.5
  @@ -77,6 +77,6 @@
       }
   
       public String toString() {
  -        return "processing-instruction(" + target + ")";
  +        return "processing-instruction('" + target + "')";
       }
   }
  
  
  
  1.6       +32 -3     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Step.java
  
  Index: Step.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/Step.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Step.java	11 Jan 2003 05:41:23 -0000	1.5
  +++ Step.java	19 Jan 2003 23:59:24 -0000	1.6
  @@ -103,9 +103,38 @@
   
       public String toString() {
           StringBuffer buffer = new StringBuffer();
  -        buffer.append(axisToString(getAxis()));
  -        buffer.append("::");
  -        buffer.append(nodeTest);
  +        int axis = getAxis();
  +        if (axis == Compiler.AXIS_CHILD) {
  +            buffer.append(nodeTest);
  +        }
  +        else if (axis == Compiler.AXIS_ATTRIBUTE) {
  +            buffer.append('@');
  +            buffer.append(nodeTest);
  +        }
  +        else if (axis == Compiler.AXIS_SELF
  +                && nodeTest instanceof NodeTypeTest
  +                && ((NodeTypeTest) nodeTest).getNodeType()
  +                    == Compiler.NODE_TYPE_NODE) {
  +            buffer.append(".");
  +        }
  +        else if (axis == Compiler.AXIS_PARENT
  +                && nodeTest instanceof NodeTypeTest
  +                && ((NodeTypeTest) nodeTest).getNodeType()
  +                    == Compiler.NODE_TYPE_NODE) {
  +            buffer.append("..");
  +        }
  +        else if (axis == Compiler.AXIS_DESCENDANT_OR_SELF
  +                && nodeTest instanceof NodeTypeTest
  +                && ((NodeTypeTest) nodeTest).getNodeType()
  +                    == Compiler.NODE_TYPE_NODE 
  +                && (predicates == null || predicates.length == 0)) {
  +            buffer.append("");
  +        }
  +        else {
  +            buffer.append(axisToString(axis));
  +            buffer.append("::");
  +            buffer.append(nodeTest);
  +        }
           Expression[] predicates = getPredicates();
           if (predicates != null) {
               for (int i = 0; i < predicates.length; i++) {
  
  
  
  1.7       +16 -41    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/TreeCompiler.java
  
  Index: TreeCompiler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/TreeCompiler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TreeCompiler.java	11 Jan 2003 05:41:23 -0000	1.6
  +++ TreeCompiler.java	19 Jan 2003 23:59:24 -0000	1.7
  @@ -85,63 +85,45 @@
       }
   
       public Object sum(Object[] arguments) {
  -        return new CoreOperation(
  -            Expression.OP_SUM,
  -            toExpressionArray(arguments));
  +        return new CoreOperationAdd(toExpressionArray(arguments));
       }
   
       public Object minus(Object left, Object right) {
  -        return new CoreOperation(
  -            Expression.OP_MINUS,
  +        return new CoreOperationSubtract(
               (Expression) left,
               (Expression) right);
       }
   
       public Object multiply(Object left, Object right) {
  -        return new CoreOperation(
  -            Expression.OP_MULT,
  -            (Expression) left,
  -            (Expression) right);
  +        return new CoreOperationMultiply((Expression) left, (Expression) right);
       }
   
       public Object divide(Object left, Object right) {
  -        return new CoreOperation(
  -            Expression.OP_DIV,
  -            (Expression) left,
  -            (Expression) right);
  +        return new CoreOperationDivide((Expression) left, (Expression) right);
       }
   
       public Object mod(Object left, Object right) {
  -        return new CoreOperation(
  -            Expression.OP_MOD,
  -            (Expression) left,
  -            (Expression) right);
  +        return new CoreOperationMod((Expression) left, (Expression) right);
       }
   
       public Object lessThan(Object left, Object right) {
  -        return new CoreOperation(
  -            Expression.OP_LT,
  -            (Expression) left,
  -            (Expression) right);
  +        return new CoreOperationLessThan((Expression) left, (Expression) right);
       }
   
       public Object lessThanOrEqual(Object left, Object right) {
  -        return new CoreOperation(
  -            Expression.OP_LTE,
  +        return new CoreOperationLessThanOrEqual(
               (Expression) left,
               (Expression) right);
       }
   
       public Object greaterThan(Object left, Object right) {
  -        return new CoreOperation(
  -            Expression.OP_GT,
  +        return new CoreOperationGreaterThan(
               (Expression) left,
               (Expression) right);
       }
   
       public Object greaterThanOrEqual(Object left, Object right) {
  -        return new CoreOperation(
  -            Expression.OP_GTE,
  +        return new CoreOperationGreaterThanOrEqual(
               (Expression) left,
               (Expression) right);
       }
  @@ -151,24 +133,20 @@
               return new NameAttributeTest((Expression) left, (Expression) right);
           }
           else {
  -            return new CoreOperation(
  -                Expression.OP_EQ,
  +            return new CoreOperationEqual(
                   (Expression) left,
                   (Expression) right);
           }
       }
   
       public Object notEqual(Object left, Object right) {
  -        return new CoreOperation(
  -            Expression.OP_NE,
  +        return new CoreOperationNotEqual(
               (Expression) left,
               (Expression) right);
       }
   
       public Object minus(Object argument) {
  -        return new CoreOperation(
  -            Expression.OP_UNARY_MINUS,
  -            (Expression) argument);
  +        return new CoreOperationNegate((Expression) argument);
       }
   
       public Object variableReference(Object qName) {
  @@ -184,20 +162,17 @@
       }
   
       public Object and(Object arguments[]) {
  -        return new CoreOperation(
  -            Expression.OP_AND,
  +        return new CoreOperationAnd(
               toExpressionArray(arguments));
       }
   
       public Object or(Object arguments[]) {
  -        return new CoreOperation(
  -            Expression.OP_OR,
  +        return new CoreOperationOr(
               toExpressionArray(arguments));
       }
   
       public Object union(Object[] arguments) {
  -        return new CoreOperation(
  -            Expression.OP_UNION,
  +        return new CoreOperationUnion(
               toExpressionArray(arguments));
       }
   
  @@ -258,7 +233,7 @@
       }
   
       private boolean isNameAttributeTest(Expression arg) {
  -        if (arg.getExpressionTypeCode() != Expression.OP_LOCATION_PATH) {
  +        if (!(arg instanceof LocationPath)) {
               return false;
           }
   
  
  
  
  1.6       +1 -2      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/VariableReference.java
  
  Index: VariableReference.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/VariableReference.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- VariableReference.java	11 Jan 2003 05:41:23 -0000	1.5
  +++ VariableReference.java	19 Jan 2003 23:59:24 -0000	1.6
  @@ -75,7 +75,6 @@
       private QName varName;
   
       public VariableReference(QName varName) {
  -        super(Expression.OP_VAR);
           this.varName = varName;
       }
   
  @@ -84,7 +83,7 @@
       }
   
       public String toString() {
  -        return "(VAR " + varName + ")";
  +        return "$" + varName;
       }
   
       public boolean isContextDependent() {
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAdd.java
  
  Index: CoreOperationAdd.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "+".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationAdd extends CoreOperation {
  
      public CoreOperationAdd(Expression[] args) {
          super(args);
      }
  
      public Object computeValue(EvalContext context) {
          double s = 0.0;
          for (int i = 0; i < args.length; i++) {
              s += InfoSetUtil.doubleValue(args[i].computeValue(context));
          }
          return new Double(s);
      }
      
      protected int getPrecedence() {
          return 4;
      }
  
      protected boolean isSymmetric() {
          return true;
      }
      
      public String getSymbol() {
          return "+";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationAnd.java
  
  Index: CoreOperationAnd.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "and".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationAnd extends CoreOperation {
  
      public CoreOperationAnd(Expression[] args) {
          super(args);
      }
  
      public Object computeValue(EvalContext context) {
          for (int i = 0; i < args.length; i++) {
              if (!InfoSetUtil.booleanValue(args[i].computeValue(context))) {
                  return Boolean.FALSE;
              }
          }
          return Boolean.TRUE;
      }
      
      protected int getPrecedence() {
          return 1;
      }
  
      protected boolean isSymmetric() {
          return true;
      }
      
      public String getSymbol() {
          return "and";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationCompare.java
  
  Index: CoreOperationCompare.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import java.util.Collection;
  import java.util.HashSet;
  import java.util.Iterator;
  
  import org.apache.commons.jxpath.Pointer;
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  import org.apache.commons.jxpath.ri.axes.InitialContext;
  import org.apache.commons.jxpath.ri.axes.SelfContext;
  
  /**
   * Common superclass for the implementations of Expression for the operations
   * "=" and "!=".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public abstract class CoreOperationCompare extends CoreOperation {
  
      public CoreOperationCompare(Expression arg1, Expression arg2) {
          super(new Expression[] { arg1, arg2 });
      }
  
      /**
       * Compares two values
       */
      protected boolean equal(
          EvalContext context,
          Expression left,
          Expression right) 
      {
          Object l = left.compute(context);
          Object r = right.compute(context);
  
  //        System.err.println("COMPARING: " +
  //            (l == null ? "null" : l.getClass().getName()) + " " +
  //            (r == null ? "null" : r.getClass().getName()));
  
          if (l instanceof InitialContext || l instanceof SelfContext) {
              l = ((EvalContext) l).getSingleNodePointer();
          }
  
          if (r instanceof InitialContext || r instanceof SelfContext) {
              r = ((EvalContext) r).getSingleNodePointer();
          }
  
          if (l instanceof Collection) {
              l = ((Collection) l).iterator();
          }
  
          if (r instanceof Collection) {
              r = ((Collection) r).iterator();
          }
  
          if ((l instanceof Iterator) && !(r instanceof Iterator)) {
              return contains((Iterator) l, r);
          }
          else if (!(l instanceof Iterator) && (r instanceof Iterator)) {
              return contains((Iterator) r, l);
          }
          else if (l instanceof Iterator && r instanceof Iterator) {
              return findMatch((Iterator) l, (Iterator) r);
          }
  
          return equal(l, r);
      }
  
      protected boolean contains(Iterator it, Object value) {
          while (it.hasNext()) {
              Object element = it.next();
              if (equal(element, value)) {
                  return true;
              }
          }
          return false;
      }
  
      protected boolean findMatch(Iterator lit, Iterator rit) {
          HashSet left = new HashSet();
          while (lit.hasNext()) {
              left.add(lit.next());
          }
          while (rit.hasNext()) {
              if (contains(left.iterator(), rit.next())) {
                  return true;
              }
          }
          return false;
      }
  
      protected boolean equal(Object l, Object r) {
          if (l instanceof Pointer && r instanceof Pointer) {
              if (l.equals(r)) {
                  return true;
              }
          }
  
          if (l instanceof Pointer) {
              l = ((Pointer) l).getValue();
          }
  
          if (r instanceof Pointer) {
              r = ((Pointer) r).getValue();
          }
  
          if (l == r) {
              return true;
          }
  
  //        System.err.println("COMPARING VALUES: " + l + " " + r);
          if (l instanceof Boolean || r instanceof Boolean) {
              return (InfoSetUtil.booleanValue(l) == InfoSetUtil.booleanValue(r));
          }
          else if (l instanceof Number || r instanceof Number) {
              return (InfoSetUtil.doubleValue(l) == InfoSetUtil.doubleValue(r));
          }
          else if (l instanceof String || r instanceof String) {
              return (
                  InfoSetUtil.stringValue(l).equals(InfoSetUtil.stringValue(r)));
          }
          else if (l == null) {
              return r == null;
          }
          return l.equals(r);
      }
  
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationDivide.java
  
  Index: CoreOperationDivide.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "div".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationDivide extends CoreOperation {
  
      public CoreOperationDivide(Expression arg1, Expression arg2) {
          super(new Expression[] { arg1, arg2 });
      }
  
      public Object computeValue(EvalContext context) {
          double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
          double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
          return new Double(l / r);
      }
      
      protected int getPrecedence() {
          return 5;
      }
  
      protected boolean isSymmetric() {
          return false;
      }
      
      public String getSymbol() {
          return "div";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationEqual.java
  
  Index: CoreOperationEqual.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  
  /**
   * Implementation of Expression for the operation "=".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationEqual extends CoreOperationCompare {
  
      public CoreOperationEqual(Expression arg1, Expression arg2) {
          super(arg1, arg2);
      }
  
      public Object computeValue(EvalContext context) {
          return equal(context, args[0], args[1]) ? Boolean.TRUE : Boolean.FALSE;
      }
      
      protected int getPrecedence() {
          return 2;
      }
  
      protected boolean isSymmetric() {
          return true;
      }
      
      public String getSymbol() {
          return "=";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThan.java
  
  Index: CoreOperationGreaterThan.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "&gt;".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationGreaterThan extends CoreOperation {
  
      public CoreOperationGreaterThan(Expression arg1, Expression arg2) {
          super(new Expression[] { arg1, arg2 });
      }
  
      public Object computeValue(EvalContext context) {
          double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
          double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
          return l > r ? Boolean.TRUE : Boolean.FALSE;
      }
      
      protected int getPrecedence() {
          return 3;
      }
  
      protected boolean isSymmetric() {
          return false;
      }
      
      public String getSymbol() {
          return ">";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationGreaterThanOrEqual.java
  
  Index: CoreOperationGreaterThanOrEqual.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "&gt;=".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationGreaterThanOrEqual extends CoreOperation {
  
      public CoreOperationGreaterThanOrEqual(Expression arg1, Expression arg2) {
          super(new Expression[] { arg1, arg2 });
      }
  
      public Object computeValue(EvalContext context) {
          double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
          double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
          return l >= r ? Boolean.TRUE : Boolean.FALSE;
      }
      
      protected int getPrecedence() {
          return 3;
      }
  
      protected boolean isSymmetric() {
          return false;
      }
      
      public String getSymbol() {
          return ">=";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThan.java
  
  Index: CoreOperationLessThan.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "&lt;".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationLessThan extends CoreOperation {
  
      public CoreOperationLessThan(Expression arg1, Expression arg2) {
          super(new Expression[] { arg1, arg2 });
      }
  
      public Object computeValue(EvalContext context) {
          double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
          double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
          return l < r ? Boolean.TRUE : Boolean.FALSE;
      }
      
      protected int getPrecedence() {
          return 3;
      }
  
      protected boolean isSymmetric() {
          return false;
      }
      
      public String getSymbol() {
          return "<";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationLessThanOrEqual.java
  
  Index: CoreOperationLessThanOrEqual.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "&lt;=".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationLessThanOrEqual extends CoreOperation {
  
      public CoreOperationLessThanOrEqual(Expression arg1, Expression arg2) {
          super(new Expression[] { arg1, arg2 });
      }
  
      public Object computeValue(EvalContext context) {
          double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
          double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
          return l <= r ? Boolean.TRUE : Boolean.FALSE;
      }
      
      protected int getPrecedence() {
          return 3;
      }
  
      protected boolean isSymmetric() {
          return false;
      }
      
      public String getSymbol() {
          return "<=";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMod.java
  
  Index: CoreOperationMod.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "mod".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationMod extends CoreOperation {
  
      public CoreOperationMod(Expression arg1, Expression arg2) {
          super(new Expression[] { arg1, arg2 });
      }
  
      public Object computeValue(EvalContext context) {
          long l = (long) InfoSetUtil.doubleValue(args[0].computeValue(context));
          long r = (long) InfoSetUtil.doubleValue(args[1].computeValue(context));
          return new Double(l % r);
      }
      
      protected int getPrecedence() {
          return 5;
      }
  
      protected boolean isSymmetric() {
          return false;
      }
      
      public String getSymbol() {
          return "mod";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationMultiply.java
  
  Index: CoreOperationMultiply.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "*".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationMultiply extends CoreOperation {
  
      public CoreOperationMultiply(Expression arg1, Expression arg2) {
          super(new Expression[] { arg1, arg2 });
      }
  
      public Object computeValue(EvalContext context) {
          double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
          double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
          return new Double(l * r);
      }
      
      protected int getPrecedence() {
          return 5;
      }
  
      protected boolean isSymmetric() {
          return true;
      }
      
      public String getSymbol() {
          return "*";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationNegate.java
  
  Index: CoreOperationNegate.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation unary "-".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationNegate extends CoreOperation {
  
      public CoreOperationNegate(Expression arg) {
          super(new Expression[] { arg });
      }
  
      public Object computeValue(EvalContext context) {
          double a = InfoSetUtil.doubleValue(args[0].computeValue(context));
          return new Double(-a);
      }
      
      protected int getPrecedence() {
          return 6;
      }
  
      protected boolean isSymmetric() {
          return false;
      }
      
      public String getSymbol() {
          return "-";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationNotEqual.java
  
  Index: CoreOperationNotEqual.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  
  /**
   * Implementation of Expression for the operation "!=".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationNotEqual extends CoreOperationCompare {
  
      public CoreOperationNotEqual(Expression arg1, Expression arg2) {
          super(arg1, arg2);
      }
  
      public Object computeValue(EvalContext context) {
          return equal(context, args[0], args[1]) ? Boolean.FALSE : Boolean.TRUE;
      }
      
      protected int getPrecedence() {
          return 2;
      }
  
      protected boolean isSymmetric() {
          return true;
      }
      
      public String getSymbol() {
          return "!=";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationOr.java
  
  Index: CoreOperationOr.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "or".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationOr extends CoreOperation {
  
      public CoreOperationOr(Expression[] args) {
          super(args);
      }
  
      public Object computeValue(EvalContext context) {
          for (int i = 0; i < args.length; i++) {
              if (InfoSetUtil.booleanValue(args[i].computeValue(context))) {
                  return Boolean.TRUE;
              }
          }
          return Boolean.FALSE;
      }
      
      protected int getPrecedence() {
          return 0;
      }
  
      protected boolean isSymmetric() {
          return true;
      }
      
      public String getSymbol() {
          return "or";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationSubtract.java
  
  Index: CoreOperationSubtract.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.InfoSetUtil;
  
  /**
   * Implementation of Expression for the operation "-".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationSubtract extends CoreOperation {
  
      public CoreOperationSubtract(Expression arg1, Expression arg2) {
          super(new Expression[] { arg1, arg2 });
      }
  
      public Object computeValue(EvalContext context) {
          double l = InfoSetUtil.doubleValue(args[0].computeValue(context));
          double r = InfoSetUtil.doubleValue(args[1].computeValue(context));
          return new Double(l - r);
      }
      
      protected int getPrecedence() {
          return 4;
      }
  
      protected boolean isSymmetric() {
          return false;
      }
      
      public String getSymbol() {
          return "-";
      }
  }
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationUnion.java
  
  Index: CoreOperationUnion.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.compiler;
  
  import org.apache.commons.jxpath.ri.EvalContext;
  import org.apache.commons.jxpath.ri.axes.UnionContext;
  
  /**
   * Implementation of Expression for the operation "|".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2003/01/19 23:59:24 $
   */
  public class CoreOperationUnion extends CoreOperation {
  
      public CoreOperationUnion(Expression args[]) {
          super(args);
      }
  
      public Object computeValue(EvalContext context) {
          EvalContext argCtxs[] = new EvalContext[args.length];
          for (int i = 0; i < args.length; i++) {
              Object value = args[i].compute(context);
              if (value instanceof EvalContext) {
                  argCtxs[i] = (EvalContext) value;
              }
              else {
                  argCtxs[i] = context.getRootContext().getConstantContext(value);
              }
          }
          return new UnionContext(context.getRootContext(), argCtxs);
      }
      
      protected int getPrecedence() {
          return 7;
      }
  
      protected boolean isSymmetric() {
          return true;
      }
      
      public String getSymbol() {
          return "|";
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>