PatchSet 5310 
Date: 2004/10/18 20:19:38
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU JAXP: improved xpath support

2004-10-18  Dalibor Topic  <[EMAIL PROTECTED]>

        * libraries/javalib/Makefile.am,
        libraries/javalib/Makefile.in,
        libraries/javalib/all.files:
        Regenerated.

        * libraries/javalib/gnu/xml/dom/DomXPathResult.java,
        libraries/javalib/gnu/xml/xpath/AndExpr.java,
        libraries/javalib/gnu/xml/xpath/ArithmeticExpr.java,
        libraries/javalib/gnu/xml/xpath/Constant.java,
        libraries/javalib/gnu/xml/xpath/EqualityExpr.java,
        libraries/javalib/gnu/xml/xpath/Expr.java,
        libraries/javalib/gnu/xml/xpath/ExpressionTest.java,
        libraries/javalib/gnu/xml/xpath/FunctionCall.java,
        libraries/javalib/gnu/xml/xpath/Index.java,
        libraries/javalib/gnu/xml/xpath/NameTest.java,
        libraries/javalib/gnu/xml/xpath/NegativeExpr.java,
        libraries/javalib/gnu/xml/xpath/NodeTypeTest.java,
        libraries/javalib/gnu/xml/xpath/OrExpr.java,
        libraries/javalib/gnu/xml/xpath/ParenthesizedExpr.java,
        libraries/javalib/gnu/xml/xpath/RelationalExpr.java,
        libraries/javalib/gnu/xml/xpath/Root.java,
        libraries/javalib/gnu/xml/xpath/Selector.java,
        libraries/javalib/gnu/xml/xpath/Step.java,
        libraries/javalib/gnu/xml/xpath/Test.java,
        libraries/javalib/gnu/xml/xpath/UnionExpr.java,
        libraries/javalib/gnu/xml/xpath/XPathParser.java,
        libraries/javalib/gnu/xml/xpath/XPathTokenizer.java:
        New files taken from GNU JAXP.

        * libraries/javalib/META-INF/MANIFEST.MF,
        libraries/javalib/gnu/xml/aelfred2/SAXDriver.java,
        libraries/javalib/gnu/xml/dom/DomImpl.java,
        libraries/javalib/gnu/xml/dom/DomXPathExpression.java,
        libraries/javalib/org/xml/sax/SAXNotRecognizedException.java,
        libraries/javalib/org/xml/sax/SAXNotSupportedException.java:
        Resynced with GNU JAXP.

        2004-10-13  Arnaud Vandyck  <[EMAIL PROTECTED]>

        Reported by John Kristian <[EMAIL PROTECTED]>:
        * manifest.mf: added Implementation Version field.

        2004-10-17  Chris Burdess  <[EMAIL PROTECTED]>

        * xpath: Added experimental XPath 1.0 engine.

Members: 
        ChangeLog:1.2862->1.2863 
        libraries/javalib/Makefile.am:1.251->1.252 
        libraries/javalib/Makefile.in:1.331->1.332 
        libraries/javalib/all.files:1.39->1.40 
        libraries/javalib/META-INF/MANIFEST.MF:1.1->1.2 
        libraries/javalib/gnu/xml/aelfred2/SAXDriver.java:1.11->1.12 
        libraries/javalib/gnu/xml/dom/DomImpl.java:1.5->1.6 
        libraries/javalib/gnu/xml/dom/DomXPathExpression.java:1.1->1.2 
        libraries/javalib/gnu/xml/dom/DomXPathResult.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/AndExpr.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/ArithmeticExpr.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/Constant.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/EqualityExpr.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/Expr.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/ExpressionTest.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/FunctionCall.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/Index.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/NameTest.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/NegativeExpr.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/NodeTypeTest.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/OrExpr.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/ParenthesizedExpr.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/RelationalExpr.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/Root.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/Selector.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/Step.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/Test.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/UnionExpr.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/XPathParser.java:INITIAL->1.1 
        libraries/javalib/gnu/xml/xpath/XPathTokenizer.java:INITIAL->1.1 
        libraries/javalib/org/xml/sax/SAXNotRecognizedException.java:1.2->1.3 
        libraries/javalib/org/xml/sax/SAXNotSupportedException.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2862 kaffe/ChangeLog:1.2863
