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 2002/04/26 05:28:37 UTC

cvs commit: jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom DOMNodePointer.java

dmitri      02/04/25 20:28:37

  Modified:    jxpath/src/java/org/apache/commons/jxpath
                        XMLDocumentContainer.java PackageFunctions.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model
                        VariablePointer.java NodePointer.java
               jxpath/src/java/org/apache/commons/jxpath/util
                        ValueUtils.java TypeUtils.java
               jxpath/src/java/org/apache/commons/jxpath/ri/parser
                        TokenMgrError.java
               jxpath/src/java/org/apache/commons/jxpath/ri/axes
                        SimplePathInterpreter.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model/beans
                        PropertyIterator.java NullPropertyPointer.java
                        NullElementPointer.java DynamicPropertyPointer.java
                        BeanPropertyPointer.java
               jxpath/src/java/org/apache/commons/jxpath/ri Parser.java
                        JXPathContextReferenceImpl.java EvalContext.java
               jxpath/src/java/org/apache/commons/jxpath/functions
                        MethodFunction.java ConstructorFunction.java
               jxpath/src/test/org/apache/commons/jxpath
                        JXPathTestCase.java
               jxpath/src/java/org/apache/commons/jxpath/ri/model/dom
                        DOMNodePointer.java
  Added:       jxpath/src/java/org/apache/commons/jxpath
                        JXPathException.java
  Log:
  Improved error reporting
  
  Revision  Changes    Path
  1.4       +11 -8     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/XMLDocumentContainer.java
  
  Index: XMLDocumentContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/XMLDocumentContainer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLDocumentContainer.java	24 Apr 2002 03:30:17 -0000	1.3
  +++ XMLDocumentContainer.java	26 Apr 2002 03:28:36 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/XMLDocumentContainer.java,v 1.3 2002/04/24 03:30:17 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/24 03:30:17 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/XMLDocumentContainer.java,v 1.4 2002/04/26 03:28:36 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:36 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -83,7 +83,7 @@
    * read at all.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/24 03:30:17 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:36 $
    */
   public class XMLDocumentContainer implements Container {
   
  @@ -98,7 +98,7 @@
       public XMLDocumentContainer(URL xmlURL){
           this.xmlURL = xmlURL;
           if (xmlURL == null){
  -            throw new RuntimeException("Source is null");
  +            throw new JXPathException("URL is null");
           }
       }
   
  @@ -133,9 +133,12 @@
                   }
               }
               catch (Exception ex){
  -                throw new RuntimeException("Cannot read XML from: " +
  -                    (xmlURL != null ? xmlURL.toString() :
  -                        (source != null ? source.getSystemId() : "<<undefined source>>")) + "\n" + ex);
  +                throw new JXPathException(
  +                    "Cannot read XML from: " +
  +                        (xmlURL != null ? xmlURL.toString() :
  +                            (source != null ?
  +                                source.getSystemId() : "<<undefined source>>")),
  +                    ex);
               }
           }
           return document;
  
  
  
  1.5       +9 -7      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java
  
  Index: PackageFunctions.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PackageFunctions.java	24 Apr 2002 03:29:33 -0000	1.4
  +++ PackageFunctions.java	26 Apr 2002 03:28:36 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java,v 1.4 2002/04/24 03:29:33 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/24 03:29:33 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java,v 1.5 2002/04/26 03:28:36 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/04/26 03:28:36 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -108,7 +108,7 @@
   
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/24 03:29:33 $
  + * @version $Revision: 1.5 $ $Date: 2002/04/26 03:28:36 $
    */
   public class PackageFunctions implements Functions {
       private String classPrefix;
  @@ -140,10 +140,10 @@
        * <li><b>subpackage.subpackage.Classname.new</b>, if looking for a constructor in
        *      a subpackage</li>
        * <li><b>Classname.methodname</b>, if looking for a static method</li>
  -     * <li><b>subpackage.subpackage.Classname.methodname</b>, if looking for a 
  +     * <li><b>subpackage.subpackage.Classname.methodname</b>, if looking for a
        *      static method of a class in a subpackage</li>
        * </ul>
  -     * 
  +     *
        * @return a MethodFunction, a ConstructorFunction or null if no function is found
        */
       public Function getFunction(String namespace, String name, Object[] parameters) {
  @@ -191,7 +191,9 @@
               functionClass = Class.forName(className);
           }
           catch (ClassNotFoundException ex) {
  -            throw new RuntimeException("Class not found: " + ex);
  +            throw new JXPathException("Cannot invoke extension function "
  +                + (namespace != null ? namespace + ":" + name : name),
  +                ex);
           }
   
           if (methodName.endsWith("new")) {
  
  
  
  1.1                  jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathException.java
  
  Index: JXPathException.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathException.java,v 1.1 2002/04/26 03:28:36 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2002/04/26 03:28:36 $
   *
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2001 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 Group.
   *
   * 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 and was
   * originally based on software copyright (c) 2001, Plotnix, Inc,
   * <http://www.plotnix.com/>.
   * For more information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath;
  
  /**
   * Thrown in various situations by JXPath; may contain a nested exception.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2002/04/26 03:28:36 $
   */
  
  public class JXPathException extends RuntimeException {
  
      /** @serial */
      private Throwable exception;
  
      /**
       * Create a new <code>JXPathException</code> with no
       * detail mesage.
       */
  
       public JXPathException() {
           super();
           this.exception = null;
       }
  
      /**
       * Create a new <code>JXPathException</code> with
       * the <code>String </code> specified as an error message.
       *
       * @param msg The error message for the exception.
       */
      public JXPathException(String msg) {
          super(msg);
          this.exception = null;
      }
  
  
      /**
       * Create a new <code>JXPathException</code> with a
       * given <code>Throwable</code> base cause of the error.
       *
       * @param e The exception to be encapsulated in a
       * JXPathException.
       */
      public JXPathException(Throwable e) {
          super(e.toString());
          this.exception = e;
      }
  
      /**
       * Create a new <code>JXPathException</code> with the
       * given <code>Exception</code> base cause and detail message.
       *
       * @param e The exception to be encapsulated in a
       * JXPathException
       * @param msg The detail message.
       */
      public JXPathException(String msg, Throwable e) {
          super(msg);
          this.exception = e;
      }
  
  
      /**
       * Return the message (if any) for this error . If there is no
       * message for the exception and there is an encapsulated
       * exception then the message of that exception will be returned.
       *
       * @return The error message.
       */
      public String getMessage () {
          String message = super.getMessage ();
  
          if (exception != null) {
              if (message == null){
                  if (exception.getMessage() != null){
                      return exception.getMessage();
                  }
                  else {
                      return exception.getClass().getName();
                  }
              }
              else {
                  if (exception.getMessage() != null){
                      return message + "; " + exception.getMessage();
                  }
                  else {
                      return message + "; " + exception.getClass().getName();
                  }
              }
          }
  
          return message;
      }
  
      /**
       * Return the actual exception (if any) that caused this exception to
       * be raised.
       *
       * @return The encapsulated exception, or null if there is none.
       */
      public Throwable getException () {
          return exception;
      }
  }
  
  
  1.4       +14 -11    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java
  
  Index: VariablePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- VariablePointer.java	26 Apr 2002 01:00:37 -0000	1.3
  +++ VariablePointer.java	26 Apr 2002 03:28:36 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 01:00:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/VariablePointer.java,v 1.4 2002/04/26 03:28:36 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:36 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -63,6 +63,7 @@
   
   import org.apache.commons.jxpath.AbstractFactory;
   import org.apache.commons.jxpath.JXPathContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.Variables;
   import org.apache.commons.jxpath.ri.QName;
   import org.apache.commons.jxpath.ri.compiler.NodeTest;
  @@ -72,7 +73,7 @@
    * Pointer to a context variable.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:36 $
    */
   public class VariablePointer extends NodePointer {
       private Variables variables;
  @@ -103,7 +104,7 @@
   
       public Object getBaseValue(){
           if (!actual){
  -            throw new RuntimeException("Undefined variable: " + name);
  +            throw new JXPathException("Undefined variable: " + name);
           }
           return variables.getVariable(name.getName());
       }
  @@ -118,7 +119,7 @@
   
       public void setValue(Object value){
           if (!actual){
  -            throw new RuntimeException("Cannot set undefined variable: " + name);
  +            throw new JXPathException("Cannot set undefined variable: " + name);
           }
           valuePointer = null;
           if (index != WHOLE_COLLECTION){
  @@ -164,7 +165,7 @@
           if (!actual){
               AbstractFactory factory = getAbstractFactory(context);
               if (!factory.declareVariable(context, name.toString())){
  -                throw new RuntimeException("Factory cannot define variable '" + name + "' for path: " + asPath());
  +                throw new JXPathException("Factory cannot define variable '" + name + "' for path: " + asPath());
               }
               findVariables(context);
               // Assert: actual == true
  @@ -178,7 +179,7 @@
               AbstractFactory factory = getAbstractFactory(context);
               // Ignore the name passed as a parameter, pass the name of the variable instead
               if (!factory.createObject(context, this, collection, getName().toString(), index)){
  -                throw new RuntimeException("Factory could not create object path: " + asPath());
  +                throw new JXPathException("Factory could not create object path: " + asPath());
               }
               setIndex(index);
           }
  @@ -197,14 +198,14 @@
   
           Object collection = getBaseValue();
           if (collection == null){
  -            throw new RuntimeException("Factory did not assign a collection to variable '" + name + "' for path: " + asPath());
  +            throw new JXPathException("Factory did not assign a collection to variable '" + name + "' for path: " + asPath());
           }
   
           if (index == WHOLE_COLLECTION){
               index = 0;
           }
           else if (index < 0){
  -            throw new RuntimeException("Index is less than 1: " + asPath());
  +            throw new JXPathException("Index is less than 1: " + asPath());
           }
   
           if (index >= getLength()){
  @@ -286,7 +287,9 @@
       private AbstractFactory getAbstractFactory(JXPathContext context){
           AbstractFactory factory = context.getFactory();
           if (factory == null){
  -            throw new RuntimeException("Factory is not set on the JXPathContext - cannot create path: " + asPath());
  +            throw new JXPathException(
  +              "Factory is not set on the JXPathContext - cannot create path: "
  +              + asPath());
           }
           return factory;
       }
  
  
  
  1.4       +15 -16    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java
  
  Index: NodePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NodePointer.java	26 Apr 2002 01:00:37 -0000	1.3
  +++ NodePointer.java	26 Apr 2002 03:28:36 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 01:00:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/NodePointer.java,v 1.4 2002/04/26 03:28:36 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:36 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -64,6 +64,7 @@
   import java.util.Locale;
   
   import org.apache.commons.jxpath.JXPathContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.JXPathIntrospector;
   import org.apache.commons.jxpath.Pointer;
   import org.apache.commons.jxpath.ri.Compiler;
  @@ -83,7 +84,7 @@
    * context-independent predicates.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:36 $
    */
   public abstract class NodePointer implements Pointer, Cloneable, Comparable {
   
  @@ -110,7 +111,7 @@
                   return pointer;
               }
           }
  -        throw new RuntimeException(
  +        throw new JXPathException(
               "Could not allocate a NodePointer for object of " + bean.getClass());
       }
   
  @@ -127,7 +128,7 @@
                   return pointer;
               }
           }
  -        throw new RuntimeException(
  +        throw new JXPathException(
               "Could not allocate a NodePointer for object of " + bean.getClass());
       }
   
  @@ -263,7 +264,7 @@
        * to a "canonical" type.
        */
       public abstract Object getNodeValue();
  -    
  +
       /**
        * Converts the value to the required type and changes the corresponding
        * object to that value.
  @@ -345,12 +346,9 @@
        * node. This method must may have to expand the collection in order to
        * assign the element.
        */
  -    public void createChild(
  -        JXPathContext context,
  -        QName name,
  -        int index,
  -        Object value) {
  -        throw new RuntimeException(
  +    public void createChild(JXPathContext context, QName name,
  +                            int index, Object value) {
  +        throw new JXPathException(
               "Cannot create an object for path "
                   + asPath()
                   + ", operation is not allowed for this type of node");
  @@ -363,7 +361,7 @@
        * newly created element.
        */
       public NodePointer createChild(JXPathContext context, QName name, int index) {
  -        throw new RuntimeException(
  +        throw new JXPathException(
               "Cannot create an object for path "
                   + asPath()
                   + ", operation is not allowed for this type of node");
  @@ -568,8 +566,9 @@
           }
   
           if (depth1 == 1){
  -            throw new RuntimeException(
  -                "Cannot compare pointers that do not belong to the same tree");
  +            throw new JXPathException(
  +                "Cannot compare pointers that do not belong to the same tree: '"
  +                + p1 + "' and '" + p2 + "'");
           }
           int r = compareNodePointers(p1.parent, depth1 - 1, p2.parent, depth2 - 1);
           if (r != 0){
  
  
  
  1.3       +19 -17    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/ValueUtils.java
  
  Index: ValueUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/ValueUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ValueUtils.java	24 Apr 2002 04:05:39 -0000	1.2
  +++ ValueUtils.java	26 Apr 2002 03:28:37 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/ValueUtils.java,v 1.2 2002/04/24 04:05:39 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/04/24 04:05:39 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/ValueUtils.java,v 1.3 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -66,11 +66,12 @@
   import java.lang.reflect.*;
   import java.util.*;
   
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.DynamicPropertyHandler;
   
   /**
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:39 $
  + * @version $Revision: 1.3 $ $Date: 2002/04/26 03:28:37 $
    */
   public class ValueUtils {
       private static Map dynamicPropertyHandlerMap = new HashMap();
  @@ -132,7 +133,7 @@
               return collection;
           }
           else {
  -            throw new RuntimeException("Cannot turn " + collection.getClass().getName() +
  +            throw new JXPathException("Cannot turn " + collection.getClass().getName() +
                       " into a collection of size " + size);
           }
       }
  @@ -148,8 +149,9 @@
                   }
               }
               catch (Exception ex){
  -                throw new RuntimeException("Cannot access property: " + propertyDescriptor.getName() +
  -                    ", " + ex.getMessage());
  +                throw new JXPathException(
  +                    "Cannot access property: " + propertyDescriptor.getName(),
  +                    ex);
               }
           }
           // We will fall through if there is no indexed read
  @@ -230,14 +232,13 @@
           try {
               Method method = getAccessibleMethod(propertyDescriptor.getReadMethod());
               if (method == null){
  -                throw new RuntimeException("No read method");
  +                throw new JXPathException("No read method");
               }
               value = method.invoke(bean, new Object[0]);
           }
           catch (Exception ex){
  -            ex.printStackTrace();
  -            throw new RuntimeException("Cannot access property: " + propertyDescriptor.getName() +
  -                ", " + ex.getMessage());
  +            throw new JXPathException(
  +                "Cannot access property: " + propertyDescriptor.getName(), ex);
           }
           return value;
       }
  @@ -246,20 +247,20 @@
           try {
               Method method = getAccessibleMethod(propertyDescriptor.getWriteMethod());
               if (method == null){
  -                throw new RuntimeException("No write method");
  +                throw new JXPathException("No write method");
               }
               value = convert(value, propertyDescriptor.getPropertyType());
               value = method.invoke(bean, new Object[]{value});
           }
           catch (Exception ex){
  -            throw new RuntimeException("Cannot modify property: " + propertyDescriptor.getName() +
  -                ", " + ex);
  +            throw new JXPathException(
  +                "Cannot modify property: " + propertyDescriptor.getName(), ex);
           }
       }
   
       private static Object convert(Object value, Class type){
           if (!TypeUtils.canConvert(value, type)){
  -            throw new RuntimeException("Cannot convert value of class " +
  +            throw new JXPathException("Cannot convert value of class " +
                       (value == null ? "null" : value.getClass().getName()) +
                       " to type " + type);
           }
  @@ -277,8 +278,9 @@
                   handler = (DynamicPropertyHandler)clazz.newInstance();
               }
               catch (Exception ex){
  -                throw new RuntimeException("Cannot allocate dynamic property handler " +
  -                    " of class " + clazz + ".\n" + ex);
  +                throw new JXPathException(
  +                    "Cannot allocate dynamic property handler of class "
  +                    + clazz.getName(), ex);
               }
               dynamicPropertyHandlerMap.put(clazz, handler);
           }
  
  
  
  1.4       +8 -7      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/TypeUtils.java
  
  Index: TypeUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/TypeUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TypeUtils.java	26 Apr 2002 00:57:11 -0000	1.3
  +++ TypeUtils.java	26 Apr 2002 03:28:37 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/TypeUtils.java,v 1.3 2002/04/26 00:57:11 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 00:57:11 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/util/TypeUtils.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -65,11 +65,12 @@
   import java.util.*;
   
   import org.apache.commons.jxpath.ExpressionContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.Pointer;
   
   /**
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 00:57:11 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
    */
   public class TypeUtils {
   
  @@ -126,7 +127,7 @@
               }
           }
           if (ambiguous){
  -            throw new RuntimeException("Ambigous constructor " + Arrays.asList(parameters));
  +            throw new JXPathException("Ambigous constructor " + Arrays.asList(parameters));
           }
           return constructor;
       }
  @@ -182,7 +183,7 @@
               }
           }
           if (ambiguous){
  -            throw new RuntimeException("Ambigous method call: " + name);
  +            throw new JXPathException("Ambigous method call: " + name);
           }
           return method;
       }
  @@ -250,7 +251,7 @@
               }
           }
           if (ambiguous){
  -            throw new RuntimeException("Ambigous method call: " + name);
  +            throw new JXPathException("Ambigous method call: " + name);
           }
           return method;
       }
  
  
  
  1.2       +20 -4     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/parser/TokenMgrError.java
  
  Index: TokenMgrError.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/parser/TokenMgrError.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TokenMgrError.java	23 Aug 2001 00:47:00 -0000	1.1
  +++ TokenMgrError.java	26 Apr 2002 03:28:37 -0000	1.2
  @@ -1,8 +1,12 @@
  -/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
  +/* Generated By:JavaCC: Do not edit this line. MODIFIED BY DMITRI PLOTNIKOV - DO NOT REGENERATE */
   package org.apache.commons.jxpath.ri.parser;
   
   public class TokenMgrError extends Error
   {
  +    private int position;
  +    private char character;
  +
  +
      /*
       * Ordinals for various reasons why an Error of this type can be thrown.
       */
  @@ -37,7 +41,7 @@
       * Replaces unprintable characters by their espaced (or unicode escaped)
       * equivalents in the given string
       */
  -   protected static final String addEscapes(String str) {
  +   public static final String addEscapes(String str) {
         StringBuffer retval = new StringBuffer();
         char ch;
         for (int i = 0; i < str.length(); i++) {
  @@ -85,7 +89,7 @@
      /**
       * Returns a detailed message for the Error when it is thrown by the
       * token manager to indicate a lexical error.
  -    * Parameters : 
  +    * Parameters :
       *    EOFSeen     : indicates if EOF caused the lexicl error
       *    curLexState : lexical state in which this error occured
       *    errorLine   : line number when the error occured
  @@ -105,7 +109,7 @@
      /**
       * You can also modify the body of this method to customize your error messages.
       * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
  -    * of end-users concern, so you can return something like : 
  +    * of end-users concern, so you can return something like :
       *
       *     "Internal Error : Please file a bug report .... "
       *
  @@ -129,5 +133,17 @@
   
      public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
         this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
  +      position = errorColumn - 1;
  +      character = curChar;
  +   }
  +
  +
  +   // ADDED BY ME - DMITRI PLOTNIKOV
  +   public int getPosition(){
  +    return position;
  +   }
  +
  +   public char getCharacter(){
  +    return character;
      }
   }
  
  
  
  1.2       +1 -1      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java
  
  Index: SimplePathInterpreter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/SimplePathInterpreter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimplePathInterpreter.java	26 Apr 2002 01:00:37 -0000	1.1
  +++ SimplePathInterpreter.java	26 Apr 2002 03:28:37 -0000	1.2
  @@ -277,7 +277,7 @@
               value = ((NodePointer)value).getValue();
           }
           if (value == null){
  -            throw new RuntimeException("Predicate is null: " + value);
  +            throw new JXPathException("Predicate is null: " + value);
           }
   
           if (value instanceof Number){
  
  
  
  1.3       +6 -5      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyIterator.java
  
  Index: PropertyIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyIterator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PropertyIterator.java	24 Apr 2002 04:05:40 -0000	1.2
  +++ PropertyIterator.java	26 Apr 2002 03:28:37 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyIterator.java,v 1.2 2002/04/24 04:05:40 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/04/24 04:05:40 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/PropertyIterator.java,v 1.3 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -61,6 +61,7 @@
    */
   package org.apache.commons.jxpath.ri.model.beans;
   
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.ri.model.NodeIterator;
   import org.apache.commons.jxpath.ri.model.NodePointer;
   
  @@ -69,7 +70,7 @@
    * Examples of such objects are JavaBeans and objects with Dynamic Properties.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2002/04/24 04:05:40 $
  + * @version $Revision: 1.3 $ $Date: 2002/04/26 03:28:37 $
    */
   public class PropertyIterator implements NodeIterator {
       private boolean empty = false;
  @@ -98,7 +99,7 @@
                   startWith = startWith.getParent();
               }
               if (startWith == null){
  -                throw new RuntimeException(
  +                throw new JXPathException(
                       "PropertyIerator startWith parameter is not a child of the supplied parent");
               }
               this.startPropertyIndex = ((PropertyPointer)startWith).getPropertyIndex();
  
  
  
  1.4       +6 -5      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java
  
  Index: NullPropertyPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NullPropertyPointer.java	26 Apr 2002 01:00:37 -0000	1.3
  +++ NullPropertyPointer.java	26 Apr 2002 03:28:37 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 01:00:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullPropertyPointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -62,12 +62,13 @@
   package org.apache.commons.jxpath.ri.model.beans;
   
   import org.apache.commons.jxpath.JXPathContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.ri.QName;
   import org.apache.commons.jxpath.ri.model.NodePointer;
   
   /**
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
    */
   public class NullPropertyPointer extends PropertyPointer {
   
  @@ -116,7 +117,7 @@
       }
   
       public void setValue(Object value){
  -        throw new RuntimeException("Cannot set property " + asPath() +
  +        throw new JXPathException("Cannot set property " + asPath() +
               ", the target object is null");
       }
   
  
  
  
  1.4       +7 -6      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java
  
  Index: NullElementPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NullElementPointer.java	26 Apr 2002 01:00:37 -0000	1.3
  +++ NullElementPointer.java	26 Apr 2002 03:28:37 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 01:00:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/NullElementPointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -62,6 +62,7 @@
   package org.apache.commons.jxpath.ri.model.beans;
   
   import org.apache.commons.jxpath.JXPathContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.ri.QName;
   import org.apache.commons.jxpath.ri.model.NodePointer;
   
  @@ -76,7 +77,7 @@
    * as the parent.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
    */
   public class NullElementPointer extends PropertyOwnerPointer {
   
  @@ -142,7 +143,7 @@
   
       public void createChild(JXPathContext context, QName name, int index, Object value){
           if (index != 0 && index != WHOLE_COLLECTION){
  -            throw new RuntimeException("Internal error. " +
  +            throw new JXPathException("Internal error. " +
                   "Indexed passed to NullElementPointer.createChild() is not 0: " + index);
           }
           if (parent instanceof PropertyPointer){
  @@ -155,7 +156,7 @@
   
       public NodePointer createChild(JXPathContext context, QName name, int index){
           if (index != 0 && index != WHOLE_COLLECTION){
  -            throw new RuntimeException("Internal error. " +
  +            throw new JXPathException("Internal error. " +
                   "Indexed passed to NullElementPointer.createChild() is not 0: " + index);
           }
           if (parent instanceof PropertyPointer){
  
  
  
  1.4       +11 -10    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java
  
  Index: DynamicPropertyPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DynamicPropertyPointer.java	26 Apr 2002 01:00:37 -0000	1.3
  +++ DynamicPropertyPointer.java	26 Apr 2002 03:28:37 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 01:00:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/DynamicPropertyPointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -66,6 +66,7 @@
   import org.apache.commons.jxpath.AbstractFactory;
   import org.apache.commons.jxpath.DynamicPropertyHandler;
   import org.apache.commons.jxpath.JXPathContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.ri.QName;
   import org.apache.commons.jxpath.ri.model.NodePointer;
   import org.apache.commons.jxpath.util.ValueUtils;
  @@ -74,7 +75,7 @@
    * Pointer pointing to a property of an object with dynamic properties.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
    */
   public class DynamicPropertyPointer extends PropertyPointer {
       private DynamicPropertyHandler handler;
  @@ -256,13 +257,13 @@
               if (collection == null){
                   AbstractFactory factory = getAbstractFactory(context);
                   if (!factory.createObject(context, this, getBean(), getPropertyName(), 0)){
  -                    throw new RuntimeException("Factory could not create an object for path: " + asPath());
  +                    throw new JXPathException("Factory could not create an object for path: " + asPath());
                   }
                   collection = getBaseValue();
               }
   
               if (index < 0){
  -                throw new RuntimeException("Index is less than 1: " + asPath());
  +                throw new JXPathException("Index is less than 1: " + asPath());
               }
   
               if (index >= getLength()){
  @@ -280,13 +281,13 @@
           if (collection == null){
               AbstractFactory factory = getAbstractFactory(context);
               if (!factory.createObject(context, this, getBean(), getPropertyName(), 0)){
  -                throw new RuntimeException("Factory could not create an object for path: " + asPath());
  +                throw new JXPathException("Factory could not create an object for path: " + asPath());
               }
               collection = getBaseValue();
           }
   
           if (index < 0){
  -            throw new RuntimeException("Index is less than 1: " + asPath());
  +            throw new JXPathException("Index is less than 1: " + asPath());
           }
   
           if (index >= getLength()){
  @@ -304,7 +305,7 @@
               AbstractFactory factory = getAbstractFactory(context);
               int inx = (index == WHOLE_COLLECTION ? 0 : index);
               if (!factory.createObject(context, this, getBean(), getPropertyName(), inx)){
  -                throw new RuntimeException("Factory could not create an object for path: " + asPath());
  +                throw new JXPathException("Factory could not create an object for path: " + asPath());
               }
           }
           return this;
  @@ -339,7 +340,7 @@
       private AbstractFactory getAbstractFactory(JXPathContext context){
           AbstractFactory factory = context.getFactory();
           if (factory == null){
  -            throw new RuntimeException("Factory is not set on the JXPathContext - cannot create path: " + asPath());
  +            throw new JXPathException("Factory is not set on the JXPathContext - cannot create path: " + asPath());
           }
           return factory;
       }
  
  
  
  1.4       +11 -10    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java
  
  Index: BeanPropertyPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BeanPropertyPointer.java	26 Apr 2002 01:00:37 -0000	1.3
  +++ BeanPropertyPointer.java	26 Apr 2002 03:28:37 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v 1.3 2002/04/26 01:00:37 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 01:00:37 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/beans/BeanPropertyPointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -66,6 +66,7 @@
   import org.apache.commons.jxpath.AbstractFactory;
   import org.apache.commons.jxpath.JXPathBeanInfo;
   import org.apache.commons.jxpath.JXPathContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.ri.QName;
   import org.apache.commons.jxpath.ri.model.NodePointer;
   import org.apache.commons.jxpath.util.ValueUtils;
  @@ -74,7 +75,7 @@
    * Pointer pointing to a property of a JavaBean.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:37 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
    */
   public class BeanPropertyPointer extends PropertyPointer {
       private String propertyName;
  @@ -205,7 +206,7 @@
       public void setValue(Object value){
           PropertyDescriptor pd = getPropertyDescriptor();
           if (pd == null){
  -            throw new RuntimeException("Cannot set property: " + asPath() + " - no such property");
  +            throw new JXPathException("Cannot set property: " + asPath() + " - no such property");
           }
   
           if (index == WHOLE_COLLECTION){
  @@ -222,7 +223,7 @@
               AbstractFactory factory = getAbstractFactory(context);
               int inx = (index == WHOLE_COLLECTION ? 0 : index);
               if (!factory.createObject(context, this, getBean(), getPropertyName(), inx)){
  -                throw new RuntimeException("Factory could not create an object for path: " + asPath());
  +                throw new JXPathException("Factory could not create an object for path: " + asPath());
               }
               baseValue = UNINITIALIZED;
               value = UNINITIALIZED;
  @@ -246,18 +247,18 @@
           // Ignore the name passed to us, use our own information
           PropertyDescriptor pd = getPropertyDescriptor();
           if (pd == null){
  -            throw new RuntimeException("Cannot create path: " + asPath() +
  +            throw new JXPathException("Cannot create path: " + asPath() +
                       " - property '" + getPropertyName() + "' does not exist");
           }
   
           if (index < 0){
  -            throw new RuntimeException("Index is less than 1: " + asPath());
  +            throw new JXPathException("Index is less than 1: " + asPath());
           }
   
           if (index >= getLength()){
               AbstractFactory factory = getAbstractFactory(context);
               if (!factory.createObject(context, this, getBean(), getPropertyName(), index)){
  -                throw new RuntimeException("Factory could not create path " + asPath());
  +                throw new JXPathException("Factory could not create path " + asPath());
               }
           }
           BeanPropertyPointer clone = (BeanPropertyPointer)this.clone();
  @@ -312,7 +313,7 @@
       private AbstractFactory getAbstractFactory(JXPathContext context){
           AbstractFactory factory = context.getFactory();
           if (factory == null){
  -            throw new RuntimeException("Factory is not set on the JXPathContext - cannot create path: " + asPath());
  +            throw new JXPathException("Factory is not set on the JXPathContext - cannot create path: " + asPath());
           }
           return factory;
       }
  
  
  
  1.4       +49 -19    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/Parser.java
  
  Index: Parser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/Parser.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Parser.java	24 Apr 2002 04:05:40 -0000	1.3
  +++ Parser.java	26 Apr 2002 03:28:37 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/Parser.java,v 1.3 2002/04/24 04:05:40 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/24 04:05:40 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/Parser.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -63,36 +63,66 @@
   
   import java.io.StringReader;
   
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.ri.parser.ParseException;
  +import org.apache.commons.jxpath.ri.parser.TokenMgrError;
   import org.apache.commons.jxpath.ri.parser.XPathParser;
   
   /**
    * XPath parser
  - * 
  + *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/24 04:05:40 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
    */
   public class Parser {
   
  -    private static XPathParser parser;
  +    private static XPathParser parser = new XPathParser(new StringReader(""));
   
  +    /**
  +     * Parses the XPath expression. Throws a JXPathException in case
  +     * of a syntax error.
  +     */
       public static Object parseExpression(String expression, Compiler compiler){
  -        if (parser == null){
  -            parser = new XPathParser(new StringReader(""));
  +        synchronized (parser){
  +            parser.setCompiler(compiler);
  +            Object expr = null;
  +            try {
  +                parser.ReInit(new StringReader(expression));
  +                expr = parser.parseExpression();
  +            }
  +            catch (TokenMgrError e) {
  +                throw new JXPathException("Invalid XPath: '"
  +                    + addEscapes(expression)
  +                    + "'. Invalid symbol '"
  +                    + addEscapes(String.valueOf(e.getCharacter()))
  +                    + "' "
  +                    + describePosition(expression, e.getPosition()));
  +            }
  +            catch (ParseException e) {
  +                throw new JXPathException("Invalid XPath: '"
  +                    + addEscapes(expression)
  +                    + "'. Syntax error "
  +                    + describePosition(expression, e.currentToken.beginColumn));
  +            }
  +            return expr;
           }
  +    }
   
  -        parser.setCompiler(compiler);
  -        parser.ReInit(new StringReader(expression));
  -
  -        Object expr = null;
  -        try {
  -            expr = parser.parseExpression();
  +    private static String describePosition(String expression, int position){
  +        if (position <= 0){
  +            return "at the beginning of the expression";
           }
  -        catch (ParseException e) {
  -//            System.err.println("Failed: " + expression );
  -//            e.printStackTrace();
  -            throw new RuntimeException(e.getMessage());
  +        else if (position >= expression.length()){
  +            return "- expression incomplete";
           }
  -        return expr;
  +        else {
  +            return "after: '"
  +                + addEscapes(expression.substring(0, position)) + "'";
  +        }
  +    }
  +
  +    private static String addEscapes(String string){
  +        // Piggy-back on the code generated by JavaCC
  +        return TokenMgrError.addEscapes(string);
       }
   }
  
  
  
  1.13      +26 -19    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
  
  Index: JXPathContextReferenceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JXPathContextReferenceImpl.java	26 Apr 2002 01:00:38 -0000	1.12
  +++ JXPathContextReferenceImpl.java	26 Apr 2002 03:28:37 -0000	1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v 1.12 2002/04/26 01:00:38 dmitri Exp $
  - * $Revision: 1.12 $
  - * $Date: 2002/04/26 01:00:38 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v 1.13 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.13 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -66,6 +66,7 @@
   import java.util.*;
   
   import org.apache.commons.jxpath.*;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.ri.axes.RootContext;
   import org.apache.commons.jxpath.ri.compiler.Expression;
   import org.apache.commons.jxpath.ri.compiler.TreeCompiler;
  @@ -80,14 +81,17 @@
   import org.apache.commons.jxpath.util.TypeUtils;
   
   /**
  + * The reference implementation of JXPathContext.
  + *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.12 $ $Date: 2002/04/26 01:00:38 $
  + * @version $Revision: 1.13 $ $Date: 2002/04/26 03:28:37 $
    */
   public class JXPathContextReferenceImpl extends JXPathContext
   {
       private static final Compiler compiler = new TreeCompiler();
       private static final Map compiled = new HashMap();
  -    private static final PackageFunctions genericFunctions = new PackageFunctions("", null);
  +    private static final PackageFunctions genericFunctions =
  +        new PackageFunctions("", null);
       private static boolean useSoftCache = true;
       private static int cleanupCount = 0;
       private static Vector nodeFactories = new Vector();
  @@ -105,7 +109,8 @@
       // The frequency of the cache cleanup
       private static final int CLEANUP_THRESHOLD = 500;
   
  -    protected JXPathContextReferenceImpl(JXPathContext parentContext, Object contextBean){
  +    protected JXPathContextReferenceImpl(JXPathContext parentContext,
  +                                         Object contextBean){
           super(parentContext, contextBean);
           synchronized (nodeFactories){
               createNodeFactoryArray();
  @@ -115,7 +120,8 @@
       private static void createNodeFactoryArray() {
           if (nodeFactoryArray == null) {
               nodeFactoryArray =
  -                (NodePointerFactory[]) nodeFactories.toArray(new NodePointerFactory[0]);
  +                (NodePointerFactory[]) nodeFactories.
  +                    toArray(new NodePointerFactory[0]);
               Arrays.sort(nodeFactoryArray, new Comparator() {
                   public int compare(Object a, Object b) {
                       int orderA = ((NodePointerFactory) a).getOrder();
  @@ -125,7 +131,6 @@
               });
           }
       }
  -
       /**
        * Call this with a custom NodePointerFactory to add support for
        * additional types of objects.  Make sure the factory returns
  @@ -191,7 +196,7 @@
   //        System.err.println("XPATH: " + xpath);
           Object result = eval(xpath, true);
           if (result == null && !lenient){
  -            throw new RuntimeException("No value for xpath: " + xpath);
  +            throw new JXPathException("No value for xpath: " + xpath);
           }
   
           if (result instanceof EvalContext){
  @@ -212,7 +217,7 @@
           Object value = getValue(xpath);
           if (value != null && requiredType != null){
               if (!TypeUtils.canConvert(value, requiredType)){
  -                throw new RuntimeException("Invalid expression type. '" + xpath +
  +                throw new JXPathException("Invalid expression type. '" + xpath +
                       "' returns " + value.getClass().getName() +
                       ". It cannot be converted to " + requiredType.getName());
               }
  @@ -262,8 +267,8 @@
               setValue(xpath, value, false);
           }
           catch (Throwable ex){
  -            throw new RuntimeException("Exception trying to set value with xpath " +
  -                    xpath + ". " + ex.getMessage());
  +            throw new JXPathException(
  +                "Exception trying to set value with xpath " + xpath, ex);
           }
       }
   
  @@ -275,9 +280,8 @@
               setValue(xpath, value, true);
           }
           catch (Throwable ex){
  -            ex.printStackTrace();
  -            throw new RuntimeException("Exception trying to create xpath " +
  -                    xpath + ". " + ex.getMessage());
  +            throw new JXPathException(
  +                "Exception trying to create xpath " + xpath, ex);
           }
       }
   
  @@ -295,7 +299,7 @@
           }
           else {
               // This should never happen
  -            throw new RuntimeException("Cannot set value for xpath: " + xpath);
  +            throw new JXPathException("Cannot set value for xpath: " + xpath);
           }
           if (create){
               ((NodePointer)pointer).createPath(this, value);
  @@ -314,7 +318,8 @@
               return Collections.singletonList((Pointer)result);
           }
           else {
  -            return Collections.singletonList(NodePointer.newNodePointer(null, result, getLocale()));
  +            return Collections.singletonList(
  +                    NodePointer.newNodePointer(null, result, getLocale()));
           }
       }
   
  @@ -326,7 +331,8 @@
       private void printPointer(NodePointer pointer){
           Pointer p = pointer;
           while (p != null){
  -            System.err.println((p == pointer ? "POINTER: " : " PARENT: ") + p.getClass() + " " + p.asPath());
  +            System.err.println((p == pointer ? "POINTER: " : " PARENT: ")
  +                + p.getClass() + " " + p.asPath());
               if (p instanceof NodePointer){
                   p = ((NodePointer)p).getParent();
               }
  @@ -401,6 +407,7 @@
           if (func != null){
               return func;
           }
  -        throw new RuntimeException("Undefined function: " + functionName.toString());
  +        throw new JXPathException(
  +            "Undefined function: " + functionName.toString());
       }
   }
  
  
  
  1.12      +10 -8     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java
  
  Index: EvalContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- EvalContext.java	26 Apr 2002 01:00:38 -0000	1.11
  +++ EvalContext.java	26 Apr 2002 03:28:37 -0000	1.12
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v 1.11 2002/04/26 01:00:38 dmitri Exp $
  - * $Revision: 1.11 $
  - * $Date: 2002/04/26 01:00:38 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v 1.12 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.12 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -78,7 +78,7 @@
    * implement behavior of various XPath axes: "child::", "parent::" etc.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.11 $ $Date: 2002/04/26 01:00:38 $
  + * @version $Revision: 1.12 $ $Date: 2002/04/26 03:28:37 $
    */
   public abstract class EvalContext implements ExpressionContext {
       protected EvalContext parentContext;
  @@ -145,7 +145,7 @@
           }
           return list;
       }
  -    
  +
       /**
        * Returns the list of all node values in this context
        */
  @@ -892,7 +892,7 @@
           }
           Function function = getRootContext().getFunction(functionName, parameters);
           if (function == null){
  -            throw new RuntimeException("No such function: " + functionName +
  +            throw new JXPathException("No such function: " + functionName +
                    Arrays.asList(parameters));
           }
   
  @@ -1265,7 +1265,8 @@
               }
               return new Double(sum);
           }
  -        throw new RuntimeException("Invalid argument type for 'sum': " + v.getClass().getName());
  +        throw new JXPathException("Invalid argument type for 'sum': "
  +            + v.getClass().getName());
       }
   
       protected Object functionFloor(CoreFunction function){
  @@ -1288,7 +1289,8 @@
   
       private void assertArgCount(CoreFunction function, int count){
           if (function.getArgumentCount() != count){
  -            throw new RuntimeException("Incorrect number of argument: " + function);
  +            throw new JXPathException("Incorrect number of argument: "
  +                + function);
           }
       }
   }
  
  
  
  1.5       +6 -7      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/functions/MethodFunction.java
  
  Index: MethodFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/functions/MethodFunction.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MethodFunction.java	24 Apr 2002 04:05:41 -0000	1.4
  +++ MethodFunction.java	26 Apr 2002 03:28:37 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/functions/MethodFunction.java,v 1.4 2002/04/24 04:05:41 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/24 04:05:41 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/functions/MethodFunction.java,v 1.5 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -66,11 +66,12 @@
   
   import org.apache.commons.jxpath.ExpressionContext;
   import org.apache.commons.jxpath.Function;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.util.TypeUtils;
   
   /**
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/24 04:05:41 $
  + * @version $Revision: 1.5 $ $Date: 2002/04/26 03:28:37 $
    */
   public class MethodFunction implements Function {
   
  @@ -122,9 +123,7 @@
               return method.invoke(target, args);
           }
           catch (Exception exception){
  -            exception.printStackTrace();
  -            // TBD
  -            throw new RuntimeException("Cannot invoke " + method + ": " + exception);
  +            throw new JXPathException("Cannot invoke " + method, exception);
           }
       }
   }
  
  
  
  1.5       +6 -7      jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/functions/ConstructorFunction.java
  
  Index: ConstructorFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/functions/ConstructorFunction.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConstructorFunction.java	24 Apr 2002 04:05:41 -0000	1.4
  +++ ConstructorFunction.java	26 Apr 2002 03:28:37 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/functions/ConstructorFunction.java,v 1.4 2002/04/24 04:05:41 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/24 04:05:41 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/functions/ConstructorFunction.java,v 1.5 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -65,13 +65,14 @@
   
   import org.apache.commons.jxpath.ExpressionContext;
   import org.apache.commons.jxpath.Function;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.util.TypeUtils;
   
   /**
    * An extension function that creates an instance using a constructor.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2002/04/24 04:05:41 $
  + * @version $Revision: 1.5 $ $Date: 2002/04/26 03:28:37 $
    */
   public class ConstructorFunction implements Function {
   
  @@ -106,9 +107,7 @@
               return constructor.newInstance(args);
           }
           catch (Exception exception){
  -            // TBD
  -            exception.printStackTrace();
  -            throw new RuntimeException("Cannot invoke constructor " + constructor + ": " + exception);
  +            throw new JXPathException("Cannot invoke constructor " + constructor, exception);
           }
       }
   }
  
  
  
  1.14      +15 -21    jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java
  
  Index: JXPathTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- JXPathTestCase.java	26 Apr 2002 01:00:38 -0000	1.13
  +++ JXPathTestCase.java	26 Apr 2002 03:28:37 -0000	1.14
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v 1.13 2002/04/26 01:00:38 dmitri Exp $
  - * $Revision: 1.13 $
  - * $Date: 2002/04/26 01:00:38 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v 1.14 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.14 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -99,7 +99,7 @@
    * </p>
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.13 $ $Date: 2002/04/26 01:00:38 $
  + * @version $Revision: 1.14 $ $Date: 2002/04/26 03:28:37 $
    */
   
   public class JXPathTestCase extends TestCase
  @@ -1066,28 +1066,22 @@
           return list;
       }
   
  -    public void testDOM(){
  +    public void testDOM() throws Exception {
           if (!enabled){
               return;
           }
           System.setProperty(JXPathContextFactory.FACTORY_NAME_PROPERTY,
                   "org.apache.commons.jxpath.ri.JXPathContextFactoryReferenceImpl");
  -        try {
  -            XMLDocumentContainer docCtr = new XMLDocumentContainer(getClass().getResource("Vendor.xml"));
  -            Document doc = (Document)docCtr.getValue();
  -            JXPathContext ctx = JXPathContextFactory.newInstance().newContext(null, doc);
  -            ctx.setLocale(Locale.US);
  -            ctx.getVariables().declareVariable("dom", doc);
  -            ctx.getVariables().declareVariable("object", docCtr);
  -            ctx.getVariables().declareVariable("null", null);
  -            TestBeanWithDOM tbwdom = createTestBeanWithDOM();
  -            ctx.getVariables().declareVariable("test", tbwdom);
  -            testXPaths(ctx, dom_tests, false);
  -        }
  -        catch (Exception ex){
  -            ex.printStackTrace();
  -            throw new RuntimeException("Test failed");
  -        }
  +        XMLDocumentContainer docCtr = new XMLDocumentContainer(getClass().getResource("Vendor.xml"));
  +        Document doc = (Document)docCtr.getValue();
  +        JXPathContext ctx = JXPathContextFactory.newInstance().newContext(null, doc);
  +        ctx.setLocale(Locale.US);
  +        ctx.getVariables().declareVariable("dom", doc);
  +        ctx.getVariables().declareVariable("object", docCtr);
  +        ctx.getVariables().declareVariable("null", null);
  +        TestBeanWithDOM tbwdom = createTestBeanWithDOM();
  +        ctx.getVariables().declareVariable("test", tbwdom);
  +        testXPaths(ctx, dom_tests, false);
       }
   
       private TestBeanWithDOM createTestBeanWithDOM(){
  
  
  
  1.4       +11 -10    jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
  
  Index: DOMNodePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DOMNodePointer.java	26 Apr 2002 01:00:38 -0000	1.3
  +++ DOMNodePointer.java	26 Apr 2002 03:28:37 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v 1.3 2002/04/26 01:00:38 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/04/26 01:00:38 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java,v 1.4 2002/04/26 03:28:37 dmitri Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/04/26 03:28:37 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -67,6 +67,7 @@
   
   import org.apache.commons.jxpath.AbstractFactory;
   import org.apache.commons.jxpath.JXPathContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.ri.Compiler;
   import org.apache.commons.jxpath.ri.QName;
   import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
  @@ -87,7 +88,7 @@
    * A Pointer that points to a DOM node.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2002/04/26 01:00:38 $
  + * @version $Revision: 1.4 $ $Date: 2002/04/26 03:28:37 $
    */
   public class DOMNodePointer extends NodePointer {
       private Node node;
  @@ -371,12 +372,12 @@
               index = 0;
           }
           if (!getAbstractFactory(context).createObject(context, this, node, name.toString(), index)){
  -            throw new RuntimeException("Factory could not create a child node for path: " +
  +            throw new JXPathException("Factory could not create a child node for path: " +
                       asPath() + "/" + name + "[" + (index+1) + "]");
           }
           NodeIterator it = childIterator(new NodeNameTest(name), false, null);
           if (it == null || !it.setPosition(index + 1)){
  -            throw new RuntimeException("Factory could not create a child node for path: " +
  +            throw new JXPathException("Factory could not create a child node for path: " +
                       asPath() + "/" + name + "[" + (index+1) + "]");
           }
           return it.getNodePointer();
  @@ -543,18 +544,18 @@
       private AbstractFactory getAbstractFactory(JXPathContext context){
           AbstractFactory factory = context.getFactory();
           if (factory == null){
  -            throw new RuntimeException("Factory is not set on the JXPathContext - cannot create path: " + asPath());
  +            throw new JXPathException("Factory is not set on the JXPathContext - cannot create path: " + asPath());
           }
           return factory;
       }
  -    
  +
       public int compareChildNodePointers(NodePointer pointer1, NodePointer pointer2){
           Node node1 = (Node)pointer1.getNodeValue();
           Node node2 = (Node)pointer2.getNodeValue();
           if (node1 == node2){
               return 0;
           }
  -        
  +
           Node current = node.getFirstChild();
           while (current != null){
               if (current == node1){
  @@ -567,5 +568,5 @@
           }
   
           return 0;
  -    }    
  +    }
   }
  
  
  

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