You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by di...@apache.org on 2006/10/02 05:59:01 UTC

svn commit: r451871 - /webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java

Author: dims
Date: Sun Oct  1 20:59:01 2006
New Revision: 451871

URL: http://svn.apache.org/viewvc?view=rev&rev=451871
Log:
Fix for AXIS2-1276 - Confusing Bug when calling webservice: The prefix xml cannot be bound to any namespace other than its usual namespace ...)

Modified:
    webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java

Modified: webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java?view=diff&rev=451871&r1=451870&r2=451871
==============================================================================
--- webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java (original)
+++ webservices/commons/trunk/modules/XmlSchema/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java Sun Oct  1 20:59:01 2006
@@ -31,10 +31,10 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
-
 public class XmlSchemaSerializer {
     private Hashtable schema_ns;
 
@@ -102,8 +102,10 @@
             //if the namespace is not entered then add 
             //the targetNamespace as its
             if (targetNS == null) {
-                serializedSchema.setAttributeNS(XMLNS_NAMESPACE_URI,
-                        "xmlns", schemaObj.syntacticalTargetNamespace);
+                if(!Constants.XMLNS_URI.equals(schemaObj.syntacticalTargetNamespace)){
+                    serializedSchema.setAttributeNS(XMLNS_NAMESPACE_URI,
+                            "xmlns", schemaObj.syntacticalTargetNamespace);
+                }
                 String prefix = null;
                 if(schemaObj.getNamespaceContext() != null) {
                     prefix = schemaObj.getNamespaceContext().getPrefix(schemaObj.syntacticalTargetNamespace);    
@@ -2525,14 +2527,21 @@
         Object prefix = ("".equals(namespace)) ? "" : schema_ns.get(namespace);
 
         if (prefix == null) {
-            int magicNumber = new java.util.Random().nextInt(999);
-            prefix = "gen" + magicNumber;
-            schema_ns.put(namespace, prefix);
-
+            if (Constants.XMLNS_URI.equals(namespace)) {
+                prefix = Constants.XMLNS_PREFIX;
+            } else {
+                int magicNumber = 0;
+                Collection prefixes = schema_ns.values();
+                while(prefixes.contains("ns" + magicNumber)){
+                    magicNumber++;
+                }
+                prefix = "ns" + magicNumber;
+                schema_ns.put(namespace, prefix);
 
-            //setting xmlns in schema
-            schemaElement.setAttributeNS(XMLNS_NAMESPACE_URI,
-                    "xmlns:" + prefix.toString(), namespace);
+                //setting xmlns in schema
+                schemaElement.setAttributeNS(XMLNS_NAMESPACE_URI,
+                        "xmlns:" + prefix.toString(), namespace);
+            }
         }
 
         prefixStr = prefix.toString();



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org