You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ch...@apache.org on 2005/11/09 07:54:58 UTC

svn commit: r331966 - in /webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2: om/ om/impl/llom/ om/impl/llom/builder/ soap/impl/llom/builder/

Author: chinthaka
Date: Tue Nov  8 22:54:44 2005
New Revision: 331966

URL: http://svn.apache.org/viewcvs?rev=331966&view=rev
Log:
Fixing dafault namespace problem. This has to be tested.

Modified:
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java?rev=331966&r1=331965&r2=331966&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java Tue Nov  8 22:54:44 2005
@@ -288,4 +288,6 @@
      * @return null for any failure to extract a qname.
      */
     QName resolveQName(String qname);
+
+    
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=331966&r1=331965&r2=331966&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java Tue Nov  8 22:54:44 2005
@@ -144,18 +144,16 @@
              */
             if (ns == null) {
                 String prefix = qname.getPrefix();
-                if (!"".equals(prefix)) {
-                    ns = declareNamespace(namespaceURI, prefix);
-                } else {
-                    ns =
-                            declareNamespace(namespaceURI,
-                                    getNextNamespacePrefix());
-                }
+                ns = declareNamespace(namespaceURI, prefix);
             }
             if (ns != null) {
                 this.ns = (ns);
             }
-        } else {
+        }
+
+        else
+
+        {
             // no namespace URI in the given QName. No need to bother about this ??
         }
 
@@ -284,7 +282,6 @@
         return declareNamespace(ns);
     }
 
-
     /**
      * @return namespace
      */
@@ -406,7 +403,7 @@
             this.attributes = new HashMap(5);
         }
         OMNamespace namespace = attr.getNamespace();
-        if ( namespace != null && this.findNamespace(namespace.getName(), namespace.getPrefix()) == null) {
+        if (namespace != null && this.findNamespace(namespace.getName(), namespace.getPrefix()) == null) {
             this.declareNamespace(namespace.getName(), namespace.getPrefix());
         }
 
@@ -632,8 +629,8 @@
         serialize(omOutput, true);
     }
 
-    ///////////////////////////////////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////
 
     protected void serialize(OMOutputImpl omOutput, boolean cache) throws XMLStreamException {
 
@@ -641,7 +638,7 @@
             //in this case we don't care whether the elements are built or not
             //we just call the serializeAndConsume methods
             OMSerializerUtil.serializeStartpart(this, omOutput);
-            //serilize children
+//serilize children
             Iterator children = this.getChildren();
             while (children.hasNext()) {
                 ((OMNode) children.next()).serialize(omOutput);
@@ -653,7 +650,7 @@
             //has nothing to do if the element is already built!
             if (this.done) {
                 OMSerializerUtil.serializeStartpart(this, omOutput);
-                //serializeAndConsume children
+//serializeAndConsume children
                 Iterator children = this.getChildren();
                 while (children.hasNext()) {
                     //A call to the  Serialize or the serializeAndConsume wont make a difference here
@@ -670,8 +667,8 @@
         }
     }
 
-    ////////////////////////////////////////////////////////////////////////////////////////////////
-    ////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////
 
     /**
      * This was requested during the second Axis2 summit. When one call this method, this will
@@ -685,7 +682,6 @@
         this.serialize(omOutput, false);
     }
 
-
     /**
      * Method getNextNamespacePrefix
      *
@@ -737,7 +733,6 @@
         return ns;
     }
 
-
     /**
      * Method setNamespace
      */
@@ -805,15 +800,15 @@
         }
     }
 
-
     /**
      * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
      * unprefixed qnames resolve to the local namespace
+     *
      * @param qname prefixed qname string to resolve
      * @return null for any failure to extract a qname.
      */
     public QName resolveQName(String qname) {
-        ElementHelper helper=new ElementHelper(this);
+        ElementHelper helper = new ElementHelper(this);
         return helper.resolveQName(qname);
     }
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java?rev=331966&r1=331965&r2=331966&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMSerializerUtil.java Tue Nov  8 22:54:44 2005
@@ -118,10 +118,6 @@
                     writer.writeStartElement(nameSpaceName,
                             element.getLocalName());
                 } else {
-                    //todo - Need to verify whether this'll cause a problem!
-                    if (prefix == null || "".equals(prefix)) {
-                        prefix = "nsss"+ ++namespaceCounter;
-                    }
                     writer.writeStartElement(prefix, element.getLocalName(),
                             nameSpaceName);
                     writer.writeNamespace(prefix, nameSpaceName);
@@ -132,14 +128,12 @@
             }
         } else {
             writer.writeStartElement(element.getLocalName());
-            /////////////////////////////////////////////////////
-            // A sort of a hack. If the OMElement is not associated with
-            // a namespace, we deliberately associate it with the empty namespace
-            // If the OMElement is associated with a namespace, even by inheritance
-            // then it shouldn't be here!!!!. kind of ugly but perfectly legal
-            // and gets the thing done!
-            // writer.writeDefaultNamespace("");
-            /////////////////////////////////////////////////////
+            // we need to check whether there's a default namespace visible at this point because
+            // otherwise this element will go into that namespace unintentionally. So we check
+            // whether there is a default NS visible and if so turn it off.
+            if (writer.getNamespaceContext().getNamespaceURI("") != null) {
+                writer.writeDefaultNamespace("");
+            }
         }
 
         // add the namespaces
