ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1333227 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-testsui...
Date Wed, 02 May 2012 22:02:04 GMT
Author: veithen
Date: Wed May  2 22:02:04 2012
New Revision: 1333227

URL: http://svn.apache.org/viewvc?rev=1333227&view=rev
Log:
AXIOM-399: Also support creation of OMSourcedElements with unknown prefix (but known local
name and namespace URI) through the OMFactory API. This provides a more consistent alternative
to AXIOM-334. In fact, with the "lossy prefix" feature introduced by AXIOM-334, some part
of the knowledge (the local name and namespace URI) is provided through the OMFactory API
while another piece of information (the fact that the prefix is unknown) is provided through
a property set on the OMDataSource. This is not very consistent.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementVariant.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java?rev=1333227&r1=1333226&r2=1333227&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMFactory.java
Wed May  2 22:02:04 2012
@@ -116,7 +116,18 @@ public interface OMFactory {
     OMSourcedElement createOMElement(OMDataSource source);
     
     /**
-     * Create a sourced element with a known local name, namespace URI and namespace prefix.
+     * Create a sourced element with a known local name and namespace URI. If the namespace
prefix
+     * is known in advance, then the caller should specify it in the provided {@link OMNamespace}
+     * object. The caller may pass an {@link OMNamespace} instance with a <code>null</code>
prefix.
+     * This indicates that the prefix is unknown and will be determined lazily by expanding
the
+     * element.
+     * <p>
+     * Note that if the provided data source implements {@link QNameAwareOMDataSource}, then
the
+     * information returned by {@link QNameAwareOMDataSource#getPrefix()} may be used to
determine
+     * the prefix. However, this is an unusual use case.
+     * <p>
+     * Also note that if the specified namespace URI is empty, then the element can't have
a prefix
+     * and it is not necessary to expand the element to determine its prefix.
      * <p>
      * This is an optional operation which may not be supported by all factories.
      * 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java?rev=1333227&r1=1333226&r2=1333227&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/custombuilder/ByteArrayCustomBuilder.java
Wed May  2 22:02:04 2012
@@ -67,6 +67,9 @@ public class ByteArrayCustomBuilder impl
         try {
             // Get the prefix of the start tag
             String prefix = reader.getPrefix();
+            if (prefix == null) {
+                prefix = "";
+            }
             
             // Stream the events to a writer starting with the current event
             StreamingOMSerializer ser = new StreamingOMSerializer();

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1333227&r1=1333226&r2=1333227&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
Wed May  2 22:02:04 2012
@@ -92,11 +92,6 @@ public class OMSourcedElementImpl extend
     
     private XMLStreamReader readerFromDS = null;  // Reader from DataSource
 
-    private static OMNamespace normalize(OMNamespace ns) {
-        // TODO: the ns.getPrefix() == null case actually doesn't make sense for a sourced
element!
-        return ns == null || (ns.getPrefix() == null || ns.getPrefix().length() == 0) &&
ns.getNamespaceURI().length() == 0 ? null : ns;
-    }
-    
     private static OMNamespace getOMNamespace(QName qName) {
         return qName.getNamespaceURI().length() == 0 ? null
                 : new OMNamespaceImpl(qName.getNamespaceURI(), qName.getPrefix());
@@ -124,8 +119,13 @@ public class OMSourcedElementImpl extend
         }
         dataSource = source;
         isExpanded = false;
-        ns = normalize(ns);
-        if (ns == null || !isLossyPrefix(dataSource)) {
+        // Normalize the namespace. Note that this also covers the case where the
+        // namespace URI is empty and the prefix is null (in which case we know that
+        // the actual prefix must be empty)
+        if (ns != null && ns.getNamespaceURI().length() == 0) {
+            ns = null;
+        }
+        if (ns == null || !(isLossyPrefix(dataSource) || ns.getPrefix() == null)) {
             // Believe the prefix and create a normal OMNamespace
             definedNamespace = ns;
         } else {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementVariant.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementVariant.java?rev=1333227&r1=1333226&r2=1333227&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementVariant.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/OMSourcedElementVariant.java
Wed May  2 22:02:04 2012
@@ -81,6 +81,14 @@ public abstract class OMSourcedElementVa
                 }
                 return factory.createOMElement(ds, qname.getLocalPart(), ns);
             }
+        },
+        new OMSourcedElementVariant("unknown-prefix", false, false, true) {
+            public OMSourcedElement createOMSourcedElement(OMFactory factory, QName qname)
throws Exception {
+                // TODO: can't use createOMElement(QName) here because it would generate
a prefix if the prefix in the QName is empty
+                OMElement orgElement = factory.createOMElement(qname.getLocalPart(), qname.getNamespaceURI(),
qname.getPrefix());
+                return factory.createOMElement(new TestDataSource(orgElement.toString()),
+                        qname.getLocalPart(), factory.createOMNamespace(qname.getNamespaceURI(),
null));
+            }
         }
     };
     



Mime
View raw message