Author: mrglavas
Date: Mon Nov  3 07:56:36 2008
New Revision: 710087

URL: http://svn.apache.org/viewvc?rev=710087&view=rev
Log:
Fixing a bug. We cannot cache the Location object from the start document event.
To get the correct line and column numbers it needs to be read at the point 
where
the error occurs. To handle this introduced a wrapper around the XMLStreamReader
which reads the Location from the reader on demand.

Modified:
    
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java

Modified: 
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java?rev=710087&r1=710086&r2=710087&view=diff
==============================================================================
--- 
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java
 (original)
+++ 
xerces/java/trunk/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java
 Mon Nov  3 07:56:36 2008
@@ -119,6 +119,9 @@
     /** XML Locator wrapper for StAX. **/
     private final StAXLocationWrapper fStAXLocationWrapper = new 
StAXLocationWrapper();
     
+    /** On demand reader of the Location from an XMLStreamReader. **/
+    private final XMLStreamReaderLocation fXMLStreamReaderLocation = new 
XMLStreamReaderLocation();
+    
     /** Map for tracking entity declarations. */
     private HashMap fEntities = null;
     
@@ -203,6 +206,7 @@
                 // Release references to application objects
                 fCurrentEvent = null;
                 fStAXLocationWrapper.setLocation(null);
+                fXMLStreamReaderLocation.setXMLStreamReader(null);
                 if (fStAXValidatorHandler != null) {
                     fStAXValidatorHandler.setStAXResult(null);
                 }
@@ -350,7 +354,8 @@
                     throw new 
SAXException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(), 
                             "StAXIllegalInitialState", null));
                 }
-                setup(reader.getLocation(), result, 
Boolean.TRUE.equals(reader.getProperty(STRING_INTERNING)));
+                fXMLStreamReaderLocation.setXMLStreamReader(reader);
+                setup(fXMLStreamReaderLocation, result, 
Boolean.TRUE.equals(reader.getProperty(STRING_INTERNING)));
                 fSchemaValidator.startDocument(fStAXLocationWrapper, null, 
fNamespaceContext, null);
                 do {
                     switch (eventType) {
@@ -631,5 +636,63 @@
             }
         }
     }
+    
+    /**
+     * On demand reader of the Location from an XMLStreamReader.
+     */
+    static final class XMLStreamReaderLocation implements Location {
+        
+        private XMLStreamReader reader;
+        
+        public XMLStreamReaderLocation() {}
+        
+        public int getCharacterOffset() {
+            Location loc = getLocation();
+            if (loc != null) {
+                return loc.getCharacterOffset();
+            }
+            return -1;
+        }
+        
+        public int getColumnNumber() {
+            Location loc = getLocation();
+            if (loc != null) {
+                return loc.getColumnNumber();
+            }
+            return -1;
+        }
+        
+        public int getLineNumber() {
+            Location loc = getLocation();
+            if (loc != null) {
+                return loc.getLineNumber();
+            }
+            return -1;
+        }
+        
+        public String getPublicId() {
+            Location loc = getLocation();
+            if (loc != null) {
+                return loc.getPublicId();
+            }
+            return null;
+        }
+        
+        public String getSystemId() {
+            Location loc = getLocation();
+            if (loc != null) {
+                return loc.getSystemId();
+            } 
+            return null;
+        }
+        
+        public void setXMLStreamReader(XMLStreamReader reader) {
+            this.reader = reader;
+        }
+        
+        private Location getLocation() {
+            return reader != null ? reader.getLocation() : null;
+        }
+    }
 
 } // StAXValidatorHelper



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to