ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1335796 - in /webservices/axiom/branches/AXIOM-420/modules: axiom-api/src/main/java/org/apache/axiom/om/impl/builder/ axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/
Date Tue, 08 May 2012 22:13:32 GMT
Author: veithen
Date: Tue May  8 22:13:31 2012
New Revision: 1335796

URL: http://svn.apache.org/viewvc?rev=1335796&view=rev
Log:
No need to perform namespace repairing. OMDataSource is expected to produce XML that is well
formed with respect to namespaces.

Modified:
    webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
    webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
    webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java?rev=1335796&r1=1335795&r2=1335796&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/BuilderUtil.java
Tue May  8 22:13:31 2012
@@ -18,19 +18,14 @@
  */
 package org.apache.axiom.om.impl.builder;
 
-import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.OMElementEx;
-import org.apache.axiom.om.impl.util.OMSerializerUtil;
 
-/**
- * For internal use only.
- */
-public class BuilderUtil {
+class BuilderUtil {
     private BuilderUtil() {}
     
-    public static void setNamespace(OMElement element, String namespaceURI, String prefix,
boolean namespaceURIInterning) {
+    static void setNamespace(OMElement element, String namespaceURI, String prefix, boolean
namespaceURIInterning) {
         if (prefix == null) {
             prefix = "";
         }
@@ -54,29 +49,4 @@ public class BuilderUtil {
             element.setNamespaceWithNoFindInCurrentScope(namespace);
         }
     }
-    
-    public static void processAttribute(OMElement element, String prefix, String namespaceURI,
String localName, String value, String type) {
-        OMNamespace namespace = null;
-        if (namespaceURI != null && namespaceURI.length() > 0) {
-
-            // prefix being null means this elements has a default namespace or it has inherited
-            // a default namespace from its parent
-            namespace = element.findNamespace(namespaceURI, prefix);
-            if (namespace == null) {
-                if (prefix == null || "".equals(prefix)) {
-                    prefix = OMSerializerUtil.getNextNSPrefix();
-                }
-                namespace = element.declareNamespace(namespaceURI, prefix);
-            }
-        }
-
-        // todo if the attributes are supposed to namespace qualified all the time
-        // todo then this should throw an exception here
-
-        OMAttribute attr = element.addAttribute(localName,
-                          value, namespace);
-        if (type != null) {
-            attr.setAttributeType(type);
-        }
-    }
 }

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1335796&r1=1335795&r2=1335796&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
Tue May  8 22:13:31 2012
@@ -21,17 +21,20 @@ package org.apache.axiom.om.impl.builder
 
 import org.apache.axiom.ext.stax.datahandler.DataHandlerReader;
 import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.util.stax.XMLStreamReaderUtils;
 import org.apache.commons.logging.Log;
@@ -202,9 +205,31 @@ public abstract class StAXBuilder implem
     protected void processAttributes(OMElement node) {
         int attribCount = parser.getAttributeCount();
         for (int i = 0; i < attribCount; i++) {
-            BuilderUtil.processAttribute(node, parser.getAttributePrefix(i),
-                    parser.getAttributeNamespace(i), parser.getAttributeLocalName(i),
-                    parser.getAttributeValue(i), parser.getAttributeType(i));
+            String uri = parser.getAttributeNamespace(i);
+            String prefix = parser.getAttributePrefix(i);
+
+
+            OMNamespace namespace = null;
+            if (uri != null && uri.length() > 0) {
+
+                // prefix being null means this elements has a default namespace or it has
inherited
+                // a default namespace from its parent
+                namespace = node.findNamespace(uri, prefix);
+                if (namespace == null) {
+                    if (prefix == null || "".equals(prefix)) {
+                        prefix = OMSerializerUtil.getNextNSPrefix();
+                    }
+                    namespace = node.declareNamespace(uri, prefix);
+                }
+            }
+
+            // todo if the attributes are supposed to namespace qualified all the time
+            // todo then this should throw an exception here
+
+            OMAttribute attr = node.addAttribute(parser.getAttributeLocalName(i),
+                              parser.getAttributeValue(i), namespace);
+            attr.setAttributeType(parser.getAttributeType(i));
+            
         }
     }
 

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1335796&r1=1335795&r2=1335796&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Tue May  8 22:13:31 2012
@@ -433,12 +433,16 @@ public class OMElementImpl extends OMNod
     }
 
     public OMNamespace addNamespaceDeclaration(String uri, String prefix) {
+        OMNamespace ns = new OMNamespaceImpl(uri, prefix);
+        addNamespaceDeclaration(ns);
+        return ns;
+    }
+    
+    void addNamespaceDeclaration(OMNamespace ns) {
         if (namespaces == null) {
             this.namespaces = new HashMap(5);
         }
-        OMNamespace ns = new OMNamespaceImpl(uri, prefix);
-        namespaces.put(prefix, ns);
-        return ns;
+        namespaces.put(ns.getPrefix(), ns);
     }
 
     /** @return Returns namespace. */
@@ -649,9 +653,6 @@ public class OMElementImpl extends OMNod
                     attr.getLocalName(), attr.getNamespace(), attr.getAttributeValue(), attr.getOMFactory());
         }
 
-        if (attributes == null) {
-            this.attributes = new LinkedHashMap(5);
-        }
         OMNamespace namespace = attr.getNamespace();
         if (namespace != null) {
             String uri = namespace.getNamespaceURI();
@@ -664,6 +665,14 @@ public class OMElementImpl extends OMNod
             }
         }
 
