Author: amilas
Date: Mon Feb 22 04:58:29 2010
New Revision: 912481

URL: http://svn.apache.org/viewvc?rev=912481&view=rev
Log:
fixing the RAMPART-282. Here the problem is that the adb MTOMAwareOMBuilder 
keeps namespaces in a map and
it does not remove the namespace when the go out of scope. Now it keeps 
namesapces added while an element at the top
and remove them when the end element is written.

Modified:
    
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
    
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMStreamNamespaceContext.java

Modified: 
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java?rev=912481&r1=912480&r2=912481&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/MTOMAwareOMBuilder.java
 Mon Feb 22 04:58:29 2010
@@ -33,9 +33,7 @@
 import javax.xml.stream.XMLStreamWriter;
 
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Stack;
+import java.util.*;
 
 
 public class MTOMAwareOMBuilder implements XMLStreamWriter, DataHandlerWriter {
@@ -54,6 +52,12 @@
 
     private OMStreamNamespaceContext omStreamNamespaceContext;
 
+    /**
+     * this stack keeps the name spaces added to the oMElementStack at a 
pirticular element
+     * when end element is written the namspeces added at a pirticulare 
element is removed.
+     */
+    private Stack<List<String>> namespacesListStack;
+
 
     public MTOMAwareOMBuilder() {
         omFactory = OMAbstractFactory.getOMFactory();
@@ -62,6 +66,7 @@
         omStreamNamespaceContext = new OMStreamNamespaceContext();
         namespaceOMNamesapceMap = new HashMap();
         prefixNum = 0;
+        namespacesListStack = new Stack<List<String>>();
 
     }
 
@@ -85,6 +90,8 @@
                 omNamespace = omFactory.createOMNamespace(namespace, prefix);
                 this.omStreamNamespaceContext.registerNamespace(namespace, 
prefix);
                 namespaceOMNamesapceMap.put(namespace, omNamespace);
+                // add this namespce to top list as well
+                namespacesListStack.peek().add(namespace);
             }
         }
         return omNamespace;
@@ -99,6 +106,8 @@
     }
 
     public void writeStartElement(String prefix, String localName, String 
namespace) throws XMLStreamException {
+        // add a new stack element at the start of a new element
+        namespacesListStack.push(new ArrayList<String>());
         OMNamespace omNamespace = getOMNamespace(namespace, prefix);
         currentOMElement = omFactory.createOMElement(localName, omNamespace);
         if (!omElementStack.isEmpty()) {
@@ -128,6 +137,12 @@
 
     public void writeEndElement() throws XMLStreamException {
         omElementStack.pop();
+        // remove the namespaces declared by this element
+        List<String> addedNamespaces = namespacesListStack.pop();
+        for (String namespace : addedNamespaces){
+            namespaceOMNamesapceMap.remove(namespace);
+            omStreamNamespaceContext.removeNamespce(namespace);
+        }
     }
 
     public void writeEndDocument() throws XMLStreamException {

Modified: 
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMStreamNamespaceContext.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMStreamNamespaceContext.java?rev=912481&r1=912480&r2=912481&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMStreamNamespaceContext.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/writer/OMStreamNamespaceContext.java
 Mon Feb 22 04:58:29 2010
@@ -52,5 +52,10 @@
         return prefixToNamespaceMap.keySet().iterator();
     }
 
+    public void removeNamespce(String namespaceURI){
+        String prefix = (String) 
this.namespaceToPrefixMap.remove(namespaceURI);
+        this.prefixToNamespaceMap.remove(prefix);
+    }
+
 
 }


Reply via email to