You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ru...@apache.org on 2005/10/17 15:45:25 UTC

svn commit: r325890 - in /webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl: dom/ dom/factory/ llom/

Author: ruchithf
Date: Mon Oct 17 06:40:59 2005
New Revision: 325890

URL: http://svn.apache.org/viewcvs?rev=325890&view=rev
Log:
An update to the OM-DOM implementation: A lot more to complete :-)

Added:
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/DOMUtil.java
Modified:
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttrImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttributeMap.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/factory/OMDOMFactory.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttrImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttrImpl.java?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttrImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttrImpl.java Mon Oct 17 06:40:59 2005
@@ -40,7 +40,7 @@
 	
 	private NamespaceImpl namespace;
 	
-	private boolean specified;
+	private boolean used;
 	
 	protected AttrImpl(DocumentImpl ownerDocument) {
 		super(ownerDocument);
@@ -51,6 +51,11 @@
 		this.attrValue = new TextImpl(value);
 		this.namespace = (NamespaceImpl)ns;
 	}
+	
+	public AttrImpl(String name, String value) {
+		this.attrName = name;
+		this.attrValue = new TextImpl(value);
+	}
 
 	///
 	///org.w3c.dom.Node methods
@@ -93,8 +98,7 @@
 	}
 
 	public int getType() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		return Node.ATTRIBUTE_NODE;
 	}
 
 	public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
@@ -118,8 +122,7 @@
 	}
 
 	public OMNamespace getNamespace() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		return this.namespace;
 	}
 
 	public QName getQName() {
@@ -155,6 +158,20 @@
 	public void setType(int nodeType) throws OMException {
 		//TODO
 		throw new UnsupportedOperationException("TODO");
+	}
+
+	/**
+	 * @return Returns the used.
+	 */
+	protected boolean isUsed() {
+		return used;
+	}
+
+	/**
+	 * @param used The used to set.
+	 */
+	protected void setUsed(boolean used) {
+		this.used = used;
 	}
 
 	

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttributeMap.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttributeMap.java?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttributeMap.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/AttributeMap.java Mon Oct 17 06:40:59 2005
@@ -38,6 +38,8 @@
 
 	public Node removeNamedItem(String name) throws DOMException {
 		// TODO 
+		
+		//TODO Set used to false
 		return super.removeNamedItem(name);
 	}
 	
@@ -78,6 +80,7 @@
         
         attr.ownerNode = this.ownerNode; //Set the owner node
         attr.isOwned(true); //To indicate that this attr belong to an element
+        attr.setUsed(true); //Setting used to true 
         
         int i = findNamePoint(attr.getNodeName(),0);
         

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java Mon Oct 17 06:40:59 2005
@@ -146,4 +146,5 @@
 		}
 		
 	}
+
 }

Added: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/DOMUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/DOMUtil.java?rev=325890&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/DOMUtil.java (added)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/DOMUtil.java Mon Oct 17 06:40:59 2005
@@ -0,0 +1,39 @@
+package org.apache.axis2.om.impl.dom;
+
+class DOMUtil {
+
+	public static boolean isValidChras(String value) {
+		// TODO check for valid characters
+		throw new UnsupportedOperationException("TODO");
+	}
+	
+	public static boolean isValidNamespace(String namespaceURI, String qualifiedname) {
+		// TODO check for valid namespace
+		/**
+		 * if the qualifiedName has a prefix and the namespaceURI is null, if
+		 * the qualifiedName has a prefix that is "xml" and the namespaceURI is
+		 * different from " http://www.w3.org/XML/1998/namespace", or if the
+		 * qualifiedName, or its prefix, is "xmlns" and the namespaceURI is
+		 * different from " http://www.w3.org/2000/xmlns/".
+		 */
+		throw new UnsupportedOperationException("TODO");
+	}
+	
+	/**
+	 * Get the local name from a qualified name 
+	 * @param qualifiedName
+	 * @return
+	 */
+	public static String getLocalName(String qualifiedName) {
+		return qualifiedName.split(":")[1];
+	}
+	
+	/**
+	 * Get the prefix from a qualified name
+	 * @param qualifiedName
+	 * @return
+	 */
+	public static String getPrefix(String qualifiedName) {
+		return qualifiedName.split(":")[0];
+	}
+}

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java Mon Oct 17 06:40:59 2005
@@ -19,28 +19,40 @@
 import org.apache.axis2.om.OMElement;
 import org.apache.axis2.om.OMException;
 import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.OMText;
 import org.apache.axis2.om.OMXMLParserWrapper;
 import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.om.impl.llom.OMNamespaceImpl;
