You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mi...@apache.org on 2004/11/12 22:34:16 UTC

cvs commit: xml-xalan/java/src/org/apache/xpath/compiler Lexer.java XPathParser.java

minchau     2004/11/12 13:34:16

  Modified:    java/src/org/apache/xpath/domapi XPathNamespaceImpl.java
                        XPathNSResolverImpl.java XPathEvaluatorImpl.java
                        XPathExpressionImpl.java XPathResultImpl.java
               java/src/org/w3c/dom/xpath XPathException.java
               java/src/org/apache/xpath/res XPATHErrorResources.java
               java/src/org/apache/xpath/compiler Lexer.java
                        XPathParser.java
  Added:       java/src/org/apache/xpath/domapi
                        XPathStylesheetDOM3Exception.java
  Log:
  PR: bug XALANJ-1985
  Submitted by:	Yash Talwar
  Reviewed by:	Brian Minchau
  
  Support for DOM 3 API, for use by an XML Parser.
  
  Revision  Changes    Path
  1.7       +5 -5      xml-xalan/java/src/org/apache/xpath/domapi/XPathNamespaceImpl.java
  
  Index: XPathNamespaceImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/domapi/XPathNamespaceImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XPathNamespaceImpl.java	17 Feb 2004 04:33:24 -0000	1.6
  +++ XPathNamespaceImpl.java	12 Nov 2004 21:34:16 -0000	1.7
  @@ -60,22 +60,22 @@
    * future versions of the XPath specification, the definition of a namespace 
    * node may be changed incomatibly, in which case incompatible changes to 
    * field values may be required to implement versions beyond XPath 1.0.
  - * <p>See also the <a href='http://www.w3.org/2002/08/WD-DOM-Level-3-XPath-20020820'>Document Object Model (DOM) Level 3 XPath Specification</a>.
  + * <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.
    * 
    * This implementation wraps the DOM attribute node that contained the 
    * namespace declaration.
  - * @xsl.usage experimental
  + * @xsl.usage internal
    */
   
  -public class XPathNamespaceImpl implements XPathNamespace {
  +class XPathNamespaceImpl implements XPathNamespace {
   
       // Node that XPathNamespaceImpl wraps
  -    Node m_attributeNode = null;
  +    final private Node m_attributeNode;
       
       /**
        * Constructor for XPathNamespaceImpl.
        */
  -    public XPathNamespaceImpl(Node node) {
  +    XPathNamespaceImpl(Node node) {
           m_attributeNode = node;
       }
   
  
  
  
  1.7       +2 -2      xml-xalan/java/src/org/apache/xpath/domapi/XPathNSResolverImpl.java
  
  Index: XPathNSResolverImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/domapi/XPathNSResolverImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XPathNSResolverImpl.java	17 Feb 2004 04:33:24 -0000	1.6
  +++ XPathNSResolverImpl.java	12 Nov 2004 21:34:16 -0000	1.7
  @@ -37,9 +37,9 @@
    * <p>See also the <a href='http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020328'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
    * 
    * @see org.w3c.dom.xpath.XPathNSResolver
  - * @xsl.usage experimental
  + * @xsl.usage internal
    */
  -public class XPathNSResolverImpl extends PrefixResolverDefault implements XPathNSResolver {
  +class XPathNSResolverImpl extends PrefixResolverDefault implements XPathNSResolver {
   
   	/**
   	 * Constructor for XPathNSResolverImpl.
  
  
  
  1.8       +26 -19    xml-xalan/java/src/org/apache/xpath/domapi/XPathEvaluatorImpl.java
  
  Index: XPathEvaluatorImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/domapi/XPathEvaluatorImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XPathEvaluatorImpl.java	17 Feb 2004 04:33:24 -0000	1.7
  +++ XPathEvaluatorImpl.java	12 Nov 2004 21:34:16 -0000	1.8
  @@ -21,11 +21,10 @@
   
   import javax.xml.transform.TransformerException;
   
  -import org.apache.xalan.res.XSLMessages;
   import org.apache.xml.utils.PrefixResolver;
   import org.apache.xpath.XPath;
   import org.apache.xpath.res.XPATHErrorResources;
  -
  +import org.apache.xpath.res.XPATHMessages;
   import org.w3c.dom.DOMException;
   import org.w3c.dom.Document;
   import org.w3c.dom.Node;
  @@ -39,7 +38,7 @@
    * The class provides an implementation of XPathEvaluator according 
    * to the DOM L3 XPath Specification, Working Draft 28, March 2002.
    *
  - * <p>See also the <a href='http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020328'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
  + * <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
    * 
    * </p>The evaluation of XPath expressions is provided by 
    * <code>XPathEvaluator</code>, which will provide evaluation of XPath 1.0 
  @@ -53,9 +52,9 @@
    * 
    * @see org.w3c.dom.xpath.XPathEvaluator
    * 
  - * @xsl.usage experimental
  + * @xsl.usage internal
    */
  -public class XPathEvaluatorImpl implements XPathEvaluator {
  +public final class XPathEvaluatorImpl implements XPathEvaluator {
   
   	/**
   	 * This prefix resolver is created whenever null is passed to the 
  @@ -63,12 +62,12 @@
   	 * requirement that if a null prefix resolver is used, an exception 
   	 * should only be thrown when an attempt is made to resolve a prefix.
   	 */
  -	class DummyPrefixResolver implements PrefixResolver {
  +	private class DummyPrefixResolver implements PrefixResolver {
   
   		/**
   		 * Constructor for DummyPrefixResolver.
   		 */
  -		public DummyPrefixResolver() {}
  +		DummyPrefixResolver() {}
   			
   		/**
   		 * @exception DOMException
  @@ -77,7 +76,7 @@
   		 * @see org.apache.xml.utils.PrefixResolver#getNamespaceForPrefix(String, Node)
   		 */
   		public String getNamespaceForPrefix(String prefix, Node context) {
  -            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_RESOLVER, null);       
  +            String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_RESOLVER, null);       
               throw new DOMException(DOMException.NAMESPACE_ERR, fmsg);   // Unable to resolve prefix with null prefix resolver.         
   		}
   
  @@ -111,16 +110,9 @@
        * The document to be searched to parallel the case where the XPathEvaluator
        * is obtained by casting a Document.
        */  
  -    private Document m_doc = null;
  -    
  -	/**
  -	 * Constructor for XPathEvaluatorImpl.
  -	 */
  -	public XPathEvaluatorImpl() {
  -		super();
  -	}
  +    private final Document m_doc;
       
  -     /**
  +    /**
        * Constructor for XPathEvaluatorImpl.
        * 
        * @param doc The document to be searched, to parallel the case where''
  @@ -129,6 +121,15 @@
       public XPathEvaluatorImpl(Document doc) {
           m_doc = doc;
       }
  +    
  +    /**
  +     * Constructor in the case that the XPath expression can be evaluated
  +     * without needing an XML document at all.
  +     *
  +     */
  +    public XPathEvaluatorImpl() {
  +            m_doc = null;
  +    }
   
   	/**
        * Creates a parsed XPath expression with resolved namespaces. This is 
  @@ -167,9 +168,15 @@
   			      XPath.SELECT);
                     
               return new XPathExpressionImpl(xpath, m_doc);
  -			      
  +			
   		} catch (TransformerException e) {
  -			throw new DOMException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());
  +			// Need to pass back exception code DOMException.NAMESPACE_ERR also.
  +			// Error found in DOM Level 3 XPath Test Suite.
  +			if(e instanceof XPathStylesheetDOM3Exception)
  +				throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
  +			else
  +				throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());
  +				
   		}
   	}
   
  
  
  
  1.8       +13 -15    xml-xalan/java/src/org/apache/xpath/domapi/XPathExpressionImpl.java
  
  Index: XPathExpressionImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/domapi/XPathExpressionImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XPathExpressionImpl.java	17 Feb 2004 04:33:24 -0000	1.7
  +++ XPathExpressionImpl.java	12 Nov 2004 21:34:16 -0000	1.8
  @@ -22,13 +22,11 @@
   
   import javax.xml.transform.TransformerException;
   
  -import org.apache.xalan.res.XSLMessages;
  -import org.apache.xml.utils.PrefixResolver;
   import org.apache.xpath.XPath;
   import org.apache.xpath.XPathContext;
   import org.apache.xpath.objects.XObject;
   import org.apache.xpath.res.XPATHErrorResources;
  -
  +import org.apache.xpath.res.XPATHMessages;
   import org.w3c.dom.DOMException;
   import org.w3c.dom.Document;
   import org.w3c.dom.Node;
  @@ -41,27 +39,27 @@
    * The class provides an implementation of XPathExpression according 
    * to the DOM L3 XPath Specification, Working Draft 28, March 2002.
    *
  - * <p>See also the <a href='http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020328'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
  + * <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
   
    * <p>The <code>XPathExpression</code> interface represents a parsed and resolved 
    * XPath expression.</p>
    * 
    * @see org.w3c.dom.xpath.XPathExpression
  + *  
  + * @xsl.usage internal
    */
  -public class XPathExpressionImpl implements XPathExpression {
  +class XPathExpressionImpl implements XPathExpression {
   
  -  private PrefixResolver m_resolver;      
  -  
     /**
      * The xpath object that this expression wraps
      */
  -  private XPath m_xpath;
  +  final private XPath m_xpath;
     
     /**
      * The document to be searched to parallel the case where the XPathEvaluator
      * is obtained by casting a Document.
      */  
  -  private Document m_doc = null;  
  +  final private Document m_doc;  
   
       /**
        * Constructor for XPathExpressionImpl.
  @@ -117,7 +115,7 @@
        *   context node.   
        * 
        * @see org.w3c.dom.xpath.XPathExpression#evaluate(Node, short, XPathResult)
  -     * @xsl.usage experimental
  +     * @xsl.usage internal
        */
       public Object evaluate(
           Node contextNode,
  @@ -130,7 +128,7 @@
           
               // Check that the context node is owned by the same document
               if ((contextNode != m_doc) && (!contextNode.getOwnerDocument().equals(m_doc))) {
  -                String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_DOCUMENT, null);       
  +                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_DOCUMENT, null);       
                   throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, fmsg);
               }
               
  @@ -144,7 +142,7 @@
                   (nodeType != Document.COMMENT_NODE) &&
                   (nodeType != Document.PROCESSING_INSTRUCTION_NODE) &&
                   (nodeType != XPathNamespace.XPATH_NAMESPACE_NODE)) {
  -                    String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_NODETYPE, null);       
  +                    String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_WRONG_NODETYPE, null);       
                       throw new DOMException(DOMException.NOT_SUPPORTED_ERR, fmsg);
               }
           }
  @@ -153,7 +151,7 @@
           // If the type is not a supported type, throw an exception and be
           // done with it!
           if (!XPathResultImpl.isValidType(type)) {
  -            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] {new Integer(type)});       
  +            String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] {new Integer(type)});       
               throw new XPathException(XPathException.TYPE_ERR,fmsg); // Invalid XPath type argument: {0}               
           }
           
  @@ -167,7 +165,7 @@
   
           XObject xobj = null;
           try {
  -            xobj = m_xpath.execute(xpathSupport, contextNode, m_resolver );         
  +            xobj = m_xpath.execute(xpathSupport, contextNode, null);         
           } catch (TransformerException te) {
               // What should we do here?
               throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,te.getMessageAndLocation()); 
  @@ -177,7 +175,7 @@
           // Reuse result object passed in?
           // The constructor will check the compatibility of type and xobj and
           // throw an exception if they are not compatible.
  -        return new XPathResultImpl(type,xobj,contextNode);
  +        return new XPathResultImpl(type,xobj,contextNode, m_xpath);
       }
   
   }
  
  
  
  1.9       +77 -44    xml-xalan/java/src/org/apache/xpath/domapi/XPathResultImpl.java
  
  Index: XPathResultImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/domapi/XPathResultImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XPathResultImpl.java	17 Feb 2004 04:33:24 -0000	1.8
  +++ XPathResultImpl.java	12 Nov 2004 21:34:16 -0000	1.9
  @@ -22,10 +22,10 @@
   
   import javax.xml.transform.TransformerException;
   
  -import org.apache.xalan.res.XSLMessages;
  +import org.apache.xpath.XPath;
   import org.apache.xpath.objects.XObject;
   import org.apache.xpath.res.XPATHErrorResources;
  -
  +import org.apache.xpath.res.XPATHMessages;
   import org.w3c.dom.DOMException;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
  @@ -41,7 +41,7 @@
    * The class provides an implementation XPathResult according 
    * to the DOM L3 XPath Specification, Working Draft 28, March 2002.
    *
  - * <p>See also the <a href='http://www.w3.org/TR/2002/WD-DOM-Level-3-XPath-20020328'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
  + * <p>See also the <a href='http://www.w3.org/TR/2004/NOTE-DOM-Level-3-XPath-20040226'>Document Object Model (DOM) Level 3 XPath Specification</a>.</p>
    * 
    * <p>The <code>XPathResult</code> interface represents the result of the 
    * evaluation of an XPath expression within the context of a particular 
  @@ -54,20 +54,25 @@
    * @see org.apache.xpath.objects.XObject
    * @see org.w3c.dom.xpath.XPathResult
    * 
  - * @xsl.usage experimental
  + * @xsl.usage internal
    */
  -public class XPathResultImpl implements XPathResult, EventListener {
  +class XPathResultImpl implements XPathResult, EventListener {
   
   	/**
        *  The wrapped XObject
        */
  -	private XObject m_resultObj;
  +	final private XObject m_resultObj;
   	
   	/**
  +	 * The xpath object that wraps the expression used for this result.
  +	 */
  +	final private XPath m_xpath;
  +		
  +	/**
        *  This the type specified by the user during construction.  Typically
   	 *  the constructor will be called by org.apache.xpath.XPath.evaluate().
        */
  -	private short m_resultType = ANY_TYPE; 
  +	final private short m_resultType; 
   	
   	private boolean m_isInvalidIteratorState = false;
   	
  @@ -75,12 +80,12 @@
        * Only used to attach a mutation event handler when specified
        * type is an iterator type.
        */
  -	private Node m_contextNode;
  +	final private Node m_contextNode;
   	
   	/**
        *  The iterator, if this is an iterator type.
        */
  -	private NodeIterator m_iterator = null;
  +	private NodeIterator m_iterator = null;;
   	
   	/**
        *  The list, if this is a snapshot type.
  @@ -93,21 +98,22 @@
        * 
        * For internal use only.
   	 */
  -	 XPathResultImpl(short type, XObject result, Node contextNode) {
  +	 XPathResultImpl(short type, XObject result, Node contextNode, XPath xpath) {
   		// Check that the type is valid
   		if (!isValidType(type)) {
  -            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] {new Integer(type)});       
  +            String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] {new Integer(type)});       
               throw new XPathException(XPathException.TYPE_ERR,fmsg); // Invalid XPath type argument: {0}           
   		}
   
           // Result object should never be null!
           if (null == result) {
  -            String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_EMPTY_XPATH_RESULT, null);       
  +            String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_EMPTY_XPATH_RESULT, null);       
               throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,fmsg); // Empty XPath result object
           }
           
           this.m_resultObj = result;
           this.m_contextNode = contextNode;
  +        this.m_xpath = xpath;
   
           // If specified result was ANY_TYPE, determine XObject type
           if (type == ANY_TYPE) {
  @@ -119,9 +125,9 @@
           // If the context node supports DOM Events and the type is one of the iterator
           // types register this result as an event listener
           if (((m_resultType == XPathResult.ORDERED_NODE_ITERATOR_TYPE) ||
  -            (m_resultType == XPathResult.UNORDERED_NODE_ITERATOR_TYPE))&&
  -            (contextNode instanceof EventTarget)) {
  -                ((EventTarget)contextNode).addEventListener("MutationEvents",this,true);
  +            (m_resultType == XPathResult.UNORDERED_NODE_ITERATOR_TYPE))) {
  +            	addEventListener();
  +                
           }// else can we handle iterator types if contextNode doesn't support EventTarget??
       				
           // If this is an iterator type get the iterator
  @@ -134,9 +140,9 @@
                   m_iterator = m_resultObj.nodeset();
               } catch (TransformerException te) {
                   // probably not a node type
  -                String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_INCOMPATIBLE_TYPES, new Object[] {getTypeString(getTypeFromXObject(m_resultObj)),getTypeString(m_resultType)});       
  -                throw new XPathException(XPathException.TYPE_ERR, fmsg);  // The returned type: {0} can not be coerced into the specified type: {1}
  -            }
  +				String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INCOMPATIBLE_TYPES, new Object[] {m_xpath.getPatternString(), getTypeString(getTypeFromXObject(m_resultObj)),getTypeString(m_resultType)});       
  +  			    throw new XPathException(XPathException.TYPE_ERR, fmsg);  // "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be coerced into the specified XPathResultType of {2}."},
  +           }
       
                   // If user requested ordered nodeset and result is unordered 
                   // need to sort...TODO
  @@ -152,8 +158,8 @@
           	   m_list = m_resultObj.nodelist();
               } catch (TransformerException te) {
           		// probably not a node type 
  -                String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_INCOMPATIBLE_TYPES, new Object[] {getTypeString(getTypeFromXObject(m_resultObj)),getTypeString(m_resultType)});       
  -                throw new XPathException(XPathException.TYPE_ERR, fmsg);  // The returned type: {0} can not be coerced into the specified type: {1}
  +				String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_INCOMPATIBLE_TYPES, new Object[] {m_xpath.getPatternString(), getTypeString(getTypeFromXObject(m_resultObj)),getTypeString(m_resultType)});       
  +				throw new XPathException(XPathException.TYPE_ERR, fmsg); // "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be coerced into the specified XPathResultType of {2}."},
               }
       	}	    	 
   	}
  @@ -174,8 +180,9 @@
   	 */
   	public double getNumberValue() throws XPathException {
   		if (getResultType() != NUMBER_TYPE) {
  -			String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_NUMBER, new Object[] {getTypeString(m_resultType)});		
  -			throw new XPathException(XPathException.TYPE_ERR,fmsg); // Can not convert {0} to a number
  +			String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});		
  +			throw new XPathException(XPathException.TYPE_ERR,fmsg);
  +//		"The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a number"
   		} else {
   			try {
   			   return m_resultObj.num();
  @@ -196,8 +203,9 @@
   	 */
   	public String getStringValue() throws XPathException {
   		if (getResultType() != STRING_TYPE) {
  -			String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_STRING, new Object[] {m_resultObj.getTypeString()});		
  -			throw new XPathException(XPathException.TYPE_ERR,fmsg); // Can not convert {0} to a string.
  +			String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_STRING, new Object[] {m_xpath.getPatternString(), m_resultObj.getTypeString()});		
  +			throw new XPathException(XPathException.TYPE_ERR,fmsg);
  +//		"The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a string."
   		} else {
   			try {
   			   return m_resultObj.str();
  @@ -213,8 +221,9 @@
   	 */
   	public boolean getBooleanValue() throws XPathException {
   		if (getResultType() != BOOLEAN_TYPE) {
  -			String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {getTypeString(m_resultType)});		
  -			throw new XPathException(XPathException.TYPE_ERR,fmsg);  // Can not convert {0} to a boolean
  +			String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});		
  +			throw new XPathException(XPathException.TYPE_ERR,fmsg);
  +//		"The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a boolean."			
   		} else {
   			try {
   			   return m_resultObj.bool();
  @@ -238,9 +247,10 @@
   		
   		if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
   		    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
  -           String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {getTypeString(m_resultType)});                        
  -		   throw new XPathException(XPathException.TYPE_ERR,fmsg); // Can not convert {0} to a single node. This getter applies to types 
  -                                                                 // ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE.
  +				String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});                        
  +				throw new XPathException(XPathException.TYPE_ERR,fmsg);
  +//				"The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node. 
  +//				 This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
   	    }
   	
   		NodeIterator result = null;
  @@ -284,9 +294,9 @@
   	
   		if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
   		    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
  -           String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_GET_SNAPSHOT_LENGTH, new Object[] {getTypeString(m_resultType)});                        
  -		   throw new XPathException(XPathException.TYPE_ERR,fmsg); // Can not get snapshot length on type: {0}. This getter applies to types 
  -                                                         //UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE.
  +				String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_GET_SNAPSHOT_LENGTH, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});                        
  +				throw new XPathException(XPathException.TYPE_ERR,fmsg); 
  +//				"The method getSnapshotLength cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
   	    }
   			
   		return m_list.getLength();
  @@ -308,17 +318,20 @@
   	public Node iterateNext() throws XPathException, DOMException {
   		if ((m_resultType != UNORDERED_NODE_ITERATOR_TYPE) &&
   		    (m_resultType != ORDERED_NODE_ITERATOR_TYPE)) {
  -          String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NON_ITERATOR_TYPE, new Object[] {getTypeString(m_resultType)});                        
  -		  throw new XPathException(XPathException.TYPE_ERR, fmsg);  // Can not iterate over non iterator type: {0}
  +          String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_ITERATOR_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});                        
  +		  throw new XPathException(XPathException.TYPE_ERR, fmsg);  
  +//		  "The method iterateNext cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}. 
  +//		  This method applies only to types UNORDERED_NODE_ITERATOR_TYPE and ORDERED_NODE_ITERATOR_TYPE."},
   	    }
   
   		if (getInvalidIteratorState()) {
  -          String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_DOC_MUTATED, null);                        
  +          String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_DOC_MUTATED, null);                        
   		  throw new DOMException(DOMException.INVALID_STATE_ERR,fmsg);  // Document mutated since result was returned. Iterator is invalid.
   		}			 
   
           Node node = m_iterator.nextNode();
  -        
  +        if(null == node)
  +        	removeEventListener(); // JIRA 1673
           // Wrap "namespace node" in an XPathNamespace 
           if (isNamespaceNode(node)) {
               return new XPathNamespaceImpl(node);
  @@ -348,9 +361,10 @@
   		
   		if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
   		    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
  -           String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {getTypeString(m_resultType)});                        
  -           throw new XPathException(XPathException.TYPE_ERR, fmsg); // Can call snapshotItem on type: {0}. This method applies to types 
  -                                                              // UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE.
  +           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});                        
  +           throw new XPathException(XPathException.TYPE_ERR, fmsg); 
  +//		"The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}. 
  +//		This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
   	    }		
           
           Node node = m_list.item(index);
  @@ -370,7 +384,7 @@
   	 * 
   	 * @return true If the specified type is supported; otherwise, returns false.
   	 */
  -	public static boolean isValidType( short type ) {
  +	static boolean isValidType( short type ) {
   		switch (type) {
   			case ANY_TYPE:
   			case NUMBER_TYPE:
  @@ -391,13 +405,12 @@
   	 */
   	public void handleEvent(Event event) {
   		
  -		if (event.getType().equals("MutationEvents")) {
  +		if (event.getType().equals("DOMSubtreeModified")) {
   			// invalidate the iterator
   			m_isInvalidIteratorState = true;
   			
   			// deregister as a listener to reduce computational load
  -			((EventTarget)m_contextNode).removeEventListener("MutationEvents",this,true);
  -			
  +			removeEventListener();
   		}
   	}
       
  @@ -407,7 +420,7 @@
      *
      * @return type string 
      */
  -  public String getTypeString(int type)
  +  private String getTypeString(int type)
     {
        switch (type) {
         case ANY_TYPE: return "ANY_TYPE";
  @@ -471,5 +484,25 @@
           return false;
        }
     }
  +  
  +/**
  + * Add m_contextNode to Event Listner to listen for Mutations Events
  + *
  + */
  +  private void addEventListener(){
  +  	if(m_contextNode instanceof EventTarget)
  +		((EventTarget)m_contextNode).addEventListener("DOMSubtreeModified",this,true);
  +  	
  +  }
  +  
  +
  +/**
  + * Remove m_contextNode to Event Listner to listen for Mutations Events
  + *
  + */
  +private void removeEventListener(){
  +	if(m_contextNode instanceof EventTarget)
  +		((EventTarget)m_contextNode).removeEventListener("DOMSubtreeModified",this,true);
  +}
     
   }
  
  
  
  1.1                  xml-xalan/java/src/org/apache/xpath/domapi/XPathStylesheetDOM3Exception.java
  
  Index: XPathStylesheetDOM3Exception.java
  ===================================================================
  /*
   * Copyright (c) 2002 World Wide Web Consortium,
   * (Massachusetts Institute of Technology, Institut National de
   * Recherche en Informatique et en Automatique, Keio University). All
   * Rights Reserved. This program is distributed under the W3C's Software
   * Intellectual Property License. This program 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 W3C License http://www.w3.org/Consortium/Legal/ for more details.
   */
  
  package org.apache.xpath.domapi;
  
  import javax.xml.transform.SourceLocator;
  import javax.xml.transform.TransformerException;
  
  /**
   *
   * A new exception to add support for DOM Level 3 XPath API.
   * This class is needed to throw a org.w3c.dom.DOMException with proper error code in
   * createExpression method of XPathEvaluatorImpl (a DOM Level 3 class).
   * 
   * This class extends TransformerException because the error message includes information
   * about where the XPath problem is in the stylesheet as well as the XPath expression itself.
   * 
   * @xsl.usage internal
   */
  final public class XPathStylesheetDOM3Exception extends TransformerException {
  	public XPathStylesheetDOM3Exception(String msg, SourceLocator arg1)
  	{
  		super(msg, arg1);
  	}
  }
  
  
  
  1.3       +2 -2      xml-xalan/java/src/org/w3c/dom/xpath/XPathException.java
  
  Index: XPathException.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/w3c/dom/xpath/XPathException.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XPathException.java	28 Oct 2002 21:48:05 -0000	1.2
  +++ XPathException.java	12 Nov 2004 21:34:16 -0000	1.3
  @@ -30,10 +30,10 @@
        * <code>XPathEvaluator</code> or contains specialized extension 
        * functions or variables not supported by this implementation.
        */
  -    public static final short INVALID_EXPRESSION_ERR    = 1;
  +    public static final short INVALID_EXPRESSION_ERR    = 51;
       /**
        * If the expression cannot be converted to return the specified type.
        */
  -    public static final short TYPE_ERR                  = 2;
  +    public static final short TYPE_ERR                  = 52;
   
   }
  
  
  
  1.26      +18 -10    xml-xalan/java/src/org/apache/xpath/res/XPATHErrorResources.java
  
  Index: XPATHErrorResources.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/res/XPATHErrorResources.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- XPATHErrorResources.java	13 Aug 2004 21:11:13 -0000	1.25
  +++ XPATHErrorResources.java	12 Nov 2004 21:34:16 -0000	1.26
  @@ -133,6 +133,8 @@
     public static final String ER_INCORRECT_ARG_LENGTH ="ER_INCORRECT_ARG_LENGTH";
     public static final String ER_CANT_CONVERT_TO_NUMBER = 
   	 "ER_CANT_CONVERT_TO_NUMBER";
  +  public static final String ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER = 
  +	   "ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER";	 
     public static final String ER_CANT_CONVERT_TO_NODELIST = 
   	 "ER_CANT_CONVERT_TO_NODELIST";
     public static final String ER_CANT_CONVERT_TO_MUTABLENODELIST = 
  @@ -298,7 +300,7 @@
   //	 "ER_ARG_LOCALNAME_INVALID";
     /** prefix in QNAME should be a valid NCName */
     //public static final String ER_ARG_PREFIX_INVALID = "ER_ARG_PREFIX_INVALID";
  -  /** Field ER_CANT_CONVERT_TO_BOOLEAN          */
  +  /** ER_CANT_CONVERT_XPATHRESULTTYPE_TO_BOOLEAN          */
     public static final String ER_CANT_CONVERT_TO_BOOLEAN = 
   	 "ER_CANT_CONVERT_TO_BOOLEAN";
     /** Field ER_CANT_CONVERT_TO_SINGLENODE       */
  @@ -1036,11 +1038,11 @@
     // message indicates that a value of a particular type could not be converted
     // to a value of type string.
   
  -  /** Field ER_CANT_CONVERT_TO_BOOLEAN          */
  +  /** ER_CANT_CONVERT_TO_BOOLEAN          */
   //  public static final int ER_CANT_CONVERT_TO_BOOLEAN = 103;
   
     { ER_CANT_CONVERT_TO_BOOLEAN,
  -       "Cannot convert {0} to a boolean."},
  +       "The XPathResult of XPath expression ''{0}'' has an XPathResultType of {1} which cannot be converted to a boolean."},
   
     // Note to translators: Do not translate ANY_UNORDERED_NODE_TYPE and 
     // FIRST_ORDERED_NODE_TYPE.
  @@ -1049,7 +1051,7 @@
     //public static final int ER_CANT_CONVERT_TO_SINGLENODE = 104;
   
     { ER_CANT_CONVERT_TO_SINGLENODE,
  -       "Cannot convert {0} to a single node. This getter applies to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."},
  +       "The XPathResult of XPath expression ''{0}'' has an XPathResultType of {1} which cannot be converted to a single node. The method getSingleNodeValue applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."},
   
     // Note to translators: Do not translate UNORDERED_NODE_SNAPSHOT_TYPE and
     // ORDERED_NODE_SNAPSHOT_TYPE.
  @@ -1058,13 +1060,13 @@
   //  public static final int ER_CANT_GET_SNAPSHOT_LENGTH = 105;
   
     { ER_CANT_GET_SNAPSHOT_LENGTH,
  -       "Cannot get snapshot length on type: {0}. This getter applies to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
  +       "The method getSnapshotLength cannot be called on the XPathResult of XPath expression ''{0}'' because its XPathResultType is {1}. This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
   
     /** Field ER_NON_ITERATOR_TYPE                */
     //public static final int ER_NON_ITERATOR_TYPE        = 106;
   
     { ER_NON_ITERATOR_TYPE,
  -       "Cannot iterate over non-iterator type: {0}"},
  +       "The method iterateNext cannot be called on the XPathResult of XPath expression ''{0}'' because its XPathResultType is {1}. This method applies only to types UNORDERED_NODE_ITERATOR_TYPE and ORDERED_NODE_ITERATOR_TYPE."},
   
     // Note to translators: This message indicates that the document being operated
     // upon changed, so the iterator object that was being used to traverse the
  @@ -1092,7 +1094,7 @@
   //  public static final int ER_INCOMPATIBLE_TYPES       = 110;
   
     { ER_INCOMPATIBLE_TYPES,
  -       "The returned type: {0} cannot be coerced into the specified type: {1}"},
  +       "The XPathResult of XPath expression ''{0}'' has an XPathResultType of {1} which cannot be coerced into the specified XPathResultType of {2}."},
   
     /** Field ER_NULL_RESOLVER                     */
    // public static final int ER_NULL_RESOLVER            = 111;
  @@ -1108,7 +1110,7 @@
   //  public static final int ER_CANT_CONVERT_TO_STRING   = 112;
   
     { ER_CANT_CONVERT_TO_STRING,
  -       "Cannot convert {0} to a string."},
  +       "The XPathResult of XPath expression ''{0}'' has an XPathResultType of {1} which cannot be converted to a string."},
   
     // Note to translators: Do not translate snapshotItem,
     // UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE.
  @@ -1117,7 +1119,7 @@
   //  public static final int ER_NON_SNAPSHOT_TYPE       = 113;
   
     { ER_NON_SNAPSHOT_TYPE,
  -       "Cannot call snapshotItem on type: {0}. This method applies to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
  +       "The method snapshotItem cannot be called on the XPathResult of XPath expression ''{0}'' because its XPathResultType is {1}. This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
   
     // Note to translators:  XPathEvaluator is a Java interface name.  An
     // XPathEvaluator is created with respect to a particular XML document, and in
  @@ -1143,6 +1145,12 @@
   
     { ER_XPATH_ERROR,
          "Unknown error in XPath."},
  +       
  +	/** Field ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER          */
  +//	  public static final int ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER = 117;
  +
  +	{ ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER,
  +		"The XPathResult of XPath expression ''{0}'' has an XPathResultType of {1} which cannot be converted to a number"},       
   
   
     // Warnings...
  
  
  
  1.15      +11 -6     xml-xalan/java/src/org/apache/xpath/compiler/Lexer.java
  
  Index: Lexer.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/Lexer.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Lexer.java	17 Feb 2004 04:32:49 -0000	1.14
  +++ Lexer.java	12 Nov 2004 21:34:16 -0000	1.15
  @@ -633,11 +633,16 @@
       }
       else
       {
  +        // To older XPath code it doesn't matter if
  +        // error() is called or errorForDOM3().
  +		m_processor.errorForDOM3(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,
  +						 new String[] {prefix});  //"Prefix must resolve to a namespace: {0}";
   
  -      // error("Could not locate namespace for prefix: "+prefix);
  -      m_processor.error(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,
  -                 new String[] {prefix});  //"Prefix must resolve to a namespace: {0}";
  -
  +/** old code commented out 17-Sep-2004
  +// error("Could not locate namespace for prefix: "+prefix);
  +//		  m_processor.error(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,
  +//					 new String[] {prefix});  //"Prefix must resolve to a namespace: {0}";
  +*/
   
         /***  Old code commented out 10-Jan-2001
         addToTokenQueue(prefix);
  
  
  
  1.30      +46 -1     xml-xalan/java/src/org/apache/xpath/compiler/XPathParser.java
  
  Index: XPathParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/XPathParser.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- XPathParser.java	1 Oct 2004 22:01:24 -0000	1.29
  +++ XPathParser.java	12 Nov 2004 21:34:16 -0000	1.30
  @@ -24,6 +24,7 @@
   import org.apache.xalan.res.XSLMessages;
   import org.apache.xml.utils.PrefixResolver;
   import org.apache.xpath.XPathProcessorException;
  +import org.apache.xpath.domapi.XPathStylesheetDOM3Exception;
   import org.apache.xpath.objects.XNumber;
   import org.apache.xpath.objects.XString;
   import org.apache.xpath.res.XPATHErrorResources;
  @@ -612,6 +613,50 @@
       }
     }
   
  +  /**
  +   * This method is added to support DOM 3 XPath API.
  +   * <p>
  +   * This method is exactly like error(String, Object[]); except that
  +   * the underlying TransformerException is 
  +   * XpathStylesheetDOM3Exception (which extends TransformerException).
  +   * <p>
  +   * So older XPath code in Xalan is not affected by this. To older XPath code
  +   * the behavior of whether error() or errorForDOM3() is called because it is
  +   * always catching TransformerException objects and is oblivious to
  +   * the new subclass of XPathStylesheetDOM3Exception. Older XPath code 
  +   * runs as before.
  +   * <p>
  +   * However, newer DOM3 XPath code upon catching a TransformerException can
  +   * can check if the exception is an instance of XPathStylesheetDOM3Exception
  +   * and take appropriate action.
  +   * 
  +   * @param msg An error msgkey that corresponds to one of the constants found 
  +   *            in {@link org.apache.xpath.res.XPATHErrorResources}, which is 
  +   *            a key for a format string.
  +   * @param args An array of arguments represented in the format string, which 
  +   *             may be null.
  +   *
  +   * @throws TransformerException if the current ErrorListoner determines to 
  +   *                              throw an exception.
  +   */
  +  void errorForDOM3(String msg, Object[] args) throws TransformerException
  +  {
  +
  +	String fmsg = XSLMessages.createXPATHMessage(msg, args);
  +	ErrorListener ehandler = this.getErrorListener();
  +
  +	TransformerException te = new XPathStylesheetDOM3Exception(fmsg, m_sourceLocator);
  +	if (null != ehandler)
  +	{
  +	  // TO DO: Need to get stylesheet Locator from here.
  +	  ehandler.fatalError(te);
  +	}
  +	else
  +	{
  +	  // System.err.println(fmsg);
  +	  throw te;
  +	}
  +  }
     /**
      * Dump the remaining token queue.
      * Thanks to Craig for this.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org