axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r365487 [3/5] - in /webservices/axis2/trunk/java/modules/saaj: ./ src/org/apache/axis2/saaj/ src/org/apache/axis2/util/ test/org/apache/axis2/saaj/
Date Tue, 03 Jan 2006 00:29:01 GMT
Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java?rev=365487&r1=365486&r2=365487&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPFaultImpl.java Mon Jan  2 16:28:43 2006
@@ -1,227 +1,257 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 package org.apache.axis2.saaj;
 
-import org.apache.axis2.om.OMAbstractFactory;
-import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.om.DOOMAbstractFactory;
+import org.apache.axis2.om.impl.dom.ElementImpl;
 import org.apache.axis2.soap.SOAPFaultCode;
-import org.apache.axis2.soap.SOAPFaultDetail;
-import org.apache.axis2.soap.SOAPFaultNode;
 import org.apache.axis2.soap.SOAPFaultReason;
+import org.apache.axis2.soap.SOAPFaultRole;
 import org.apache.axis2.soap.SOAPFaultText;
 import org.apache.axis2.soap.SOAPFaultValue;
+import org.apache.axis2.soap.impl.dom.soap11.SOAP11FaultDetailImpl;
+import org.apache.axis2.soap.impl.dom.soap11.SOAP11FaultReasonImpl;
+import org.apache.axis2.soap.impl.dom.soap11.SOAP11FaultRoleImpl;
+import org.apache.axis2.soap.impl.dom.soap11.SOAP11FaultTextImpl;
 
 import javax.xml.soap.Detail;
 import javax.xml.soap.Name;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFault;
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayOutputStream;
 import java.util.Locale;
 