+import org.apache.axis2.om.impl.llom.OMStAXWrapper;
+import org.apache.axis2.om.impl.llom.traverse.OMChildElementIterator;
+import org.apache.axis2.om.impl.llom.util.EmptyIterator;
+import org.apache.axis2.soap.impl.llom.SOAPConstants;
 import org.w3c.dom.Attr;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import java.io.ByteArrayOutputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-import java.util.Iterator;
 
 /**
+ * Implementation of the org.w3c.dom.Element and org.apache.axis2.om.Element
+ * interfaces.
  * @author Ruchith Fernando (ruchith.fernando@gmail.com)
  */
 public class ElementImpl extends ParentNode implements Element,OMElement {
 	
-	private NamespaceImpl namespace;
+	private OMNamespace namespace;
 	private String tagName;
-	
+	private AttributeMap attributes;
+	private HashMap namespaces;
 	/**
 	 * @param ownerDocument
 	 */
@@ -112,15 +124,7 @@
 		//This is an Eement Node...
 	}
 
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMNode#serialize(org.apache.axis2.om.OMOutput)
-	 */
-	public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
-	}
 
-	
 	///
 	/// org.w3c.dom.Element methods
 	///
@@ -132,116 +136,252 @@
 		return this.tagName;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Removes an attribute by name.
+	 * @param name The name of the attribute to remove
 	 * @see org.w3c.dom.Element#removeAttribute(java.lang.String)
 	 */
-	public void removeAttribute(String arg0) throws DOMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public void removeAttribute(String name) throws DOMException {
+		if(this.isReadonly()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
+		}
+		
+		if(this.attributes != null) {
+			this.attributes.removeNamedItem(name);
+		}
 	}
 
 	/* (non-Javadoc)
 	 * @see org.w3c.dom.Element#hasAttribute(java.lang.String)
 	 */
-	public boolean hasAttribute(String arg0) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public boolean hasAttribute(String name) {
+		return this.getAttributeNode(name) != null;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Look in the local list of attributes and return if found
+	 * if the local list is null return null
 	 * @see org.w3c.dom.Element#getAttribute(java.lang.String)
 	 */
 	public String getAttribute(String arg0) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		if(attributes == null) {
+			return "";
+		} else {
+			return ((Attr)attributes.getNamedItem(arg0)).getValue();
+		}
 	}
 
 	/* (non-Javadoc)
 	 * @see org.w3c.dom.Element#removeAttributeNS(java.lang.String, java.lang.String)
 	 */
-	public void removeAttributeNS(String arg0, String arg1) throws DOMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
+		if(this.isReadonly()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
+		}
+		
+		if(this.attributes != null) {
+			this.attributes.removeNamedItemNS(namespaceURI, localName);
+		}
 	}
 
 	/* (non-Javadoc)
 	 * @see org.w3c.dom.Element#setAttribute(java.lang.String, java.lang.String)
 	 */
-	public void setAttribute(String arg0, String arg1) throws DOMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public void setAttribute(String name, String value) throws DOMException {
+		//Check for invalid charaters
+		if(!DOMUtil.isValidChras(name)) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
+            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
+		}
+		
+		if(this.isReadonly()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
+		}
+		if(this.attributes == null) {
+			this.attributes = new AttributeMap((ParentNode)this.ownerNode);
+		}
+		this.attributes.setNamedItem(new AttrImpl(name, value));
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Returns whether the  given attr is available or not
 	 * @see org.w3c.dom.Element#hasAttributeNS(java.lang.String, java.lang.String)
 	 */