--- kaffe/ChangeLog:1.2862      Mon Oct 18 13:38:52 2004
+++ kaffe/ChangeLog     Mon Oct 18 20:19:38 2004
@@ -1,5 +1,53 @@
 2004-10-18  Dalibor Topic  <[EMAIL PROTECTED]>
 
+       * libraries/javalib/Makefile.am,
+       libraries/javalib/Makefile.in,
+       libraries/javalib/all.files:
+       Regenerated.
+
+       * libraries/javalib/gnu/xml/dom/DomXPathResult.java,
+       libraries/javalib/gnu/xml/xpath/AndExpr.java,
+       libraries/javalib/gnu/xml/xpath/ArithmeticExpr.java,
+       libraries/javalib/gnu/xml/xpath/Constant.java,
+       libraries/javalib/gnu/xml/xpath/EqualityExpr.java,
+       libraries/javalib/gnu/xml/xpath/Expr.java,
+       libraries/javalib/gnu/xml/xpath/ExpressionTest.java,
+       libraries/javalib/gnu/xml/xpath/FunctionCall.java,
+       libraries/javalib/gnu/xml/xpath/Index.java,
+       libraries/javalib/gnu/xml/xpath/NameTest.java,
+       libraries/javalib/gnu/xml/xpath/NegativeExpr.java,
+       libraries/javalib/gnu/xml/xpath/NodeTypeTest.java,
+       libraries/javalib/gnu/xml/xpath/OrExpr.java,
+       libraries/javalib/gnu/xml/xpath/ParenthesizedExpr.java,
+       libraries/javalib/gnu/xml/xpath/RelationalExpr.java,
+       libraries/javalib/gnu/xml/xpath/Root.java,
+       libraries/javalib/gnu/xml/xpath/Selector.java,
+       libraries/javalib/gnu/xml/xpath/Step.java,
+       libraries/javalib/gnu/xml/xpath/Test.java,
+       libraries/javalib/gnu/xml/xpath/UnionExpr.java,
+       libraries/javalib/gnu/xml/xpath/XPathParser.java,
+       libraries/javalib/gnu/xml/xpath/XPathTokenizer.java:
+       New files taken from GNU JAXP.
+
+       * libraries/javalib/META-INF/MANIFEST.MF,
+       libraries/javalib/gnu/xml/aelfred2/SAXDriver.java,
+       libraries/javalib/gnu/xml/dom/DomImpl.java,
+       libraries/javalib/gnu/xml/dom/DomXPathExpression.java,
+       libraries/javalib/org/xml/sax/SAXNotRecognizedException.java,
+       libraries/javalib/org/xml/sax/SAXNotSupportedException.java:
+       Resynced with GNU JAXP.
+
+       2004-10-13  Arnaud Vandyck  <[EMAIL PROTECTED]>
+
+        Reported by John Kristian <[EMAIL PROTECTED]>:
+        * manifest.mf: added Implementation Version field.
+
+       2004-10-17  Chris Burdess  <[EMAIL PROTECTED]>
+
+        * xpath: Added experimental XPath 1.0 engine.
+
+2004-10-18  Dalibor Topic  <[EMAIL PROTECTED]>
+
        * libraries/javalib/gnu/java/security/provider/DSAParameters.java:
         Resynced with GNU Classpath.
 
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.251 
kaffe/libraries/javalib/Makefile.am:1.252
--- kaffe/libraries/javalib/Makefile.am:1.251   Sun Oct 17 19:06:49 2004
+++ kaffe/libraries/javalib/Makefile.am Mon Oct 18 20:19:41 2004
@@ -160,6 +160,7 @@
        $(gnu_xml_libxmlj_util_SRCS) \
        $(gnu_xml_pipeline_SRCS) \
        $(gnu_xml_util_SRCS) \
