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 th...@apache.org on 2006/09/14 18:04:11 UTC

svn commit: r443391 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-tests/src/test/j...

Author: thilina
Date: Thu Sep 14 09:04:10 2006
New Revision: 443391

URL: http://svn.apache.org/viewvc?view=rev&rev=443391
Log:
Fixing http://issues.apache.org/jira/browse/WSCOMMONS-90 as discussed in the JIRA.
Also added new methods to OMText to see whether it contains binary and to get the namespace out in the case of a QName


Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.java?view=diff&rev=443391&r1=443390&r2=443391
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.java Thu Sep 14 09:04:10 2006
@@ -36,6 +36,13 @@
     boolean isCharacters();
 
     QName getTextAsQName();
+    
+    /**
+     * Returns the Namespace if this contains a QName
+     * Return null otherwise
+     * @return OMNamespace 
+     */
+    OMNamespace getNamespace();
 
     /**
      * Gets the datahandler.
@@ -54,6 +61,19 @@
      * @param value
      */
     void setOptimize(boolean value);
+    
+    /**
+     * @return Returns boolean flag saying whether the node contains
+     *         binary or not.
+     */
+    boolean isBinary();
+
+    /**
+     * Sets the isBinary flag.
+     * @param value
+     */
+    void setBinary(boolean value);
+    
 
     /**
      * Gets the content id.

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java?view=diff&rev=443391&r1=443390&r2=443391
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java Thu Sep 14 09:04:10 2006
@@ -586,4 +586,21 @@
 			this.getDataHandler();
 		}
 	}
+	public boolean isBinary() {
+		return isBinary;
+	}
+
+    /**
+     * Receiving binary can happen as either MTOM attachments or as Base64 Text
+     * In the case of Base64 user has to explicitly specify that the content is 
+     * binary, before calling getDataHandler(), getInputStream()....
+     */
+	public void setBinary(boolean value) {
+		this.isBinary = value;
+		
+	}
+
+	public OMNamespace getNamespace() {
+		return textNS;
+	}
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?view=diff&rev=443391&r1=443390&r2=443391
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java Thu Sep 14 09:04:10 2006
@@ -21,6 +21,7 @@
 import org.apache.axiom.om.impl.OMNamespaceImpl;
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
 import org.apache.axiom.om.impl.traverse.OMChildElementIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
 import org.apache.axiom.om.impl.traverse.OMChildrenQNameIterator;
@@ -186,8 +187,13 @@
      * front of the children list.
      */
     public void addChild(OMNode child) {
-        addChild((OMNodeImpl) child);
+		if (child.getOMFactory() instanceof OMLinkedListImplFactory) {
+			addChild((OMNodeImpl) child);
+		} else {
+			addChild(importNode(child));
+		}
     }
+    
 
     /**
      * Searches for children with a given QName and returns an iterator to traverse through

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java?view=diff&rev=443391&r1=443390&r2=443391
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java Thu Sep 14 09:04:10 2006
@@ -20,6 +20,8 @@
 import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
 import org.apache.axiom.om.util.StAXUtils;
 
 import javax.xml.stream.XMLStreamException;
@@ -78,11 +80,12 @@
      */
     public OMNodeImpl(OMContainer parent, OMFactory factory, boolean done) {
         this.done = done;
+        this.factory = factory;
         if ((parent != null)) {
             this.parent = (OMContainerEx) parent;
             parent.addChild(this);
         }
-        this.factory = factory;
+        
     }
 
     /**
@@ -140,6 +143,11 @@
      * @param node
      */
     public void setNextOMSibling(OMNode node) {
+		if (node ==null || node.getOMFactory() instanceof OMLinkedListImplFactory) {
+			this.nextSibling = (OMNodeImpl) node;
+		} else {
+			this.nextSibling = (OMNodeImpl)importNode(node);
+		}
         this.nextSibling = (OMNodeImpl) node;
     }
 