-	public boolean hasAttributeNS(String arg0, String arg1) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public boolean hasAttributeNS(String namespaceURI, String localName) {
+		return this.getAttributeNodeNS(namespaceURI, localName) != null;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Retrieves an attribute node by name. 
 	 * @see org.w3c.dom.Element#getAttributeNode(java.lang.String)
 	 */
-	public Attr getAttributeNode(String arg0) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public Attr getAttributeNode(String name) {
+		if(this.attributes == null) {
+			return null;
+		}
+		
+		return (AttrImpl)this.attributes.getNamedItem(name);
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Removes the specified attribute node
 	 * @see org.w3c.dom.Element#removeAttributeNode(org.w3c.dom.Attr)
 	 */
-	public Attr removeAttributeNode(Attr arg0) throws DOMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
+		if(isReadonly()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
+		} 
+		if(this.attributes == null || this.attributes.getNamedItem(oldAttr.getName()) == null) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
+            throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
+		}
+		AttrImpl tempAttr = (AttrImpl)this.attributes.removeNamedItem(oldAttr.getName());
+		return tempAttr;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Adds a new attribute node.
 	 * @see org.w3c.dom.Element#setAttributeNode(org.w3c.dom.Attr)
 	 */
-	public Attr setAttributeNode(Attr arg0) throws DOMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public Attr setAttributeNode(Attr attr) throws DOMException {
+		AttrImpl attrImpl = (AttrImpl)attr;
+
+		if(attrImpl.isOwned()) {//check for ownership
+			if(!this.getOwnerDocument().equals(attr.getOwnerDocument())) {
+				String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
+	            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
+			}
+		}
+		
+		if(this.isReadonly()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
+		}
+		
+		//check whether the attr is in use
+		if(attrImpl.isUsed()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INUSE_ATTRIBUTE_ERR", null);
+            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
+		}
+		
+		if(this.attributes == null) {
+			this.attributes = new AttributeMap((ParentNode)this.ownerNode);
+		}
+
+		return (Attr)this.attributes.setNamedItem(attr);
+
 	}
 
 	/* (non-Javadoc)
 	 * @see org.w3c.dom.Element#setAttributeNodeNS(org.w3c.dom.Attr)
 	 */
-	public Attr setAttributeNodeNS(Attr arg0) throws DOMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public Attr setAttributeNodeNS(Attr attr) throws DOMException {
+		
+		AttrImpl attrImpl = (AttrImpl)attr;
+
+		if(attrImpl.isOwned()) {//check for ownership
+			if(!this.getOwnerDocument().equals(attr.getOwnerDocument())) {
+				String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
+	            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
+			}
+		}
+		
+		if(this.isReadonly()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
+		}
+		
+		//check whether the attr is in use
+		if(attrImpl.isUsed()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INUSE_ATTRIBUTE_ERR", null);
+            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, msg);
+		}
+		
+		if(this.attributes == null) {
+			this.attributes = new AttributeMap((ParentNode)this.ownerNode);
+		}
+
+		//handle the namespaces
+        if (attr.getNamespaceURI() != null && findNamespace(attr.getNamespaceURI(), attr.getPrefix()) == null) {
+        	//TODO checkwhether the same ns is declared with a different prefix and remove it
+        	this.declareNamespace(new NamespaceImpl(attr.getNamespaceURI(),attr.getPrefix()));
+        }
+		
+		return (Attr)this.attributes.setNamedItemNS(attr);
+		
 	}
 
-	/* (non-Javadoc)
-	 * @see org.w3c.dom.Element#getElementsByTagName(java.lang.String)
-	 */
-	public NodeList getElementsByTagName(String arg0) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
-	}
 
-	/* (non-Javadoc)
+	/**
+	 * Retrieves an attribute value by local name and namespace URI. 
 	 * @see org.w3c.dom.Element#getAttributeNS(java.lang.String, java.lang.String)
 	 */