+       $(gnu_xml_xpath_SRCS) \
        $(java_applet_SRCS) \
        $(java_awt_SRCS) \
        $(java_awt_color_SRCS) \
@@ -1384,6 +1385,7 @@
        gnu/xml/dom/DomText.java \
        gnu/xml/dom/DomXPathExpression.java \
        gnu/xml/dom/DomXPathNSResolver.java \
+       gnu/xml/dom/DomXPathResult.java \
        gnu/xml/dom/ImplementationList.java \
        gnu/xml/dom/ImplementationSource.java \
        gnu/xml/dom/JAXPFactory.java
@@ -1460,6 +1462,28 @@
        gnu/xml/util/XCat.java \
        gnu/xml/util/XHTMLWriter.java \
        gnu/xml/util/XMLWriter.java
+gnu_xml_xpath_SRCS = \
+       gnu/xml/xpath/AndExpr.java \
+       gnu/xml/xpath/ArithmeticExpr.java \
+       gnu/xml/xpath/Constant.java \
+       gnu/xml/xpath/EqualityExpr.java \
+       gnu/xml/xpath/Expr.java \
+       gnu/xml/xpath/ExpressionTest.java \
+       gnu/xml/xpath/FunctionCall.java \
+       gnu/xml/xpath/Index.java \
+       gnu/xml/xpath/NameTest.java \
+       gnu/xml/xpath/NegativeExpr.java \
+       gnu/xml/xpath/NodeTypeTest.java \
+       gnu/xml/xpath/OrExpr.java \
+       gnu/xml/xpath/ParenthesizedExpr.java \
+       gnu/xml/xpath/RelationalExpr.java \
+       gnu/xml/xpath/Root.java \
+       gnu/xml/xpath/Selector.java \
+       gnu/xml/xpath/Step.java \
+       gnu/xml/xpath/Test.java \
+       gnu/xml/xpath/UnionExpr.java \
+       gnu/xml/xpath/XPathParser.java \
+       gnu/xml/xpath/XPathTokenizer.java
 java_applet_SRCS = \
        java/applet/Applet.java \
        java/applet/AppletContext.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.331 
kaffe/libraries/javalib/Makefile.in:1.332
--- kaffe/libraries/javalib/Makefile.in:1.331   Sun Oct 17 19:06:50 2004
+++ kaffe/libraries/javalib/Makefile.in Mon Oct 18 20:19:43 2004
@@ -501,6 +501,7 @@
        $(gnu_xml_libxmlj_util_SRCS) \
        $(gnu_xml_pipeline_SRCS) \
        $(gnu_xml_util_SRCS) \
+       $(gnu_xml_xpath_SRCS) \
        $(java_applet_SRCS) \
        $(java_awt_SRCS) \
        $(java_awt_color_SRCS) \
@@ -1824,6 +1825,7 @@
        gnu/xml/dom/DomText.java \
        gnu/xml/dom/DomXPathExpression.java \
        gnu/xml/dom/DomXPathNSResolver.java \
+       gnu/xml/dom/DomXPathResult.java \
        gnu/xml/dom/ImplementationList.java \
        gnu/xml/dom/ImplementationSource.java \
        gnu/xml/dom/JAXPFactory.java
@@ -1907,6 +1909,29 @@
        gnu/xml/util/XCat.java \
        gnu/xml/util/XHTMLWriter.java \
        gnu/xml/util/XMLWriter.java
+
+gnu_xml_xpath_SRCS = \
+       gnu/xml/xpath/AndExpr.java \
+       gnu/xml/xpath/ArithmeticExpr.java \
+       gnu/xml/xpath/Constant.java \
+       gnu/xml/xpath/EqualityExpr.java \
+       gnu/xml/xpath/Expr.java \
+       gnu/xml/xpath/ExpressionTest.java \
+       gnu/xml/xpath/FunctionCall.java \
+       gnu/xml/xpath/Index.java \
+       gnu/xml/xpath/NameTest.java \
+       gnu/xml/xpath/NegativeExpr.java \
+       gnu/xml/xpath/NodeTypeTest.java \
+       gnu/xml/xpath/OrExpr.java \
+       gnu/xml/xpath/ParenthesizedExpr.java \
+       gnu/xml/xpath/RelationalExpr.java \
+       gnu/xml/xpath/Root.java \
+       gnu/xml/xpath/Selector.java \
+       gnu/xml/xpath/Step.java \
+       gnu/xml/xpath/Test.java \
+       gnu/xml/xpath/UnionExpr.java \
+       gnu/xml/xpath/XPathParser.java \
+       gnu/xml/xpath/XPathTokenizer.java
 
 java_applet_SRCS = \
        java/applet/Applet.java \