+        appendAttribute(attr);
+        return attr;
+    }
+    
+    void appendAttribute(OMAttribute attr) {
+        if (attributes == null) {
+            this.attributes = new LinkedHashMap(5);
+        }
         // Set the owner element of the attribute
         ((OMAttributeImpl)attr).owner = this;
         OMAttributeImpl oldAttr = (OMAttributeImpl)attributes.put(attr.getQName(), attr);
@@ -671,7 +680,6 @@ public class OMElementImpl extends OMNod
         if (oldAttr != null) {
             oldAttr.owner = null;
         }
-        return attr;
     }
 
     public void removeAttribute(OMAttribute attr) {

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1335796&r1=1335795&r2=1335796&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
Tue May  8 22:13:31 2012
@@ -383,6 +383,10 @@ public class OMSourcedElementImpl extend
         return super.addNamespaceDeclaration(uri, prefix);
     }
 
+    void addNamespaceDeclaration(OMNamespace ns) {
+        super.addNamespaceDeclaration(ns);
+    }
+
     public void undeclarePrefix(String prefix) {
         forceExpand();
         super.undeclarePrefix(prefix);
@@ -438,6 +442,10 @@ public class OMSourcedElementImpl extend
         return super.addAttribute(attributeName, value, namespace);
     }
 
+    void appendAttribute(OMAttribute attr) {
+        super.appendAttribute(attr);
+    }
+
     public void removeAttribute(OMAttribute attr) {
         forceExpand();
         super.removeAttribute(attr);

Modified: webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java?rev=1335796&r1=1335795&r2=1335796&view=diff
==============================================================================
--- webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
(original)
+++ webservices/axiom/branches/AXIOM-420/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/PushOMBuilder.java
Tue May  8 22:13:31 2012
@@ -25,11 +25,12 @@ import javax.xml.stream.XMLStreamExcepti
 
 import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
+import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.impl.builder.BuilderUtil;
 import org.apache.axiom.util.stax.AbstractXMLStreamWriter;
 
 // TODO: need to seed the namespace context with the namespace context from the parent!
@@ -71,14 +72,40 @@ public class PushOMBuilder extends Abstr
         throw new XMLStreamException("A DTD must not appear in element content");
     }
 
+    private OMNamespace getOMNamespace(String prefix, String namespaceURI, boolean isDecl)
{
+        if (prefix == null) {
+            prefix = "";
+        }
+        if (namespaceURI == null) {
+            namespaceURI = "";
+        }
+        if (!isDecl && namespaceURI.length() == 0) {
+            return null;
+        } else {
+            if (parent != null) {
+                // If possible, locate an existing OMNamespace object
+                OMNamespace ns = parent.findNamespaceURI(prefix);
+                if (ns != null && ns.getNamespaceURI().equals(namespaceURI)) {
+                    return ns;
+                }
+            }
+            return factory.createOMNamespace(namespaceURI, prefix);
+        }
+    }
+    
     protected void doWriteStartElement(String prefix, String localName, String namespaceURI)
{
+        // Get the OMNamespace object before we change the parent
+        OMNamespace ns = getOMNamespace(prefix, namespaceURI, false);
         if (parent == null) {
             root.validateName(prefix, localName, namespaceURI);
             parent = root;
         } else {
+            // We don't pass the namespace here in order to avoid creation of a namespace
declaration
             parent = factory.createOMElement(localName, null, parent);
         }
-        BuilderUtil.setNamespace(parent, namespaceURI, prefix, false);
+        if (ns != null) {
+            parent.setNamespaceWithNoFindInCurrentScope(ns);
+        }
     }
 
     protected void doWriteStartElement(String localName) throws XMLStreamException {
@@ -105,7 +132,11 @@ public class PushOMBuilder extends Abstr
     }
 
     protected void doWriteAttribute(String prefix, String namespaceURI, String localName,
String value) {
-        BuilderUtil.processAttribute(parent, prefix, namespaceURI, localName, value, null);
+        OMAttribute attr = factory.createOMAttribute(localName, getOMNamespace(prefix, namespaceURI,
false), value);
+        // Use the internal appendAttribute method instead of addAttribute in order to avoid
+        // automatic of a namespace declaration (the OMDataSource is required to produce
well formed
+        // XML with respect to namespaces, so it will take care of the namespace declarations).
+        ((OMElementImpl)parent).appendAttribute(attr);
     }
 
     protected void doWriteAttribute(String localName, String value) throws XMLStreamException
{
@@ -113,20 +144,11 @@ public class PushOMBuilder extends Abstr
     }
 
     protected void doWriteNamespace(String prefix, String namespaceURI) {
-        if (namespaceURI == null) {
-            namespaceURI = "";
-        }
-        // Note that the namespace declaration may already have been added automatically
by writeStartElement
-        // or writeAttribute; we count on declareNamespace to do the necessary checks
-        if (prefix == null || prefix.length() == 0) {
-            parent.declareDefaultNamespace(namespaceURI);
-        } else {
-            parent.declareNamespace(namespaceURI, prefix);
-        }
+        ((OMElementImpl)parent).addNamespaceDeclaration(getOMNamespace(prefix, namespaceURI,
true));
     }
 
     protected void doWriteDefaultNamespace(String namespaceURI) {
-        parent.declareDefaultNamespace(namespaceURI == null ? "" : namespaceURI);
+        doWriteNamespace(null, namespaceURI);
     }
 
     protected void doWriteCharacters(char[] text, int start, int len) {



Mime
View raw message