@@ -198,15 +192,15 @@
     }
 
     public static void serializeByPullStream(OMElement element, org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
-        serializeByPullStream(element,omOutput,false);
+        serializeByPullStream(element, omOutput, false);
     }
 
-    public static void serializeByPullStream(OMElement element, org.apache.axis2.om.impl.OMOutputImpl omOutput,boolean cache) throws XMLStreamException {
+    public static void serializeByPullStream(OMElement element, org.apache.axis2.om.impl.OMOutputImpl omOutput, boolean cache) throws XMLStreamException {
         StreamingOMSerializer streamingOMSerializer = new StreamingOMSerializer();
-        if (cache){
+        if (cache) {
             streamingOMSerializer.serialize(element.getXMLStreamReader(),
                     omOutput);
-        }else{
+        } else {
             XMLStreamReader xmlStreamReaderWithoutCaching = element.getXMLStreamReaderWithoutCaching();
             streamingOMSerializer.serialize(xmlStreamReaderWithoutCaching,
                     omOutput);

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java?rev=331966&r1=331965&r2=331966&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/builder/StAXOMBuilder.java Tue Nov  8 22:54:44 2005
@@ -303,28 +303,19 @@
 
         OMNamespace namespace = null;
         if (namespaceURI != null && namespaceURI.length() > 0) {
-            if (prefix == null) {
-                // this means, this elements has a default namespace or it has inherited a default namespace from its parent
-                namespace = node.findNamespace(namespaceURI, "");
-                if (namespace == null) {
-                    namespace = node.declareNamespace(namespaceURI, createPrefix());
-                }
-                if (node.getNamespace() == null) {
-                    node.setNamespace(namespace);
-                }
-            } else {
-                namespace = node.findNamespace(namespaceURI, prefix);
-                if (namespace == null) {
-                    node.setNamespace(
-                            omfactory.createOMNamespace(namespaceURI, prefix));
-                } else {
-                    node.setNamespace(namespace);
-                }
-            }
 
+            // prefix being null means this elements has a default namespace or it has inherited
+            // a default namespace from its parent
+            prefix = prefix == null ? "" : prefix;
+            namespace = node.findNamespace(namespaceURI, prefix);
 
+            if (namespace == null) {
+                namespace = node.declareNamespace(namespaceURI, prefix);
+            }
+            node.setNamespace(namespace);
         }
 
+
         int namespaceCount = parser.getNamespaceCount();
         for (int i = 0; i < namespaceCount; i++) {
             if (!parser.getNamespaceURI(i).equals(namespaceURI)){
@@ -334,7 +325,7 @@
         }
     }
 
-    
+
 
     public void setDoDebug(boolean doDebug) {
         this.doDebug = doDebug;

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java?rev=331966&r1=331965&r2=331966&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/soap/impl/llom/builder/StAXSOAPModelBuilder.java Tue Nov  8 22:54:44 2005
@@ -69,7 +69,6 @@
     private boolean processingFault = false;
 
 
-
     //added
     /* This is used to indicate whether detail element is processing in soap 1.2 builderhelper
     */
@@ -101,10 +100,10 @@
      * @param parser
      * @param factory
      * @param soapVersion parameter is to give the soap version from the transport. For example, in
-     *          HTTP case you can identify the version of the soap message u have recd by looking at
-     *          the HTTP headers. By passing that here is to check whether actually the soap message
-     *          contained also of that version. If one is not creating the builder from the transport
-     *          he can just pass null for this.
+     *                    HTTP case you can identify the version of the soap message u have recd by looking at
+     *                    the HTTP headers. By passing that here is to check whether actually the soap message
+     *                    contained also of that version. If one is not creating the builder from the transport
+     *                    he can just pass null for this.
      */
     public StAXSOAPModelBuilder(XMLStreamReader parser, SOAPFactory factory, String soapVersion) {
         super(parser);
@@ -191,8 +190,8 @@
                     constructNode((OMElement) lastNode.getParent(),
                             elementName,
                             false);
-            ((OMNodeEx)lastNode).setNextOMSibling(node);
-            ((OMNodeEx)node).setPreviousOMSibling(lastNode);
+            ((OMNodeEx) lastNode).setNextOMSibling(node);
+            ((OMNodeEx) node).setPreviousOMSibling(lastNode);
         } else {
             OMElement e = (OMElement) lastNode;
             node = constructNode((OMElement) lastNode, elementName, false);
@@ -309,36 +308,36 @@
     }
 
     private String getSenderFaultCode() {
-        if(senderfaultCode == null){
+        if (senderfaultCode == null) {
             senderfaultCode = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(envelopeNamespace.getName()) ? SOAP12Constants.FAULT_CODE_SENDER : SOAP11Constants.FAULT_CODE_SENDER;
         }
         return senderfaultCode;
     }
 
     private String getReceiverFaultCode() {
-        if(receiverfaultCode == null){
+        if (receiverfaultCode == null) {
             receiverfaultCode = SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(envelopeNamespace.getName()) ? SOAP12Constants.FAULT_CODE_RECEIVER : SOAP11Constants.FAULT_CODE_RECEIVER;
         }
         return receiverfaultCode;
     }
 
-    public void endElement(){
+    public void endElement() {
         if (lastNode.isComplete()) {
             OMElement parent = (OMElement) lastNode.getParent();
-            ((OMNodeEx)parent).setComplete(true);
+            ((OMNodeEx) parent).setComplete(true);
             lastNode = parent;
         } else {
             OMNode e = lastNode;
-            ((OMNodeEx)e).setComplete(true);
+            ((OMNodeEx) e).setComplete(true);
         }
         elementLevel--;
     }
 
     /**
      * Method createDTD
-     * 
+     * <p/>
      * Overriding the default behaviour as a SOAPMessage
-     *  should not have a DTD
+     * should not have a DTD
      */
     protected OMNode createDTD() throws OMException {
         throw new OMException("SOAP message MUST NOT contain a Document Type Declaration(DTD)");
@@ -346,8 +345,8 @@
 
     /**
      * Method createPI
-     * 
-     * Overriding the default behaviour as a SOAP Message 
+     * <p/>
+     * Overriding the default behaviour as a SOAP Message
      * should not have a PI
      */
     protected OMNode createPI() throws OMException {
@@ -376,24 +375,21 @@
         String prefix = parser.getPrefix();
         OMNamespace namespace = null;
         if (namespaceURI != null && namespaceURI.length() > 0) {
-            if (prefix == null) {
-                // this means, this elements has a default namespace or it has inherited a default namespace from its parent
-                namespace = node.findNamespace(namespaceURI, "");
-                if (namespace == null) {
-                    namespace = node.declareNamespace(namespaceURI, createPrefix());
-                }
-            } else {
-                namespace = node.findNamespace(namespaceURI, prefix);
-                if(namespace == null){
-                    namespace = node.declareNamespace(namespaceURI, prefix);
-                }
+
+            // prefix being null means this elements has a default namespace or it has inherited
+            // a default namespace from its parent
+            prefix = prefix == null ? "" : prefix;
+            namespace = node.findNamespace(namespaceURI, prefix);
+
+            if (namespace == null) {
+                namespace = node.declareNamespace(namespaceURI, prefix);
             }
             node.setNamespace(namespace);
-        }
+        } 
 
         int namespaceCount = parser.getNamespaceCount();
         for (int i = 0; i < namespaceCount; i++) {
-            if (!parser.getNamespaceURI(i).equals(namespaceURI)){
+            if (!parser.getNamespaceURI(i).equals(namespaceURI)) {
                 node.declareNamespace(parser.getNamespaceURI(i),
                         parser.getNamespacePrefix(i));
             }
@@ -405,15 +401,17 @@
                     !node.getNamespace().getName().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
                 throw new SOAPProcessingException("invalid SOAP namespace URI. " +
                         "Only " + SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI +
-                        " and "+ SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI +
+                        " and " + SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI +
                         " are supported.", SOAP12Constants.FAULT_CODE_SENDER);
             }
         }
 
     }
 
+
 /*these three methods to set and check detail element processing or mandatory fault element are present
 */
+
     public OMNamespace getEnvelopeNamespace() {
         return envelopeNamespace;
     }