Index: kaffe/libraries/javalib/all.files
diff -u kaffe/libraries/javalib/all.files:1.39 kaffe/libraries/javalib/all.files:1.40
--- kaffe/libraries/javalib/all.files:1.39      Sun Oct 17 19:06:50 2004
+++ kaffe/libraries/javalib/all.files   Mon Oct 18 20:19:44 2004
@@ -966,6 +966,7 @@
 gnu/xml/dom/DomText.java
 gnu/xml/dom/DomXPathExpression.java
 gnu/xml/dom/DomXPathNSResolver.java
+gnu/xml/dom/DomXPathResult.java
 gnu/xml/dom/ImplementationList.java
 gnu/xml/dom/ImplementationSource.java
 gnu/xml/dom/JAXPFactory.java
@@ -1035,6 +1036,27 @@
 gnu/xml/util/XCat.java
 gnu/xml/util/XHTMLWriter.java
 gnu/xml/util/XMLWriter.java
+gnu/xml/xpath/AndExpr.java
+gnu/xml/xpath/ArithmeticExpr.java
+gnu/xml/xpath/Constant.java
+gnu/xml/xpath/EqualityExpr.java
+gnu/xml/xpath/Expr.java
+gnu/xml/xpath/ExpressionTest.java
+gnu/xml/xpath/FunctionCall.java
+gnu/xml/xpath/Index.java
+gnu/xml/xpath/NameTest.java
+gnu/xml/xpath/NegativeExpr.java
+gnu/xml/xpath/NodeTypeTest.java
+gnu/xml/xpath/OrExpr.java
+gnu/xml/xpath/ParenthesizedExpr.java
+gnu/xml/xpath/RelationalExpr.java
+gnu/xml/xpath/Root.java
+gnu/xml/xpath/Selector.java
+gnu/xml/xpath/Step.java
+gnu/xml/xpath/Test.java
+gnu/xml/xpath/UnionExpr.java
+gnu/xml/xpath/XPathParser.java
+gnu/xml/xpath/XPathTokenizer.java
 java/applet/Applet.java
 java/applet/AppletContext.java
 java/applet/AppletStub.java
Index: kaffe/libraries/javalib/META-INF/MANIFEST.MF
diff -u kaffe/libraries/javalib/META-INF/MANIFEST.MF:1.1 
kaffe/libraries/javalib/META-INF/MANIFEST.MF:1.2
--- kaffe/libraries/javalib/META-INF/MANIFEST.MF:1.1    Wed Apr 14 19:40:35 2004
+++ kaffe/libraries/javalib/META-INF/MANIFEST.MF        Mon Oct 18 20:19:45 2004
@@ -2,6 +2,7 @@
 Implementation-Title: GNU JAXP
 Implementation-URL: http://www.gnu.org/software/classpathx/jaxp
 Implementation-Vendor: Free Software Foundation
+Implementation-Version: 1.1
 Main-Class: gnu.xml.util.DoParse
 
 Name: gnu/xml/aelfred2/
Index: kaffe/libraries/javalib/gnu/xml/aelfred2/SAXDriver.java
diff -u kaffe/libraries/javalib/gnu/xml/aelfred2/SAXDriver.java:1.11 
kaffe/libraries/javalib/gnu/xml/aelfred2/SAXDriver.java:1.12
--- kaffe/libraries/javalib/gnu/xml/aelfred2/SAXDriver.java:1.11        Fri Sep 17 
21:02:01 2004
+++ kaffe/libraries/javalib/gnu/xml/aelfred2/SAXDriver.java     Mon Oct 18 20:19:45 
2004
@@ -1361,5 +1361,6 @@
     {
         this.name = name;
         this.value = value;
+        this.nameSpace = "";
     }
 }
