Author: veithen
Date: Sat Jul  7 13:26:00 2012
New Revision: 1358563

URL: http://svn.apache.org/viewvc?rev=1358563&view=rev
Log:
Fixed a ClassCastException that occurs when attempting to discard a document 
element.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDiscardDocumentElement.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1358563&r1=1358562&r2=1358563&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
 Sat Jul  7 13:26:00 2012
@@ -350,17 +350,16 @@ public abstract class StAXBuilder implem
                  }
 
             } else {
-                OMElement parent = (OMElement) element.getParent();
+                OMContainer parent = element.getParent();
                 if (parent == null) {
                     throw new OMException();
+                } else {
+                    ((OMContainerEx) parent).setFirstChild(null);
+                    lastNode = parent instanceof OMDocument ? null : 
(OMNode)parent;
                 }
-                ((OMContainerEx) parent).setFirstChild(null);
-                lastNode = parent;
             }
             
-        } catch (OMException e) {
-            throw e;
-        } catch (Exception e) {
+        } catch (XMLStreamException e) {
             throw new OMException(e);
         } 
     }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1358563&r1=1358562&r2=1358563&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
 Sat Jul  7 13:26:00 2012
@@ -152,6 +152,7 @@ public class OMTestSuiteBuilder extends 
         addTest(new 
org.apache.axiom.ts.om.element.TestDeclareNamespaceWithGeneratedPrefix3(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestDigestWithNamespace(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestDigestWithoutNamespace(metaFactory));
+        addTest(new 
org.apache.axiom.ts.om.element.TestDiscardDocumentElement(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestDiscardIncomplete(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestDiscardPartiallyBuilt(metaFactory));
         addTest(new 
org.apache.axiom.ts.om.element.TestFindNamespaceByNamespaceURIMasked(metaFactory));

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDiscardDocumentElement.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDiscardDocumentElement.java?rev=1358563&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDiscardDocumentElement.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDiscardDocumentElement.java
 Sat Jul  7 13:26:00 2012
@@ -0,0 +1,48 @@
+/*
+ * 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.om.element;
+
+import java.io.StringReader;
+
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMNode#discard()} on an incomplete {@link 
OMElement} that is a
+ * document element, i.e. the parent of which is an {@link OMDocument}.
+ */
+public class TestDiscardDocumentElement extends AxiomTestCase {
+    public TestDiscardDocumentElement(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        OMDocument document = OMXMLBuilderFactory.createOMBuilder(factory, new 
StringReader(
+                "<root><a>text</a></root>")).getDocument();
+        OMElement element = document.getOMDocumentElement();
+        element.discard();
+        assertNull(document.getFirstOMChild());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestDiscardDocumentElement.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to