-	public String getAttributeNS(String arg0, String arg1) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public String getAttributeNS(String namespaceURI, String localName) {
+		if(this.attributes == null) {
+			return "";
+		}
+		
+		return this.attributes.getNamedItemNS(namespaceURI, localName).getNodeValue();
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Adds a new attribute
 	 * @see org.w3c.dom.Element#setAttributeNS(java.lang.String, java.lang.String, java.lang.String)
 	 */
-	public void setAttributeNS(String arg0, String arg1, String arg2) throws DOMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException {
+		
+        if (namespaceURI != null && findNamespace(namespaceURI, DOMUtil.getPrefix(qualifiedName)) == null) {
+        	//TODO checkwhether the same ns is declared with a different prefix and remove it
+        	this.declareNamespace(new NamespaceImpl(namespaceURI,DOMUtil.getPrefix(qualifiedName)));
+        }
+        
+		this.addAttribute(namespaceURI,qualifiedName,value);
+	}
+	
+	private OMAttribute addAttribute(String namespaceURI, String qualifiedName, String value) throws DOMException {
+		if(!DOMUtil.isValidChras(qualifiedName)) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
+            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
+		}
+		
+		if(this.isReadonly()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
+		}
+		
+		if(!DOMUtil.isValidNamespace(namespaceURI, qualifiedName)) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR", null);
+            throw new DOMException(DOMException.NAMESPACE_ERR, msg);			
+		}
+		
+		if(this.attributes == null) {
+			this.attributes = new AttributeMap((ParentNode)this.ownerNode);
+		}
+		
+		//Check whether there's an existing Attr with same local name and namespace URI
+		Attr attributeNode = this.getAttributeNodeNS(namespaceURI, DOMUtil.getLocalName(qualifiedName));
+		if(attributeNode != null) {
+			AttrImpl tempAttr = ((AttrImpl)attributeNode);
+			tempAttr.setOMNamespace(new NamespaceImpl(namespaceURI,DOMUtil.getPrefix(qualifiedName)));
+			tempAttr.setValue(value);
+			return tempAttr;
+		} else {
+			NamespaceImpl ns = new NamespaceImpl(namespaceURI, DOMUtil.getPrefix(qualifiedName));
+			AttrImpl attr = new AttrImpl(DOMUtil.getLocalName(qualifiedName),ns,value);
+			return attr;
+		}
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Retrieves an Attr node by local name and namespace URI. 
 	 * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String, java.lang.String)
 	 */
-	public Attr getAttributeNodeNS(String arg0, String arg1) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public Attr getAttributeNodeNS(String namespaceURI, String localName) {
+		return (this.attributes == null)?null:(Attr)this.attributes.getNamedItemNS(namespaceURI,localName);
 	}
 
 	/* (non-Javadoc)
@@ -251,23 +391,14 @@
 		//TODO
 		throw new UnsupportedOperationException("TODO");
 	}
-	
 
-	public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
-	}
-
-	public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
-	}
-
-	public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException {
+	/* (non-Javadoc)
+	 * @see org.w3c.dom.Element#getElementsByTagName(java.lang.String)
+	 */
+	public NodeList getElementsByTagName(String arg0) {
 		//TODO
 		throw new UnsupportedOperationException("TODO");
 	}
-
 	
 	///
 	///OmElement methods
@@ -277,181 +408,344 @@
 	 * @see org.apache.axis2.om.OMElement#addAttribute(org.apache.axis2.om.OMAttribute)
 	 */
 	public OMAttribute addAttribute(OMAttribute attr) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		
+        OMNamespace namespace = attr.getNamespace();
+        if ( namespace != null && this.findNamespace(namespace.getName(), namespace.getPrefix()) == null) {
+            this.declareNamespace(namespace.getName(), namespace.getPrefix());
+        }
+        
+		if(attr.getNamespace() != null) { //If the attr has a namespace
+			return (AttrImpl)this.setAttributeNode((Attr)attr);
+		} else {
+			return (AttrImpl)this.setAttributeNodeNS((Attr)attr);
+		}
 	}
 
 	/**
+	 * The behaviour of this is the same as org.w3c.dom.Element#setAttributeNS
 	 * @see org.apache.axis2.om.OMElement#addAttribute(java.lang.String, java.lang.String, org.apache.axis2.om.OMNamespace)
 	 */
 	public OMAttribute addAttribute(String attributeName, String value, OMNamespace ns) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		
+        if (ns != null && findNamespace(ns.getName(), ns.getPrefix()) != null){
+            declareNamespace(ns);
+        }
+        
+		return this.addAttribute(ns.getName(),attributeName,value);
 	}
 
 	/**
 	 * @see org.apache.axis2.om.OMElement#declareNamespace(org.apache.axis2.om.OMNamespace)
 	 */
 	public OMNamespace declareNamespace(OMNamespace namespace) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+        if (namespaces == null) {
+            this.namespaces = new HashMap(5);
+        }
+        namespaces.put(namespace.getPrefix(), namespace);
+        return namespace;
 	}
 
 	/**
 	 * @see org.apache.axis2.om.OMElement#declareNamespace(java.lang.String, java.lang.String)
 	 */
 	public OMNamespace declareNamespace(String uri, String prefix) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+        OMNamespaceImpl ns = new OMNamespaceImpl(uri, prefix);
+        return declareNamespace(ns);
 	}
 
 	/**
 	 * @see org.apache.axis2.om.OMElement#findNamespace(java.lang.String, java.lang.String)
 	 */
 	public OMNamespace findNamespace(String uri, String prefix) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