-/**
- * Class SOAPFaultImpl
- *         SOAPFault specific classes not implemented in OM, so
- *         throwing unsupported operation for the time being
- */
 public class SOAPFaultImpl extends SOAPBodyElementImpl implements SOAPFault {
 
-    /**
-     * Field fault   The omSOAPFault field
-     */
     protected org.apache.axis2.soap.SOAPFault fault;
 
     /**
-     * Constructor SOAPFaultImpl
-     *
-     * @param fault
+     * @param element
      */
-    public SOAPFaultImpl(org.apache.axis2.soap.SOAPFault fault) {
-        this.fault = fault;
-    }
-
-    public org.apache.axis2.soap.SOAPFault getOMFault() {
-        return fault;
+    public SOAPFaultImpl(org.apache.axis2.soap.SOAPFault element) {
+        super((ElementImpl) element);
+        fault = element;
     }
 
     /**
-     * Method setFaultCode
-     *
-     * @param faultCode
-     * @throws SOAPException
-     * @see javax.xml.soap.SOAPFault#setFaultCode(java.lang.String)
+     * Sets this <CODE>SOAPFault</CODE> object with the given
+     * fault code.
+     * <p/>
+     * <P>Fault codes, which given information about the fault,
+     * are defined in the SOAP 1.1 specification.</P>
+     *
+     * @param faultCode a <CODE>String</CODE> giving
+     *                  the fault code to be set; must be one of the fault codes
+     *                  defined in the SOAP 1.1 specification
+     * @throws SOAPException if there was an error in
+     *                       adding the <CODE>faultCode</CODE> to the underlying XML
+     *                       tree.
+     * @see #getFaultCode() getFaultCode()
      */
     public void setFaultCode(String faultCode) throws SOAPException {
-        // No direct mapping of SOAP 1.1 faultCode to SOAP 1.2, Mapping it to
-        // (Fault Value of FaultCode) in OM impl
-        SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
+        /*SOAPFaultCode code = new SOAP11FaultCodeImpl(fault);
+        SOAP11FaultValueImpl faultValueImpl = new SOAP11FaultValueImpl(code);
+        faultValueImpl.setText(faultCode);
+        code.setValue(faultValueImpl);
+        this.fault.setCode(code);*/
+
+        org.apache.axis2.soap.SOAPFactory soapFactory = DOOMAbstractFactory.getSOAP11Factory();
         SOAPFaultCode fCode = soapFactory.createSOAPFaultCode(fault);
-        SOAPFaultValue value = soapFactory.createSOAPFaultValue(fCode);
-        fCode.setValue(value);
-        value.setText(faultCode);
+        SOAPFaultValue fValue = soapFactory.createSOAPFaultValue(fCode);
+        fCode.setValue(fValue);
+        fValue.setText(faultCode);
+
+        this.fault.setCode(fCode);
+
+        /*try {
+            {
+                System.err.println("########################## Fault Code #########");
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                fCode.serialize(baos);
+                String xml2 = new String(baos.toByteArray());
+                System.out.println(xml2);
+                System.err.println("##########################");
+            }
+            System.err.println("########################## Fault -------");
+            ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+            fault.serialize(baos2);
+            String xml3 = new String(baos2.toByteArray());
+            System.out.println(xml3);
+            System.err.println("##########################-----------");
+        } catch (XMLStreamException e) {
+            e.printStackTrace();
+        }*/
     }
 
     /**
-     * Method getFaultCode
+     * Gets the fault code for this <CODE>SOAPFault</CODE>
+     * object.
      *
-     * @return
-     * @see javax.xml.soap.SOAPFault#getFaultCode()
+     * @return a <CODE>String</CODE> with the fault code
+     * @see #setFaultCode(java.lang.String) setFaultCode(java.lang.String)
      */
     public String getFaultCode() {
-
-        //FaultCode mapped to Fault.FaultCode.FaultValue in OM
-        return fault.getCode().getValue().getText();
+        return this.fault.getCode().getValue().getText();
     }
 
-    /**
-     * method setFaultActor
-     *
-     * @param faultActor
-     * @throws SOAPException
-     * @see javax.xml.soap.SOAPFault#setFaultActor(java.lang.String)
-     */
+    /* (non-Javadoc)
+      * @see javax.xml.soap.SOAPFault#setFaultActor(java.lang.String)
+      */
     public void setFaultActor(String faultActor) throws SOAPException {
-
-        //faultActor mapped to SOAPFaultNode in OM
-        SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
-        SOAPFaultNode fNode = soapFactory.createSOAPFaultNode(fault);
-        fNode.setNodeValue(faultActor);
+        if (this.fault.getRole() == null) {
+            SOAP11FaultRoleImpl faultRoleImpl = new SOAP11FaultRoleImpl(this.fault);
+            faultRoleImpl.setRoleValue(faultActor);
+            this.fault.setRole(faultRoleImpl);
+        } else {
+            SOAPFaultRole role = this.fault.getRole();
+            role.setRoleValue(faultActor);
+        }
     }
 
-    /**
-     * method getFaultActor
-     *
-     * @return
-     * @see javax.xml.soap.SOAPFault#getFaultActor()
-     */
+    /* (non-Javadoc)
+      * @see javax.xml.soap.SOAPFault#getFaultActor()
+      */
     public String getFaultActor() {
-
-        // return the text value in SOAPFaultNode of OM
-        return fault.getNode().getNodeValue();
+        if (this.fault.getRole() != null) {
+            return this.fault.getRole().getRoleValue();
+        }
+        return null;
     }
 
     /**
-     * method setFaultString
-     *
-     * @param faultString
-     * @throws SOAPException
-     * @see javax.xml.soap.SOAPFault#setFaultString(java.lang.String)
+     * Sets the fault string for this <CODE>SOAPFault</CODE>
+     * object to the given string.
+     *
+     * @param faultString a <CODE>String</CODE>
+     *                    giving an explanation of the fault
+     * @throws SOAPException if there was an error in
+     *                       adding the <CODE>faultString</CODE> to the underlying XML
+     *                       tree.
+     * @see #getFaultString() getFaultString()
      */
     public void setFaultString(String faultString) throws SOAPException {
-
-        //FaultString mapped to text elemtnt of SOAPFaultReason->SOAPFaultText in OM
-        SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
-        SOAPFaultReason fReason = soapFactory.createSOAPFaultReason(fault);
-        SOAPFaultText text = soapFactory.createSOAPFaultText(fReason);
-        text.setText(faultString);
-        fReason.setSOAPText(text);
-    }
-
-    /**
-     * method getFaultString
-     *
-     * @return
-     * @see javax.xml.soap.SOAPFault#getFaultString()
-     */
+        if (this.fault.getReason() != null) {
+            SOAPFaultReason reason = this.fault.getReason();
+            if (reason.getSOAPText() != null) {
+                reason.getSOAPText().setText(faultString);
+            } else {
+                SOAPFaultText text = new SOAP11FaultTextImpl(reason);
+                text.setText(faultString);
+                reason.setSOAPText(text);
+            }
+        } else {
+            /*SOAPFaultReason fReason = new SOAP11FaultReasonImpl(this.fault);
+            SOAPFaultText fText = new SOAP11FaultTextImpl(fReason);
+            fText.setText(faultString);
+            fReason.setSOAPText(fText);
+            this.fault.setReason(fReason);*/
+
+            org.apache.axis2.soap.SOAPFactory soapFactory = DOOMAbstractFactory.getSOAP11Factory();
+            SOAPFaultReason fReason = soapFactory.createSOAPFaultReason(fault);
+            SOAPFaultText fText = soapFactory.createSOAPFaultText(fReason);
+            fText.setText(faultString);
+            fReason.setSOAPText(fText);
+
+            this.fault.setReason(fReason);
+
+            try {
+              /*  System.err.println("########################## Fault String ######");
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                fReason.serialize(baos);
+                String xml2 = new String(baos.toByteArray());
+                System.out.println(xml2);
+                System.err.println("##########################");*/
+
+                System.err.println("########################## Fault -------");
+                ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+                fault.serialize(baos2);
+                String xml3 = new String(baos2.toByteArray());
+                System.out.println(xml3);
+                System.err.println("##########################-----------");
+
+            } catch (XMLStreamException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+      * @see javax.xml.soap.SOAPFault#getFaultString()
+      */
     public String getFaultString() {
-
-        //return text elemtnt of SOAPFaultReason->SOAPFaultText in OM
-        return fault.getReason().getSOAPText().getText();
+        if (this.fault.getReason() != null && this.fault.getReason().getSOAPText() != null) {
+            return this.fault.getReason().getSOAPText().getText();
+        }
+        return null;
     }
 
-    /**
-     * method getDetail
-     *
-     * @return
-     * @see javax.xml.soap.SOAPFault#getDetail()
-     */
+    /* (non-Javadoc)
+      * @see javax.xml.soap.SOAPFault#getDetail()
+      */
     public Detail getDetail() {
-
-        SOAPFaultDetail detail = fault.getDetail();
-        return new DetailImpl(detail);
+        if (this.fault.getDetail() != null) {
+            return new DetailImpl(this.fault.getDetail());
+        }
+        return null;
     }
 
-    /**
-     * method addDetail
-     *
-     * @return
-     * @throws SOAPException
-     * @see javax.xml.soap.SOAPFault#addDetail()
-     */
+    /* (non-Javadoc)
+      * @see javax.xml.soap.SOAPFault#addDetail()
+      */
     public Detail addDetail() throws SOAPException {
-
-        SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
-        SOAPFaultDetail detail = soapFactory.createSOAPFaultDetail(fault);
-        return new DetailImpl(detail);
+        SOAP11FaultDetailImpl omDetail = new SOAP11FaultDetailImpl(this.fault);
+        this.fault.setDetail(omDetail);
+        return new DetailImpl(omDetail);
     }
 
-    /**
-     * method setFaultCode
-     *
-     * @param name
-     * @throws SOAPException
-     * @see javax.xml.soap.SOAPFault#setFaultCode(javax.xml.soap.Name)
-     */
+    /* (non-Javadoc)
+      * @see javax.xml.soap.SOAPFault#setFaultCode(javax.xml.soap.Name)
+      */
     public void setFaultCode(Name name) throws SOAPException {
-
-        /*QName qName = new QName(name.getURI(), name.getLocalName(), name.getPrefix());
-        fault.setFaultCode(qName);*/
-        throw new UnsupportedOperationException("No supoprted for M2 release");
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
     }
 
-    /**
-     * method getFaultCodeAsName
-     *
-     * @return
-     * @see javax.xml.soap.SOAPFault#getFaultCodeAsName()
-     */
+    /* (non-Javadoc)
+      * @see javax.xml.soap.SOAPFault#getFaultCodeAsName()
+      */
     public Name getFaultCodeAsName() {
-
-        /*QName qName = fault.getFaultCode();
-        Name name = new PrefixedQName(qName);
-        return name;*/
-        throw new UnsupportedOperationException("No supoprted for M2 release");
-    }
-
-    /**
-     * method seFaultString
-     *
-     * @param faultString
-     * @param locale
-     * @throws SOAPException
-     * @see javax.xml.soap.SOAPFault#setFaultString(java.lang.String, java.util.Locale)
-     */
-    public void setFaultString(String faultString, Locale locale)
-            throws SOAPException {
-        //FaultString mapped to text elemtnt of SOAPFaultReason->SOAPFaultText in OM
-        // Not using Locale information
-        SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
-        SOAPFaultReason fReason = soapFactory.createSOAPFaultReason(fault);
-        SOAPFaultText text = soapFactory.createSOAPFaultText(fReason);
-        text.setText(faultString);
-        fReason.setSOAPText(text);
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
     }
 
-    /**
-     * method getFaultStringLocale
-     *
-     * @return
-     * @see javax.xml.soap.SOAPFault#getFaultStringLocale()
-     */
+    /* (non-Javadoc)
+      * @see javax.xml.soap.SOAPFault#setFaultString(java.lang.String, java.util.Locale)
+      */
+    public void setFaultString(String faultString, Locale locale) throws SOAPException {
+        if (this.fault.getReason() != null) {
+            SOAPFaultReason reason = this.fault.getReason();
+            if (reason.getSOAPText() != null) {
+                reason.getSOAPText().setText(faultString);
+                reason.getSOAPText().setLang(locale.getLanguage());
+            } else {
+                SOAPFaultText text = new SOAP11FaultTextImpl(reason);
+                text.setText(faultString);
+                text.setLang(locale.getLanguage());
+                reason.setSOAPText(text);
+            }
+        } else {
+            SOAPFaultReason reason = new SOAP11FaultReasonImpl(this.fault);
+            SOAPFaultText text = new SOAP11FaultTextImpl(reason);
+            text.setText(faultString);
+            text.setLang(locale.getLanguage());
+            reason.setSOAPText(text);
+            this.fault.setReason(reason);
+        }
+    }
+
+    /* (non-Javadoc)
+      * @see javax.xml.soap.SOAPFault#getFaultStringLocale()
+      */
     public Locale getFaultStringLocale() {
-        //No implementation in Axis 1.2 also, not sure what to do here
-        return null;  //TODO
+        //We only save the language in OM,
+        //Can we construct a Locale with it :-?
+        // TODO TODO
+        throw new UnsupportedOperationException("TODO");
     }
 
 }

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderElementImpl.java?rev=365487&r1=365486&r2=365487&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderElementImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderElementImpl.java Mon Jan  2 16:28:43 2006
@@ -15,74 +15,83 @@
  */
 package org.apache.axis2.saaj;
 
+import org.apache.axis2.om.impl.dom.ElementImpl;
 import org.apache.axis2.soap.SOAPHeaderBlock;
 
 import javax.xml.soap.SOAPHeaderElement;
 
-/**
- * Class SOAPHeaderImpl
- */
-public class SOAPHeaderElementImpl extends SOAPElementImpl implements
-        SOAPHeaderElement {
+public class SOAPHeaderElementImpl extends SOAPElementImpl implements SOAPHeaderElement {
 
-    /**
-     * Field omHeaderElement
-     */
-    SOAPHeaderBlock omHeaderElement;
+    private SOAPHeaderBlock headerElem;
 
     /**
-     * Constructor SOAPHeaderElementImpl
-     *
-     * @param headerElement
+     * @param element
      */
-    public SOAPHeaderElementImpl(
-            org.apache.axis2.soap.SOAPHeaderBlock headerElement) {
-        super(headerElement);
-        this.omHeaderElement = headerElement;
+    public SOAPHeaderElementImpl(SOAPHeaderBlock element) {
+        super((ElementImpl) element);
+        this.headerElem = element;
     }
 
     /**
-     * method setActor
+     * Sets the actor associated with this <CODE>
+     * SOAPHeaderElement</CODE> object to the specified actor. The
+     * default value of an actor is: <CODE>
+     * SOAPConstants.URI_SOAP_ACTOR_NEXT</CODE>
      *
-     * @param actorURI
-     * @see javax.xml.soap.SOAPHeaderElement#setActor(java.lang.String)
+     * @param actorURI a <CODE>String</CODE> giving
+     *                 the URI of the actor to set
+     * @throws java.lang.IllegalArgumentException
+     *          if
+     *          there is a problem in setting the actor.
+     * @see #getActor() getActor()
      */
     public void setActor(String actorURI) {
-
-        omHeaderElement.setRole(actorURI);
+        this.headerElem.setRole(actorURI);
     }
 
     /**
-     * method getActor
+     * Returns the uri of the actor associated with this <CODE>
+     * SOAPHeaderElement</CODE> object.
      *
-     * @return
-     * @see javax.xml.soap.SOAPHeaderElement#getActor()
+     * @return a <CODE>String</CODE> giving the URI of the
+     *         actor
+     * @see #setActor(java.lang.String) setActor(java.lang.String)
      */
     public String getActor() {
-
-        return omHeaderElement.getRole();
+        return this.headerElem.getRole();
     }
 
     /**
-     * method setMustUnderstand
+     * Sets the mustUnderstand attribute for this <CODE>
+     * SOAPHeaderElement</CODE> object to be on or off.
+     * <p/>
+     * <P>If the mustUnderstand attribute is on, the actor who
+     * receives the <CODE>SOAPHeaderElement</CODE> must process it
+     * correctly. This ensures, for example, that if the <CODE>
+     * SOAPHeaderElement</CODE> object modifies the message, that
+     * the message is being modified correctly.</P>
      *
-     * @param mustUnderstand
-     * @see javax.xml.soap.SOAPHeaderElement#setMustUnderstand(boolean)
+     * @param mustUnderstand <CODE>true</CODE> to
+     *                       set the mustUnderstand attribute on; <CODE>false</CODE>
+     *                       to turn if off
+     * @throws java.lang.IllegalArgumentException
+     *          if
+     *          there is a problem in setting the actor.
+     * @see #getMustUnderstand() getMustUnderstand()
      */
     public void setMustUnderstand(boolean mustUnderstand) {
-
-        omHeaderElement.setMustUnderstand(mustUnderstand);
+        this.headerElem.setMustUnderstand(mustUnderstand);
     }
 
     /**
-     * method getMustUnderstand
+     * Returns whether the mustUnderstand attribute for this
+     * <CODE>SOAPHeaderElement</CODE> object is turned on.
      *
-     * @return
-     * @see javax.xml.soap.SOAPHeaderElement#getMustUnderstand()
+     * @return <CODE>true</CODE> if the mustUnderstand attribute of
+     *         this <CODE>SOAPHeaderElement</CODE> object is turned on;
+     *         <CODE>false</CODE> otherwise
      */
     public boolean getMustUnderstand() {
-
-        return omHeaderElement.getMustUnderstand();
+        return this.headerElem.getMustUnderstand();
     }
-
 }

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderImpl.java?rev=365487&r1=365486&r2=365487&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPHeaderImpl.java Mon Jan  2 16:28:43 2006
@@ -15,182 +15,157 @@
  */
 package org.apache.axis2.saaj;
 
-import org.apache.axis2.om.OMAbstractFactory;
-import org.apache.axis2.om.OMFactory;
 import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.impl.dom.ElementImpl;
+import org.apache.axis2.om.impl.dom.NamespaceImpl;
+import org.apache.axis2.soap.SOAPHeaderBlock;
+import org.apache.axis2.soap.impl.dom.soap11.SOAP11HeaderBlockImpl;
 
 import javax.xml.soap.Name;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPHeaderElement;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 
-/**
- * Class SOAPHeaderImpl
- */
 public class SOAPHeaderImpl extends SOAPElementImpl implements SOAPHeader {
 
-    /**
-     * Field omHeader	OM's SOAPHeader field
-     */
-    private org.apache.axis2.soap.SOAPHeader omHeader;
+    private org.apache.axis2.soap.SOAPHeader omSOAPHeader;
 
     /**
-     * Constructor SOAPHeaderImpl
+     * Constructor
      *
      * @param header
      */
     public SOAPHeaderImpl(org.apache.axis2.soap.SOAPHeader header) {
-        super(header);
-        this.omHeader = header;
+        super((ElementImpl) header);
+        omSOAPHeader = header;
     }
 
     /**
-     * Method addHeaderElement
-     *
-     * @param name
-     * @return
-     * @throws SOAPException
-     * @see javax.xml.soap.SOAPHeader#addHeaderElement(javax.xml.soap.Name)
+     * Creates a new <CODE>SOAPHeaderElement</CODE> object
+     * initialized with the specified name and adds it to this
+     * <CODE>SOAPHeader</CODE> object.
+     *
+     * @param name a <CODE>Name</CODE> object with
+     *             the name of the new <CODE>SOAPHeaderElement</CODE>
+     *             object
+     * @return the new <CODE>SOAPHeaderElement</CODE> object that
+     *         was inserted into this <CODE>SOAPHeader</CODE>
+     *         object
+     * @throws SOAPException if a SOAP error occurs
      */
     public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException {
-        // Create an OMHeaderBlock out of name and add it a SOAPHeaderElement
-        //to SOAPHeader
-        String localName = name.getLocalName();
-        OMFactory omFactory = OMAbstractFactory.getOMFactory();
-        OMNamespace ns = omFactory.createOMNamespace(name.getURI(),
-                name.getPrefix());
-        org.apache.axis2.soap.SOAPHeaderBlock headerBlock = omHeader.addHeaderBlock(
-                localName, ns);
-        return (new SOAPHeaderElementImpl(headerBlock));
+        OMNamespace ns = new NamespaceImpl(name.getURI(), name.getPrefix());
+        SOAPHeaderBlock headerBlock = new SOAP11HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader);
+        return new SOAPHeaderElementImpl(headerBlock);
     }
 
     /**
-     * method examineHeaderElements
-     *
-     * @param actor
-     * @return
-     * @see javax.xml.soap.SOAPHeader#examineHeaderElements(java.lang.String)
+     * Returns a list of all the <CODE>SOAPHeaderElement</CODE>
+     * objects in this <CODE>SOAPHeader</CODE> object that have the
+     * the specified actor. An actor is a global attribute that
+     * indicates the intermediate parties to whom the message should
+     * be sent. An actor receives the message and then sends it to
+     * the next actor. The default actor is the ultimate intended
+     * recipient for the message, so if no actor attribute is
+     * included in a <CODE>SOAPHeader</CODE> object, the message is
+     * sent to its ultimate destination.
+     *
+     * @param actor a <CODE>String</CODE> giving the
+     *              URI of the actor for which to search
+     * @return an <CODE>Iterator</CODE> object over all the <CODE>
+     *         SOAPHeaderElement</CODE> objects that contain the
+     *         specified actor
+     * @see #extractHeaderElements(java.lang.String) extractHeaderElements(java.lang.String)
      */
     public Iterator examineHeaderElements(String actor) {
-        // Get all the om specific header elements in an iterator and wrap it
-        // in a soap specific iterator and return
-        Iterator headerElementsIter = omHeader.examineHeaderBlocks(actor);
-        ArrayList aList = new ArrayList();
-        while (headerElementsIter.hasNext()) {
-            Object o = headerElementsIter.next();
-            if (o instanceof org.apache.axis2.soap.SOAPHeaderBlock) {
-                org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock) o;
-                SOAPHeaderElement element = (new SOAPHeaderElementImpl(
-                        headerBlock));
-                aList.add(element);
-            }
-        }
-        return aList.iterator();
+        Collection elements = new ArrayList();
+        for (Iterator iterator = omSOAPHeader.examineHeaderBlocks(actor); iterator.hasNext();) {
+            elements.add(new SOAPHeaderElementImpl((SOAPHeaderBlock) iterator.next()));
+        }
+        return elements.iterator();
     }
 
     /**
-     * method extractHeaderElements
-     *
-     * @param actor
-     * @return
-     * @see javax.xml.soap.SOAPHeader#extractHeaderElements(java.lang.String)
+     * Returns a list of all the <CODE>SOAPHeaderElement</CODE>
+     * objects in this <CODE>SOAPHeader</CODE> object that have
+     * the the specified actor and detaches them from this <CODE>
+     * SOAPHeader</CODE> object.
+     * <p/>
+     * <P>This method allows an actor to process only the parts of
+     * the <CODE>SOAPHeader</CODE> object that apply to it and to
+     * remove them before passing the message on to the next
+     * actor.
+     *
+     * @param actor a <CODE>String</CODE> giving the
+     *              URI of the actor for which to search
+     * @return an <CODE>Iterator</CODE> object over all the <CODE>
+     *         SOAPHeaderElement</CODE> objects that contain the
+     *         specified actor
+     * @see #examineHeaderElements(java.lang.String) examineHeaderElements(java.lang.String)
      */
     public Iterator extractHeaderElements(String actor) {
-        // Get all the om specific header elements in an iterator and wrap it
-        // in a soap specific iterator and return
-        Iterator headerElementsIter = omHeader.extractHeaderBlocks(actor);
-        ArrayList aList = new ArrayList();
-        while (headerElementsIter.hasNext()) {
-            Object o = headerElementsIter.next();
-            if (o instanceof org.apache.axis2.soap.SOAPHeaderBlock) {
-                org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock) o;
-                SOAPHeaderElement element = (new SOAPHeaderElementImpl(
-                        headerBlock));
-                aList.add(element);
-            }
+        Collection elements = new ArrayList();
+        for (Iterator iterator = omSOAPHeader.extractHeaderBlocks(actor); iterator.hasNext();) {
+            elements.add(new SOAPHeaderElementImpl((SOAPHeaderBlock) iterator.next()));
         }
-        return aList.iterator();
+        return elements.iterator();
     }
 
     /**
-     * method examineMustUnderstandHeaderElements
+     * Returns an <code>Iterator</code> over all the
+     * <code>SOAPHeaderElement</code> objects in this <code>SOAPHeader</code>
+     * object that have the specified actor and that have a MustUnderstand
+     * attribute whose value is equivalent to <code>true</code>.
      *
-     * @param actor
-     * @return
-     * @see javax.xml.soap.SOAPHeader#examineMustUnderstandHeaderElements(java.lang.String)
+     * @param actor a <code>String</code> giving the URI of the actor for which
+     *              to search
+     * @return an <code>Iterator</code> object over all the
+     *         <code>SOAPHeaderElement</code> objects that contain the
+     *         specified actor and are marked as MustUnderstand
      */
     public Iterator examineMustUnderstandHeaderElements(String actor) {
-        // Get all the om specific header elements in an iterator and wrap it
-        // in a soap specific iterator and return
-        Iterator headerElementsIter = omHeader.examineMustUnderstandHeaderBlocks(
-                actor);
-        ArrayList aList = new ArrayList();
-        while (headerElementsIter.hasNext()) {
-            Object o = headerElementsIter.next();
-            if (o instanceof org.apache.axis2.soap.SOAPHeaderBlock) {
-                org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock) o;
-                SOAPHeaderElement element = (new SOAPHeaderElementImpl(
-                        headerBlock));
-                aList.add(element);
-            }
+        Collection elements = new ArrayList();
+        for (Iterator iterator = omSOAPHeader.examineMustUnderstandHeaderBlocks(actor); iterator.hasNext();)
+        {
+            elements.add(new SOAPHeaderElementImpl((SOAPHeaderBlock) iterator.next()));
         }
-        return aList.iterator();
+        return elements.iterator();
     }
 
     /**
-     * method examineAllHeaderElements
+     * Returns an <code>Iterator</code> over all the
+     * <code>SOAPHeaderElement</code> objects in this <code>SOAPHeader</code>
+     * object.
      *
-     * @return
-     * @see javax.xml.soap.SOAPHeader#examineAllHeaderElements()
+     * @return an <code>Iterator</code> object over all the
+     *         <code>SOAPHeaderElement</code> objects contained by this
+     *         <code>SOAPHeader</code>
      */
     public Iterator examineAllHeaderElements() {
-        // Get all the om specific header elements in an iterator and wrap it
-        // in a soap specific iterator and return
-        Iterator headerElementsIter = omHeader.examineAllHeaderBlocks();
-        ArrayList aList = new ArrayList();
-        while (headerElementsIter.hasNext()) {
-            Object o = headerElementsIter.next();
-            if (o instanceof org.apache.axis2.soap.SOAPHeaderBlock) {
-                org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock) o;
-                SOAPHeaderElement element = (new SOAPHeaderElementImpl(
-                        headerBlock));
-                aList.add(element);
-            }
+        Collection elements = new ArrayList();
+        for (Iterator iterator = omSOAPHeader.examineAllHeaderBlocks(); iterator.hasNext();) {
+            elements.add(new SOAPHeaderElementImpl((SOAPHeaderBlock) iterator.next()));
         }
-        return aList.iterator();
+        return elements.iterator();
     }
 
     /**
-     * method extractAllHeaderElements
+     * Returns an <code>Iterator</code> over all the
+     * <code>SOAPHeaderElement</code> objects in this <code>SOAPHeader </code>
+     * object and detaches them from this <code>SOAPHeader</code> object.
      *
-     * @return
-     * @see javax.xml.soap.SOAPHeader#extractAllHeaderElements()
+     * @return an <code>Iterator</code> object over all the
+     *         <code>SOAPHeaderElement</code> objects contained by this
+     *         <code>SOAPHeader</code>
      */
     public Iterator extractAllHeaderElements() {
-        // Get all the om specific header elements in an iterator and wrap it
-        // in a soap specific iterator and return
-        Iterator headerElementsIter = omHeader.extractAllHeaderBlocks();
-        ArrayList aList = new ArrayList();
-        while (headerElementsIter.hasNext()) {
-            Object o = headerElementsIter.next();
-            if (o instanceof org.apache.axis2.soap.SOAPHeaderBlock) {
-                org.apache.axis2.soap.SOAPHeaderBlock headerBlock = (org.apache.axis2.soap.SOAPHeaderBlock) o;
-                SOAPHeaderElement element = (new SOAPHeaderElementImpl(
-                        headerBlock));
-                aList.add(element);
-            }
+        Collection elements = new ArrayList();
+        for (Iterator iterator = omSOAPHeader.extractAllHeaderBlocks(); iterator.hasNext();) {
+            elements.add(new SOAPHeaderElementImpl((SOAPHeaderBlock) iterator.next()));
         }
-        return aList.iterator();
+        return elements.iterator();
     }
-
-    /*public boolean equals(Object o){
-        if(o instanceof SOAPHeaderImpl){
-            if(this.omHeader.equals(((SOAPHeaderImpl)o).omHeader))
-                    return true;
-        }
-        return false;
-    }*/
-
-}
+}
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java?rev=365487&r1=365486&r2=365487&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java (original)
+++ webservices/axis2/trunk/java/modules/saaj/src/org/apache/axis2/saaj/SOAPMessageImpl.java Mon Jan  2 16:28:43 2006
@@ -17,90 +17,59 @@
 
 import org.apache.axis2.om.OMOutputFormat;
 import org.apache.axis2.transport.http.HTTPConstants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MimeHeader;
 import javax.xml.soap.SOAPBody;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPHeader;
 import javax.xml.soap.SOAPMessage;
 import javax.xml.soap.SOAPPart;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.Map;
 
 public class SOAPMessageImpl extends SOAPMessage {
 
-    private SOAPPartImpl mSOAPPart;
-    private ArrayList attachments = new ArrayList();
-    private java.util.Hashtable mProps = new java.util.Hashtable();
-    private MimeHeaders headers;
-    private Log log = LogFactory.getLog(getClass());
+    private SOAPPart soapPart;
+    private Collection attachmentParts = new ArrayList();
+    private MimeHeadersEx mimeHeaders;
+
+    private Map props = new Hashtable();
+
+    public SOAPMessageImpl(SOAPEnvelopeImpl soapEnvelope) {
+        String contentType = null;
+        if (mimeHeaders != null) {
+            String contentTypes[] = mimeHeaders.getHeader("Content-Type");
+            contentType = (contentTypes != null) ? contentTypes[0] : null;
+        }
 
+        setCharsetEncoding(contentType);
 
-    public SOAPMessageImpl(Object initialContents) {
-        try {
-            setup(initialContents, false, null, null, null);
-        } catch (SOAPException e) {
-           log.error("Error in creating SOAPMessage", e);
-        }
-    }
+        soapPart = new SOAPPartImpl(this, soapEnvelope);
 
-    public SOAPMessageImpl(Object initialContents,
-                           boolean bodyInStream,
-                           javax.xml.soap.MimeHeaders headers) {
-        try {
-            setup(initialContents,
-                    bodyInStream,
-                    null,
-                    null,
-                    headers);
-        } catch (SOAPException e) {
-            log.error(e.getMessage(), e);
-        }
+        this.mimeHeaders = new MimeHeadersEx();
     }
 
-    private void setup(Object initialContents, boolean bodyInStream,
-                       String contentType, String contentLocation,
-                       javax.xml.soap.MimeHeaders mimeHeaders) throws SOAPException {
-        if(contentType == null && mimeHeaders != null) {
+    public SOAPMessageImpl(InputStream inputstream,
+                           javax.xml.soap.MimeHeaders mimeHeaders) throws SOAPException {
+        String contentType = null;
+        if (mimeHeaders != null) {
             String contentTypes[] = mimeHeaders.getHeader("Content-Type");
-            contentType = (contentTypes != null)? contentTypes[0] : null;
-        }
-        
-        if(contentLocation == null && mimeHeaders != null) {
-            String contentLocations[] = mimeHeaders.getHeader("Content-Location");
-            contentLocation = (contentLocations != null)? contentLocations[0] : null;
-        }
-        
-        if (contentType != null) {
-            int delimiterIndex = contentType.lastIndexOf("charset");
-            if (delimiterIndex > 0) {
-                String charsetPart = contentType.substring(delimiterIndex);
-                int charsetIndex = charsetPart.indexOf('=');
-                String charset = charsetPart.substring(charsetIndex + 1).trim();
-                if ((charset.startsWith("\"") || charset.startsWith("\'"))) {
-                    charset = charset.substring(1, charset.length());
-                }
-                if ((charset.endsWith("\"") || charset.endsWith("\'"))) {
-                    charset = charset.substring(0, charset.length()-1);
-                }
-                try {
-                    setProperty(SOAPMessage.CHARACTER_SET_ENCODING, charset);
-                } catch (SOAPException e) {
-                }
-            }
+            contentType = (contentTypes != null) ? contentTypes[0] : null;
         }
-    	
-    	if (null == mSOAPPart)
-            mSOAPPart = new SOAPPartImpl(this, initialContents, bodyInStream);
-        else
-            mSOAPPart.setMessage(this);
 
-        headers = (mimeHeaders == null) ?
-                new MimeHeaders() : new MimeHeaders(mimeHeaders);
+        setCharsetEncoding(contentType);
+        soapPart = new SOAPPartImpl(this, inputstream);
+
+        this.mimeHeaders = (mimeHeaders == null) ?
+                           new MimeHeadersEx() :
+                           new MimeHeadersEx(mimeHeaders);
     }
 
     /**
@@ -113,10 +82,10 @@
      * @see #setContentDescription(java.lang.String) setContentDescription(java.lang.String)
      */
     public String getContentDescription() {
-        String values[] = headers.getHeader(
-                HTTPConstants.HEADER_CONTENT_DESCRIPTION);
-        if (values != null && values.length > 0)
+        String values[] = mimeHeaders.getHeader(HTTPConstants.HEADER_CONTENT_DESCRIPTION);
+        if (values != null && values.length > 0) {
             return values[0];
+        }
         return null;
     }
 
@@ -129,132 +98,305 @@
      * @see #getContentDescription() getContentDescription()
      */
     public void setContentDescription(String description) {
-        headers.setHeader(HTTPConstants.HEADER_CONTENT_DESCRIPTION,
-                description);
+        mimeHeaders.setHeader(HTTPConstants.HEADER_CONTENT_DESCRIPTION, description);
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#getSOAPPart()
+     * Gets the SOAP part of this <CODE>SOAPMessage</CODE> object.
+     * <p/>
+     * <p/>
+     * <P>If a <CODE>SOAPMessage</CODE> object contains one or
+     * more attachments, the SOAP Part must be the first MIME body
+     * part in the message.</P>
+     *
+     * @return the <CODE>SOAPPart</CODE> object for this <CODE>
+     *         SOAPMessage</CODE> object
      */
     public SOAPPart getSOAPPart() {
-        return mSOAPPart;
-    }
-
-    public SOAPBody getSOAPBody() throws SOAPException {
-        return mSOAPPart.getEnvelope().getBody();
-    }
-
-    public SOAPHeader getSOAPHeader() throws SOAPException {
-        return mSOAPPart.getEnvelope().getHeader();
-    }
-
-    public void setProperty(String property, Object value) throws SOAPException {
-        mProps.put(property, value);
-    }
-
-    public Object getProperty(String property) throws SOAPException {
-        return mProps.get(property);
+        return soapPart;
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#removeAllAttachments()
+     * Removes all <CODE>AttachmentPart</CODE> objects that have
+     * been added to this <CODE>SOAPMessage</CODE> object.
+     * <p/>
+     * <P>This method does not touch the SOAP part.</P>
      */
     public void removeAllAttachments() {
-        
-    	attachments.clear();
+        attachmentParts.clear();
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#countAttachments()
+     * Gets a count of the number of attachments in this
+     * message. This count does not include the SOAP part.
+     *
+     * @return the number of <CODE>AttachmentPart</CODE> objects
+     *         that are part of this <CODE>SOAPMessage</CODE>
+     *         object
      */
     public int countAttachments() {
-        
-        return attachments.size();
+        return attachmentParts.size();
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#getAttachments()
+     * Retrieves all the <CODE>AttachmentPart</CODE> objects
+     * that are part of this <CODE>SOAPMessage</CODE> object.
+     *
+     * @return an iterator over all the attachments in this
+     *         message
      */
     public Iterator getAttachments() {
-        
-        return attachments.iterator();
+        return attachmentParts.iterator();
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#getAttachments(javax.xml.soap.MimeHeaders)
+     * Retrieves all the AttachmentPart objects that have header entries that match the specified
+     * headers.
+     * Note that a returned attachment could have headers in addition to those specified.
+     *
+     * @param headers a {@link javax.xml.soap.MimeHeaders}
+     *                object containing the MIME headers for which to search
+     * @return an iterator over all attachments({@link javax.xml.soap.AttachmentPart})
+     *         that have a header that matches one of the given headers
      */
     public Iterator getAttachments(javax.xml.soap.MimeHeaders headers) {
-        
-    	ArrayList temp = new ArrayList();
-    	Iterator iterator = getAttachments();
-    	while(iterator.hasNext()){
-    		AttachmentPartImpl part = (AttachmentPartImpl)iterator.next();
-    		if(part.matches(headers)){
-    			temp.add(part);
-    		}
-    	}
-        return temp.iterator();
+        Collection matchingAttachmentParts = new ArrayList();
+        Iterator iterator = getAttachments();
+        {
+            AttachmentPartImpl part;
+            while (iterator.hasNext()) {
+                part = (AttachmentPartImpl) iterator.next();
+                if (part.matches(headers)) {
+                    matchingAttachmentParts.add(part);
+                }
+            }
+        }
+        return matchingAttachmentParts.iterator();
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#addAttachmentPart(javax.xml.soap.AttachmentPart)
+     * Adds the given <CODE>AttachmentPart</CODE> object to this
+     * <CODE>SOAPMessage</CODE> object. An <CODE>
+     * AttachmentPart</CODE> object must be created before it can be
+     * added to a message.
+     *
+     * @param attachmentPart an <CODE>
+     *                       AttachmentPart</CODE> object that is to become part of
+     *                       this <CODE>SOAPMessage</CODE> object
+     * @throws java.lang.IllegalArgumentException
+     *
      */
-    public void addAttachmentPart(AttachmentPart attachmentpart) {
-        
-    	if(attachmentpart != null){
-    		attachments.add(attachmentpart);
-    		headers.setHeader("Content-Type","multipart/related");
-    	}
-
+    public void addAttachmentPart(AttachmentPart attachmentPart) {
+        if (attachmentPart != null) {
+            attachmentParts.add(attachmentPart);
+            mimeHeaders.setHeader("Content-Type", "multipart/related");
+        }
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#createAttachmentPart()
+     * Creates a new empty <CODE>AttachmentPart</CODE> object.
+     * Note that the method <CODE>addAttachmentPart</CODE> must be
+     * called with this new <CODE>AttachmentPart</CODE> object as
+     * the parameter in order for it to become an attachment to this
+     * <CODE>SOAPMessage</CODE> object.
+     *
+     * @return a new <CODE>AttachmentPart</CODE> object that can be
+     *         populated and added to this <CODE>SOAPMessage</CODE>
+     *         object
      */
     public AttachmentPart createAttachmentPart() {
-        
         return new AttachmentPartImpl();
     }
 
-    /** 
-     * @see javax.xml.soap.SOAPMessage#getMimeHeaders()
+    /**
+     * Returns all the transport-specific MIME headers for this
+     * <CODE>SOAPMessage</CODE> object in a transport-independent
+     * fashion.
+     *
+     * @return a <CODE>MimeHeaders</CODE> object containing the
+     *         <CODE>MimeHeader</CODE> objects
      */
     public javax.xml.soap.MimeHeaders getMimeHeaders() {
-
-        return headers;
+        return mimeHeaders;
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#saveChanges()
+     * Updates this <CODE>SOAPMessage</CODE> object with all the
+     * changes that have been made to it. This method is called
+     * automatically when a message is sent or written to by the
+     * methods <CODE>ProviderConnection.send</CODE>, <CODE>
+     * SOAPConnection.call</CODE>, or <CODE>
+     * SOAPMessage.writeTo</CODE>. However, if changes are made to
+     * a message that was received or to one that has already been
+     * sent, the method <CODE>saveChanges</CODE> needs to be
+     * called explicitly in order to save the changes. The method
+     * <CODE>saveChanges</CODE> also generates any changes that
+     * can be read back (for example, a MessageId in profiles that
+     * support a message id). All MIME headers in a message that
+     * is created for sending purposes are guaranteed to have
+     * valid values only after <CODE>saveChanges</CODE> has been
+     * called.
+     * <p/>
+     * <P>In addition, this method marks the point at which the
+     * data from all constituent <CODE>AttachmentPart</CODE>
+     * objects are pulled into the message.</P>
+     *
+     * @throws SOAPException if there was a problem saving changes to this message.
      */
     public void saveChanges() throws SOAPException {
-        // TODO Not sure what we should do here
+        // TODO not sure of the implementation
+//        throw new UnsupportedOperationException("TODO");
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#saveRequired()
+     * Indicates whether this <CODE>SOAPMessage</CODE> object
+     * has had the method {@link #saveChanges()} called on
+     * it.
+     *
+     * @return <CODE>true</CODE> if <CODE>saveChanges</CODE> has
+     *         been called on this message at least once; <CODE>
+     *         false</CODE> otherwise.
      */
     public boolean saveRequired() {
         return false;
     }
 
     /**
-     * @see javax.xml.soap.SOAPMessage#writeTo(java.io.OutputStream)
+     * Writes this <CODE>SOAPMessage</CODE> object to the given
+     * output stream. The externalization format is as defined by
+     * the SOAP 1.1 with Attachments specification.
+     * <p/>
+     * <P>If there are no attachments, just an XML stream is
+     * written out. For those messages that have attachments,
+     * <CODE>writeTo</CODE> writes a MIME-encoded byte stream.</P>
+     *
+     * @param out the <CODE>OutputStream</CODE>
+     *            object to which this <CODE>SOAPMessage</CODE> object will
+     *            be written
+     * @throws SOAPException if there was a problem in externalizing this SOAP message
+     * @throws IOException   if an I/O error occurs
      */
     public void writeTo(OutputStream out) throws SOAPException, IOException {
         try {
             OMOutputFormat format = new OMOutputFormat();
-            format.setCharSetEncoding((String)getProperty(CHARACTER_SET_ENCODING));
-            String writeXmlDecl = (String)getProperty(WRITE_XML_DECLARATION);
-            if(writeXmlDecl==null || writeXmlDecl.equals("false")) { //SAAJ default case doesn't send XML decl
-            	format.setIgnoreXMLDeclaration(true);
+            format.setCharSetEncoding((String) getProperty(CHARACTER_SET_ENCODING));
+            String writeXmlDecl = (String) getProperty(WRITE_XML_DECLARATION);
+            if (writeXmlDecl == null || writeXmlDecl.equals("false")) {
+
+                //SAAJ default case doesn't send XML decl
+                format.setIgnoreXMLDeclaration(true);
             }
+
             //the writeTo method forces the elements to be built!!!
-            ((SOAPEnvelopeImpl) mSOAPPart.getEnvelope()).getOMEnvelope()
-                    .serialize(out, format);
+            ((SOAPEnvelopeImpl) soapPart.getEnvelope()).getOMEnvelope().serialize(out, format);
         } catch (Exception e) {
+            e.printStackTrace();
             throw new SOAPException(e);
         }
     }
 
+    /**
+     * Associates the specified value with the specified property. If there was
+     * already a value associated with this property, the old value is replaced.
+     * <p/>
+     * The valid property names include <code>WRITE_XML_DECLARATION</code> and
+     * <code>CHARACTER_SET_ENCODING</code>. All of these standard SAAJ
+     * properties are prefixed by "javax.xml.soap". Vendors may also add
+     * implementation specific properties. These properties must be prefixed
+     * with package names that are unique to the vendor.
+     * <p/>
+     * Setting the property <code>WRITE_XML_DECLARATION</code> to
+     * <code>"true"</code> will cause an XML Declaration to be written out at
+     * the start of the SOAP message. The default value of "false" suppresses
+     * this declaration.
+     * <p/>
+     * The property <code>CHARACTER_SET_ENCODING</code> defaults to the value
+     * <code>"utf-8"</code> which causes the SOAP message to be encoded using
+     * UTF-8. Setting <code>CHARACTER_SET_ENCODING</code> to
+     * <code>"utf-16"</code> causes the SOAP message to be encoded using UTF-16.
+     * <p/>
+     * Some implementations may allow encodings in addition to UTF-8 and UTF-16.
+     * Refer to your vendor's documentation for details.
+     *
+     * @param property the property with which the specified value is to be
+     *                 associated
+     * @param value    the value
+     *                 to be associated with the specified property
+     */
+    public void setProperty(String property, Object value) {
+        props.put(property, value);
+    }
+
+    /**
+     * Retrieves value of the specified property.
+     *
+     * @param property the name of the property to retrieve
+     * @return the value of the property or <code>null</code> if no such
+     *         property exists
+     * @throws SOAPException if the property name is not recognized
+     */
+    public Object getProperty(String property) throws SOAPException {
+        return props.get(property);
+    }
+
+    /**
+     * Gets the SOAP Header contained in this <code>SOAPMessage</code> object.
+     *
+     * @return the <code>SOAPHeader</code> object contained by this
+     *         <code>SOAPMessage</code> object
+     * @throws javax.xml.soap.SOAPException if the SOAP Header does not exist or cannot be
+     *                                      retrieved
+     */
+    public SOAPHeader getSOAPHeader() throws SOAPException {
+        return this.soapPart.getEnvelope().getHeader();
+    }
+
+    /**
+     * Gets the SOAP Body contained in this <code>SOAPMessage</code> object.
+     *
+     * @return the <code>SOAPBody</code> object contained by this
+     *         <code>SOAPMessage</code> object
+     * @throws javax.xml.soap.SOAPException if the SOAP Body does not exist or cannot be
+     *                                      retrieved
+     */
+    public SOAPBody getSOAPBody() throws SOAPException {
+        return this.soapPart.getEnvelope().getBody();
+    }
+
+    /**
+     * Retrieve the MIME Header names by providing the {@link javax.xml.soap.MimeHeaders} Object
+     *
+     * @param headers The {@link javax.xml.soap.MimeHeaders} Object
+     * @return MIME Header names corresponding to the <code>headers</code>
+     */
+    private String[] getMimeHeaderNames(final javax.xml.soap.MimeHeaders headers) {
+        Collection mimeHeaderNames = new ArrayList();
+        for (Iterator iterator = headers.getAllHeaders(); iterator.hasNext();) {
+            mimeHeaderNames.add(((MimeHeader) iterator.next()).getName());
+        }
+        return (String[]) mimeHeaderNames.toArray(new String[0]);
+    }
+
+    /**
+     * Set the character encoding based on the <code>contentType</code> parameter
+     *
+     * @param contentType
+     */
+    private void setCharsetEncoding(final String contentType) {
+        if (contentType != null) {
+            int delimiterIndex = contentType.lastIndexOf("charset");
+            if (delimiterIndex > 0) {
+                String charsetPart = contentType.substring(delimiterIndex);
+                int charsetIndex = charsetPart.indexOf('=');
+                String charset = charsetPart.substring(charsetIndex + 1).trim();
+                if ((charset.startsWith("\"") || charset.startsWith("\'"))) {
+                    charset = charset.substring(1, charset.length());
+                }
+                if ((charset.endsWith("\"") || charset.endsWith("\'"))) {
+                    charset = charset.substring(0, charset.length() - 1);
+                }
+                setProperty(SOAPMessage.CHARACTER_SET_ENCODING, charset);
+            }
+        }
+    }
 }



Mime
View raw message