From 176f6afc0662e66b14e56e7569da47ff3efa843f Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 25 Feb 2009 23:55:37 +0000 Subject: Fix the push/pop out of sequence issue git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@747972 13f79535-47bb-0310-9956-ffa450edef68 --- .../processor/TuscanyXMLStreamReader.java | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'branches/sca-java-1.x/modules') diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java index f2afe419a3..e1b218d9f4 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/TuscanyXMLStreamReader.java @@ -75,22 +75,25 @@ public class TuscanyXMLStreamReader extends StreamReaderDelegate implements XMLS this.characterEncodingScheme = super.getCharacterEncodingScheme(); } + // A flag to indicate if the next() is called from nextTag() + private boolean withinNextTagMethod = false; + /* * Overriding the next() method to perform PUSH and POP operations * for the NamespaceContext for the current element */ - @Override public int next() throws XMLStreamException { - // POP the context if the element ends - if (this.getEventType() == END_ELEMENT) { + // POP the namespaces if the reader leaves the end element + if (!withinNextTagMethod && this.getEventType() == END_ELEMENT) { popContext(); } - //get the next event + // get the next event int nextEvent = super.next(); - //PUSH the events info onto the Stack - if (nextEvent == START_ELEMENT) { + + // PUSH the namespaces onto the stack as the reader enters the start element + if (!withinNextTagMethod && nextEvent == START_ELEMENT) { pushContext(); } return nextEvent; @@ -98,14 +101,20 @@ public class TuscanyXMLStreamReader extends StreamReaderDelegate implements XMLS @Override public int nextTag() throws XMLStreamException { + withinNextTagMethod = true; + // POP the namespaces out of the stack if the reader leaves the end element + if (this.getEventType() == END_ELEMENT) { + popContext(); + } + + // REVIEW: what if nextTag() calls next()? int event = super.nextTag(); + // PUSH the namespaces onto the stack as the reader enters the start element if (event == START_ELEMENT) { pushContext(); } - if (event == END_ELEMENT) { - popContext(); - } + withinNextTagMethod = false; return event; } -- cgit v1.2.3