You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2014/07/26 14:05:32 UTC

svn commit: r1613609 - in /webservices/axiom/trunk: aspects/core-aspects/src/main/java/org/apache/axiom/core/ implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ modules/axiom-api/src/main/java/org/apache/axiom/om/dom/ src/site/apt/ t...

Author: veithen
Date: Sat Jul 26 12:05:32 2014
New Revision: 1613609

URL: http://svn.apache.org/r1613609
Log:
DOOM's DocumentFragment implementation should not implement any Axiom APIs.

Added:
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/document/TestCreateDocumentFragmentInterfaces.java   (with props)
Modified:
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/dom/DOMMetaFactory.java
    webservices/axiom/trunk/src/site/apt/roadmap.apt
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java

Modified: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java?rev=1613609&r1=1613608&r2=1613609&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java (original)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java Sat Jul 26 12:05:32 2014
@@ -32,6 +32,5 @@ public interface CoreParentNode extends 
     void coreSetBuilder(OMXMLParserWrapper builder);
     int getState();
     void coreSetState(int state);
-    boolean isComplete();
     void build();
 }

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java?rev=1613609&r1=1613608&r2=1613609&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java (original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java Sat Jul 26 12:05:32 2014
@@ -27,7 +27,6 @@ import org.apache.axiom.om.OMCloneOption
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.impl.common.IContainer;
 import org.apache.axiom.om.impl.common.serializer.push.Serializer;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Node;
@@ -35,9 +34,8 @@ import org.w3c.dom.Node;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
-// TODO: we should not implement IContainer here
 public class DocumentFragmentImpl extends RootNode implements
-        DOMDocumentFragment, IContainer, NonDeferringParentNode {
+        DOMDocumentFragment, NonDeferringParentNode {
 
     /** @param ownerDocument  */
     public DocumentFragmentImpl(OMFactory factory) {
@@ -82,12 +80,6 @@ public class DocumentFragmentImpl extend
         return new DocumentFragmentImpl(getOMFactory());
     }
 
-    public final void setComplete(boolean state) {
-        if (state != true) {
-            throw new IllegalStateException();
-        }
-    }
-
     public final void build() {
         // A document fragment doesn't have a builder
     }

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1613609&r1=1613608&r2=1613609&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Sat Jul 26 12:05:32 2014
@@ -78,7 +78,12 @@ public class ElementImpl extends ParentN
         coreSetBuilder(builder);
         coreSetState(builder == null ? COMPLETE : INCOMPLETE);
         if (parentNode != null) {
-            ((IContainer)parentNode).addChild(this, builder != null);
+            // TODO: dirty hack to get the correct semantics (reordering) if the parent is a SOAP envelope
+            if (parentNode instanceof IContainer) {
+                ((IContainer)parentNode).addChild(this, builder != null);
+            } else {
+                parentNode.coreAppendChild(this, builder != null);
+            }
         }
         this.attributes = new AttributeMap(this);
         internalSetNamespace(generateNSDecl ? handleNamespace(this, ns, false, true) : ns);

Modified: webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/dom/DOMMetaFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/dom/DOMMetaFactory.java?rev=1613609&r1=1613608&r2=1613609&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/dom/DOMMetaFactory.java (original)
+++ webservices/axiom/trunk/modules/axiom-api/src/main/java/org/apache/axiom/om/dom/DOMMetaFactory.java Sat Jul 26 12:05:32 2014
@@ -43,6 +43,7 @@ import org.w3c.dom.Comment;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.DOMImplementation;
 import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.DocumentType;
 import org.w3c.dom.Element;
 import org.w3c.dom.EntityReference;
@@ -99,6 +100,10 @@ import org.w3c.dom.Text;
  * <td>{@link OMEntityReference}</td>
  * <td>{@link EntityReference}</td>
  * </tr>
+ * <tr>
+ * <td>-</td>
+ * <td>{@link DocumentFragment}</td>
+ * </tr>
  * </table>
  * <dl>
  * <dt>[1]
@@ -158,6 +163,11 @@ import org.w3c.dom.Text;
  * when explicitly requested using DOM's {@link Node#getOwnerDocument()} API) to avoid creating a
  * large number of temporary {@link Document} instances when the Axiom API is used. Note however
  * that this has no impact on the behavior visible to the application code.
+ * <p>
+ * As indicated in the table above, although {@link Attr} and {@link DocumentFragment} nodes are
+ * parent nodes in the DOM API, they MUST NOT implement the {@link OMContainer} interface. Only
+ * {@link OMDocument} and {@link OMElement} instances can implement that interface.
+ * <!-- TODO: describe the implications for the getParent method -->
  */
 public interface DOMMetaFactory extends OMMetaFactory {
     /**

Modified: webservices/axiom/trunk/src/site/apt/roadmap.apt
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/src/site/apt/roadmap.apt?rev=1613609&r1=1613608&r2=1613609&view=diff
==============================================================================
--- webservices/axiom/trunk/src/site/apt/roadmap.apt (original)
+++ webservices/axiom/trunk/src/site/apt/roadmap.apt Sat Jul 26 12:05:32 2014
@@ -332,3 +332,14 @@ Miscellaneous
   A new major release would be the right moment to change this and make non coalescing mode the default.
   This enables a couple of optimizations (e.g. when reading and decoding base64 from a text node) and
   ensures that an XML document can be streamed with constant memory, even if it contains large text nodes.
+
+* Don't allow <<<addChild>>> to reorder children
+
+  The <<<SOAPEnvelope>>> implementations in LLOM and DOOM override the <<<addChild>>> method to
+  reorder the nodes if an attempt is made to add a <<<SOAPHeader>>> after the <<<SOAPBody>>>.
+  This introduces unnecessary complexity in the implementation and is questionable from an OO
+  design perspective because it breaks the general contract of the <<<addChild>>> method which is
+  to add the node as the last child.
+  
+  The <<<addChild>>> implementation for <<<SOAPEnvelope>>> should not do this. Instead it should
+  just throw an exception if a <<<SOAPHeader>>> is added at the wrong position.
\ No newline at end of file

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java?rev=1613609&r1=1613608&r2=1613609&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java Sat Jul 26 12:05:32 2014
@@ -38,6 +38,7 @@ public class OMDOMTestSuiteBuilder exten
         addTest(new org.apache.axiom.ts.omdom.attr.TestGetNamespaceNormalized(metaFactory));
         addTest(new org.apache.axiom.ts.omdom.document.TestAppendChildForbidden(metaFactory, true));
         addTest(new org.apache.axiom.ts.omdom.document.TestAppendChildForbidden(metaFactory, false));
+        addTest(new org.apache.axiom.ts.omdom.document.TestCreateDocumentFragmentInterfaces(metaFactory));
         addTest(new org.apache.axiom.ts.omdom.document.TestGetOMFactory1(metaFactory));
         addTest(new org.apache.axiom.ts.omdom.document.TestGetOMFactory2(metaFactory));
         addTest(new org.apache.axiom.ts.omdom.document.TestImportNode(metaFactory));

Added: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/document/TestCreateDocumentFragmentInterfaces.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/document/TestCreateDocumentFragmentInterfaces.java?rev=1613609&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/document/TestCreateDocumentFragmentInterfaces.java (added)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/document/TestCreateDocumentFragmentInterfaces.java Sat Jul 26 12:05:32 2014
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.omdom.document;
+
+import org.apache.axiom.om.OMInformationItem;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.dom.DOMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+
+/**
+ * Tests that the {@link DocumentFragment} instances created by
+ * {@link Document#createDocumentFragment()} don't implement any Axiom interfaces.
+ */
+public class TestCreateDocumentFragmentInterfaces extends AxiomTestCase {
+    public TestCreateDocumentFragmentInterfaces(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = ((DOMMetaFactory)metaFactory).newDocumentBuilderFactory().newDocumentBuilder().newDocument();
+        DocumentFragment fragment = document.createDocumentFragment();
+        assertFalse(fragment instanceof OMInformationItem);
+    }
+}

Propchange: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/document/TestCreateDocumentFragmentInterfaces.java
------------------------------------------------------------------------------
    svn:eol-style = native