-	}
-
-	/**
-	 * @see org.apache.axis2.om.OMElement#getAllAttributes()
-	 */
-	public Iterator getAllAttributes() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
-	}
 
+        // check in the current element
+        OMNamespace namespace = findDeclaredNamespace(uri, prefix);
+        if (namespace != null) {
+            return namespace;
+        }
+
+        // go up to check with ancestors
+        if (this.parentNode != null) {
+            //For the OMDocumentImpl there won't be any explicit namespace
+            //declarations, so going up the parent chain till the document
+            //element should be enough.
+            if (parentNode instanceof OMElement) {
+                namespace = ((ElementImpl) parentNode).findNamespace(uri, prefix);
+            }
+        }
+
+        if (namespace == null && uri != null && prefix != null
+                && prefix.equals(SOAPConstants.XMLNS_PREFIX)
+                && uri.equals(SOAPConstants.XMLNS_URI)) {
+            declareNamespace(SOAPConstants.XMLNS_URI, SOAPConstants.XMLNS_PREFIX);
+            namespace = findNamespace(uri, prefix);
+        }
+        return namespace;
+	}
+    /**
+     * This will ckeck for the namespace <B>only</B> in the current Element.
+     * <p/>
+     * This can also be used to retrieve the prefix of a known namespace URI
+     */
+    private OMNamespace findDeclaredNamespace(String uri, String prefix) {
+        if (namespaces == null) {
+            return null;
+        }
+        if (prefix == null || "".equals(prefix)) {
+            Iterator namespaceListIterator = namespaces.values().iterator();
+            while (namespaceListIterator.hasNext()) {
+                OMNamespace omNamespace =
+                        (OMNamespace) namespaceListIterator.next();
+                if (omNamespace.getName() != null &&
+                        omNamespace.getName().equals(uri)) {
+                    return omNamespace;
+                }
+            }
+            return null;
+        } else {
+            return (OMNamespace) namespaces.get(prefix);
+        }
+    }
+    
 	/**
-	 * @see org.apache.axis2.om.OMElement#getAllDeclaredNamespaces()
-	 */
-	public Iterator getAllDeclaredNamespaces() throws OMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
-	}
-
-	/* (non-Javadoc)
+	 * Returns a named attribute if present.
 	 * @see org.apache.axis2.om.OMElement#getAttribute(javax.xml.namespace.QName)
 	 */
 	public OMAttribute getAttribute(QName qname) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		if(this.attributes == null) {
+			return null;
+		}
+		
+		if(qname.getNamespaceURI() == null || qname.getNamespaceURI().equals("")){
+			return (AttrImpl)this.getAttributeNode(qname.getLocalPart());
+		} else {
+			return (AttrImpl)this.getAttributeNodeNS(qname.getNamespaceURI(), qname.getLocalPart());
+		}
 	}
 
 	/* (non-Javadoc)
 	 * @see org.apache.axis2.om.OMElement#getBuilder()
 	 */
 	public OMXMLParserWrapper getBuilder() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		return this.builder;
 	}
 
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMElement#getChildElements()
-	 */
-	public Iterator getChildElements() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
-	}
 
-	/* (non-Javadoc)
+	/**
+	 * Returns the first attribute of the set of attributes if there
+	 * are any attributes. Otherwise returns null
 	 * @see org.apache.axis2.om.OMElement#getFirstAttribute(javax.xml.namespace.QName)
 	 */
 	public OMAttribute getFirstAttribute(QName qname) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		if(this.attributes == null) {
+			return null;
+		} else {
+			return (AttrImpl)this.attributes.getItem(0);
+		}
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Returns the first Element node
 	 * @see org.apache.axis2.om.OMElement#getFirstElement()
 	 */
 	public OMElement getFirstElement() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+        OMNode node = getFirstOMChild();
+        while (node != null) {
+            if (node.getType() == Node.ELEMENT_NODE) {
+                return (OMElement) node;
+            } else {
+                node = node.getNextOMSibling();
+            }
+        }
+        return null;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Returns the namespace of this element
 	 * @see org.apache.axis2.om.OMElement#getNamespace()
 	 */
 	public OMNamespace getNamespace() throws OMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		return this.namespace;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Returns the QName of this element
 	 * @see org.apache.axis2.om.OMElement#getQName()
 	 */
 	public QName getQName() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+        QName qName;
