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 ve...@apache.org on 2008/12/22 23:42:54 UTC

svn commit: r728816 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/test/java/org/apache/axiom/om/ axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/ axiom-dom/src/te...

Author: veithen
Date: Mon Dec 22 14:42:53 2008
New Revision: 728816

URL: http://svn.apache.org/viewvc?rev=728816&view=rev
Log:
DOOM: Added a ProcessingInstruction implementation.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMDocumentTestBase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMDocumentTestBase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMDocumentTestBase.java?rev=728816&r1=728815&r2=728816&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMDocumentTestBase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/OMDocumentTestBase.java Mon Dec 22 14:42:53 2008
@@ -43,7 +43,11 @@
         this.omImplementation = omImplementation;
     }
 
-    public void testOMDocument() throws XMLStreamException {
+    public void testParse() {
+        checkSampleXML(getSampleOMDocument(sampleXML));
+    }
+    
+    public void testSerializeAndConsume() throws XMLStreamException {
         // read the string in to the builder
         OMDocument omDocument = getSampleOMDocument(sampleXML);
 
@@ -54,12 +58,14 @@
         outXML = new String(outStream.toByteArray());
 
         // again load that to another builder
-        OMDocument secondDocument = getSampleOMDocument(outXML);
-
+        checkSampleXML(getSampleOMDocument(outXML));
+    }
+    
+    private void checkSampleXML(OMDocument document) {
         // check for the comment and the PI
         boolean commentFound = false;
         boolean piFound = false;
-        Iterator children = secondDocument.getChildren();
+        Iterator children = document.getChildren();
         while (children.hasNext()) {
             OMNode omNode = (OMNode) children.next();
             if (omNode instanceof OMComment) {
@@ -72,8 +78,6 @@
             }
         }
         assertTrue(commentFound && piFound);
-
-
     }
 
     /**

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=728816&r1=728815&r2=728816&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java Mon Dec 22 14:42:53 2008
@@ -221,10 +221,9 @@
         throw new UnsupportedOperationException("TODO");
     }
 
-    public ProcessingInstruction createProcessingInstruction(String arg0,
-                                                             String arg1) throws DOMException {
-        // TODO
-        throw new UnsupportedOperationException("TODO");
+    public ProcessingInstruction createProcessingInstruction(String target,
+                                                             String data) throws DOMException {
+        return new ProcessingInstructionImpl(this, target, data, factory);
     }
 
     public Text createTextNode(String value) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=728816&r1=728815&r2=728816&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java Mon Dec 22 14:42:53 2008
@@ -232,9 +232,10 @@
                 // set the document element
                 ((DocumentImpl) this).documentElement = (ElementImpl) newDomChild;
             } else if (!(newDomChild instanceof CommentImpl
+                    || newDomChild instanceof ProcessingInstructionImpl
                     || newDomChild instanceof DocumentFragmentImpl)) {
-                // TODO: we should also check for ProcessingInstruction and DocumentType,
-                //       but since we don't have implementations yet, we can leave it
+                // TODO: we should also check for DocumentType,
+                //       but since we don't have an implementation yet, we can leave it
                 //       like this for now
                 throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                         DOMMessageFormatter.formatMessage(

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java?rev=728816&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ProcessingInstructionImpl.java Mon Dec 22 14:42:53 2008
@@ -0,0 +1,106 @@
+/*
+ * 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.om.impl.dom;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMProcessingInstruction;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Node;
+import org.w3c.dom.ProcessingInstruction;
+
+public class ProcessingInstructionImpl extends ChildNode implements ProcessingInstruction, OMProcessingInstruction {
+    private String target;
+    private String value;
+
+    public ProcessingInstructionImpl(DocumentImpl ownerDocument, String target, String value,
+            OMFactory factory) {
+        
+        super(ownerDocument, factory);
+        this.target = target;
+        this.value = value;
+        done = true;
+    }
+
+    public int getType() {
+        return OMNode.PI_NODE;
+    }
+
+    public void setType(int nodeType) throws OMException {
+        if (nodeType != OMNode.PI_NODE) {
+            throw new OMException("Can't change the type of a ProcessingInstruction node");
+        }
+    }
+    
+    public short getNodeType() {
+        return Node.PROCESSING_INSTRUCTION_NODE;
+    }
+
+    public String getTarget() {
+        return target;
+    }
+
+    public void setTarget(String target) {
+        this.target = target;
+    }
+
+    public String getValue() {
+        return value;
+    }
+    
+    public void setValue(String text) {
+        this.value = text;
+    }
+    
+    public String getData() {
+        return value;
+    }
+    
+    public void setData(String data) throws DOMException {
+        if (!isReadonly()) {
+            value = data;
+        } else {
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                                   DOMMessageFormatter.formatMessage(
+                                           DOMMessageFormatter.DOM_DOMAIN,
+                                           "NO_MODIFICATION_ALLOWED_ERR", null));
+        }
+    }
+    
+    public String getNodeName() {
+        return target;
+    }
+
+    public String getNodeValue() throws DOMException {
+        return value;
+    }
+
+    public void internalSerialize(XMLStreamWriter writer) throws XMLStreamException {
+        writer.writeProcessingInstruction(target + " ", value);
+    }
+
+    public void internalSerializeAndConsume(XMLStreamWriter writer) throws XMLStreamException {
+        internalSerialize(writer);
+    }
+}

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=728816&r1=728815&r2=728816&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Mon Dec 22 14:42:53 2008
@@ -46,6 +46,7 @@
 import org.apache.axiom.om.impl.dom.NamespaceImpl;
 import org.apache.axiom.om.impl.dom.OMDOMException;
 import org.apache.axiom.om.impl.dom.ParentNode;
+import org.apache.axiom.om.impl.dom.ProcessingInstructionImpl;
 import org.apache.axiom.om.impl.dom.TextImpl;
 import org.w3c.dom.Node;
 
@@ -361,8 +362,10 @@
 
     public OMProcessingInstruction createOMProcessingInstruction(
             OMContainer parent, String piTarget, String piData) {
-        // TODO
-        throw new UnsupportedOperationException("TODO");
+        ProcessingInstructionImpl pi =
+            new ProcessingInstructionImpl(getDocumentFromParent(parent), piTarget, piData, this);
+        parent.addChild(pi);
+        return pi;
     }
 
     public OMComment createOMComment(OMContainer parent, String content) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java?rev=728816&r1=728815&r2=728816&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DocumentImplTest.java Mon Dec 22 14:42:53 2008
@@ -36,7 +36,7 @@
         super(new OMDOMImplementation());
     }
 
-    public void testOMDocument() throws XMLStreamException {
+    public void testSerializeAndConsume() throws XMLStreamException {
         // TODO: temporarily skip this; doesn't work yet
     }
 
@@ -119,6 +119,7 @@
                 Document doc = dbf.newDocumentBuilder().newDocument();
                 
                 doc.appendChild(doc.createComment("some comment"));
+                doc.appendChild(doc.createProcessingInstruction("pi", "data"));
                 
                 // Document Object Model (DOM) Level 3 Core Specification, section 1.1.1
                 // says that text nodes are not allowed as children of a document.
@@ -139,7 +140,8 @@
                     assertEquals(DOMException.HIERARCHY_REQUEST_ERR, ex.code);
                 }
                 
-                // A comment after the document element is allowed
+                // PIs and comments after the document element are allowed
+                doc.appendChild(doc.createProcessingInstruction("pi", "data"));
                 doc.appendChild(doc.createComment("some comment"));
                 
                 // Again, text nodes are not allowed