Index: kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java
diff -u kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java:1.5 
kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java:1.6
--- kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java:1.5        Fri Sep 17 21:02:02 
2004
+++ kaffe/libraries/javalib/gnu/xml/dom/DomImpl.java    Mon Oct 18 20:19:46 2004
@@ -114,7 +114,12 @@
                    return true;
                if ("2.0".equals (version))
                    return true;
-       }
+       } else if ("xpath".equals (name)) {
+          if (version == null || version.equals (""))
+            return true;
+          if ("1.0".equals (version))
+            return true;
+        }
 
        // views
        // stylesheets
Index: kaffe/libraries/javalib/gnu/xml/dom/DomXPathExpression.java
diff -u kaffe/libraries/javalib/gnu/xml/dom/DomXPathExpression.java:1.1 
kaffe/libraries/javalib/gnu/xml/dom/DomXPathExpression.java:1.2
--- kaffe/libraries/javalib/gnu/xml/dom/DomXPathExpression.java:1.1     Sun Oct 10 
18:43:17 2004
+++ kaffe/libraries/javalib/gnu/xml/dom/DomXPathExpression.java Mon Oct 18 20:19:46 
2004
@@ -38,11 +38,17 @@
 
 package gnu.xml.dom;
 
+import java.io.IOException;
+import java.util.Collection;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Node;
 import org.w3c.dom.xpath.XPathException;
 import org.w3c.dom.xpath.XPathExpression;
 import org.w3c.dom.xpath.XPathNSResolver;
+import org.w3c.dom.xpath.XPathResult;
+import gnu.xml.xpath.Expr;
+import gnu.xml.xpath.XPathParser;
+import gnu.xml.xpath.XPathTokenizer;
 
 /**
  * An XPath expression.
@@ -53,23 +59,75 @@
 implements XPathExpression
 {
 
-  DomDocument doc;
-  String expression;
-  XPathNSResolver resolver;
+  final DomDocument doc;
+  final Expr expression;
+  final XPathNSResolver resolver;
 
   DomXPathExpression (DomDocument doc, String expression,
                       XPathNSResolver resolver)
+    throws XPathException
   {
     this.doc = doc;
-    this.expression = expression;
     this.resolver = resolver;
+    
+    XPathParser parser = new XPathParser ();
+    XPathTokenizer tokenizer = new XPathTokenizer (expression);
+    try
+      {
+        this.expression = (Expr) parser.yyparse (tokenizer);
+      }
+    catch (IOException e)
+      {
+        throw new XPathException (XPathException.INVALID_EXPRESSION_ERR,
+                                  e.getMessage ());
+      }
+    catch (XPathParser.yyException e)
+      {
+        throw new XPathException (XPathException.INVALID_EXPRESSION_ERR,
+                                  e.getMessage ());
+      }
+    System.out.println("expression="+this.expression);
   }
 
   public Object evaluate (Node contextNode, short type, Object result)
     throws XPathException, DOMException
   {
-    // TODO
-    return null;
+    Object val = expression.evaluate (contextNode);
+    switch (type)
+      {
+      case XPathResult.BOOLEAN_TYPE:
+        if (!(val instanceof Boolean))
+          {
+            throw new XPathException (XPathException.TYPE_ERR, null);
+          }
+        break;
+      case XPathResult.NUMBER_TYPE:
+        if (!(val instanceof Double))
+          {
+            throw new XPathException (XPathException.TYPE_ERR, null);
+          }
+        break;
+      case XPathResult.STRING_TYPE:
+        if (!(val instanceof String))
+          {
+            throw new XPathException (XPathException.TYPE_ERR, null);
+          }
+        break;
+      case XPathResult.ANY_UNORDERED_NODE_TYPE:
+      case XPathResult.FIRST_ORDERED_NODE_TYPE:
+      case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
+      case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
+        if (!(val instanceof Collection))
+          {
+            throw new XPathException (XPathException.TYPE_ERR, null);
+          }
+        break;
+      case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
+      case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
+        /* We don't support ordered node-sets */
+        throw new XPathException (XPathException.TYPE_ERR, null);
+      }
+    return new DomXPathResult (val, type);
   }
   
 }