+        if (namespace != null) {
+            if (namespace.getPrefix() != null) {
+                qName = new QName(namespace.getName(), tagName, namespace.getPrefix());
+            } else {
+                qName = new QName(namespace.getName(), tagName);
+            }
+        } else {
+            qName = new QName(tagName);
+        }
+        return qName;
 	}
 
-    public String toStringWithConsume() throws XMLStreamException {
-        // TODO : Ruchith please implement this ;).
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
-    }
 
-    /* (non-Javadoc)
-      * @see org.apache.axis2.om.OMElement#getText()
-      */
-    public String getText() {
-        //TODO
-        throw new UnsupportedOperationException("TODO");
-    }
 
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMElement#getXMLStreamReader()
-	 */
-	public XMLStreamReader getXMLStreamReader() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
-	}
+    /**
+	 * select all the text children and concat them to a single string
+	 * @see org.apache.axis2.om.OMElement#getText()
+	 */
+	public String getText() {
+		String childText = "";
+		OMNode child = this.getFirstOMChild();
+		OMText textNode;
+
+		while (child != null) {
+			if (child.getType() == OMNode.TEXT_NODE) {
+				textNode = (OMText) child;
+				if (textNode.getText() != null
+						&& !"".equals(textNode.getText())) {
+					childText += textNode.getText();
+				}
+			}
+			child = child.getNextOMSibling();
+		}
 
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMElement#getXMLStreamReaderWithoutCaching()
-	 */
-	public XMLStreamReader getXMLStreamReaderWithoutCaching() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		return childText;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Removes an attribute fron the element
+	 * 
 	 * @see org.apache.axis2.om.OMElement#removeAttribute(org.apache.axis2.om.OMAttribute)
 	 */
 	public void removeAttribute(OMAttribute attr) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		this.removeAttributeNode((AttrImpl)attr);
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Sets the OM builder
 	 * @see org.apache.axis2.om.OMElement#setBuilder(org.apache.axis2.om.OMXMLParserWrapper)
 	 */
 	public void setBuilder(OMXMLParserWrapper wrapper) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		this.builder = wrapper;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Set the local name
 	 * @see org.apache.axis2.om.OMElement#setLocalName(java.lang.String)
 	 */
 	public void setLocalName(String localName) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		this.tagName = localName;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Set the namespace
 	 * @see org.apache.axis2.om.OMElement#setNamespace(org.apache.axis2.om.OMNamespace)
 	 */
 	public void setNamespace(OMNamespace namespace) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		this.namespace = namespace;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Creates a text node with the given value and adds it to the 
+	 * element
 	 * @see org.apache.axis2.om.OMElement#setText(java.lang.String)
 	 */
 	public void setText(String text) {
+		if(this.isReadonly()) {
+			String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
+		}
+		
+		TextImpl textNode = (TextImpl)((DocumentImpl)this.ownerNode).createTextNode(text);
+		this.addChild(textNode);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.om.OMNode#serialize(org.apache.axis2.om.OMOutput)
+	 */
+	public void serialize(OMOutputImpl omOutput) throws XMLStreamException {
 		//TODO
 		throw new UnsupportedOperationException("TODO");
 	}
+
+	public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {
+		//TODO
+		throw new UnsupportedOperationException("TODO");
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.om.OMElement#getXMLStreamReaderWithoutCaching()
+	 */
+	public XMLStreamReader getXMLStreamReaderWithoutCaching() {
+		return getXMLStreamReader(false);
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.om.OMElement#getXMLStreamReader()
+	 */
+	public XMLStreamReader getXMLStreamReader() {
+		return getXMLStreamReader(true);
+	}
 	
+
+    /**
+     * getXMLStreamReader
+     *
+     * @return reader
+     */
+    private XMLStreamReader getXMLStreamReader(boolean cache) {
+        if ((builder == null) && !cache) {
+            throw new UnsupportedOperationException(
+                    "This element was not created in a manner to be switched");
+        }
+        if (builder.isCompleted() && !cache) {
+            throw new UnsupportedOperationException(
+                    "The parser is already consumed!");
+        }
+        return new OMStAXWrapper(builder, this, cache);
+    }
+    
+	
+    public String toStringWithConsume() throws XMLStreamException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OMOutputImpl out = new OMOutputImpl(baos, false);
+        this.serializeAndConsume(out);
+        out.flush();
+        return new String(baos.toByteArray());
+    }
+    
+    /**
+     * Overridden toString() for ease of debuging
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+    	return (this.namespace != null)?namespace.getName():"" + this.tagName;
+    }
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.om.OMElement#getChildElements()
+	 */
+	public Iterator getChildElements() {
+		return new OMChildElementIterator(getFirstElement());
+	}
+	
+	/**
+	 * @see org.apache.axis2.om.OMElement#getAllDeclaredNamespaces()
+	 */
+	public Iterator getAllDeclaredNamespaces() throws OMException {
+        if (namespaces == null) {
+            return null;
+        }
+        return namespaces.values().iterator();
+	}
+	
+	/**
+	 * @see org.apache.axis2.om.OMElement#getAllAttributes()
+	 */
+	public Iterator getAllAttributes() {
+        if (attributes == null) {
+            return new EmptyIterator();
+        }
+//        return 
+        //TODO Create a new AttrIterator and return it
+        throw new UnsupportedOperationException("TODO");
+	}
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java Mon Oct 17 06:40:59 2005
@@ -28,6 +28,7 @@
 import org.w3c.dom.NodeList;
 
 import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
 
 /**
  * @author Ruchith Fernando (ruchith.fernando@gmail.com)
@@ -71,6 +72,7 @@
     protected NodeImpl(DocumentImpl ownerDocument) {
     
         this.ownerNode = ownerDocument;
+        this.isOwned(true);
     }
 
     protected NodeImpl() {
@@ -436,7 +438,8 @@
 						"HIERARCHY_REQUEST_ERR", null));		
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Build next element
 	 * @see org.apache.axis.om.OMNode#build()
 	 */
 	public void build() {
@@ -444,8 +447,26 @@
 			this.builder.next();
 	}
 	
+	/**
+	 * sets the owner document
+	 * @param document
+	 */
 	protected void SetOwnerDocument(DocumentImpl document) {
 		this.ownerNode = document;
+		this.isOwned(true);
 	}
+	
+    public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
+        serialize(omOutput);
+        omOutput.flush();
+    }
+    
+    public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
+        serializeAndConsume(omOutput);
+        omOutput.flush();
+    }
+
 	
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java Mon Oct 17 06:40:59 2005
@@ -321,5 +321,5 @@
 		//TODO isAncestor
 		return true;
 	}