@@ -289,7 +297,11 @@
      * @param previousSibling
      */
     public void setPreviousOMSibling(OMNode previousSibling) {
-        this.previousSibling = (OMNodeImpl) previousSibling;
+		if (previousSibling ==null || previousSibling.getOMFactory() instanceof OMLinkedListImplFactory) {
+			this.previousSibling = (OMNodeImpl) previousSibling;
+		} else {
+			this.previousSibling = (OMNodeImpl)importNode(previousSibling);
+		}   
     }
 
     /**
@@ -410,4 +422,70 @@
     public OMFactory getOMFactory() {
         return this.factory;
     }
+    
+ 	/**	
+	 * This method is intended only to be used by Axiom intenals when merging Objects
+	 * from different Axiom implementations to the LLOM implementation.
+	 * 
+	 * @param child
+	 * @return
+	 */
+ 	protected OMNode importNode(OMNode child)
+ 	{
+ 		int type = child.getType();
+		switch (type) {
+		case (OMNode.ELEMENT_NODE): 
+		{
+			OMElement childElement = (OMElement) child;
+			OMElement newElement = (new StAXOMBuilder(this.factory, childElement
+					.getXMLStreamReader())).getDocumentElement();
+			newElement.build();
+			return newElement;
+		}
+		case (OMNode.TEXT_NODE): 
+		{
+			OMText importedText = (OMText) child;
+			OMText newText;
+			if (importedText.isBinary()) {
+				boolean isOptimize = importedText.isOptimized();
+				newText = this.factory.createOMText(importedText
+						.getDataHandler(), isOptimize);
+			}
+			else if (importedText.getNamespace()!=null)
+			{
+				newText = this.factory.createOMText(null,importedText.getTextAsQName(),importedText.getType());
+			}
+			else if (importedText.isCharacters()) {
+				newText = this.factory.createOMText(null, importedText
+						.getTextCharacters(), importedText.getType());
+			} else {
+				newText = this.factory.createOMText(null, importedText
+						.getText()/*, importedText.getOMNodeType()*/);
+			}
+			return newText;
+		}
+		
+		case (OMNode.PI_NODE): {
+			OMProcessingInstruction importedPI = (OMProcessingInstruction) child;
+			OMProcessingInstruction newPI = this.factory
+					.createOMProcessingInstruction(null, importedPI
+							.getTarget(), importedPI.getValue());
+			return newPI;
+		}
+		case (OMNode.COMMENT_NODE): {
+			OMComment importedComment = (OMComment) child;
+			OMComment newComment = this.factory.createOMComment(null,
+					importedComment.getValue());
+			return newComment;
+		}
+		case (OMNode.DTD_NODE) :{
+			OMDocType importedDocType = (OMDocType)child;
+			OMDocType newDocType = this.factory.createOMDocType(null,importedDocType.getValue());
+			return newDocType;
+		}
+		default: {
+			throw new UnsupportedOperationException("Not Implemented Yet for the given node type");
+		}
+		}
+ 	}
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java?view=diff&rev=443391&r1=443390&r2=443391
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java Thu Sep 14 09:04:10 2006
@@ -301,6 +301,13 @@
             }
         }
     }
+    
+	/* (non-Javadoc)
+	 * @see org.apache.axiom.om.OMText#getNamespace()
+	 */
+	public OMNamespace getNamespace() {
+		return textNS;
+	}
 
     public boolean isOptimized() {
         return optimize;
@@ -321,6 +328,12 @@
     public void setBinary(boolean value) {     
             isBinary = value;
     }
+    
+    public boolean isBinary()
+    {
+    	return isBinary;
+    }
+
 
     /**
      * Gets the datahandler.

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java?view=diff&rev=443391&r1=443390&r2=443391
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/llom/OMElementTest.java Thu Sep 14 09:04:10 2006
@@ -23,12 +23,16 @@
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMTestCase;
 import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
 import java.util.Iterator;
 
 public class OMElementTest extends OMTestCase implements OMConstants {
@@ -122,7 +126,41 @@
         secondElement.detach();
         assertTrue("First child should be the text child", firstElement.getFirstOMChild() instanceof OMText);
 
-
     }
 
+    public void testAddDOOMElementAsChild() throws XMLStreamException {
+    	OMFactory doomFactory = DOOMAbstractFactory.getOMFactory();
+    	OMFactory llomFactory = OMAbstractFactory.getOMFactory();
+    	String text = "This was a DOOM Text";
+    	
+    	OMElement llomRoot = llomFactory.createOMElement("root",null);
+    	
+    	OMElement doomElement = doomFactory.createOMElement("second","test","a");
+    	doomElement.setText(text);
+    	llomRoot.addChild(doomElement);
+    	
+    	OMElement newElement = (new StAXOMBuilder(this.factory, llomRoot
+				.getXMLStreamReader())).getDocumentElement();
+		newElement.build();
+		OMElement secondElement = newElement.getFirstElement();
+		assertNotNull(secondElement);
+		assertEquals(secondElement.getText(),text);		
+    }
+    
+    public void testAddDOOMTextAsChild() throws XMLStreamException {
+    	OMFactory doomFactory = DOOMAbstractFactory.getOMFactory();
+    	OMFactory llomFactory = OMAbstractFactory.getOMFactory();
+    	String text = "This was a DOOM Text";
+    	
+    	OMElement llomRoot = llomFactory.createOMElement("root",null);
+    	
+    	OMText doomText = doomFactory.createOMText(text);
+    	llomRoot.addChild(doomText);
+    	
+    	OMElement newElement = (new StAXOMBuilder(this.factory, llomRoot
+				.getXMLStreamReader())).getDocumentElement();
+		newElement.build();
+		assertEquals(newElement.getText(),text);		
+    }
+    
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org