===================================================================
Checking out kaffe/libraries/javalib/gnu/xml/dom/DomXPathResult.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/xml/dom/DomXPathResult.java,v
VERS: 1.1
***************
--- /dev/null   Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/xml/dom/DomXPathResult.java     Mon Oct 18 20:23:46 
2004
@@ -0,0 +1,205 @@
+/*
+ * DomXPathResult.java
+ * Copyright (C) 2004 The Free Software Foundation
+ * 
+ * This file is part of GNU JAXP, a library.
+ *
+ * GNU JAXP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU JAXP is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library.  Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on this library.  If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obliged to do so.  If you do not wish to do so, delete this
+ * exception statement from your version. 
+ */
+
+package gnu.xml.dom;
+
+import java.util.Collection;
+import java.util.Iterator;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Node;
+import org.w3c.dom.xpath.XPathException;
+import org.w3c.dom.xpath.XPathNSResolver;
+import org.w3c.dom.xpath.XPathResult;
+
+/**
+ * An XPath result object.
+ *
+ * @author <a href='mailto:[EMAIL PROTECTED]'>Chris Burdess</a>
+ */
+class DomXPathResult
+implements XPathResult
+{
+
+  final Object value;
+  final short type;
+  Iterator iterator;
+
+  DomXPathResult (Object value, short requestedType)
+  {
+    this.value = value;
+    if (value instanceof Boolean)
+      {
+        type = XPathResult.BOOLEAN_TYPE;
+      }
+    else if (value instanceof Double)
+      {
+        type = XPathResult.NUMBER_TYPE;
+      }
+    else if (value instanceof String)
+      {
+        type = XPathResult.STRING_TYPE;
+      }
+    else if (value instanceof Collection)
+      {
+        Collection ns = (Collection) value;
+        switch (requestedType)
+          {
+          case XPathResult.ANY_TYPE:
+          case XPathResult.ANY_UNORDERED_NODE_TYPE:
+            type = (ns.size () == 1) ? XPathResult.FIRST_ORDERED_NODE_TYPE :
+              XPathResult.UNORDERED_NODE_ITERATOR_TYPE;
+            break;
+          default:
+            type = requestedType;
+          }
+        iterator = ns.iterator ();
+      }
+    else
+      {
+        throw new IllegalArgumentException ();
+      }
+  }
+
+  public boolean getBooleanValue()
+  {
+    if (type == XPathResult.BOOLEAN_TYPE)
+      {
+        return ((Boolean) value).booleanValue ();
+      }
+    throw new XPathException (XPathException.TYPE_ERR, value.toString ());
+  }
+
+  public boolean getInvalidIteratorState()
+  {
+    return iterator == null;
+  }
+
+  public double getNumberValue()
+  {
+    if (type == XPathResult.NUMBER_TYPE)
+      {
+        return ((Double) value).doubleValue ();
+      }
+    throw new XPathException (XPathException.TYPE_ERR, value.toString ());
+  }
+
+  public short getResultType()
+  {
+    return type;
+  }
+
+  public Node getSingleNodeValue()
+  {
+    switch (type)
+      {
+      case XPathResult.FIRST_ORDERED_NODE_TYPE:
+      case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
+      case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
+        Collection ns = (Collection) value;
+        if (ns.isEmpty ())
+          {
+            return null;
+          }
+        else
+          {
+            return (Node) ns.iterator ().next ();
+          }
+      }
+    throw new XPathException (XPathException.TYPE_ERR, value.toString ());
+  }
+
+  public int getSnapshotLength()
+  {
+    switch (type)
+      {
+      case XPathResult.FIRST_ORDERED_NODE_TYPE:
+      case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
+      case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
+        return ((Collection) value).size ();
+      }
+    throw new XPathException (XPathException.TYPE_ERR, value.toString ());
+  }
+
+  public String getStringValue()
+  {
+    if (type == XPathResult.STRING_TYPE)
+      {
+        return (String) value;
+      }
+    throw new XPathException (XPathException.TYPE_ERR, value.toString ());
+  }
+
+  public Node iterateNext()
+  {
+    if (iterator != null)
+      {
+        if (iterator.hasNext ())
+          {
+            return (Node) iterator.next ();
+          }
+        else
+          {
+            iterator = null;
+            return null;
+          }
+      }
+    throw new XPathException (XPathException.TYPE_ERR, value.toString ());
+  }
+
+  public Node snapshotItem(int index)
+  {
+    switch (type)
+      {
+      case XPathResult.FIRST_ORDERED_NODE_TYPE:
+      case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
+      case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
+        Collection ns = (Collection) value;
+        Node[] nodes = new Node[ns.size ()];
+        ns.toArray (nodes);
+        return nodes[index];
+      }
+    throw new XPathException (XPathException.TYPE_ERR, value.toString ());
+  }
+
+  public String toString ()
+  {
+    return getClass ().getName () + "[type=" + type + ",value=" +
+      value + ']';
+  }
+
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/xml/xpath/AndExpr.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/xml/xpath/AndExpr.java,v
VERS: 1.1
***************
--- /dev/null   Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/xml/xpath/AndExpr.java  Mon Oct 18 20:23:46 2004
@@ -0,0 +1,77 @@
+/*
+ * AndExpr.java
+ * Copyright (C) 2004 The Free Software Foundation
+ * 
+ * This file is part of GNU JAXP, a library.
+ *
+ * GNU JAXP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU JAXP is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library.  Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on this library.  If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obliged to do so.  If you do not wish to do so, delete this
+ * exception statement from your version. 
+ */
+
+package gnu.xml.xpath;
+
+import org.w3c.dom.Node;
+
+/**
+ * Logical and.
+ *
+ * @author <a href='mailto:[EMAIL PROTECTED]'>Chris Burdess</a>
+ */
+class AndExpr
+extends Expr
+{
+
+  final Expr lhs;
+  final Expr rhs;
+
+  AndExpr (Expr lhs, Expr rhs)
+  {
+    this.lhs = lhs;
+    this.rhs = rhs;
+  }
+
+  public Object evaluate (Node context)
+  {
+    Object left = lhs.evaluate (context);
+    if (!_boolean (context, left))
+      {
+        return Boolean.FALSE;
+      }
+    Object right = rhs.evaluate (context);
+    return _boolean (context, right) ? Boolean.TRUE : Boolean.FALSE;
+  }
+
+  public String toString ()
+  {
+    return lhs + " and " + rhs;
+  }
+  
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/xml/xpath/ArithmeticExpr.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/xml/xpath/ArithmeticExpr.java,v
VERS: 1.1
***************
--- /dev/null   Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/xml/xpath/ArithmeticExpr.java   Mon Oct 18 20:23:46 
2004
@@ -0,0 +1,121 @@
+/*
+ * ArithmeticExpr.java
+ * Copyright (C) 2004 The Free Software Foundation
+ * 
+ * This file is part of GNU JAXP, a library.
+ *
+ * GNU JAXP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU JAXP is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library.  Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on this library.  If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obliged to do so.  If you do not wish to do so, delete this
+ * exception statement from your version. 
+ */
+
+package gnu.xml.xpath;
+
+import org.w3c.dom.Node;
+
+/**
+ * Binary arithmetic expression.
+ *
+ * @author <a href='mailto:[EMAIL PROTECTED]'>Chris Burdess</a>
+ */
+class ArithmeticExpr
+extends Expr
+{
+
+  static final int ADD = 0;
+  static final int SUBTRACT = 1;
+  static final int MULTIPLY = 2;
+  static final int DIVIDE = 3;
+  static final int MODULO = 4;
+
+  final Expr lhs;
+  final Expr rhs;
+  final int op;
+
+  ArithmeticExpr (Expr lhs, Expr rhs, int op)
+  {
+    this.lhs = lhs;
+    this.rhs = rhs;
+    this.op = op;
+  }
+
+  public Object evaluate (Node context)
+  {
+    Object left = lhs.evaluate (context);
+    Object right = rhs.evaluate (context);
+
+    double ln = _number (context, left);
+    double rn = _number (context, right);
+    switch (op)
+      {
+      case ADD:
+        return new Double (ln + rn);
+      case SUBTRACT:
+        return new Double (ln - rn);
+      case MULTIPLY:
+        return new Double (ln * rn);
+      case DIVIDE:
+        return new Double (ln / rn);
+      case MODULO:
+        return new Double (ln % rn);
+      default:
+        throw new IllegalStateException ();
+      }
+  }
+
+  public String toString ()
+  {
+    StringBuffer buf = new StringBuffer ();
+    buf.append (lhs);
+    buf.append (' ');
+    switch (op)
+      {
+      case ADD:
+        buf.append ('+');
+        break;
+      case SUBTRACT:
+        buf.append ('-');
+        break;
+      case MULTIPLY:
+        buf.append ('*');
+        break;
+      case DIVIDE:
+        buf.append ("div");
+        break;
+      case MODULO:
+        buf.append ("mod");
+        break;
+      }
+    buf.append (' ');
+    buf.append (rhs);
+    return buf.toString ();
+  }
+  
+}
===================================================================
Checking out kaffe/libraries/javalib/gnu/xml/xpath/Constant.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/xml/xpath/Constant.java,v
VERS: 1.1
***************
--- /dev/null   Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/xml/xpath/Constant.java Mon Oct 18 20:23:46 2004
@@ -0,0 +1,88 @@
+/*
+ * Constant.java
+ * Copyright (C) 2004 The Free Software Foundation
+ * 
+ * This file is part of GNU JAXP, a library.
+ *
+ * GNU JAXP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU JAXP is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library.  Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on this library.  If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obliged to do so.  If you do not wish to do so, delete this
+ * exception statement from your version. 
+ */
+
+package gnu.xml.xpath;
+
+import org.w3c.dom.Node;
+
+/**
+ * Constant value (string literal or number).
+ *
+ * @author <a href='mailto:[EMAIL PROTECTED]'>Chris Burdess</a>
+ */
+class Constant
+extends Expr
+{
+
+  final Object value;
+
+  Constant (Object value)
+  {
+    this.value = value;
+  }
+
+  public Object evaluate (Node context)
+  {
+    return value;
+  }
+
+  public String toString ()
+  {
+    String ret = value.toString ();
+    if (value instanceof String)
+      {
+        if (ret.indexOf ('\'') == -1)
+          {
+            return '\'' + ret + '\'';
+          }
+        else
+          {
+            return '"' + ret + '"';
+          }
+      }
+    if (value instanceof Double)
+      {
+        if (ret.endsWith (".0"))
+          {
+            ret = ret.substring (0, ret.length () - 2);
+          }
+      }
+    return ret;
+  }
+  
+} 
===================================================================
Checking out kaffe/libraries/javalib/gnu/xml/xpath/EqualityExpr.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/gnu/xml/xpath/EqualityExpr.java,v
VERS: 1.1
***************
--- /dev/null   Sun Aug  4 19:57:58 2002
+++ kaffe/libraries/javalib/gnu/xml/xpath/EqualityExpr.java     Mon Oct 18 20:23:46 
2004
@@ -0,0 +1,220 @@
+/*
+ * EqualityExpr.java
+ * Copyright (C) 2004 The Free Software Foundation
+ * 
+ * This file is part of GNU JAXP, a library.
+ *
+ * GNU JAXP is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNU JAXP is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library.  Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ *
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module.  An independent module is a module which is not derived from
+ * or based on this library.  If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obliged to do so.  If you do not wish to do so, delete this
+ * exception statement from your version. 
+ */

*** Patch too long, truncated ***

_______________________________________________
kaffe mailing list
[EMAIL PROTECTED]
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe

Reply via email to