-	
+
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/factory/OMDOMFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/factory/OMDOMFactory.java?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/factory/OMDOMFactory.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/factory/OMDOMFactory.java Mon Oct 17 06:40:59 2005
@@ -39,6 +39,10 @@
 
 import javax.xml.namespace.QName;
 
+/**
+ * 
+ * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ */
 public class OMDOMFactory implements OMFactory {
 	
 	public OMDocument createOMDocument() {

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java Mon Oct 17 06:40:59 2005
@@ -16,7 +16,16 @@
 
 package org.apache.axis2.om.impl.llom;
 
-import org.apache.axis2.om.*;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMAttribute;
+import org.apache.axis2.om.OMConstants;
+import org.apache.axis2.om.OMContainer;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.OMText;
+import org.apache.axis2.om.OMXMLParserWrapper;
 import org.apache.axis2.om.impl.OMContainerEx;
 import org.apache.axis2.om.impl.OMNodeEx;
 import org.apache.axis2.om.impl.OMOutputImpl;
@@ -28,13 +37,14 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
 import java.io.ByteArrayOutputStream;
 import java.util.HashMap;
 import java.util.Iterator;
 
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
 /**
  * Class OMElementImpl
  */
@@ -684,7 +694,7 @@
      *
      * @throws XMLStreamException
      */
-    public void serializeAndConsume(org.apache.axis2.om.impl.OMOutputImpl omOutput) throws XMLStreamException {
+    public void serializeAndConsume(OMOutputImpl omOutput) throws XMLStreamException {
         this.serialize(omOutput, false);
     }
 

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java?rev=325890&r1=325889&r2=325890&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMStAXWrapper.java Mon Oct 17 06:40:59 2005
@@ -156,7 +156,7 @@
      * @param builder
      * @param startNode
      */
-    OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode) {
+    public OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode) {
         this(builder, startNode, false);
     }
 
@@ -167,7 +167,7 @@
      * @param startNode
      * @param cache
      */
-    OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode,
+    public OMStAXWrapper(OMXMLParserWrapper builder, OMElement startNode,
                   boolean cache) {
 
         // create a navigator