You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by gd...@apache.org on 2005/07/11 17:49:55 UTC
svn commit: r210150 [13/35] - in /webservices/axis/trunk/java: ./ etc/
modules/addressing/
modules/addressing/src/org/apache/axis2/handlers/addressing/
modules/addressing/test-resources/
modules/addressing/test/org/apache/axis2/handlers/addressing/ mod...
Modified: webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java?rev=210150&r1=210149&r2=210150&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java (original)
+++ webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPBodyImpl.java Mon Jul 11 08:49:30 2005
@@ -27,149 +27,152 @@
/**
* Class SOAPBodeImpl
- *
+ *
* @author Jayachandra
- * jayachandra@gmail.com
+ * jayachandra@gmail.com
*/
public class SOAPBodyImpl extends SOAPElementImpl implements SOAPBody {
- /**
- * Field omSOAPBody
- * omSOAPBody is the OM's SOAPBody object that is used for delegation purpose
- */
- private org.apache.axis2.soap.SOAPBody omSOAPBody;
-
- /**
- * Constructor SOAPBodeImpl
- * The constructor to facilitate conversion of SAAJ SOAPBody out of OM SOAPBody
- * @param omSoapBody
- */
- public SOAPBodyImpl(org.apache.axis2.soap.SOAPBody omSoapBody)
- {
- super(omSoapBody);
- this.omSOAPBody = omSoapBody;
- }
-
- /**
- * Method addFault
- * @see javax.xml.soap.SOAPBody#addFault()
- * @return
- * @throws SOAPException
- */
- public SOAPFault addFault() throws SOAPException {
- try{
- //OM SOAPFaultImpl has SOAPFaultImpl(OMElement parent, Exception e) constructor, will use that
- SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
- org.apache.axis2.soap.SOAPFault omSoapFault = soapFactory.createSOAPFault(omSOAPBody, new Exception("No explicit faultstring available"));
- omSOAPBody.addFault(omSoapFault);
- return (new SOAPFaultImpl(omSoapFault));
- }catch(Exception e)
- {
- throw new SOAPException(e);
- }
- }
-
- /**
- * Method hasFault
- * @see javax.xml.soap.SOAPBody#hasFault()
- * @return
- */
- public boolean hasFault() {
- return omSOAPBody.hasFault();
- }
-
- /**
- * Method getFault
- * @see javax.xml.soap.SOAPBody#getFault()
- * @return
- */
- public SOAPFault getFault() {
- return (new SOAPFaultImpl(omSOAPBody.getFault()));
- }
-
- /**
- * Method addBodyElement
- * @param name
- * @return
- * @throws SOAPException
- * @see javax.xml.soap.SOAPBody#addBodyElement(javax.xml.soap.Name)
- */
- public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
-
- try {
- OMFactory omFactory = OMAbstractFactory.getOMFactory();
- QName qname = new QName(name.getURI(), name.getLocalName(), name.getPrefix());
- OMElement bodyElement = omFactory.createOMElement(qname, omSOAPBody);
- omSOAPBody.addChild(bodyElement);
- return (new SOAPBodyElementImpl(bodyElement));
- } catch (Exception e)
- {
- throw new SOAPException(e);
- }
- }
-
- /**
- * Method addFault
- * @param faultCode
- * @param faultString
- * @param
- * @throws SOAPException
- * @see javax.xml.soap.SOAPBody#addFault(javax.xml.soap.Name, java.lang.String, java.util.Locale)
- */
- public SOAPFault addFault(Name faultCode, String faultString, Locale locale)
- throws SOAPException {
- try{
- //OM SOAPFaultImpl has SOAPFaultImpl(OMElement parent, Exception e) constructor, will use that
- //actually soap fault is created with the OM's default SOAPFAULT_LOCALNAME and PREFIX, b'coz I've droppe the name param
- //a work around can be possible but would be confusing as there is no straight forward soapfault constructor in om.
- //So am deferring it.
- //even locale param is dropped, don't know how to handle it at the moment. so dropped it.
- SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
- org.apache.axis2.soap.SOAPFault omSoapFault = soapFactory.createSOAPFault(omSOAPBody, new Exception(faultString));
- omSOAPBody.addFault(omSoapFault);
- return (new SOAPFaultImpl(omSoapFault));
- }catch(Exception e)
- {
- throw new SOAPException(e);
- }
- }
-
- /**
- * Method addFault
- * @param faultCode
- * @param faultString
- * @return
- * @throws SOAPException
- * @see javax.xml.soap.SOAPBody#addFault(javax.xml.soap.Name, java.lang.String)
- */
- public SOAPFault addFault(Name faultCode, String faultString)
- throws SOAPException {
- try{
- //OM SOAPFaultImpl has SOAPFaultImpl(OMElement parent, Exception e) constructor, will use that
- //actually soap fault is created with the OM's default SOAPFAULT_LOCALNAME and PREFIX, b'coz I've droppe the name param
- //a work around can be possible but would be confusing as there is no straight forward soapfault constructor in om.
- //So am deferring it.
- SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
- org.apache.axis2.soap.SOAPFault omSoapFault = soapFactory.createSOAPFault(omSOAPBody, new Exception(faultString));
- omSOAPBody.addFault(omSoapFault);
- return (new SOAPFaultImpl(omSoapFault));
- }catch(Exception e)
- {
- throw new SOAPException(e);
- }
- }
-
- /**
- * Method addDocument
- * @param document
- * @return
- * @throws SOAPException
- * @see javax.xml.soap.SOAPBody#addDocument(org.w3c.dom.Document)
- */
- public SOAPBodyElement addDocument(Document document) throws SOAPException {
- /*
- * Don't know how to resolve this as yet. So deferring it.
- */
- return null;
- }
+ /**
+ * Field omSOAPBody
+ * omSOAPBody is the OM's SOAPBody object that is used for delegation purpose
+ */
+ private org.apache.axis2.soap.SOAPBody omSOAPBody;
+
+ /**
+ * Constructor SOAPBodeImpl
+ * The constructor to facilitate conversion of SAAJ SOAPBody out of OM SOAPBody
+ *
+ * @param omSoapBody
+ */
+ public SOAPBodyImpl(org.apache.axis2.soap.SOAPBody omSoapBody) {
+ super(omSoapBody);
+ this.omSOAPBody = omSoapBody;
+ }
+
+ /**
+ * Method addFault
+ *
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPBody#addFault()
+ */
+ public SOAPFault addFault() throws SOAPException {
+ try {
+ //OM SOAPFaultImpl has SOAPFaultImpl(OMElement parent, Exception e) constructor, will use that
+ SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
+ org.apache.axis2.soap.SOAPFault omSoapFault = soapFactory.createSOAPFault(omSOAPBody, new Exception("No explicit faultstring available"));
+ omSOAPBody.addFault(omSoapFault);
+ return (new SOAPFaultImpl(omSoapFault));
+ } catch (Exception e) {
+ throw new SOAPException(e);
+ }
+ }
+
+ /**
+ * Method hasFault
+ *
+ * @return
+ * @see javax.xml.soap.SOAPBody#hasFault()
+ */
+ public boolean hasFault() {
+ return omSOAPBody.hasFault();
+ }
+
+ /**
+ * Method getFault
+ *
+ * @return
+ * @see javax.xml.soap.SOAPBody#getFault()
+ */
+ public SOAPFault getFault() {
+ return (new SOAPFaultImpl(omSOAPBody.getFault()));
+ }
+
+ /**
+ * Method addBodyElement
+ *
+ * @param name
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPBody#addBodyElement(javax.xml.soap.Name)
+ */
+ public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
+
+ try {
+ OMFactory omFactory = OMAbstractFactory.getOMFactory();
+ QName qname = new QName(name.getURI(), name.getLocalName(), name.getPrefix());
+ OMElement bodyElement = omFactory.createOMElement(qname, omSOAPBody);
+ omSOAPBody.addChild(bodyElement);
+ return (new SOAPBodyElementImpl(bodyElement));
+ } catch (Exception e) {
+ throw new SOAPException(e);
+ }
+ }
+
+ /**
+ * Method addFault
+ *
+ * @param faultCode
+ * @param faultString
+ * @param
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPBody#addFault(javax.xml.soap.Name, java.lang.String, java.util.Locale)
+ */
+ public SOAPFault addFault(Name faultCode, String faultString, Locale locale)
+ throws SOAPException {
+ try {
+ //OM SOAPFaultImpl has SOAPFaultImpl(OMElement parent, Exception e) constructor, will use that
+ //actually soap fault is created with the OM's default SOAPFAULT_LOCALNAME and PREFIX, b'coz I've droppe the name param
+ //a work around can be possible but would be confusing as there is no straight forward soapfault constructor in om.
+ //So am deferring it.
+ //even locale param is dropped, don't know how to handle it at the moment. so dropped it.
+ SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
+ org.apache.axis2.soap.SOAPFault omSoapFault = soapFactory.createSOAPFault(omSOAPBody, new Exception(faultString));
+ omSOAPBody.addFault(omSoapFault);
+ return (new SOAPFaultImpl(omSoapFault));
+ } catch (Exception e) {
+ throw new SOAPException(e);
+ }
+ }
+
+ /**
+ * Method addFault
+ *
+ * @param faultCode
+ * @param faultString
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPBody#addFault(javax.xml.soap.Name, java.lang.String)
+ */
+ public SOAPFault addFault(Name faultCode, String faultString)
+ throws SOAPException {
+ try {
+ //OM SOAPFaultImpl has SOAPFaultImpl(OMElement parent, Exception e) constructor, will use that
+ //actually soap fault is created with the OM's default SOAPFAULT_LOCALNAME and PREFIX, b'coz I've droppe the name param
+ //a work around can be possible but would be confusing as there is no straight forward soapfault constructor in om.
+ //So am deferring it.
+ SOAPFactory soapFactory = OMAbstractFactory.getDefaultSOAPFactory();
+ org.apache.axis2.soap.SOAPFault omSoapFault = soapFactory.createSOAPFault(omSOAPBody, new Exception(faultString));
+ omSOAPBody.addFault(omSoapFault);
+ return (new SOAPFaultImpl(omSoapFault));
+ } catch (Exception e) {
+ throw new SOAPException(e);
+ }
+ }
+
+ /**
+ * Method addDocument
+ *
+ * @param document
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPBody#addDocument(org.w3c.dom.Document)
+ */
+ public SOAPBodyElement addDocument(Document document) throws SOAPException {
+ /*
+ * Don't know how to resolve this as yet. So deferring it.
+ */
+ return null;
+ }
}
Modified: webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionFactoryImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionFactoryImpl.java?rev=210150&r1=210149&r2=210150&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionFactoryImpl.java (original)
+++ webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionFactoryImpl.java Mon Jul 11 08:49:30 2005
@@ -21,21 +21,22 @@
/**
* Class SOAPConnectionFactoryImpl
- *
+ *
* @author Ashutosh Shahi
- * ashutosh.shahi@gmail.com
+ * ashutosh.shahi@gmail.com
*/
public class SOAPConnectionFactoryImpl extends SOAPConnectionFactory {
/**
* Create a new <CODE>SOAPConnection</CODE>.
+ *
* @return the new <CODE>SOAPConnection</CODE> object.
- * @throws SOAPException if there was an exception
- * creating the <CODE>SOAPConnection</CODE> object.
+ * @throws SOAPException if there was an exception
+ * creating the <CODE>SOAPConnection</CODE> object.
*/
- public SOAPConnection createConnection() throws SOAPException {
-
- return new SOAPConnectionImpl();
- }
+ public SOAPConnection createConnection() throws SOAPException {
+
+ return new SOAPConnectionImpl();
+ }
}
Modified: webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java?rev=210150&r1=210149&r2=210150&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java (original)
+++ webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java Mon Jul 11 08:49:30 2005
@@ -30,42 +30,41 @@
/**
* Class SOAPConnectionImpl
- *
- * @author Ashutosh Shahi (ashutosh.shahi@gmail.com)
*
+ * @author Ashutosh Shahi (ashutosh.shahi@gmail.com)
*/
public class SOAPConnectionImpl extends SOAPConnection {
-
- /* (non-Javadoc)
- * @see javax.xml.soap.SOAPConnection#call(javax.xml.soap.SOAPMessage, java.lang.Object)
- */
- public SOAPMessage call(SOAPMessage request, Object endpoint)
- throws SOAPException {
- try{
- org.apache.axis2.soap.SOAPEnvelope envelope = ((SOAPEnvelopeImpl)request.getSOAPPart().getEnvelope()).getOMEnvelope();
-
- Call call = new Call();
- URL url = new URL(endpoint.toString());
- call.setTransportInfo(Constants.TRANSPORT_HTTP,Constants.TRANSPORT_HTTP, true);
- call.setTo(new EndpointReference(AddressingConstants.WSA_TO, url.toString()));
- org.apache.axis2.soap.SOAPEnvelope responseEnv = (org.apache.axis2.soap.SOAPEnvelope)call.invokeBlocking("echo", envelope);
- SOAPEnvelopeImpl response = new SOAPEnvelopeImpl(responseEnv);
- return new SOAPMessageImpl(response);
-
- }catch (MalformedURLException mue) {
- throw new SOAPException(mue);
- }catch (AxisFault af){
- throw new SOAPException(af);
- }
- }
-
-
- /* (non-Javadoc)
- * @see javax.xml.soap.SOAPConnection#close()
- */
- public void close() throws SOAPException {
- // TODO Auto-generated method stub
- }
+ /* (non-Javadoc)
+ * @see javax.xml.soap.SOAPConnection#call(javax.xml.soap.SOAPMessage, java.lang.Object)
+ */
+ public SOAPMessage call(SOAPMessage request, Object endpoint)
+ throws SOAPException {
+ try {
+ org.apache.axis2.soap.SOAPEnvelope envelope = ((SOAPEnvelopeImpl) request.getSOAPPart().getEnvelope()).getOMEnvelope();
+
+ Call call = new Call();
+ URL url = new URL(endpoint.toString());
+ call.setTransportInfo(Constants.TRANSPORT_HTTP, Constants.TRANSPORT_HTTP, true);
+ call.setTo(new EndpointReference(AddressingConstants.WSA_TO, url.toString()));
+ org.apache.axis2.soap.SOAPEnvelope responseEnv = (org.apache.axis2.soap.SOAPEnvelope) call.invokeBlocking("echo", envelope);
+ SOAPEnvelopeImpl response = new SOAPEnvelopeImpl(responseEnv);
+ return new SOAPMessageImpl(response);
+
+ } catch (MalformedURLException mue) {
+ throw new SOAPException(mue);
+ } catch (AxisFault af) {
+ throw new SOAPException(af);
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see javax.xml.soap.SOAPConnection#close()
+ */
+ public void close() throws SOAPException {
+ // TODO Auto-generated method stub
+
+ }
}
Modified: webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPDocumentImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPDocumentImpl.java?rev=210150&r1=210149&r2=210150&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPDocumentImpl.java (original)
+++ webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPDocumentImpl.java Mon Jul 11 08:49:30 2005
@@ -23,16 +23,16 @@
/**
* @author Ashutosh Shahi ashutosh.shahi@gmail.com
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
+ * <p/>
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
*/
public class SOAPDocumentImpl implements Document {
// Depending on the user's parser preference
protected Document delegate = null;
protected SOAPPartImpl soapPart = null;
-
+
/**
* Construct the Document
*
@@ -46,16 +46,15 @@
}
soapPart = sp;
}
-
+
public DOMImplementation getImplementation() {
return delegate.getImplementation();
}
/**
- *
* Creates an empty <code>DocumentFragment</code> object. @todo not
* implemented yet
- *
+ *
* @return A new <code>DocumentFragment</code>.
*/
public DocumentFragment createDocumentFragment() {
@@ -63,9 +62,8 @@
}
/**
- * @todo : link with SOAP
- *
* @return
+ * @todo : link with SOAP
*/
public DocumentType getDoctype() {
return delegate.getDoctype();
@@ -73,7 +71,7 @@
/**
* should not be called, the method will be handled in SOAPPart
- *
+ *
* @return
*/
public Element getDocumentElement() {
@@ -87,29 +85,29 @@
return delegate.createAttribute(name);
}
- /* (non-Javadoc)
- * @see org.w3c.dom.Document#createCDATASection(java.lang.String)
- */
- public CDATASection createCDATASection(String arg0) throws DOMException {
- // Not implementing this one, as it may not be supported in om
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Document#createComment(java.lang.String)
- */
- public Comment createComment(String arg0) {
- //Not implementing this one, as it may not be supported in om
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Document#createElement(java.lang.String)
- */
- public Element createElement(String arg0) throws DOMException {
- // TODO Auto-generated method stub
- return null;
- }
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Document#createCDATASection(java.lang.String)
+ */
+ public CDATASection createCDATASection(String arg0) throws DOMException {
+ // Not implementing this one, as it may not be supported in om
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Document#createComment(java.lang.String)
+ */
+ public Comment createComment(String arg0) {
+ //Not implementing this one, as it may not be supported in om
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Document#createElement(java.lang.String)
+ */
+ public Element createElement(String arg0) throws DOMException {
+ // TODO Auto-generated method stub
+ return null;
+ }
public Element getElementById(String elementId) {
return delegate.getElementById(elementId);
@@ -122,105 +120,101 @@
* DOMException
*/
public EntityReference createEntityReference(String name)
- throws DOMException {
- throw new java.lang.UnsupportedOperationException(
- "createEntityReference");
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Document#importNode(org.w3c.dom.Node, boolean)
- */
- public Node importNode(Node arg0, boolean arg1) throws DOMException {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Document#getElementsByTagName(java.lang.String)
- */
- public NodeList getElementsByTagName(String localName) {
- try{
- NodeListImpl list = new NodeListImpl();
- if (soapPart != null) {
- SOAPEnvelopeImpl soapEnv = (SOAPEnvelopeImpl)soapPart.getEnvelope();
- SOAPHeaderImpl header = (SOAPHeaderImpl)soapEnv.getHeader();
+ throws DOMException {
+ throw new java.lang.UnsupportedOperationException("createEntityReference");
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Document#importNode(org.w3c.dom.Node, boolean)
+ */
+ public Node importNode(Node arg0, boolean arg1) throws DOMException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Document#getElementsByTagName(java.lang.String)
+ */
+ public NodeList getElementsByTagName(String localName) {
+ try {
+ NodeListImpl list = new NodeListImpl();
+ if (soapPart != null) {
+ SOAPEnvelopeImpl soapEnv = (SOAPEnvelopeImpl) soapPart.getEnvelope();
+ SOAPHeaderImpl header = (SOAPHeaderImpl) soapEnv.getHeader();
if (header != null) {
list.addNodeList(header.getElementsByTagName(localName));
}
- SOAPBodyImpl body = (SOAPBodyImpl)soapEnv.getBody();
+ SOAPBodyImpl body = (SOAPBodyImpl) soapEnv.getBody();
if (body != null) {
list.addNodeList(body.getElementsByTagName(localName));
}
- }
- return list;
- }catch (SOAPException se) {
+ }
+ return list;
+ } catch (SOAPException se) {
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
- }
+ }
- /* (non-Javadoc)
- * @see org.w3c.dom.Document#createTextNode(java.lang.String)
- */
- public Text createTextNode(String data) {
- TextImpl me = new TextImpl(delegate.createTextNode(data));
- me.setOwnerDocument(soapPart);
- return me;
- }
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Document#createTextNode(java.lang.String)
+ */
+ public Text createTextNode(String data) {
+ TextImpl me = new TextImpl(delegate.createTextNode(data));
+ me.setOwnerDocument(soapPart);
+ return me;
+ }
/**
* Attribute is not particularly dealt with in SAAJ.
- *
*/
public Attr createAttributeNS(String namespaceURI, String qualifiedName)
- throws DOMException {
+ throws DOMException {
return delegate.createAttributeNS(namespaceURI, qualifiedName);
}
- /* (non-Javadoc)
- * @see org.w3c.dom.Document#createElementNS(java.lang.String, java.lang.String)
- */
- public Element createElementNS(String arg0, String arg1)
- throws DOMException {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Document#getElementsByTagNameNS(java.lang.String, java.lang.String)
- */
- public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
- try{
- NodeListImpl list = new NodeListImpl();
- if (soapPart != null) {
- SOAPEnvelopeImpl soapEnv = (SOAPEnvelopeImpl)soapPart.getEnvelope();
- SOAPHeaderImpl header = (SOAPHeaderImpl)soapEnv.getHeader();
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Document#createElementNS(java.lang.String, java.lang.String)
+ */
+ public Element createElementNS(String arg0, String arg1)
+ throws DOMException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Document#getElementsByTagNameNS(java.lang.String, java.lang.String)
+ */
+ public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
+ try {
+ NodeListImpl list = new NodeListImpl();
+ if (soapPart != null) {
+ SOAPEnvelopeImpl soapEnv = (SOAPEnvelopeImpl) soapPart.getEnvelope();
+ SOAPHeaderImpl header = (SOAPHeaderImpl) soapEnv.getHeader();
if (header != null) {
list.addNodeList(header.getElementsByTagNameNS(namespaceURI, localName));
}
- SOAPBodyImpl body = (SOAPBodyImpl)soapEnv.getBody();
+ SOAPBodyImpl body = (SOAPBodyImpl) soapEnv.getBody();
if (body != null) {
list.addNodeList(body.getElementsByTagNameNS(namespaceURI, localName));
}
- }
- return list;
- }catch (SOAPException se) {
+ }
+ return list;
+ } catch (SOAPException se) {
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
- }
+ }
- public ProcessingInstruction createProcessingInstruction(
- String target,
- String data)
- throws DOMException {
- throw new java.lang.UnsupportedOperationException(
- "createProcessingInstruction");
+ public ProcessingInstruction createProcessingInstruction(String target,
+ String data)
+ throws DOMException {
+ throw new java.lang.UnsupportedOperationException("createProcessingInstruction");
}
/**
* override it in sub-classes
- *
+ *
* @return
*/
public short getNodeType() {
@@ -258,15 +252,14 @@
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
-
- public String getNodeName() {
- return null;
- }
+
+ public String getNodeName() {
+ return null;
+ }
public String getNodeValue() throws DOMException {
- throw new DOMException(
- DOMException.NO_DATA_ALLOWED_ERR,
- "Cannot use TextNode.get in " + this);
+ throw new DOMException(DOMException.NO_DATA_ALLOWED_ERR,
+ "Cannot use TextNode.get in " + this);
}
public String getPrefix() {
@@ -274,9 +267,8 @@
}
public void setNodeValue(String nodeValue) throws DOMException {
- throw new DOMException(
- DOMException.NO_DATA_ALLOWED_ERR,
- "Cannot use TextNode.set in " + this);
+ throw new DOMException(DOMException.NO_DATA_ALLOWED_ERR,
+ "Cannot use TextNode.set in " + this);
}
@@ -285,7 +277,6 @@
}
/**
- *
* we have to have a link to them...
*/
public Document getOwnerDocument() {
@@ -300,7 +291,7 @@
try {
if (soapPart != null)
return (org.apache.axis2.saaj.SOAPEnvelopeImpl) soapPart
- .getEnvelope();
+ .getEnvelope();
else
return null;
} catch (SOAPException se) {
@@ -308,26 +299,26 @@
}
}
- public Node getLastChild() {
+ public Node getLastChild() {
try {
if (soapPart != null)
return (org.apache.axis2.saaj.SOAPEnvelopeImpl) soapPart
- .getEnvelope();
+ .getEnvelope();
else
return null;
} catch (SOAPException se) {
throw new DOMException(DOMException.INVALID_STATE_ERR, "");
}
- }
+ }
- public Node getNextSibling() {
+ public Node getNextSibling() {
return null;
}
- public Node getParentNode() {
- return null;
- }
+ public Node getParentNode() {
+ return null;
+ }
public Node getPreviousSibling() {
return null;
@@ -337,7 +328,7 @@
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
-
+
public NodeList getChildNodes() {
try {
if (soapPart != null) {
@@ -354,7 +345,7 @@
}
// fill appropriate features
- private String[] features = { "foo", "bar" };
+ private String[] features = {"foo", "bar"};
private String version = "version 2.0";
public boolean isSupported(String feature, String version) {
@@ -384,12 +375,12 @@
}
public Node insertBefore(Node newChild, Node refChild)
- throws DOMException {
+ throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
public Node replaceChild(Node newChild, Node oldChild)
- throws DOMException {
+ throws DOMException {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "");
}
Modified: webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java?rev=210150&r1=210149&r2=210150&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java (original)
+++ webservices/axis/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPElementImpl.java Mon Jul 11 08:49:30 2005
@@ -25,722 +25,759 @@
import javax.xml.soap.SOAPException;
import java.util.ArrayList;
import java.util.Iterator;
+
/**
* Class SOAPElementImpl
*
* @author Jayachandra
- * jayachandra@gmail.com
+ * jayachandra@gmail.com
*/
public class SOAPElementImpl extends NodeImpl implements SOAPElement {
- /**
- * Field omElement
- * The corresponding OM object for SOAPElement is OMElement, so we would
- * have a datamember of type OMElement in this class
- */
- protected org.apache.axis2.om.OMElement omElement;
-
- /**
- * Constructor SOAPElementImpl
- * The standard constructor for being able to create SOAPElement given a omElement
- * @param omElement
- */
- public SOAPElementImpl(org.apache.axis2.om.OMElement omElement)
- {
- super(omElement);
- this.omElement = omElement;
- }
-
- /**
- * Constructor SOAPElementImpl
- * The empty constructor
- */
- public SOAPElementImpl() {
- super();
- }
-
- /**
- * Method getOMElement
- * getter method on the data member omElement
- * @return
- */
- public org.apache.axis2.om.OMElement getOMElement() {
- return this.omElement;
- }
-
- /**
- * Method addChildElement
- * @param name
- * @return SOAPElement
- * @throws SOAPException
- * @see javax.xml.soap.SOAPElement#addChildElement(javax.xml.soap.Name)
- */
- public SOAPElement addChildElement(Name name) throws SOAPException {
- //We will create a new OMElement and add that as a child to the OMElement datamember that
- //we are carrying along. And return back a wrapped SOAPElement corresponding to the
- //created OMElement
-
- //Since a <code>Name</code> object is given as parameter we should try to create an OMElement
- //and register it with the contents of the <code>name</code> element
- org.apache.axis2.om.OMElement newOMElement = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMElement(new QName(name.getURI(), name.getLocalName(), name.getPrefix()), omElement);
- omElement.addChild(newOMElement);
- return new SOAPElementImpl(newOMElement);
- }
-
- /**
- * Method addChildElement
- * @param localName
- * @return
- * @throws SOAPException
- * @see javax.xml.soap.SOAPElement#addChildElement(java.lang.String)
- */
- public SOAPElement addChildElement(String localName) throws SOAPException {
- //We will create a new OMElement and add that as a child to the OMElement datamember that
- //we are carrying along. And return back a wrapped SOAPElement corresponding to the
- //created OMElement
- org.apache.axis2.om.OMElement newOMElement = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMElement(new QName(localName), omElement);
- omElement.addChild(newOMElement);
- return new SOAPElementImpl(newOMElement);
- }
-
- /**
- * Method addChildElement
- * @param localName
- * @param prefix
- * @return
- * @throws SOAPException
- * @see javax.xml.soap.SOAPElement#addChildElement(java.lang.String, java.lang.String)
- */
- public SOAPElement addChildElement(String localName, String prefix)
- throws SOAPException {
- org.apache.axis2.om.OMElement newOMElement = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMElement(new QName(null,localName,prefix), omElement);
- omElement.addChild(newOMElement);
- return new SOAPElementImpl(newOMElement);
- }
-
- /**
- * Method addChildElement
- * @param localName
- * @param prefix
- * @return
- * @throws SOAPException
- * @see javax.xml.soap.SOAPElement#addChildElement(java.lang.String, java.lang.String, java.lang.String)
- */
- public SOAPElement addChildElement(String localName, String prefix,
- String uri) throws SOAPException {
- org.apache.axis2.om.OMElement newOMElement = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMElement(new QName(uri,localName,prefix), omElement);
- omElement.addChild(newOMElement);
- return new SOAPElementImpl(newOMElement);
- }
-
- /**
- * Method addChildElement
- * @param element
- * @return
- * @throws SOAPException
- * @see javax.xml.soap.SOAPElement#addChildElement(javax.xml.soap.SOAPElement)
- */
- public SOAPElement addChildElement(SOAPElement element)
- throws SOAPException {
- //TODO:
- //The fragment rooted in element is either added as a whole or not at all, if there was an error.
- //The fragment rooted in element cannot contain elements named Envelope, Header or Body
- //and in the SOAP namespace. Any namespace prefixes present in the fragment should be fully
- //resolved using appropriate namespace declarations within the fragment itself.
-
- org.apache.axis2.om.OMElement omElementToAdd = ((SOAPElementImpl)element).getOMElement();
- omElementToAdd.setParent(omElement);
- omElement.addChild(omElementToAdd);
- return new SOAPElementImpl(omElementToAdd);
- }
-
- /**
- * Method addTextNode
- * @param text
- * @return
- * @throws SOAPException
- * @see javax.xml.soap.SOAPElement#addTextNode(java.lang.String)
- */
- public SOAPElement addTextNode(String text) throws SOAPException {
- //We need to create an OMText node and add that to
- //the omElement delegate member that we have with us. All this OMElement's setText() does
- omElement.setText(text);
- return this;
- }
-
- /**
- * Method addAttribute
- * This method adds an attribute to the underlying omElement datamember and returns ourselves
- * @param name
- * @param value
- * @return ourself
- * @throws SOAPException
- * @see javax.xml.soap.SOAPElement#addAttribute(javax.xml.soap.Name, java.lang.String)
- */
- public SOAPElement addAttribute(Name name, String value)
- throws SOAPException {
- org.apache.axis2.om.OMNamespace omNS = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMNamespace(name.getURI(), name.getPrefix());
- //TODO:
- //The namespace of the attribute must be within the scope of the SOAPElement
- //That check should be performed here.
- omElement.addAttribute(name.getLocalName(), value, omNS);
- return this;
- }
-
- /**
- * Method addNamespaceDeclaration
- * @param prefix
- * @param uri
- * @return
- * @throws SOAPException
- * @see javax.xml.soap.SOAPElement#addNamespaceDeclaration(java.lang.String, java.lang.String)
- */
- public SOAPElement addNamespaceDeclaration(String prefix, String uri)
- throws SOAPException {
- omElement.declareNamespace(uri, prefix);
- return this;
- }
-
- /**
- * Method getAttributeValue
- * @param name
- * @return
- * @see javax.xml.soap.SOAPElement#getAttributeValue(javax.xml.soap.Name)
- */
- public String getAttributeValue(Name name) {
- //This method is waiting on the finalization of the name for a method
- //in OMElement that returns a OMAttribute from an input QName
- return omElement.getFirstAttribute( new QName(name.getURI(),name.getLocalName(),name.getPrefix())).getValue();
- }
-
- /**
- * Method getAllAttributes
- * @return
- * @see javax.xml.soap.SOAPElement#getAllAttributes()
- */
- public Iterator getAllAttributes() {
- Iterator attrIter = omElement.getAttributes();
- ArrayList arrayList = new ArrayList();
- while (attrIter.hasNext()) {
- Object o = attrIter.next();
- if (o instanceof org.apache.axis2.om.OMAttribute) {
- //we need to create a SOAPNode for this and add to the arrayList
- javax.xml.soap.Node soapNode = new NodeImpl((org.apache.axis2.om.OMAttribute)o);
- arrayList.add(soapNode);
- }
- }
- return arrayList.iterator();
- }
-
- /**
- * Method getNamespaceURI
- * @param prefix
- * @return
- * @see javax.xml.soap.SOAPElement#getNamespaceURI(java.lang.String)
- */
- public String getNamespaceURI(String prefix) {
- //Lets get all the inscope namespaces of this SOAPElement and iterate over them,
- //whenever the prefix mathces break and return the corresponding URI.
- Iterator nsIter = omElement.getAllDeclaredNamespaces();
-
- //loop over to see a prefix matching namespace.
- while(nsIter.hasNext()) {
- Object o = nsIter.next();
- if (o instanceof org.apache.axis2.om.OMNamespace) {
- org.apache.axis2.om.OMNamespace ns = (org.apache.axis2.om.OMNamespace)o;
- if( ns.getPrefix().equalsIgnoreCase(prefix))
- return ns.getName();
- }
- }
- return null;
- }
-
- /**
- * method getNamespacePrefixes
- * This method returns an iterator over all the declared namespaces prefix names.
- * @return Iterator
- * @see javax.xml.soap.SOAPElement#getNamespacePrefixes()
- */
- public Iterator getNamespacePrefixes() {
- //Get all declared namespace, make a list of their prefixes and return an iterator over that list
- ArrayList prefixList = new ArrayList();
- Iterator nsIter = omElement.getAllDeclaredNamespaces();
- while(nsIter.hasNext()) {
- Object o = nsIter.next();
- if (o instanceof org.apache.axis2.om.OMNamespace) {
- org.apache.axis2.om.OMNamespace ns = (org.apache.axis2.om.OMNamespace)o;
- prefixList.add(ns.getPrefix());
- }
- }
- return prefixList.iterator();
- }
-
- /**
- * Method getElementName
- * @return
- * @see javax.xml.soap.SOAPElement#getElementName()
- */
- public Name getElementName() {
- QName qName = omElement.getQName();
- return (Name)(new PrefixedQName(qName.getNamespaceURI(), qName.getLocalPart(), qName.getPrefix()));
- }
-
- /**
- * method removeAttribute
- * This method removes an attribute with the specified name from the element.
- * Returns true if the attribute was removed successfully; false if it was not
- * @param name
- * @return boolean
- * @see javax.xml.soap.SOAPElement#removeAttribute(javax.xml.soap.Name)
- */
- public boolean removeAttribute(Name name) {
- //get the OMAttribute with the given Name first, and call a removeAttribute(OMAttribute)
- //method on the omElement datamember this SOAPElement has in it.
- org.apache.axis2.om.OMAttribute attr = omElement.getFirstAttribute(new QName(name.getURI(),name.getLocalName(),name.getPrefix()));
- if (attr != null) {
- omElement.removeAttribute(attr);
- return true;
- }
- return false;
- }
-
- /**
- * method removeNamespaceDeclaration
- * @param prefix
- * @return
- * @see javax.xml.soap.SOAPElement#removeNamespaceDeclaration(java.lang.String)
- */
- public boolean removeNamespaceDeclaration(String prefix) {
- //TODO:
- //I'm waiting on a removeNamespace method to be added to OMElement API
- return false;
- }
-
- /**
- * method getChildElements
- * @return
- * @see javax.xml.soap.SOAPElement#getChildElements()
- */
- public Iterator getChildElements() {
- //Actually all the children are being treated as OMNodes and are being
- //wrapped accordingly to a single type (SOAPElement) and being returned in an iterator.
- //Text nodes and element nodes are all being treated alike here. Is that a serious issue???
- Iterator childIter = omElement.getChildren();
- ArrayList arrayList = new ArrayList();
- while(childIter.hasNext()) {
- Object o = childIter.next();
- if (o instanceof org.apache.axis2.om.OMNode) {
- if(o instanceof org.apache.axis2.om.OMText){
- javax.xml.soap.Text childText = new TextImpl(((org.apache.axis2.om.OMText)o).getText());
- arrayList.add(childText);
- }else{
- SOAPElement childElement = new SOAPElementImpl((org.apache.axis2.om.OMElement)o);
- arrayList.add(childElement);
- }
- //javax.xml.soap.Node childElement = new NodeImpl((org.apache.axis2.om.OMNode)o);
-
- }
- }
- return arrayList.iterator();
- }
-
- /**
- * method getChildElements
- * @param name
- * @return
- * @see javax.xml.soap.SOAPElement#getChildElements(javax.xml.soap.Name)
- */
- public Iterator getChildElements(Name name) {
- QName qName = new QName(name.getURI(),name.getLocalName());
- Iterator childIter = omElement.getChildrenWithName(qName);
- ArrayList arrayList = new ArrayList();
- while(childIter.hasNext()) {
- Object o = childIter.next();
- if (o instanceof org.apache.axis2.om.OMNode) {
- SOAPElement childElement = new SOAPElementImpl((org.apache.axis2.om.OMElement)o);
- arrayList.add(childElement);
- }
- }
- return arrayList.iterator();
- }
-
- /**
- * method setEncodingStyle
- * @param encodingStyle
- * @see javax.xml.soap.SOAPElement#setEncodingStyle(java.lang.String)
- */
- public void setEncodingStyle(String encodingStyle) throws SOAPException {
-
- //TODO:
- //Donno how to tackle this right now.
- //Couldn't figure out corresponding functionality in OM
- //Should re-visit
-
- }
-
- /**
- * method getEncodingStyle
- * @return
- * @see javax.xml.soap.SOAPElement#getEncodingStyle()
- */
- public String getEncodingStyle() {
- //TODO:
- //This is incomplete, needs to be revisited later
- return null;
- }
-
- /**
- * method removeContents
- * @see javax.xml.soap.SOAPElement#removeContents()
- */
- public void removeContents() {
- //We will get all the children and iteratively call the detach() on all of 'em.
- Iterator childIter = omElement.getChildren();
-
- while(childIter.hasNext()) {
- Object o = childIter.next();
- if(o instanceof org.apache.axis2.om.OMNode)
- ((org.apache.axis2.om.OMNode)o).detach();
- }
- }
-
- /**
- * method getVisibleNamespacePrefixes
- * @return
- * @see javax.xml.soap.SOAPElement#getVisibleNamespacePrefixes()
- */
- public Iterator getVisibleNamespacePrefixes() {
- //I'll recursively return all the declared namespaces till this node, including its parents etc.
- Iterator namespacesIter = omElement.getAllDeclaredNamespaces();
- ArrayList returnList = new ArrayList();
- while(namespacesIter.hasNext()) {
- Object o = namespacesIter.next();
- if (o instanceof org.apache.axis2.om.OMNamespace) {
- javax.xml.soap.Node soapNode = new NodeImpl((org.apache.axis2.om.OMNamespace)o);
- returnList.add(soapNode);
- }
- }//taken care of adding namespaces of this node.
- //now we have to take care of adding the namespaces that are in the scope till the level of
- //this nodes' parent.
- org.apache.axis2.om.OMContainer parent = omElement.getParent();
- if (parent!=null && parent instanceof org.apache.axis2.om.OMElement) {
- Iterator parentScopeNamespacesIter = ((org.apache.axis2.om.OMElement)parent).getAllDeclaredNamespaces();
- while(parentScopeNamespacesIter.hasNext()) {
- Object o = parentScopeNamespacesIter.next();
- if (o instanceof org.apache.axis2.om.OMNamespace) {
- javax.xml.soap.Node soapNode = new NodeImpl((org.apache.axis2.om.OMNamespace)o);
- returnList.add(soapNode);
- }
- }
- }
- return returnList.iterator();
- }
-
- /**
- * method getTagName
- * @return
- * @see org.w3c.dom.Element#getTagName()
- */
- public String getTagName() {
- return this.getLocalName();
- }
-
- /**
- * method removeAttribute
- * @param arg0
- * @see org.w3c.dom.Element#removeAttribute(java.lang.String)
- */
- public void removeAttribute(String localName) throws DOMException {
- //just got a localName, so assuming the namespace to be that of element
- Name elementQualifiedName = this.getElementName();
- //now try to remove that Attribute from this SOAPElement
- this.removeAttribute(new PrefixedQName(elementQualifiedName.getURI(), localName, elementQualifiedName.getPrefix()));
- }
-
- /**
- * method hasAttribute
- * This method returns true when an attribute with a given name is specified
- * on this element, false otherwise.
- * @param localName
- * @return
- * @see org.w3c.dom.Element#hasAttribute(java.lang.String)
- */
- public boolean hasAttribute(String localName) {
- Iterator attrIter = omElement.getAttributes();
- while(attrIter.hasNext()) {
- org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute)(attrIter.next());
- if (omAttr.getLocalName().equals(localName)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * method getAttribute
- * This method retrieves the value of an attribute having specified localname.
- * In case of an element having multiple attributes with same localname but declared
- * in different namespaces, use of this method is unadvised.
- * @param name
- * @return String
- * @see org.w3c.dom.Element#getAttribute(java.lang.String)
- */
- public String getAttribute(String name) {
- Iterator attrIter = omElement.getAttributes();
- while(attrIter.hasNext()) {
- org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute)(attrIter.next());
- if (omAttr.getLocalName().equals(name)) {
- return omAttr.getValue();
- }
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.w3c.dom.Element#removeAttributeNS(java.lang.String, java.lang.String)
- */
- public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
- Name name = new PrefixedQName(namespaceURI, localName, null);
- this.removeAttribute(name);
- }
-
- /**
- * Method setAttribute
- * This method creates and adds an attribute with the given localName and value
- * into the underlying OM. It uses the namespace of omElement datamember of this SOAPElement for the
- * newly added attribute.
- * @param localName
- * @param value
- * @return
- * @see org.w3c.dom.Element#setAttribute(java.lang.String, java.lang.String)
- */
- public void setAttribute(String localName, String value) throws DOMException {
- //We will create a OMAttribute for the given input params, add it
- //to the omElement datamemeber
- org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(localName, omElement.getNamespace(), value);
- omElement.addAttribute(omAttr);
- }
-
- /**
- * method hasAttributeNS
- * This method returns true when an attribute with a given local name and
- * namespace URI is specified on this element or has a default value, false
- * otherwise.
- * @param namespaceURI
- * @param localName
- * @return boolean
- * @see org.w3c.dom.Element#hasAttributeNS(java.lang.String, java.lang.String)
- */
- public boolean hasAttributeNS(String namespaceURI, String localName) {
- Iterator attrIter = omElement.getAttributes();
- while(attrIter.hasNext()) {
- org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute)(attrIter.next());
- if (omAttr.getLocalName().equals(localName) && omAttr.getNamespace().getName().equals(namespaceURI)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * method getAttributeNode
- * This method retrieves an attribute node by the specified localname
- * @param name
- * @returns Attr
- * @see org.w3c.dom.Element#getAttributeNode(java.lang.String)
- */
- public Attr getAttributeNode(String localName) {
- Iterator attrIter = omElement.getAttributes();
- while(attrIter.hasNext()) {
- org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute)(attrIter.next());
- if (omAttr.getLocalName().equals(localName)) {
- //So we have the right OMAttribute in hand.
- //wrap it into a org.w3c.dom.Attr object and return
- return (new org.apache.axis2.saaj.AttrImpl(omAttr, this));
- }
- }
- return null;
- }
-
- /**
- * method removeAttributeNode
- * This method removes the specified attribute node from this element.
- * @param Attr
- * The attribute node that should be removed.
- * @return Attr
- * The removed attribute node
- * @see org.w3c.dom.Element#removeAttributeNode(org.w3c.dom.Attr)
- */
- public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
- //create a OMAttribute with the input object's localName, namespace (URI + prefix), value
- //remove from underlying omElement such an attribute
- //wrap the OMAttribute used for removing, into a dom Attr object and return.
- org.apache.axis2.om.OMNamespace oldAttrNS = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMNamespace(oldAttr.getNamespaceURI(),oldAttr.getPrefix());
- org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(oldAttr.getName(), oldAttrNS, oldAttr.getValue());
- omElement.removeAttribute( omAttr );
- return ( new org.apache.axis2.saaj.AttrImpl(omAttr, this));
- }
-
- /**
- * Method setAttributeNode
- * This method creates and adds an attribute corresponding to the supplied <code>Attr</code>
- * object into the underlying OM. The attribute that gets added to OM is created against this.omElement's namespace
- * @param attr - a dom Attr object
- * @return Attr - a dom Attr object corresponding to the added attribute.
- * @see org.w3c.dom.Element#setAttributeNode(org.w3c.dom.Attr)
- */
- public Attr setAttributeNode(Attr attr) throws DOMException {
- //Create a OMAttribute out of the supplied Attr, add this to the
- //omElement and now wrap the created OMAttribute into a Attr and return
- org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(attr.getName(), omElement.getNamespace(), attr.getValue());
- omElement.addAttribute(omAttr);
- return (new org.apache.axis2.saaj.AttrImpl(omAttr, this));
- }
-
- /**
- * Method setAttributeNode
- * This method creates and adds an attribute corresponding to the supplied <code>Attr</code>
- * object into the underlying OM. The attribute added is created against it's own namespace
- * @param attr - a dom Attr object
- * @return Attr - a dom Attr object corresponding to the added attribute.
- * @see org.w3c.dom.Element#setAttributeNodeNS(org.w3c.dom.Attr)
- */
- public Attr setAttributeNodeNS(Attr attr) throws DOMException {
- org.apache.axis2.om.OMNamespace attrNS = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMNamespace(attr.getNamespaceURI(), attr.getPrefix());
- org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(attr.getName(), attrNS, attr.getValue());
- omElement.addAttribute(omAttr);
- return (new org.apache.axis2.saaj.AttrImpl(omAttr, this));
- }
-
- /**
- * Method getElementsByTagName
- * Returns a NodeList of all the descendant Elements with the given local
- * name, in the order in which they are encountered in a preorder traversal
- * of this Element tree.
- * Current SOAPElement MAY not feature in the returned NodeList, only
- * the descendant elements matching the criterion should be added.
- * @param localName
- * @return NodeList
- * @see org.w3c.dom.Element#getElementsByTagName(java.lang.String)
- */
- public NodeList getElementsByTagName(String localName) {
- Iterator childIter = this.getChildElements();
- NodeListImpl returnList;
- if (childIter==null)
- return null;
- else {
- returnList = new NodeListImpl();
- while(childIter.hasNext()) {
- NodeList list = getElementsByTagNamePreOrder((SOAPElement)childIter.next(), localName);
- //should *append* this list to the existing list. Remember, we are doing preorder
- returnList.addNodeList(list);
- }
- }
- return (NodeList)returnList;
- }
-
- private NodeList getElementsByTagNamePreOrder(SOAPElement child, String localName) {
- NodeListImpl returnList = new NodeListImpl();
- //We are doing preorder, so see if root itself is a match and place it first in the order
- if(child.getLocalName().equals(localName)) {
- //so this must be first in the returnList
- returnList.addNode((org.w3c.dom.Node)child);
- }
- returnList.addNodeList(child.getElementsByTagName(localName));
- return returnList;
- }
-
- /**
- * method getAttributeNS
- * This method retrieves the value of the attribute matching the specified namespaceURI, and localName
- * @param namespaceURI
- * @param localName
- * @return String
- * @see org.w3c.dom.Element#getAttributeNS(java.lang.String, java.lang.String)
- */
- public String getAttributeNS(String namespaceURI, String localName) {
- Iterator attrIter = omElement.getAttributes();
- while(attrIter.hasNext()) {
- org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute)(attrIter.next());
- if (omAttr.getLocalName().equals(localName) && omAttr.getNamespace().getName().equals(namespaceURI)) {
- return omAttr.getValue();
- }
- }
- return null;
- }
-
- /**
- * Method setAttributeNS
- * This method creates and adds an attribute with the given namespaceURI, localName and value
- * into the underlying OM.
- * @param localName
- * @param value
- * @return
- * @see org.w3c.dom.Element#setAttributeNS(java.lang.String, java.lang.String, java.lang.String)
- */
- public void setAttributeNS(String namespaceURI, String localName, String value)
- throws DOMException {
- //since no prefix is given, we create a OMNamespace with given URI and null prefix. How good is it???
- org.apache.axis2.om.OMNamespace attrNS = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMNamespace(namespaceURI,null);
- org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(localName, attrNS, value);
- omElement.addAttribute( omAttr );
- }
-
- /**
- * method getAttributeNodeNS
- * This method retrieves an org.w3c.dom.Attr node matching the specified namespaceURI and localName
- * @param namespaceURI
- * @param localName
- * @return Attr
- * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String, java.lang.String)
- */
- public Attr getAttributeNodeNS(String namespaceURI, String localName) {
- Iterator attrIter = omElement.getAttributes();
- while(attrIter.hasNext()) {
- org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute)(attrIter.next());
- if (omAttr.getLocalName().equals(localName) && omAttr.getNamespace().getName().equals(namespaceURI)) {
- return (new org.apache.axis2.saaj.AttrImpl(omAttr, this));
- }
- }
- return null;
- }
-
- /**
- * getElementsByTagNameNS
- * Returns a NodeList of all the descendant Elements with a given local
- * name and namespace URI in the order in which they are encountered in a
- * preorder traversal of this Element tree.
- * Current SOAPElement MAY not feature in the returned NodeList, only
- * the descendant elements matching the criterion should be added.
- * @param namespaceURI
- * @param localName
- * @return NodeList
- * @see org.w3c.dom.Element#getElementsByTagNameNS(java.lang.String, java.lang.String)
- */
- public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
- Iterator childIter = this.getChildElements();
- NodeListImpl returnList;
- if (childIter==null)
- return null;
- else {
- returnList = new NodeListImpl();
- while(childIter.hasNext()) {
- NodeList list = getElementsByTagNameNSPreOrder((SOAPElement)childIter.next(), namespaceURI, localName);
- //should *append* this list to the existing list. Remember, we are doing preorder
- returnList.addNodeList(list);
- }
- }
- return (NodeList)returnList;
- }
-
- private NodeList getElementsByTagNameNSPreOrder(SOAPElement child, String namespaceURI, String localName) {
- NodeListImpl returnList = new NodeListImpl();
- //We are doing preorder, so see if root itself is a match and place it first in the order
- if(child.getNamespaceURI().equals(namespaceURI) && child.getLocalName().equals(localName)) {
- //so this must be first in the returnList
- returnList.addNode((org.w3c.dom.Node)child);
- }
- returnList.addNodeList(child.getElementsByTagNameNS(namespaceURI, localName));
- return returnList;
- }
+ /**
+ * Field omElement
+ * The corresponding OM object for SOAPElement is OMElement, so we would
+ * have a datamember of type OMElement in this class
+ */
+ protected org.apache.axis2.om.OMElement omElement;
+
+ /**
+ * Constructor SOAPElementImpl
+ * The standard constructor for being able to create SOAPElement given a omElement
+ *
+ * @param omElement
+ */
+ public SOAPElementImpl(org.apache.axis2.om.OMElement omElement) {
+ super(omElement);
+ this.omElement = omElement;
+ }
+
+ /**
+ * Constructor SOAPElementImpl
+ * The empty constructor
+ */
+ public SOAPElementImpl() {
+ super();
+ }
+
+ /**
+ * Method getOMElement
+ * getter method on the data member omElement
+ *
+ * @return
+ */
+ public org.apache.axis2.om.OMElement getOMElement() {
+ return this.omElement;
+ }
+
+ /**
+ * Method addChildElement
+ *
+ * @param name
+ * @return SOAPElement
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPElement#addChildElement(javax.xml.soap.Name)
+ */
+ public SOAPElement addChildElement(Name name) throws SOAPException {
+ //We will create a new OMElement and add that as a child to the OMElement datamember that
+ //we are carrying along. And return back a wrapped SOAPElement corresponding to the
+ //created OMElement
+
+ //Since a <code>Name</code> object is given as parameter we should try to create an OMElement
+ //and register it with the contents of the <code>name</code> element
+ org.apache.axis2.om.OMElement newOMElement = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMElement(new QName(name.getURI(), name.getLocalName(), name.getPrefix()), omElement);
+ omElement.addChild(newOMElement);
+ return new SOAPElementImpl(newOMElement);
+ }
+
+ /**
+ * Method addChildElement
+ *
+ * @param localName
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPElement#addChildElement(java.lang.String)
+ */
+ public SOAPElement addChildElement(String localName) throws SOAPException {
+ //We will create a new OMElement and add that as a child to the OMElement datamember that
+ //we are carrying along. And return back a wrapped SOAPElement corresponding to the
+ //created OMElement
+ org.apache.axis2.om.OMElement newOMElement = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMElement(new QName(localName), omElement);
+ omElement.addChild(newOMElement);
+ return new SOAPElementImpl(newOMElement);
+ }
+
+ /**
+ * Method addChildElement
+ *
+ * @param localName
+ * @param prefix
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPElement#addChildElement(java.lang.String, java.lang.String)
+ */
+ public SOAPElement addChildElement(String localName, String prefix)
+ throws SOAPException {
+ org.apache.axis2.om.OMElement newOMElement = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMElement(new QName(null, localName, prefix), omElement);
+ omElement.addChild(newOMElement);
+ return new SOAPElementImpl(newOMElement);
+ }
+
+ /**
+ * Method addChildElement
+ *
+ * @param localName
+ * @param prefix
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPElement#addChildElement(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public SOAPElement addChildElement(String localName, String prefix,
+ String uri) throws SOAPException {
+ org.apache.axis2.om.OMElement newOMElement = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMElement(new QName(uri, localName, prefix), omElement);
+ omElement.addChild(newOMElement);
+ return new SOAPElementImpl(newOMElement);
+ }
+
+ /**
+ * Method addChildElement
+ *
+ * @param element
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPElement#addChildElement(javax.xml.soap.SOAPElement)
+ */
+ public SOAPElement addChildElement(SOAPElement element)
+ throws SOAPException {
+ //TODO:
+ //The fragment rooted in element is either added as a whole or not at all, if there was an error.
+ //The fragment rooted in element cannot contain elements named Envelope, Header or Body
+ //and in the SOAP namespace. Any namespace prefixes present in the fragment should be fully
+ //resolved using appropriate namespace declarations within the fragment itself.
+
+ org.apache.axis2.om.OMElement omElementToAdd = ((SOAPElementImpl) element).getOMElement();
+ omElementToAdd.setParent(omElement);
+ omElement.addChild(omElementToAdd);
+ return new SOAPElementImpl(omElementToAdd);
+ }
+
+ /**
+ * Method addTextNode
+ *
+ * @param text
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPElement#addTextNode(java.lang.String)
+ */
+ public SOAPElement addTextNode(String text) throws SOAPException {
+ //We need to create an OMText node and add that to
+ //the omElement delegate member that we have with us. All this OMElement's setText() does
+ omElement.setText(text);
+ return this;
+ }
+
+ /**
+ * Method addAttribute
+ * This method adds an attribute to the underlying omElement datamember and returns ourselves
+ *
+ * @param name
+ * @param value
+ * @return ourself
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPElement#addAttribute(javax.xml.soap.Name, java.lang.String)
+ */
+ public SOAPElement addAttribute(Name name, String value)
+ throws SOAPException {
+ org.apache.axis2.om.OMNamespace omNS = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMNamespace(name.getURI(), name.getPrefix());
+ //TODO:
+ //The namespace of the attribute must be within the scope of the SOAPElement
+ //That check should be performed here.
+ omElement.addAttribute(name.getLocalName(), value, omNS);
+ return this;
+ }
+
+ /**
+ * Method addNamespaceDeclaration
+ *
+ * @param prefix
+ * @param uri
+ * @return
+ * @throws SOAPException
+ * @see javax.xml.soap.SOAPElement#addNamespaceDeclaration(java.lang.String, java.lang.String)
+ */
+ public SOAPElement addNamespaceDeclaration(String prefix, String uri)
+ throws SOAPException {
+ omElement.declareNamespace(uri, prefix);
+ return this;
+ }
+
+ /**
+ * Method getAttributeValue
+ *
+ * @param name
+ * @return
+ * @see javax.xml.soap.SOAPElement#getAttributeValue(javax.xml.soap.Name)
+ */
+ public String getAttributeValue(Name name) {
+ //This method is waiting on the finalization of the name for a method
+ //in OMElement that returns a OMAttribute from an input QName
+ return omElement.getFirstAttribute(new QName(name.getURI(), name.getLocalName(), name.getPrefix())).getValue();
+ }
+
+ /**
+ * Method getAllAttributes
+ *
+ * @return
+ * @see javax.xml.soap.SOAPElement#getAllAttributes()
+ */
+ public Iterator getAllAttributes() {
+ Iterator attrIter = omElement.getAttributes();
+ ArrayList arrayList = new ArrayList();
+ while (attrIter.hasNext()) {
+ Object o = attrIter.next();
+ if (o instanceof org.apache.axis2.om.OMAttribute) {
+ //we need to create a SOAPNode for this and add to the arrayList
+ javax.xml.soap.Node soapNode = new NodeImpl((org.apache.axis2.om.OMAttribute) o);
+ arrayList.add(soapNode);
+ }
+ }
+ return arrayList.iterator();
+ }
+
+ /**
+ * Method getNamespaceURI
+ *
+ * @param prefix
+ * @return
+ * @see javax.xml.soap.SOAPElement#getNamespaceURI(java.lang.String)
+ */
+ public String getNamespaceURI(String prefix) {
+ //Lets get all the inscope namespaces of this SOAPElement and iterate over them,
+ //whenever the prefix mathces break and return the corresponding URI.
+ Iterator nsIter = omElement.getAllDeclaredNamespaces();
+
+ //loop over to see a prefix matching namespace.
+ while (nsIter.hasNext()) {
+ Object o = nsIter.next();
+ if (o instanceof org.apache.axis2.om.OMNamespace) {
+ org.apache.axis2.om.OMNamespace ns = (org.apache.axis2.om.OMNamespace) o;
+ if (ns.getPrefix().equalsIgnoreCase(prefix))
+ return ns.getName();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * method getNamespacePrefixes
+ * This method returns an iterator over all the declared namespaces prefix names.
+ *
+ * @return Iterator
+ * @see javax.xml.soap.SOAPElement#getNamespacePrefixes()
+ */
+ public Iterator getNamespacePrefixes() {
+ //Get all declared namespace, make a list of their prefixes and return an iterator over that list
+ ArrayList prefixList = new ArrayList();
+ Iterator nsIter = omElement.getAllDeclaredNamespaces();
+ while (nsIter.hasNext()) {
+ Object o = nsIter.next();
+ if (o instanceof org.apache.axis2.om.OMNamespace) {
+ org.apache.axis2.om.OMNamespace ns = (org.apache.axis2.om.OMNamespace) o;
+ prefixList.add(ns.getPrefix());
+ }
+ }
+ return prefixList.iterator();
+ }
+
+ /**
+ * Method getElementName
+ *
+ * @return
+ * @see javax.xml.soap.SOAPElement#getElementName()
+ */
+ public Name getElementName() {
+ QName qName = omElement.getQName();
+ return (Name) (new PrefixedQName(qName.getNamespaceURI(), qName.getLocalPart(), qName.getPrefix()));
+ }
+
+ /**
+ * method removeAttribute
+ * This method removes an attribute with the specified name from the element.
+ * Returns true if the attribute was removed successfully; false if it was not
+ *
+ * @param name
+ * @return boolean
+ * @see javax.xml.soap.SOAPElement#removeAttribute(javax.xml.soap.Name)
+ */
+ public boolean removeAttribute(Name name) {
+ //get the OMAttribute with the given Name first, and call a removeAttribute(OMAttribute)
+ //method on the omElement datamember this SOAPElement has in it.
+ org.apache.axis2.om.OMAttribute attr = omElement.getFirstAttribute(new QName(name.getURI(), name.getLocalName(), name.getPrefix()));
+ if (attr != null) {
+ omElement.removeAttribute(attr);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * method removeNamespaceDeclaration
+ *
+ * @param prefix
+ * @return
+ * @see javax.xml.soap.SOAPElement#removeNamespaceDeclaration(java.lang.String)
+ */
+ public boolean removeNamespaceDeclaration(String prefix) {
+ //TODO:
+ //I'm waiting on a removeNamespace method to be added to OMElement API
+ return false;
+ }
+
+ /**
+ * method getChildElements
+ *
+ * @return
+ * @see javax.xml.soap.SOAPElement#getChildElements()
+ */
+ public Iterator getChildElements() {
+ //Actually all the children are being treated as OMNodes and are being
+ //wrapped accordingly to a single type (SOAPElement) and being returned in an iterator.
+ //Text nodes and element nodes are all being treated alike here. Is that a serious issue???
+ Iterator childIter = omElement.getChildren();
+ ArrayList arrayList = new ArrayList();
+ while (childIter.hasNext()) {
+ Object o = childIter.next();
+ if (o instanceof org.apache.axis2.om.OMNode) {
+ if (o instanceof org.apache.axis2.om.OMText) {
+ javax.xml.soap.Text childText = new TextImpl(((org.apache.axis2.om.OMText) o).getText());
+ arrayList.add(childText);
+ } else {
+ SOAPElement childElement = new SOAPElementImpl((org.apache.axis2.om.OMElement) o);
+ arrayList.add(childElement);
+ }
+ //javax.xml.soap.Node childElement = new NodeImpl((org.apache.axis2.om.OMNode)o);
+
+ }
+ }
+ return arrayList.iterator();
+ }
+
+ /**
+ * method getChildElements
+ *
+ * @param name
+ * @return
+ * @see javax.xml.soap.SOAPElement#getChildElements(javax.xml.soap.Name)
+ */
+ public Iterator getChildElements(Name name) {
+ QName qName = new QName(name.getURI(), name.getLocalName());
+ Iterator childIter = omElement.getChildrenWithName(qName);
+ ArrayList arrayList = new ArrayList();
+ while (childIter.hasNext()) {
+ Object o = childIter.next();
+ if (o instanceof org.apache.axis2.om.OMNode) {
+ SOAPElement childElement = new SOAPElementImpl((org.apache.axis2.om.OMElement) o);
+ arrayList.add(childElement);
+ }
+ }
+ return arrayList.iterator();
+ }
+
+ /**
+ * method setEncodingStyle
+ *
+ * @param encodingStyle
+ * @see javax.xml.soap.SOAPElement#setEncodingStyle(java.lang.String)
+ */
+ public void setEncodingStyle(String encodingStyle) throws SOAPException {
+
+ //TODO:
+ //Donno how to tackle this right now.
+ //Couldn't figure out corresponding functionality in OM
+ //Should re-visit
+
+ }
+
+ /**
+ * method getEncodingStyle
+ *
+ * @return
+ * @see javax.xml.soap.SOAPElement#getEncodingStyle()
+ */
+ public String getEncodingStyle() {
+ //TODO:
+ //This is incomplete, needs to be revisited later
+ return null;
+ }
+
+ /**
+ * method removeContents
+ *
+ * @see javax.xml.soap.SOAPElement#removeContents()
+ */
+ public void removeContents() {
+ //We will get all the children and iteratively call the detach() on all of 'em.
+ Iterator childIter = omElement.getChildren();
+
+ while (childIter.hasNext()) {
+ Object o = childIter.next();
+ if (o instanceof org.apache.axis2.om.OMNode)
+ ((org.apache.axis2.om.OMNode) o).detach();
+ }
+ }
+
+ /**
+ * method getVisibleNamespacePrefixes
+ *
+ * @return
+ * @see javax.xml.soap.SOAPElement#getVisibleNamespacePrefixes()
+ */
+ public Iterator getVisibleNamespacePrefixes() {
+ //I'll recursively return all the declared namespaces till this node, including its parents etc.
+ Iterator namespacesIter = omElement.getAllDeclaredNamespaces();
+ ArrayList returnList = new ArrayList();
+ while (namespacesIter.hasNext()) {
+ Object o = namespacesIter.next();
+ if (o instanceof org.apache.axis2.om.OMNamespace) {
+ javax.xml.soap.Node soapNode = new NodeImpl((org.apache.axis2.om.OMNamespace) o);
+ returnList.add(soapNode);
+ }
+ }//taken care of adding namespaces of this node.
+ //now we have to take care of adding the namespaces that are in the scope till the level of
+ //this nodes' parent.
+ org.apache.axis2.om.OMContainer parent = omElement.getParent();
+ if (parent != null && parent instanceof org.apache.axis2.om.OMElement) {
+ Iterator parentScopeNamespacesIter = ((org.apache.axis2.om.OMElement) parent).getAllDeclaredNamespaces();
+ while (parentScopeNamespacesIter.hasNext()) {
+ Object o = parentScopeNamespacesIter.next();
+ if (o instanceof org.apache.axis2.om.OMNamespace) {
+ javax.xml.soap.Node soapNode = new NodeImpl((org.apache.axis2.om.OMNamespace) o);
+ returnList.add(soapNode);
+ }
+ }
+ }
+ return returnList.iterator();
+ }
+
+ /**
+ * method getTagName
+ *
+ * @return
+ * @see org.w3c.dom.Element#getTagName()
+ */
+ public String getTagName() {
+ return this.getLocalName();
+ }
+
+ /**
+ * method removeAttribute
+ *
+ * @param arg0
+ * @see org.w3c.dom.Element#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String localName) throws DOMException {
+ //just got a localName, so assuming the namespace to be that of element
+ Name elementQualifiedName = this.getElementName();
+ //now try to remove that Attribute from this SOAPElement
+ this.removeAttribute(new PrefixedQName(elementQualifiedName.getURI(), localName, elementQualifiedName.getPrefix()));
+ }
+
+ /**
+ * method hasAttribute
+ * This method returns true when an attribute with a given name is specified
+ * on this element, false otherwise.
+ *
+ * @param localName
+ * @return
+ * @see org.w3c.dom.Element#hasAttribute(java.lang.String)
+ */
+ public boolean hasAttribute(String localName) {
+ Iterator attrIter = omElement.getAttributes();
+ while (attrIter.hasNext()) {
+ org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute) (attrIter.next());
+ if (omAttr.getLocalName().equals(localName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * method getAttribute
+ * This method retrieves the value of an attribute having specified localname.
+ * In case of an element having multiple attributes with same localname but declared
+ * in different namespaces, use of this method is unadvised.
+ *
+ * @param name
+ * @return String
+ * @see org.w3c.dom.Element#getAttribute(java.lang.String)
+ */
+ public String getAttribute(String name) {
+ Iterator attrIter = omElement.getAttributes();
+ while (attrIter.hasNext()) {
+ org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute) (attrIter.next());
+ if (omAttr.getLocalName().equals(name)) {
+ return omAttr.getValue();
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#removeAttributeNS(java.lang.String, java.lang.String)
+ */
+ public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
+ Name name = new PrefixedQName(namespaceURI, localName, null);
+ this.removeAttribute(name);
+ }
+
+ /**
+ * Method setAttribute
+ * This method creates and adds an attribute with the given localName and value
+ * into the underlying OM. It uses the namespace of omElement datamember of this SOAPElement for the
+ * newly added attribute.
+ *
+ * @param localName
+ * @param value
+ * @return
+ * @see org.w3c.dom.Element#setAttribute(java.lang.String, java.lang.String)
+ */
+ public void setAttribute(String localName, String value) throws DOMException {
+ //We will create a OMAttribute for the given input params, add it
+ //to the omElement datamemeber
+ org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(localName, omElement.getNamespace(), value);
+ omElement.addAttribute(omAttr);
+ }
+
+ /**
+ * method hasAttributeNS
+ * This method returns true when an attribute with a given local name and
+ * namespace URI is specified on this element or has a default value, false
+ * otherwise.
+ *
+ * @param namespaceURI
+ * @param localName
+ * @return boolean
+ * @see org.w3c.dom.Element#hasAttributeNS(java.lang.String, java.lang.String)
+ */
+ public boolean hasAttributeNS(String namespaceURI, String localName) {
+ Iterator attrIter = omElement.getAttributes();
+ while (attrIter.hasNext()) {
+ org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute) (attrIter.next());
+ if (omAttr.getLocalName().equals(localName) && omAttr.getNamespace().getName().equals(namespaceURI)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * method getAttributeNode
+ * This method retrieves an attribute node by the specified localname
+ *
+ * @param name
+ * @returns Attr
+ * @see org.w3c.dom.Element#getAttributeNode(java.lang.String)
+ */
+ public Attr getAttributeNode(String localName) {
+ Iterator attrIter = omElement.getAttributes();
+ while (attrIter.hasNext()) {
+ org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute) (attrIter.next());
+ if (omAttr.getLocalName().equals(localName)) {
+ //So we have the right OMAttribute in hand.
+ //wrap it into a org.w3c.dom.Attr object and return
+ return (new org.apache.axis2.saaj.AttrImpl(omAttr, this));
+ }
+ }
+ return null;
+ }
+
+ /**
+ * method removeAttributeNode
+ * This method removes the specified attribute node from this element.
+ *
+ * @param Attr The attribute node that should be removed.
+ * @return Attr
+ * The removed attribute node
+ * @see org.w3c.dom.Element#removeAttributeNode(org.w3c.dom.Attr)
+ */
+ public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
+ //create a OMAttribute with the input object's localName, namespace (URI + prefix), value
+ //remove from underlying omElement such an attribute
+ //wrap the OMAttribute used for removing, into a dom Attr object and return.
+ org.apache.axis2.om.OMNamespace oldAttrNS = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMNamespace(oldAttr.getNamespaceURI(), oldAttr.getPrefix());
+ org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(oldAttr.getName(), oldAttrNS, oldAttr.getValue());
+ omElement.removeAttribute(omAttr);
+ return (new org.apache.axis2.saaj.AttrImpl(omAttr, this));
+ }
+
+ /**
+ * Method setAttributeNode
+ * This method creates and adds an attribute corresponding to the supplied <code>Attr</code>
+ * object into the underlying OM. The attribute that gets added to OM is created against this.omElement's namespace
+ *
+ * @param attr - a dom Attr object
+ * @return Attr - a dom Attr object corresponding to the added attribute.
+ * @see org.w3c.dom.Element#setAttributeNode(org.w3c.dom.Attr)
+ */
+ public Attr setAttributeNode(Attr attr) throws DOMException {
+ //Create a OMAttribute out of the supplied Attr, add this to the
+ //omElement and now wrap the created OMAttribute into a Attr and return
+ org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(attr.getName(), omElement.getNamespace(), attr.getValue());
+ omElement.addAttribute(omAttr);
+ return (new org.apache.axis2.saaj.AttrImpl(omAttr, this));
+ }
+
+ /**
+ * Method setAttributeNode
+ * This method creates and adds an attribute corresponding to the supplied <code>Attr</code>
+ * object into the underlying OM. The attribute added is created against it's own namespace
+ *
+ * @param attr - a dom Attr object
+ * @return Attr - a dom Attr object corresponding to the added attribute.
+ * @see org.w3c.dom.Element#setAttributeNodeNS(org.w3c.dom.Attr)
+ */
+ public Attr setAttributeNodeNS(Attr attr) throws DOMException {
+ org.apache.axis2.om.OMNamespace attrNS = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMNamespace(attr.getNamespaceURI(), attr.getPrefix());
+ org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(attr.getName(), attrNS, attr.getValue());
+ omElement.addAttribute(omAttr);
+ return (new org.apache.axis2.saaj.AttrImpl(omAttr, this));
+ }
+
+ /**
+ * Method getElementsByTagName
+ * Returns a NodeList of all the descendant Elements with the given local
+ * name, in the order in which they are encountered in a preorder traversal
+ * of this Element tree.
+ * Current SOAPElement MAY not feature in the returned NodeList, only
+ * the descendant elements matching the criterion should be added.
+ *
+ * @param localName
+ * @return NodeList
+ * @see org.w3c.dom.Element#getElementsByTagName(java.lang.String)
+ */
+ public NodeList getElementsByTagName(String localName) {
+ Iterator childIter = this.getChildElements();
+ NodeListImpl returnList;
+ if (childIter == null)
+ return null;
+ else {
+ returnList = new NodeListImpl();
+ while (childIter.hasNext()) {
+ NodeList list = getElementsByTagNamePreOrder((SOAPElement) childIter.next(), localName);
+ //should *append* this list to the existing list. Remember, we are doing preorder
+ returnList.addNodeList(list);
+ }
+ }
+ return (NodeList) returnList;
+ }
+
+ private NodeList getElementsByTagNamePreOrder(SOAPElement child, String localName) {
+ NodeListImpl returnList = new NodeListImpl();
+ //We are doing preorder, so see if root itself is a match and place it first in the order
+ if (child.getLocalName().equals(localName)) {
+ //so this must be first in the returnList
+ returnList.addNode((org.w3c.dom.Node) child);
+ }
+ returnList.addNodeList(child.getElementsByTagName(localName));
+ return returnList;
+ }
+
+ /**
+ * method getAttributeNS
+ * This method retrieves the value of the attribute matching the specified namespaceURI, and localName
+ *
+ * @param namespaceURI
+ * @param localName
+ * @return String
+ * @see org.w3c.dom.Element#getAttributeNS(java.lang.String, java.lang.String)
+ */
+ public String getAttributeNS(String namespaceURI, String localName) {
+ Iterator attrIter = omElement.getAttributes();
+ while (attrIter.hasNext()) {
+ org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute) (attrIter.next());
+ if (omAttr.getLocalName().equals(localName) && omAttr.getNamespace().getName().equals(namespaceURI)) {
+ return omAttr.getValue();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Method setAttributeNS
+ * This method creates and adds an attribute with the given namespaceURI, localName and value
+ * into the underlying OM.
+ *
+ * @param localName
+ * @param value
+ * @return
+ * @see org.w3c.dom.Element#setAttributeNS(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void setAttributeNS(String namespaceURI, String localName, String value)
+ throws DOMException {
+ //since no prefix is given, we create a OMNamespace with given URI and null prefix. How good is it???
+ org.apache.axis2.om.OMNamespace attrNS = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMNamespace(namespaceURI, null);
+ org.apache.axis2.om.OMAttribute omAttr = org.apache.axis2.om.OMAbstractFactory.getOMFactory().createOMAttribute(localName, attrNS, value);
+ omElement.addAttribute(omAttr);
+ }
+
+ /**
+ * method getAttributeNodeNS
+ * This method retrieves an org.w3c.dom.Attr node matching the specified namespaceURI and localName
+ *
+ * @param namespaceURI
+ * @param localName
+ * @return Attr
+ * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String, java.lang.String)
+ */
+ public Attr getAttributeNodeNS(String namespaceURI, String localName) {
+ Iterator attrIter = omElement.getAttributes();
+ while (attrIter.hasNext()) {
+ org.apache.axis2.om.OMAttribute omAttr = (org.apache.axis2.om.OMAttribute) (attrIter.next());
+ if (omAttr.getLocalName().equals(localName) && omAttr.getNamespace().getName().equals(namespaceURI)) {
+ return (new org.apache.axis2.saaj.AttrImpl(omAttr, this));
+ }
+ }
+ return null;
+ }
+
+ /**
+ * getElementsByTagNameNS
+ * Returns a NodeList of all the descendant Elements with a given local
+ * name and namespace URI in the order in which they are encountered in a
+ * preorder traversal of this Element tree.
+ * Current SOAPElement MAY not feature in the returned NodeList, only
+ * the descendant elements matching the criterion should be added.
+ *
+ * @param namespaceURI
+ * @param localName
+ * @return NodeList
+ * @see org.w3c.dom.Element#getElementsByTagNameNS(java.lang.String, java.lang.String)
+ */
+ public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
+ Iterator childIter = this.getChildElements();
+ NodeListImpl returnList;
+ if (childIter == null)
+ return null;
+ else {
+ returnList = new NodeListImpl();
+ while (childIter.hasNext()) {
+ NodeList list = getElementsByTagNameNSPreOrder((SOAPElement) childIter.next(), namespaceURI, localName);
+ //should *append* this list to the existing list. Remember, we are doing preorder
+ returnList.addNodeList(list);
+ }
+ }
+ return (NodeList) returnList;
+ }
+
+ private NodeList getElementsByTagNameNSPreOrder(SOAPElement child, String namespaceURI, String localName) {
+ NodeListImpl returnList = new NodeListImpl();
+ //We are doing preorder, so see if root itself is a match and place it first in the order
+ if (child.getNamespaceURI().equals(namespaceURI) && child.getLocalName().equals(localName)) {
+ //so this must be first in the returnList
+ returnList.addNode((org.w3c.dom.Node) child);
+ }
+ returnList.addNodeList(child.getElementsByTagNameNS(namespaceURI, localName));
+ return returnList;
+ }
}