You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2006/08/21 06:53:50 UTC

svn commit: r433148 - /xerces/java/branches/stax-dev/src/org/apache/xerces/stax/

Author: mrglavas
Date: Sun Aug 20 21:53:50 2006
New Revision: 433148

URL: http://svn.apache.org/viewvc?rev=433148&view=rev
Log:
JIRA Issue #1178
https://issues.apache.org/jira/browse/XERCESJ-1178

Bug fixes and other updates to the SAX and DOM XMLStreamReaders from Hua Lei.
The summary of the changes is listed in the JIRA issue though I did make a
few modifications to fix:

1) A stack underflow in the namespace context.
2) A threading problem in the SAX XMLStreamReader which was preventing the VM from exiting.

Added:
    xerces/java/branches/stax-dev/src/org/apache/xerces/stax/ConfigurationContext.java   (with props)
Modified:
    xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AsyncSAXParser.java
    xerces/java/branches/stax-dev/src/org/apache/xerces/stax/DOMXMLStreamReaderImpl.java
    xerces/java/branches/stax-dev/src/org/apache/xerces/stax/NamespaceContextImpl.java
    xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXLocation.java
    xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java
    xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java
    xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java

Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AsyncSAXParser.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AsyncSAXParser.java?rev=433148&r1=433147&r2=433148&view=diff
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AsyncSAXParser.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/AsyncSAXParser.java Sun Aug 20 21:53:50 2006
@@ -27,7 +27,7 @@
  */
 final class AsyncSAXParser extends Thread {
     
-    private XMLReader xr;
+    XMLReader xr;
     private InputSource is;
     
     // The flag which represents the status of AsyncSAXParser. If true,
@@ -43,12 +43,15 @@
     
     // The current element name
     private String eleName;
+    private String uri;
+    
+    Exception ex = null;
     
     public AsyncSAXParser(XMLReader xr, InputSource is) {
         this.xr = xr;
         this.is = is;
         
-        this.runningFlag = true;     
+        this.runningFlag = false;     
     }
     
     /**
@@ -59,8 +62,11 @@
             xr.parse(is);
         }
         catch(Exception e){
-            System.out.print("Error occurs during the SAX parsing process at ");
-            e.printStackTrace();
+//          System.out.print("Error occurs during the SAX parsing process at ");
+//          System.out.flush();
+//          e.printStackTrace();
+            ex = e;
+//          throw new RuntimeException(e.getMessage(), e);
         }
     }  
     
@@ -91,11 +97,13 @@
      * @param length
      */
     public void setCharacters(char[] ch, int start, int length) {
-        charactersBuf = null;
-        charactersBuf = new char[length];
-        for (int i = 0; i < length; i++, start++) {
-            charactersBuf[i] = ch[start];
+        if(ch == null) {
+            charactersBuf = new char[0];
+            return;
         }
+        
+        charactersBuf = new char[length];
+        System.arraycopy(ch, start, charactersBuf, 0, length);
     }
     
     /**
@@ -158,5 +166,13 @@
     
     public String getPITarget() {
         return piTarget;
+    }
+    
+    public String getUri() {
+        return uri;
+    }
+    
+    public void setUri(String uri) {
+        this.uri = uri;
     }
 }

Added: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/ConfigurationContext.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/ConfigurationContext.java?rev=433148&view=auto
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/ConfigurationContext.java (added)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/ConfigurationContext.java Sun Aug 20 21:53:50 2006
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.xerces.stax;
+
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Hashtable;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLReporter;
+import javax.xml.stream.XMLResolver;
+import javax.xml.stream.util.XMLEventAllocator;
+
+/**
+ * @author Hua Lei
+ * 
+ * @version $Id$
+ */
+final class ConfigurationContext {
+    
+    private static HashSet supportedFeatures;
+    
+    private static String NOTATIONS = "javax.xml.stream.notations";
+    private static String ENTITIES = "javax.xml.stream.entities";
+    static final String REPORT_CDATA = "http://java.sun.com/xml/stream/properties/report-cdata-event";
+    static {
+        supportedFeatures = new HashSet();
+        supportedFeatures.add(XMLInputFactory.IS_VALIDATING);
+        supportedFeatures.add(XMLInputFactory.IS_COALESCING);
+        supportedFeatures.add(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES);
+        supportedFeatures.add(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
+        supportedFeatures.add(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
+        supportedFeatures.add(XMLInputFactory.IS_NAMESPACE_AWARE);
+        supportedFeatures.add(XMLInputFactory.SUPPORT_DTD);
+        supportedFeatures.add(XMLInputFactory.REPORTER);
+        supportedFeatures.add(XMLInputFactory.RESOLVER);
+        supportedFeatures.add(XMLInputFactory.ALLOCATOR);
+        supportedFeatures.add(NOTATIONS);
+        supportedFeatures.add(ENTITIES);
+        supportedFeatures.add(REPORT_CDATA);
+    };
+    
+    private Hashtable features = new Hashtable();
+    public ConfigurationContext() {
+        features.put(XMLInputFactory.IS_VALIDATING,
+                Boolean.FALSE);
+        features.put(XMLInputFactory.IS_COALESCING,
+                Boolean.FALSE);
+        features.put(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,
+                Boolean.TRUE);
+        features.put(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
+                Boolean.FALSE);
+        features.put(XMLInputFactory.IS_NAMESPACE_AWARE,
+                Boolean.TRUE);
+        features.put(XMLInputFactory.SUPPORT_DTD,
+                Boolean.FALSE);
+        features.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
+                Boolean.FALSE);
+        
+    }
+    
+    public void setEventAllocator(XMLEventAllocator a) {
+        features.put(XMLInputFactory.ALLOCATOR,a);
+    }
+    public XMLEventAllocator getEventAllocator() {
+        return (XMLEventAllocator) features.get(XMLInputFactory.ALLOCATOR);
+    }
+    
+    public void setProperty(String name, Object feature) {
+        if (name.equals(XMLInputFactory.IS_VALIDATING)) {
+            setValidating(((Boolean) feature).booleanValue());
+        } else if (name.equals(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES)) {
+            setSupportExternalEntities(((Boolean) feature).booleanValue());
+        } else if (name.equals(XMLInputFactory.IS_NAMESPACE_AWARE)) {
+            setNamespaceAware(((Boolean) feature).booleanValue());
+        } else {
+            check(name);
+            features.put(name,feature);
+        }
+    }
+    
+    public void check(String name) {
+        if (!supportedFeatures.contains(name))
+            throw new IllegalArgumentException("Unable to access unsupported "+
+                    "property "+name);
+    }
+    
+    public Object getProperty(String name) {
+        check(name);
+        return features.get(name);
+    }
+    
+    public void setXMLReporter(XMLReporter r) {
+        features.put(XMLInputFactory.REPORTER,r);
+    }
+    
+    public XMLReporter getXMLReporter() {
+        return (XMLReporter) features.get(XMLInputFactory.REPORTER);
+    }
+    
+    public void setXMLResolver(XMLResolver r) {
+        features.put(XMLInputFactory.RESOLVER,r);
+    }
+    
+    public XMLResolver getXMLResolver() {
+        return (XMLResolver) features.get(XMLInputFactory.RESOLVER);
+    }
+    
+    public boolean getBool(String name) {
+        check(name);
+        Boolean val = (Boolean) features.get(name);
+        return val.booleanValue();
+    }
+    
+    public void setBool(String name, boolean val) {
+        check(name);
+        features.put(name, val ? Boolean.TRUE : Boolean.FALSE);
+    }
+    
+    public void setCoalescing(boolean val) {
+        setBool(XMLInputFactory.IS_COALESCING,val);
+    }
+    
+    public boolean isCoalescing() {
+        return getBool(XMLInputFactory.IS_COALESCING);
+    }
+    
+    public void setValidating(boolean val) {
+        if (val) {
+            throw new IllegalArgumentException("This implementation does not " +
+            "support validation");
+        }
+        // No need to re-set to the same value...
+    }
+    
+    public boolean isValidating() {
+        return getBool(XMLInputFactory.IS_VALIDATING);
+    }
+    
+    public void setReplacingEntities(boolean val) {
+        setBool(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,val);
+    }
+    
+    public boolean isReplacingEntities() {
+        return getBool(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES);
+    }
+    
+    public void setSupportExternalEntities(boolean val) {
+        if (val) {
+            throw new IllegalArgumentException("This implementation does not " +
+            "resolve external entities ");
+        }
+        // Already false...
+    }
+    
+    public boolean isSupportingExternalEntities() {
+        return getBool(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
+    }
+    
+    public void setPrefixDefaulting(boolean val) {
+        setBool(XMLOutputFactory.IS_REPAIRING_NAMESPACES,val);
+    }
+    
+    public boolean isPrefixDefaulting() {
+        return getBool(XMLOutputFactory.IS_REPAIRING_NAMESPACES);
+    }
+    
+    public void setNamespaceAware(boolean val) {
+        if (!val) {
+            throw new IllegalArgumentException("This implementation does not allow disabling namespace processing");
+        }
+        // Already true
+    }
+    
+    public boolean isNamespaceAware() {
+        return getBool(XMLInputFactory.IS_NAMESPACE_AWARE);
+    }
+    
+    public String getVersion() {
+        return "1.0";
+    }
+    
+    public Enumeration getProperties() {
+        return features.keys();
+    }
+    
+    public boolean isPropertySupported(String name) {
+        return supportedFeatures.contains(name);
+    }
+    
+}
\ No newline at end of file

Propchange: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/ConfigurationContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/ConfigurationContext.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/DOMXMLStreamReaderImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/DOMXMLStreamReaderImpl.java?rev=433148&r1=433147&r2=433148&view=diff
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/DOMXMLStreamReaderImpl.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/DOMXMLStreamReaderImpl.java Sun Aug 20 21:53:50 2006
@@ -72,7 +72,9 @@
     private boolean elementEndFlag = false;
     
     // Represent "javax.xml.stream.isCoalescing" feature
-    protected boolean isCoalesce = false;
+    protected boolean isCoalescing = false;
+    
+    protected boolean isReplaceEntityRef = true;
     
     // Record the continue character nodes
     private int contiNum = 0;
@@ -94,12 +96,18 @@
         this.domNode = domNode;
         this.xif = xif;
         this.curNode = domNode;
-        curType = DOMXMLStreamReaderImpl.getStAXType(domNode);
+        curType = getStAXType(domNode);
         
         curAttrs = new ArrayList();
         curNamespaces = new ArrayList();
         
-        isCoalesce = Boolean.getBoolean(XMLInputFactory.IS_COALESCING);
+        Object obj = xif.getProperty(XMLInputFactory.IS_COALESCING);
+        if(obj != null)
+            isCoalescing = ((Boolean)obj).booleanValue();
+        
+        obj = xif.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES);
+        if(obj != null)
+            isReplaceEntityRef = ((Boolean)obj).booleanValue();
         
         dc = new NamespaceContextImpl();
         
@@ -170,7 +178,7 @@
             Node curChild = curNode.getFirstChild();
             
             // The current node has a child
-            if (curChild != null && !elementEndFlag) {
+            if (curChild != null && !elementEndFlag && curNode.getNodeType() != Node.ENTITY_REFERENCE_NODE) {
                 curNode = curChild;
             }
             // Go to the next sibling, if null, go to parent's next sibling
@@ -207,11 +215,11 @@
                 }
                 curNode = curSibling;
             }
-            curType = DOMXMLStreamReaderImpl.getStAXType(curNode);
+            curType = getStAXType(curNode);
             
             initialElementAttrs();
             
-            if (isCoalesce && curType == XMLStreamConstants.CHARACTERS) {
+            if (isCoalescing && curType == XMLStreamConstants.CHARACTERS) {
                 contiNum = 0;
                 while (peekNext() == XMLStreamConstants.CHARACTERS) {
                     next();
@@ -222,6 +230,7 @@
             return curType;
         }
         catch(Exception e) {
+            e.printStackTrace();
             throw new XMLStreamException("Error occurs when processing DOMSource", e);
         }
     }
@@ -240,7 +249,7 @@
         Node curChild = peekNode.getFirstChild();
         
         // The current node has a child
-        if (curChild != null && !elementEndFlag) {
+        if (curChild != null && !elementEndFlag && peekNode.getNodeType() != Node.ENTITY_REFERENCE_NODE) {
             peekNode = curChild;
         }
         // Go to the next sibling, if null, go to parent's next sibling
@@ -268,7 +277,7 @@
             peekNode = curSibling;
         }
         
-        return DOMXMLStreamReaderImpl.getStAXType(peekNode);
+        return getStAXType(peekNode);
     }
     
     /**
@@ -278,7 +287,7 @@
      */
     private void initialElementAttrs() {
         if (curType == XMLStreamConstants.START_ELEMENT || 
-            curType == XMLStreamConstants.END_ELEMENT ) {
+                curType == XMLStreamConstants.END_ELEMENT ) {
             curAttrs.clear();
             curNamespaces.clear();
             NamedNodeMap attrs = curNode.getAttributes();
@@ -286,14 +295,17 @@
                 for(int i = 0; i < attrs.getLength(); i++){
                     Attr attr = (Attr)attrs.item(i);
                     String name = attr.getName();
-                    if(name.startsWith("xmlns")){
+                    if(name.equals("xmlns") || name.startsWith("xmlns:")){
                         String value = attr.getValue();
                         String prefix = "";
                         if(!name.equals("xmlns"))
                             prefix += name.substring(6);
                         
-                        if(curType == XMLStreamConstants.START_ELEMENT)
+                        if(curType == XMLStreamConstants.START_ELEMENT) {
+                            if(name.equals("xmlns") && "".equals(value))
+                                value = null;
                             dc.addNamespace(prefix, value);  
+                        }
                         curNamespaces.add(attr);
                     }
                     else
@@ -451,7 +463,7 @@
                 }
             }
             workNode = workNode.getParentNode();
-            workType = DOMXMLStreamReaderImpl.getStAXType(workNode);
+            workType = getStAXType(workNode);
         }
         return null;
     }
@@ -547,7 +559,7 @@
      * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
      */
     public int getAttributeCount(){
-        int count = 0;
+//      int count = 0;
         String attrName;
         if (curType == XMLStreamConstants.START_ELEMENT) {
             return curAttrs.size();
@@ -576,21 +588,21 @@
     public QName getAttributeName(int index){
         String localName;
         String namespaceURI;
-        Attr attr = null;
+//      Attr attr = null;
         
         if (curType == XMLStreamConstants.START_ELEMENT) {
             int leng = getAttributeCount();
             if(index + 1 > leng || index < 0)
                 throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
             
-            attr = (Attr) curAttrs.get(index);
+//          attr = (Attr) curAttrs.get(index);
             namespaceURI = this.getAttributeNamespace(index);
             localName = this.getAttributeLocalName(index);
             
             return new QName(namespaceURI, localName);
         }
         if (curType == XMLStreamConstants.ATTRIBUTE) {
-            attr = (Attr) curNode;
+//          attr = (Attr) curNode;
             
             namespaceURI = this.getAttributeNamespace(index);
             localName = this.getAttributeLocalName(index);
@@ -901,17 +913,17 @@
         // reported as XMLStreamConstants.CHARACTERS
         if (curType == XMLStreamConstants.CHARACTERS) {
             String text = "";
-            CharacterData cur = (CharacterData)curNode;
-            if (this.isCoalesce) {
-                text = cur.getData();
+            Node cur = curNode;
+            if (this.isCoalescing) {
+                text = getText(cur);
                 while(contiNum >0){
-                    cur = (CharacterData)cur.getPreviousSibling();
-                    text = cur.getData()+ text;
+                    cur = cur.getPreviousSibling();
+                    text = getText(cur)+ text;
                     contiNum--;
                 }
             }
             else{
-                text = cur.getData();
+                text = getText(cur);
             }
             return text;
         }
@@ -923,15 +935,31 @@
             DocumentType dt = (DocumentType)curNode;
             return dt.getInternalSubset();
         }
-        // The EntityReferencce is to be solved
-        /*if(curType == XMLStreamConstants.ENTITY_REFERENCE){
-         EntityReference er = (EntityReference)curNode;
-         return er.getTextContent();
-         }*/
+        
+        if(curType == XMLStreamConstants.ENTITY_REFERENCE){
+//          EntityReference er = (EntityReference)curNode;
+            if(curNode.hasChildNodes()) {
+                return ((CharacterData)curNode.getFirstChild()).getData();
+            }
+            else {
+                return "";
+            }
+        }
         throw new IllegalStateException(
         "The current event is not a valid text state.");	
     }
     
+    private String getText(Node node) {
+        if(node.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
+            node = node.getFirstChild();
+        }
+        
+        if(node == null)
+            return "";
+        else
+            return ((CharacterData)node).getData();
+    }
+    
     /**
      * Returns an array which contains the characters from this event.
      * This array should be treated as read-only and transient. I.e. the array will
@@ -969,7 +997,7 @@
      * @throws NullPointerException is if target is null
      */
     public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) 
-        throws XMLStreamException {
+    throws XMLStreamException {
         
         if(target == null)
             throw new NullPointerException();
@@ -983,7 +1011,8 @@
         if(length < 0)
             throw new ArrayIndexOutOfBoundsException("The length is out of index");
         
-        int len = getTextLength();
+        char[] intBuf = getTextCharacters();
+        int len = intBuf.length;
         if (sourceStart < 0 || sourceStart > len) {
             throw new ArrayIndexOutOfBoundsException("The start position of source is out of index");
         }
@@ -996,7 +1025,6 @@
         }
         
         
-        char[] intBuf = getTextCharacters();
         int intStart = getTextStart();
         System.arraycopy(intBuf, intStart + sourceStart,
                 target, targetStart, length);
@@ -1093,10 +1121,8 @@
             else
                 return node.substring(index + 1);
         }
-        else if (curType == XMLStreamConstants.START_ELEMENT) {
+        else if (curType == XMLStreamConstants.ENTITY_REFERENCE) {
             EntityReference er = (EntityReference)curNode;
-            
-            // Not quite sure
             return er.getNodeName();
         }
         throw new IllegalStateException(
@@ -1232,8 +1258,8 @@
         throw new IllegalStateException(
         "The current event is not PROCESSING_INSTRUCTION.");
     }
-
-    private static int getStAXType(Node node) {
+    
+    private int getStAXType(Node node) {
         switch (node.getNodeType()) {
             case Node.ELEMENT_NODE:
                 return XMLStreamConstants.START_ELEMENT;
@@ -1251,7 +1277,10 @@
             case Node.DOCUMENT_TYPE_NODE:
                 return XMLStreamConstants.DTD;
             case Node.ENTITY_REFERENCE_NODE:
-                return XMLStreamConstants.ENTITY_REFERENCE;
+                if(isReplaceEntityRef)
+                    return XMLStreamConstants.CHARACTERS;
+                else
+                    return XMLStreamConstants.ENTITY_REFERENCE;
             case Node.ENTITY_NODE:
                 return XMLStreamConstants.ENTITY_DECLARATION;
             case Node.NOTATION_NODE:

Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/NamespaceContextImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/NamespaceContextImpl.java?rev=433148&r1=433147&r2=433148&view=diff
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/NamespaceContextImpl.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/NamespaceContextImpl.java Sun Aug 20 21:53:50 2006
@@ -16,12 +16,13 @@
 
 package org.apache.xerces.stax;
 
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Stack;
-import java.util.ArrayList;
 
-import javax.xml.namespace.NamespaceContext;
 import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
 
 /**
  * <p>NamespaceContext for the SAX and DOM XMLStreamReaders.</p>
@@ -36,7 +37,9 @@
     private Stack namespaceStack;
     
     // Record the namespaces of START_ELEMENT and END_ELEMENT for SAXSource
-    private ArrayList eleNamespaces;
+    private ArrayList eleNamespaces = new ArrayList();
+    
+    private Stack enStack;
     
     /**
      * The initialization method of DOMNamespaceContext, 
@@ -44,15 +47,19 @@
      */
     public NamespaceContextImpl() {
         namespaceStack = new Stack();
-        eleNamespaces = new ArrayList();
+        enStack = new Stack();
     }
     
     /**
      * When encounters a StartElement event, the namespace level in the namespace
      * stack is increased.
-     *
      */
     public void onStartElement() {
+        if(eleNamespaces != null) {
+            enStack.push(eleNamespaces);
+        }
+        
+        eleNamespaces = new ArrayList();
         if (!namespaceStack.empty()) {
             Iterator iter = namespaceStack.iterator();
             while(iter.hasNext()){
@@ -69,6 +76,8 @@
      * and removed from avaliable stack.
      */
     public void onEndElement() {
+        eleNamespaces = (ArrayList)enStack.pop();
+        
         if (!namespaceStack.empty()) {
             
             Iterator iter = namespaceStack.iterator();
@@ -167,15 +176,22 @@
             throw new IllegalArgumentException("The input namespaceURI should not be null");
         
         if (namespaceURI.equals(XMLConstants.XML_NS_URI)) return "xml";
-        if (namespaceURI.equals(XMLConstants.XML_NS_URI)) return "xmlns";
+        if (namespaceURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) return "xmlns";
         
         int size = namespaceStack.size();
         
+        HashSet prefixes = new HashSet();
         while (size > 0) {
             Namespace dc = (Namespace) namespaceStack.elementAt(--size);
-            String namespace = dc.getNamespaceURI();
-            if (namespaceURI.equals(namespace))
-                return dc.getPrefix();
+            if (namespaceURI.equals(dc.namespaceURI)) {
+                if(!prefixes.contains(dc.prefix))
+                    return dc.prefix;
+                else
+                    return null;
+            }
+            else {
+                prefixes.add(dc.prefix);
+            }
         }
         
         return null;

Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXLocation.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXLocation.java?rev=433148&r1=433147&r2=433148&view=diff
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXLocation.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXLocation.java Sun Aug 20 21:53:50 2006
@@ -29,10 +29,6 @@
     
     private Locator loc;
     
-    public SAXLocation(Locator loc) {
-        this.loc = loc;
-    }
-    
     /**
      * Return the line number where the current event ends,
      * returns -1 if none is available.
@@ -77,6 +73,10 @@
      */
     public String getSystemId() {
         return loc.getSystemId();
+    }
+    
+    public void setLocator(Locator loc) {
+        this.loc = loc;
     }
     
 }

Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java?rev=433148&r1=433147&r2=433148&view=diff
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/SAXXMLStreamReaderImpl.java Sun Aug 20 21:53:50 2006
@@ -29,9 +29,7 @@
 
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
 import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.LocatorImpl;
 
 /**
  * <p>An XMLStreamReader created from a SAXSource.</p>
@@ -52,15 +50,12 @@
     private StAXSAXHandler handler;
     
     // The current event type
-    private int curType;
-    
-    // Record the location of SAX parser
-    private Locator loc;
+    int curType;
     
     private SAXLocation sl;
     
     // The attribute of element event
-    private Attributes attrs;
+    //  private Attributes attrs;
     
     private String xmlVersion = "1.0" ;
     
@@ -78,11 +73,14 @@
         public String local;
         public String value;
         public String type;
+        public String uri;
     }
     
     // Record the current namespace context
     private NamespaceContextImpl dc;
     
+    boolean isCoalescing = false;
+    
     /**
      * The construction method of SAXXMLStreamReader
      * 
@@ -95,12 +93,16 @@
         this.xif = xif;
         this.curAttrs = new ArrayList();
         
+        Object obj = xif.getProperty(XMLInputFactory.IS_COALESCING);
+        if(obj != null)
+            isCoalescing = ((Boolean)obj).booleanValue();
+        
         try {
             asp = new AsyncSAXParser(xr, is);
-            loc = new LocatorImpl();
-            sl = new SAXLocation(loc);		
+            asp.setDaemon(true);
+            sl = new SAXLocation();		
             
-            handler = new StAXSAXHandler(asp, this, loc);
+            handler = new StAXSAXHandler(asp, this, sl);
             
             xr.setContentHandler(handler);
             xr.setDTDHandler(handler);
@@ -110,7 +112,6 @@
             dc = new NamespaceContextImpl();
             
             asp.start();
-            
             synchronized (asp) {
                 while (asp.getRunningFlag() == true)
                     asp.wait();
@@ -166,13 +167,20 @@
         if (hasNext() == false) {
             throw new XMLStreamException("No such element!");
         }
+        
+        if(asp.ex != null)
+            throw new XMLStreamException(asp.ex.getMessage(), asp.ex);
+        
         synchronized(asp) {
             asp.setRunningFlag(true);
             asp.notify();
             
             try {
-                while (asp.getRunningFlag() == true)
+                while (asp.getRunningFlag() == true) {
+                    if(asp.ex != null)
+                        throw new XMLStreamException(asp.ex.getMessage(), asp.ex);
                     asp.wait();
+                }
                 
                 return curType;
             } 
@@ -186,49 +194,101 @@
     /**
      * This method is to record attribute(not namespace) and namespace of
      * current element
+     * @throws XMLStreamException 
      * 
      */
-    protected void initialElementAttrs(Attributes attrs) {
+    protected void initialElementAttrs(Attributes attrs) throws XMLStreamException {
         if (curType == XMLStreamConstants.START_ELEMENT) {
             curAttrs.clear();
             
-            this.attrs = attrs;
+//          this.attrs = attrs;
             if (attrs != null) {
                 for (int i = 0; i < attrs.getLength(); i++) {
                     
-                    String name = attrs.getQName(i);
+                    String qname = attrs.getQName(i);
                     String value = attrs.getValue(i);
                     String type = attrs.getType(i);
+                    String uri = attrs.getURI(i);
+                    String local = attrs.getLocalName(i);
+                    
+                    //namespaces
                     
-                    if (!name.startsWith("xmlns")) {
+                    String prefix = null;
+                    if(qname.equals("xmlns")) {
+                        prefix = "";
+                        if("".equals(value))
+                            value = null;
+                        dc.addNamespace(prefix, value);
+                    }
+                    else if(qname.startsWith("xmlns:")){
+                        prefix = qname.substring(6);
+                        dc.addNamespace(prefix, value);
+                    }
+                    else { //attributes
                         Attribute attr = new Attribute();
-                        String prefix = null;
-                        String local = name;
-                        int indexPre = name.indexOf(":");
-                        if (indexPre != -1){
-                            local = name.substring(indexPre + 1);
-                            prefix = name.substring(0, indexPre);
+                        if(qname != null && !"".equals(qname)) {
+                            int indexPre = qname.indexOf(":");
+                            if (indexPre != -1){
+                                local = qname.substring(indexPre + 1);
+                                prefix = qname.substring(0, indexPre);
+                            }
+                            else {
+                                local = qname;
+                            }
                         }
+                        
                         attr.value = value;
                         attr.prefix = prefix;
                         attr.local = local;
                         attr.type = type;
+                        attr.uri = uri;
                         curAttrs.add(attr);
                     }
-                    else {
-                        
-                        String prefix = "";
-                        if (!name.equals("xmlns")) {
-                            prefix += name.substring(6);
-                        }
-                        dc.addNamespace(prefix, value);  
-                    }
                 }
+                checkDupAttrs();
             }
         }
         
     }
     
+    private void checkDupAttrs() throws XMLStreamException {
+        Attribute attr1, attr2;
+        String uri1, uri2;
+        
+        int size = curAttrs.size();
+        for(int i = 0; i < size - 1; ++i) {
+            attr1 = (Attribute)curAttrs.get(i);
+            
+            //get attr1's namespace uri
+            uri1 = attr1.uri;
+            if(uri1 == null || "".equals(uri1)) {
+                if(attr1.prefix != null)
+                    uri1 = dc.getNamespaceURI(attr1.prefix);
+                else
+                    uri1 = null;
+            }
+            
+            for(int j = i + 1; j < size; ++j) {
+                attr2 = (Attribute)curAttrs.get(j);
+                uri2 = attr2.uri;
+                
+                //get a's namespace uri
+                if(uri2 == null || "".equals(uri2)) {
+                    if(attr2.prefix != null)
+                        uri2 = dc.getNamespaceURI(attr2.prefix);
+                    else
+                        uri2 = null;
+                }
+                
+                //compare a with attr
+                if(uri1 == null && uri2 == null || uri1 != null && uri1.equals(uri2)) {
+                    if(attr1.local.equals(attr2.local))
+                        throw new XMLStreamException("Duplicate attributes");
+                }
+            }
+        }
+    }
+    
     /**
      * Test if the current event is of the given type and if the namespace and name match the current
      * namespace and name of the current event.  If the namespaceURI is null it is not checked for equality,
@@ -239,7 +299,30 @@
      * @throws XMLStreamException if the required values are not matched.
      */
     public void require(int type, String namespaceURI, String localName) throws XMLStreamException {
-        // Need to be realized
+        boolean ok = (type == this.curType);
+        
+        if (ok && localName != null) {
+            if (curType == START_ELEMENT || curType == END_ELEMENT
+                    || curType == ENTITY_REFERENCE) {
+                ok = localName.equals(getLocalName());
+            } else {
+                throw new XMLStreamException("Not Match.");
+            }
+        }
+        
+        if (ok && namespaceURI != null) {
+            if (curType == START_ELEMENT || curType == START_ELEMENT) {
+                String currNsUri = getNamespaceURI();
+                if (namespaceURI.length() == 0) {
+                    ok = (currNsUri == null);
+                } else {
+                    ok = namespaceURI.equals(currNsUri);
+                }
+            }
+        }
+        
+        if (!ok)
+            throw new XMLStreamException ("Not Match.");
     }
     
     
@@ -396,6 +479,13 @@
         return false;
     }
     
+    private Attribute getAttribute(int index) {
+        int leng = getAttributeCount();//current state being checked in this method 
+        if (index + 1 > leng || index < 0)
+            throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
+        
+        return (Attribute)curAttrs.get(index);
+    }
     
     /**
      * Returns the normalized attribute value of the
@@ -410,13 +500,20 @@
      */
     public String getAttributeValue(String namespaceURI,
             String localName) {
-        if(curType == XMLStreamConstants.START_ELEMENT){
-            String value = null;
+        if(curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.ATTRIBUTE){
+            Attribute attr;
+            String uri;
             for(int i = 0; i < curAttrs.size(); i++){
-                Attribute attr = (Attribute)curAttrs.get(i);
-                if(attr.local.equals(localName)) return attr.value;
+                attr = (Attribute)curAttrs.get(i);
+                uri = getAttributeNamespace(i);
+                if(attr.local.equals(localName)) {
+                    if(namespaceURI == null && uri == null ||
+                            namespaceURI != null && namespaceURI.equals(uri)) {
+                        return attr.value;
+                    }
+                }
             }
-            return value;
+            return null;
         }
         
         throw new IllegalStateException("Current event is not START_ELEMENT or ATTRIBUTE");
@@ -431,7 +528,7 @@
      * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
      */
     public int getAttributeCount() {
-        if (curType == XMLStreamConstants.START_ELEMENT) {
+        if (curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.ATTRIBUTE) {
             return curAttrs.size();
         }
         throw new IllegalStateException(
@@ -449,17 +546,8 @@
      *             if this is not a START_ELEMENT or ATTRIBUTE
      */
     public QName getAttributeName(int index) {
-        if (curType == XMLStreamConstants.START_ELEMENT) {
-            int leng = getAttributeCount();
-            if (index + 1 > leng || index < 0)
-                throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
-            
-            String name =  this.getAttributeLocalName(index);
-            String uri = this.getAttributeNamespace(index);
-            return new QName(uri, name);
-        }
-        throw new IllegalStateException(
-        "Current event is not START_ELEMENT or ATTRIBUTE");
+        Attribute attr = getAttribute(index);
+        return new QName(getAttributeNamespace(index), attr.local, attr.prefix);
     }
     
     /**
@@ -470,8 +558,15 @@
      * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
      */
     public String getAttributeNamespace(int index) {
-        String pre = this.getAttributePrefix(index);
-        return dc.getNamespaceURI(pre);		
+        Attribute attr = getAttribute(index);
+        if(attr.uri == null || "".equals(attr.uri)) {
+            if(attr.prefix != null)
+                return dc.getNamespaceURI(attr.prefix);
+            else
+                return null;
+        }
+        
+        return attr.uri;
     }
     
     /**
@@ -482,22 +577,8 @@
      * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
      */
     public String getAttributeLocalName(int index) {
-        
-        String attrName;
-        int leng = getAttributeCount();
-        
-        if (index + 1 > leng || index < 0)
-            throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
-        
-        if (curType == XMLStreamConstants.START_ELEMENT) {
-            Attribute indexAttr = (Attribute) curAttrs.get(index);
-            attrName = indexAttr.local;
-        }
-        else {
-            throw new IllegalStateException(
-            "Current event is not START_ELEMENT or ATTRIBUTE");
-        }
-        return attrName;
+        Attribute attr = getAttribute(index);
+        return attr.local;
     }
     
     /**
@@ -508,21 +589,8 @@
      * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
      */
     public String getAttributePrefix(int index) {
-        String attrName;
-        int leng = getAttributeCount();
-        
-        if (index + 1 > leng || index < 0)
-            throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
-        
-        if (curType == XMLStreamConstants.START_ELEMENT) {
-            Attribute indexAttr = (Attribute) curAttrs.get(index);
-            attrName = indexAttr.prefix;
-        }
-        else {
-            throw new IllegalStateException(
-            "Current event is not START_ELEMENT or ATTRIBUTE");
-        }
-        return attrName;
+        Attribute attr = getAttribute(index);
+        return attr.prefix;
     }
     
     /**
@@ -533,21 +601,8 @@
      * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
      */
     public String getAttributeType(int index) {
-        String attrType;
-        int leng = getAttributeCount();
-        
-        if (index + 1 > leng || index < 0)
-            throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
-        
-        if (curType == XMLStreamConstants.START_ELEMENT) {
-            Attribute indexAttr = (Attribute) curAttrs.get(index);
-            attrType = indexAttr.type;
-        }
-        else {
-            throw new IllegalStateException(
-            "Current event is not START_ELEMENT or ATTRIBUTE");
-        }
-        return attrType;
+        Attribute attr = getAttribute(index);
+        return attr.type;
     }
     
     /**
@@ -558,21 +613,8 @@
      * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
      */
     public String getAttributeValue(int index) {
-        String attrValue;
-        int leng = getAttributeCount();
-        
-        if (index + 1 > leng || index < 0)
-            throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
-        
-        if (curType == XMLStreamConstants.START_ELEMENT) {
-            Attribute indexAttr = (Attribute) curAttrs.get(index);
-            attrValue = indexAttr.value;
-        }
-        else {
-            throw new IllegalStateException(
-            "Current event is not START_ELEMENT or ATTRIBUTE");
-        }
-        return attrValue;
+        Attribute attr = getAttribute(index);
+        return attr.value;
     }
     
     
@@ -584,7 +626,15 @@
      * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
      */
     public boolean isAttributeSpecified(int index) {
-        return false;
+        if(curType != XMLStreamConstants.START_ELEMENT && curType != XMLStreamConstants.ATTRIBUTE) {
+            throw new IllegalStateException("Current event is not START_ELEMENT or ATTRIBUTE");
+        }
+        
+        int leng = getAttributeCount();        
+        if (index + 1 > leng || index < 0)
+            throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
+        
+        return true;
     }
     
     /**
@@ -600,7 +650,10 @@
         if(curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.END_ELEMENT){
             ArrayList al = dc.getNamespaces();
             
-            return al.size();
+            if(al == null)
+                return 0;
+            else
+                return al.size();
         }
         if(curType == XMLStreamConstants.NAMESPACE)
             return 1;
@@ -623,7 +676,7 @@
         if(index + 1 > leng || index < 0)
             throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
         
-        if(curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.START_ELEMENT) { 
+        if(curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.END_ELEMENT) { 
             return dc.getNamespacePrefix(index);
         }
         else
@@ -646,7 +699,7 @@
         if(index + 1 > leng || index < 0)
             throw new IndexOutOfBoundsException("The index "+ index+ " should be between 0..."+ (leng-1));
         
-        if(curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.START_ELEMENT) { 
+        if(curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.END_ELEMENT) { 
             return dc.getNamespaceURI(index);
         }
         else
@@ -691,7 +744,9 @@
      * a valid text state.
      */
     public String getText() {
-        if(curType == XMLStreamConstants.CHARACTERS || curType == XMLStreamConstants.SPACE){
+        if(curType == XMLStreamConstants.CHARACTERS || curType == XMLStreamConstants.ENTITY_REFERENCE ||
+                curType == XMLStreamConstants.COMMENT || curType == XMLStreamConstants.SPACE || 
+                curType == XMLStreamConstants.DTD || curType == XMLStreamConstants.CDATA){
             char[] chars = asp.getCharacters();
             
             return  String.valueOf(chars);
@@ -713,8 +768,14 @@
      * a valid text state.
      */
     public char[] getTextCharacters() {
-        String text = getText();
-        return text.toCharArray();
+        if(curType == XMLStreamConstants.CHARACTERS || curType == XMLStreamConstants.CDATA ||
+                curType == XMLStreamConstants.COMMENT || curType == XMLStreamConstants.SPACE){
+            String text = getText();
+            return text.toCharArray();
+        }
+        
+        throw new IllegalStateException(
+        "The current event is not a valid text state.");	
     }
     
     /**
@@ -779,7 +840,14 @@
      * a valid text state.
      */
     public int getTextStart() {
-        return 0;
+        if(curType == XMLStreamConstants.CHARACTERS || curType == XMLStreamConstants.CDATA ||
+                curType == XMLStreamConstants.COMMENT || curType == XMLStreamConstants.SPACE){
+//          return asp.getCharacterStart();
+            return 0;
+        }
+        
+        throw new IllegalStateException(
+        "The current event is not a valid text state.");	
     }
     
     /**
@@ -789,8 +857,14 @@
      * a valid text state.
      */
     public int getTextLength() {
-        String text = getText();
-        return text.length();
+        if(curType == XMLStreamConstants.CHARACTERS || curType == XMLStreamConstants.CDATA ||
+                curType == XMLStreamConstants.COMMENT || curType == XMLStreamConstants.SPACE){
+//          return asp.getCharacterLength();
+            return asp.getCharacters().length;
+        }
+        
+        throw new IllegalStateException(
+        "The current event is not a valid text state.");	
     }
     
     /**
@@ -835,8 +909,17 @@
      * END_ELEMENT
      */
     public QName getName() {
-        if (curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.END_ELEMENT) { 
-            return new QName(getNamespaceURI(), getLocalName());
+        if (curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.END_ELEMENT) {
+            String prefix = getPrefix();
+            
+            QName qname;
+            if(prefix == null) {
+                qname = new QName(getNamespaceURI(), getLocalName());
+            }
+            else {
+                qname = new QName(getNamespaceURI(), getLocalName(), getPrefix()); 
+            }
+            return qname;
         }
         throw new IllegalStateException(
         "The current event is not START_ELEMENT or END_ELEMENT.");
@@ -853,7 +936,8 @@
      * END_ELEMENT or ENTITY_REFERENCE
      */
     public String getLocalName() {
-        if(curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.END_ELEMENT) { 
+        if(curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.END_ELEMENT
+                || curType == XMLStreamConstants.ENTITY_REFERENCE) { 
             String local = asp.getElementName();
             int indexPre = local.indexOf(":");
             if (indexPre != -1){
@@ -887,10 +971,19 @@
      *    or ATTRIBUTE
      */
     public String getNamespaceURI() {
-        String prefix = getPrefix();  
-        
-        if(prefix == null) prefix = ""; 
-        return dc.getNamespaceURI(prefix);
+        if(curType == XMLStreamConstants.START_ELEMENT || curType == XMLStreamConstants.END_ELEMENT || curType == XMLStreamConstants.ATTRIBUTE) { 
+            String uri = asp.getUri();
+            if(uri == null || "".equals(uri)) {
+                String prefix = getPrefix();
+                if(prefix == null) 
+                    prefix = "";
+                uri = dc.getNamespaceURI(prefix);
+            }
+            
+            return uri;
+        }
+        else
+            throw new IllegalStateException("Current event is not START_ELEMENT, END_ELEMENT");
     }
     
     /**

Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java?rev=433148&r1=433147&r2=433148&view=diff
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/StAXSAXHandler.java Sun Aug 20 21:53:50 2006
@@ -17,6 +17,7 @@
 package org.apache.xerces.stax;
 
 import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
 
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
@@ -31,25 +32,35 @@
     
     private AsyncSAXParser asp;
     private SAXXMLStreamReaderImpl reader;
-    private Locator loc;
+    private SAXLocation loc;
+    private StringBuffer buf;
     
-    public StAXSAXHandler(AsyncSAXParser asp, SAXXMLStreamReaderImpl reader, Locator loc) {
+    public StAXSAXHandler(AsyncSAXParser asp, SAXXMLStreamReaderImpl reader, SAXLocation loc) {
         this.asp = asp;
-        this.reader = reader;  
+        this.reader = reader;
         this.loc = loc;
+        if(reader.isCoalescing)
+            buf = new StringBuffer();
     }
     
     public void characters(char[] ch, int start, int length) {
         try {
             synchronized (asp) {
-                while (asp.getRunningFlag() == false)
-                    asp.wait();
-                
                 reader.setCurType(XMLStreamConstants.CHARACTERS);
                 
-                asp.setRunningFlag(false);
-                asp.setCharacters(ch, start, length);
-                asp.notify();
+                if(reader.isCoalescing) {
+                    buf.append(ch, start, length);
+                }
+                else {
+                    asp.setCharacters(ch, start, length);
+                    
+                    while (asp.getRunningFlag() == false) {
+                        asp.notify();
+                        asp.wait();
+                    }
+                    
+                    asp.setRunningFlag(false);
+                }
             }
         }
         catch(Exception e) {}
@@ -58,13 +69,15 @@
     public void endDocument(){
         try {
             synchronized (asp) {
-                while (asp.getRunningFlag() == false)
-                    asp.wait();
+                checkCoalescing();
                 
                 reader.setCurType(XMLStreamConstants.END_DOCUMENT);
+                while (asp.getRunningFlag() == false) {
+                    asp.notify();
+                    asp.wait();
+                }                
                 
                 asp.setRunningFlag(false);
-                asp.notify();
             }
         }
         catch(Exception e) {}
@@ -73,18 +86,23 @@
     public synchronized void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName){
         try {
             synchronized (asp) {
-                while (asp.getRunningFlag() == false)
-                    asp.wait();
+                checkCoalescing();
                 
                 reader.setCurType(XMLStreamConstants.END_ELEMENT);
+                if(qName != null && !"".equals(qName))
+                    asp.setElementName(qName);
+                else
+                    asp.setElementName(localName);
+                asp.setUri(uri);
                 
-                asp.setRunningFlag(false);
+                while (asp.getRunningFlag() == false) {
+                    asp.notify();
+                    asp.wait();
+                }
                 
                 NamespaceContextImpl nci = (NamespaceContextImpl)reader.getNamespaceContext();
                 nci.onEndElement();
-                
-                asp.setElementName(qName);
-                asp.notify();
+                asp.setRunningFlag(false);
             }
         }
         catch(Exception e){}
@@ -93,14 +111,17 @@
     public synchronized void ignorableWhitespace(char[] ch, int start, int length){
         try {
             synchronized (asp) {
-                while (asp.getRunningFlag() == false)
-                    asp.wait();
+                checkCoalescing();
                 
                 reader.setCurType(XMLStreamConstants.SPACE);
+                asp.setCharacters(ch, start, length);
+                
+                while (asp.getRunningFlag() == false) {
+                    asp.notify();
+                    asp.wait();
+                }                
                 
                 asp.setRunningFlag(false);
-                asp.setCharacters(ch, start, length);
-                asp.notify();
             }
         }
         catch(Exception e) {}
@@ -109,30 +130,30 @@
     public synchronized void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId){
         try {
             synchronized (asp) {
-                while (asp.getRunningFlag() == false)
-                    asp.wait();
-                
                 reader.setCurType(XMLStreamConstants.NOTATION_DECLARATION);
+                while (asp.getRunningFlag() == false) {
+                    asp.notify();
+                    asp.wait();
+                }
                 
                 asp.setRunningFlag(false);
-                asp.notify();
             }
         }
         catch(Exception e) {}
     }
     
     public synchronized void processingInstruction(java.lang.String target, java.lang.String data){
-        
         try {
+            reader.setCurType(XMLStreamConstants.PROCESSING_INSTRUCTION);
+            asp.setPI(data, target);
+            
             synchronized (asp) {
-                while (asp.getRunningFlag() == false)
+                while (asp.getRunningFlag() == false) {
+                    asp.notify();
                     asp.wait();
+                }
                 
-                reader.setCurType(XMLStreamConstants.PROCESSING_INSTRUCTION);
-                
-                asp.setPI(data, target);
                 asp.setRunningFlag(false);
-                asp.notify();
             }
         }
         catch(Exception e) {}
@@ -140,16 +161,15 @@
     
     public synchronized void startDocument() {
         try {
+            reader.setCurType(XMLStreamConstants.START_DOCUMENT);
+            
             synchronized (asp) {
-                while (asp.getRunningFlag() == false)
+                while (asp.getRunningFlag() == false) {
+                    asp.notify();
                     asp.wait();
-                
-                setDocumentLocator(loc);
-                
-                reader.setCurType(XMLStreamConstants.START_DOCUMENT);
+                }
                 
                 asp.setRunningFlag(false);
-                asp.notify();
             }
         }
         catch(Exception e) {}
@@ -158,54 +178,103 @@
     public synchronized void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, Attributes attributes){
         try {
             synchronized (asp) {
-                while (asp.getRunningFlag() == false)
-                    asp.wait();
+                checkCoalescing();
                 
                 reader.setCurType(XMLStreamConstants.START_ELEMENT);
-                
-                asp.setRunningFlag(false);
-                
                 reader.initialElementAttrs(attributes);
                 
                 NamespaceContextImpl nci = (NamespaceContextImpl)reader.getNamespaceContext();
                 nci.onStartElement();
-                asp.setElementName(qName);
-                asp.notify();
+                if(qName != null && !"".equals(qName))
+                    asp.setElementName(qName);
+                else
+                    asp.setElementName(localName);
+                asp.setUri(uri);
+                
+                while (asp.getRunningFlag() == false) {
+                    asp.notify();
+                    asp.wait();
+                }
+                
+                asp.setRunningFlag(false);                
             }
         }
-        catch(Exception e) {}
+        catch(XMLStreamException e) {
+            asp.ex = e;
+        } catch (InterruptedException e) {
+        }
     }
     
     
     public synchronized void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName){
-        System.out.println("ENTITY_DECLARATION");
+//      System.out.println("ENTITY_DECLARATION");
         try {
             synchronized (asp) {
-                while (asp.getRunningFlag() == false)
-                    asp.wait();
                 reader.setCurType(XMLStreamConstants.ENTITY_DECLARATION);
+                while (asp.getRunningFlag() == false) {
+                    asp.notify();
+                    asp.wait();
+                }
+                
                 asp.setRunningFlag(false);
-                asp.notify();
             }
         }
         catch(Exception e) {}
     }
     
-    // Need to be realized
-    /*
-     public synchronized void startPrefixMapping(java.lang.String prefix, java.lang.String uri){
-     System.out.println("startPrefixMapping");
-     asp.setRunningFlag(false);
-     }
-     
-     public synchronized void endPrefixMapping(java.lang.String prefix){
-     System.out.println("endPrefixMapping");
-     asp.setRunningFlag(false);
-     }
-     
-     public synchronized void skippedEntity(java.lang.String name){
-     System.out.println("skippedEntity");
-     asp.setRunningFlag(false);
-     }
+    /**
+     * If feature http://xml.org/sax/features/namespace-prefixes is set to false,
+     * namespace binding is done in this method.
      */
+    public synchronized void startPrefixMapping(java.lang.String prefix, java.lang.String uri){
+        try {
+            if(!asp.xr.getFeature("http://xml.org/sax/features/namespace-prefixes")) {
+                NamespaceContextImpl nci = (NamespaceContextImpl)reader.getNamespaceContext();
+                nci.addNamespace(prefix, uri);
+            }
+        } catch (Exception e) {
+            //It is said that
+            //all XMLReaders are required to recognize the http://xml.org/sax/features/namespaces 
+            //and the http://xml.org/sax/features/namespace-prefixes feature names
+            //in SAX JavaDoc.
+        }
+    }
+    
+    public synchronized void setDocumentLocator(Locator locator) {
+        loc.setLocator(locator);
+    }
+    
+    public synchronized void skippedEntity(java.lang.String name){
+        try {
+            synchronized (asp) {
+                checkCoalescing();
+                
+                reader.setCurType(XMLStreamConstants.ENTITY_REFERENCE);
+                asp.setElementName(name);
+                asp.setCharacters(null, 0, 0);
+                while (asp.getRunningFlag() == false) {
+                    asp.notify();
+                    asp.wait();
+                }
+                
+                asp.setRunningFlag(false);
+            }
+        }
+        catch(Exception e) {}
+    }
+    
+    private void checkCoalescing() throws InterruptedException {
+        if(reader.isCoalescing && reader.curType == XMLStreamConstants.CHARACTERS) {
+            char[] chs = buf.toString().toCharArray();
+            asp.setCharacters(chs, 0, chs.length);
+            buf.setLength(0);
+            
+            while (asp.getRunningFlag() == false) {
+                asp.notify();
+                asp.wait();
+            }
+            
+            asp.setRunningFlag(false);
+        }
+    }
 }

Modified: xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java?rev=433148&r1=433147&r2=433148&view=diff
==============================================================================
--- xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java (original)
+++ xerces/java/branches/stax-dev/src/org/apache/xerces/stax/XMLInputFactoryImpl.java Sun Aug 20 21:53:50 2006
@@ -44,24 +44,27 @@
  * @version $Id$
  */
 public class XMLInputFactoryImpl extends XMLInputFactory {
-
+    
+    ConfigurationContext config = new ConfigurationContext();
+    
     public XMLInputFactoryImpl() {}
-
+    
     public XMLStreamReader createXMLStreamReader(Reader reader)
-            throws XMLStreamException {
+    throws XMLStreamException {
         return null;
     }
-
+    
     public XMLStreamReader createXMLStreamReader(Source source)
-        throws XMLStreamException {
+    throws XMLStreamException {
         if (source instanceof SAXSource) {
             SAXSource ss = (SAXSource) source;
             InputSource is = ss.getInputSource();
             XMLReader xr = ss.getXMLReader();
-            SAXXMLStreamReaderImpl sxsReader = new SAXXMLStreamReaderImpl(xr, is, this);
             if(is == null || xr == null)
                 throw new XMLStreamException(
                 "Can only create StAX reader for a SAXSource if Reader and InputStream exposed by getSource()");
+            
+            SAXXMLStreamReaderImpl sxsReader = new SAXXMLStreamReaderImpl(xr, is, this);
             return sxsReader;
         }
         if (source instanceof DOMSource) {
@@ -76,10 +79,10 @@
     }
     
     public XMLStreamReader createXMLStreamReader(InputStream stream)
-            throws XMLStreamException {
+    throws XMLStreamException {
         return null;
     }
-
+    
     public XMLStreamReader createXMLStreamReader(InputStream stream,
             String encoding) throws XMLStreamException {
         return null;
@@ -89,34 +92,34 @@
             InputStream stream) throws XMLStreamException {
         return null;
     }
-
+    
     public XMLStreamReader createXMLStreamReader(String systemId, Reader reader)
-            throws XMLStreamException {
+    throws XMLStreamException {
         return null;
     }
     
     public XMLEventReader createXMLEventReader(Reader reader)
-            throws XMLStreamException {
+    throws XMLStreamException {
         return null;
     }
-
+    
     public XMLEventReader createXMLEventReader(String systemId, Reader reader)
-            throws XMLStreamException {
+    throws XMLStreamException {
         return null;
     }
-
+    
     public XMLEventReader createXMLEventReader(XMLStreamReader reader)
-            throws XMLStreamException {
+    throws XMLStreamException {
         return null;
     }
     
     public XMLEventReader createXMLEventReader(Source source)
-            throws XMLStreamException {
+    throws XMLStreamException {
         return null;
     }
-
+    
     public XMLEventReader createXMLEventReader(InputStream stream)
-            throws XMLStreamException {
+    throws XMLStreamException {
         return null;
     }
     
@@ -124,12 +127,12 @@
             String encoding) throws XMLStreamException {
         return null;
     }
-
+    
     public XMLEventReader createXMLEventReader(String systemId,
             InputStream stream) throws XMLStreamException {
         return null;
     }
-
+    
     public XMLStreamReader createFilteredReader(XMLStreamReader reader,
             StreamFilter filter) throws XMLStreamException {
         return null;
@@ -139,37 +142,77 @@
             EventFilter filter) throws XMLStreamException {
         return null;
     }
-
+    
+    /**
+     * The resolver that will be set on any XMLStreamReader or XMLEventReader created by this factory instance.
+     */
     public XMLResolver getXMLResolver() {
-        return null;
+        return config.getXMLResolver();
     }
     
-    public void setXMLResolver(XMLResolver resolver) {
+    /**
+     * The resolver that will be set on any XMLStreamReader or XMLEventReader created by this factory instance.
+     * @param resolver the resolver to use to resolve references
+     */
+    public void  setXMLResolver(XMLResolver resolver) {
+        config.setXMLResolver(resolver);
     }
     
+    /**
+     * The reporter that will be set on any XMLStreamReader or XMLEventReader created by this factory instance.
+     */
     public XMLReporter getXMLReporter() {
-        return null;
+        return config.getXMLReporter();
     }
-
+    
+    /**
+     * The reporter that will be set on any XMLStreamReader or XMLEventReader created by this factory instance.
+     * @param reporter the resolver to use to report non fatal errors
+     */
     public void setXMLReporter(XMLReporter reporter) {
+        config.setXMLReporter(reporter);
     }
-
-    public void setProperty(String name, Object value)
-            throws IllegalArgumentException {
+    
+    
+    /**
+     * Set a user defined event allocator for events
+     * @param allocator the user defined allocator
+     */
+    public void setEventAllocator(XMLEventAllocator allocator) { 
+        config.setEventAllocator(allocator);
     }
-
-    public Object getProperty(String name) throws IllegalArgumentException {
-        return null;
+    
+    /**
+     * Gets the allocator used by streams created with this factory
+     */
+    public XMLEventAllocator getEventAllocator() {
+        return config.getEventAllocator();
     }
-
-    public boolean isPropertySupported(String name) {
-        return false;
+    
+    /**
+     * Specifies that the stream produced by this code will append all adjacent text nodes. 
+     */  
+    public void setCoalescing(boolean coalescing){
+        config.setCoalescing(coalescing);
     }
-
-    public void setEventAllocator(XMLEventAllocator allocator) {
+    
+    /**
+     * Indicates whether or not the factory is configured to produced streams that coalesce adjacent text nodes.
+     */
+    public boolean isCoalescing(){
+        return config.isCoalescing();
     }
-
-    public XMLEventAllocator getEventAllocator() {
-        return null;
+    
+    public void setProperty(String name, Object value) throws IllegalArgumentException {
+        // TODO - cwitt : check against supported feature list
+        config.setProperty(name,value);
+    }
+    
+    public Object getProperty(String name) throws IllegalArgumentException {
+        return config.getProperty(name);
+    }
+    
+    public boolean isPropertySupported(String name) {
+        return config.isPropertySupported(name);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org