FileDocCategorySizeDatePackage
SOAPPart.javaAPI DocApache Axis 1.443652Sat Apr 22 18:57:28 BST 2006org.apache.axis

SOAPPart

public class SOAPPart extends SOAPPart implements Part
The SOAPPart provides access to the root part of the Message which contains the envelope.

SOAPPart implements Part, providing common MIME operations.

SOAPPart also allows access to its envelope, as a string, byte[], InputStream, or SOAPEnvelope. (This functionality used to be in Message, and has been moved here more or less verbatim pending further cleanup.)

author
Rob Jellinghaus (robj@unrealities.com)
author
Doug Davis (dug@us.ibm.com)
author
Glen Daniels (gdaniels@allaire.com)
author
Heejune Ahn (cityboy@tmax.co.kr)

Fields Summary
protected static Log
log
public static final int
FORM_STRING
public static final int
FORM_INPUTSTREAM
public static final int
FORM_SOAPENVELOPE
public static final int
FORM_BYTES
public static final int
FORM_BODYINSTREAM
public static final int
FORM_FAULT
public static final int
FORM_OPTIMIZED
private int
currentForm
public static final String
ALLOW_FORM_OPTIMIZATION
property used to set SOAPEnvelope as default form
private org.apache.axis.message.MimeHeaders
mimeHeaders
private static final String[]
formNames
private Object
currentMessage
The current representation of the SOAP contents of this part. May be a String, byte[], InputStream, or SOAPEnvelope, depending on whatever was last asked for. (ack)

currentForm must have the corresponding value.

As someone once said: "Just a placeholder until we figure out what the actual Message object is."

private String
currentEncoding
default message encoding charset
private String
currentMessageAsString
private byte[]
currentMessageAsBytes
private org.apache.axis.message.SOAPEnvelope
currentMessageAsEnvelope
private Message
msgObject
Message object this part is tied to. Used for serialization settings.
private Source
contentSource
Field contentSource.
private Document
document
Implementation of org.w3c.Document Most of methods will be implemented using the delgate instance of SOAPDocumentImpl This is for two reasons: - possible change of message classes, by extenstion of xerces implementation - we cannot extends SOAPPart (multiple inheritance), since it is defined as Abstract class ***********************************************************
protected Document
mDocument
SOAPEnvelope is the Document Elements of this XML docuement
Constructors Summary
public SOAPPart(Message parent, Object initialContents, boolean isBodyStream)
Create a new SOAPPart.

Do not call this directly! Should only be called by Message.

param
parent the parent Message
param
initialContents the initial contens Object
param
isBodyStream if the body is in a stream


                     
    // private Object originalMessage ; //free up reference  this is not in use.

                                                
           

        setMimeHeader(HTTPConstants.HEADER_CONTENT_ID , SessionUtils.generateSessionId());
        setMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE , "text/xml");

        msgObject=parent;
        // originalMessage = initialContents;
        int form = FORM_STRING;
        if (initialContents instanceof SOAPEnvelope) {
            form = FORM_SOAPENVELOPE;
            ((SOAPEnvelope)initialContents).setOwnerDocument(this);
        } else if (initialContents instanceof InputStream) {
            form = isBodyStream ? FORM_BODYINSTREAM : FORM_INPUTSTREAM;
        } else if (initialContents instanceof byte[]) {
            form = FORM_BYTES;
        } else if (initialContents instanceof AxisFault) {
            form = FORM_FAULT;
        }

        if (log.isDebugEnabled()) {
            log.debug("Enter: SOAPPart ctor(" + formNames[form] + ")");
        }

        setCurrentMessage(initialContents, form);

        if (log.isDebugEnabled()) {
            log.debug("Exit: SOAPPart ctor()");
        }
    
Methods Summary
public voidaddMimeHeader(java.lang.String header, java.lang.String value)
Add the specified MIME header, as per JAXM.

param
header the header to add
param
value the value of that header

        mimeHeaders.addHeader(header, value);
    
public org.w3c.dom.NodeadoptNode(org.w3c.dom.Node node)

        throw new UnsupportedOperationException("Not yet implemented.77");
    
public org.w3c.dom.NodeappendChild(org.w3c.dom.Node newChild)

        return document.appendChild(newChild);
    
public org.w3c.dom.NodecloneNode(boolean deep)

        return document.cloneNode(deep);
    
public org.w3c.dom.AttrcreateAttribute(java.lang.String name)

        return document.createAttribute(name);
    
public org.w3c.dom.AttrcreateAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName)

        return document.createAttributeNS(namespaceURI, qualifiedName);
    
public org.w3c.dom.CDATASectioncreateCDATASection(java.lang.String data)

        return document.createCDATASection(data);
    
public org.w3c.dom.CommentcreateComment(java.lang.String data)

        return document.createComment(data);
    
public org.w3c.dom.DocumentFragmentcreateDocumentFragment()

        return document.createDocumentFragment();
    
public org.w3c.dom.ElementcreateElement(java.lang.String tagName)

param
tagName
return
throws
DOMException

        return document.createElement(tagName);
    
public org.w3c.dom.ElementcreateElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName)

        return document.createElementNS(namespaceURI, qualifiedName);
    
public org.w3c.dom.EntityReferencecreateEntityReference(java.lang.String name)

        return document.createEntityReference(name);
    
public org.w3c.dom.ProcessingInstructioncreateProcessingInstruction(java.lang.String target, java.lang.String data)

        return document.createProcessingInstruction(target,data);
    
public org.w3c.dom.TextcreateTextNode(java.lang.String data)

        return document.createTextNode(data);
    
public java.util.IteratorgetAllMimeHeaders()
Retrieves all the headers for this SOAPPart object as an iterator over the MimeHeader objects.

return
an Iterator object with all of the Mime headers for this SOAPPart object

        return mimeHeaders.getAllHeaders();
    
public byte[]getAsBytes()
Get the contents of this Part (not the headers!), as a byte array. This will force buffering of the message.

return
an array of bytes containing a byte representation of this Part
throws
AxisFault if this Part can't be serialized to the byte array

        log.debug("Enter: SOAPPart::getAsBytes");
        if ( currentForm == FORM_OPTIMIZED ) {
            log.debug("Exit: SOAPPart::getAsBytes");
            try {
                return ((ByteArray) currentMessage).toByteArray();
            } catch (IOException e) {
                throw AxisFault.makeFault(e);
            }
        }
        if ( currentForm == FORM_BYTES ) {
            log.debug("Exit: SOAPPart::getAsBytes");
            return (byte[])currentMessage;
        }

        if ( currentForm == FORM_BODYINSTREAM ) {
            try {
                getAsSOAPEnvelope();
            } catch (Exception e) {
                log.fatal(Messages.getMessage("makeEnvFail00"), e);
                log.debug("Exit: SOAPPart::getAsBytes");
                return null;
            }
        }

        if ( currentForm == FORM_INPUTSTREAM ) {
            // Assumes we don't need a content length
            try {
                InputStream  inp = null;
                byte[]  buf = null;
                try{
                    inp = (InputStream) currentMessage ;
                    ByteArrayOutputStream  baos = new ByteArrayOutputStream();
                    buf = new byte[4096];
                    int len ;
                    while ( (len = inp.read(buf,0,4096)) != -1 )
                        baos.write( buf, 0, len );
                    buf = baos.toByteArray();
                }finally{
                  if(inp != null &&
                    currentMessage instanceof org.apache.axis.transport.http.SocketInputStream )
                    inp.close();
                }
                setCurrentForm( buf, FORM_BYTES );
                log.debug("Exit: SOAPPart::getAsBytes");
                return (byte[])currentMessage;
            }
            catch( Exception e ) {
                log.error(Messages.getMessage("exception00"), e);
            }
            log.debug("Exit: SOAPPart::getAsBytes");
            return null;
        }

        if ( currentForm == FORM_SOAPENVELOPE ||
             currentForm == FORM_FAULT ){
            currentEncoding = XMLUtils.getEncoding(msgObject, null);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            BufferedOutputStream os = new BufferedOutputStream(baos);
            try {
                this.writeTo(os);
                os.flush();
            } catch (Exception e) {
                throw AxisFault.makeFault(e);
            }
            setCurrentForm(baos.toByteArray(), FORM_BYTES);
            if (log.isDebugEnabled()) {
                log.debug("Exit: SOAPPart::getAsBytes(): " + currentMessage);
            }
            return (byte[]) currentMessage;
        }

        if ( currentForm == FORM_STRING ) {
            // If the current message was already converted from
            // a byte[] to String, return the byte[] representation
            // (this is done to avoid unnecessary conversions)
            if (currentMessage == currentMessageAsString &&
                currentMessageAsBytes != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Exit: SOAPPart::getAsBytes()");
                }
                return currentMessageAsBytes;
            }
            // Save this message in case it is requested later in getAsString
            currentMessageAsString = (String) currentMessage;
            try{
                currentEncoding = XMLUtils.getEncoding(msgObject, null);
                setCurrentForm( ((String)currentMessage).getBytes(currentEncoding),
                    FORM_BYTES );
            }catch(UnsupportedEncodingException ue){
               setCurrentForm( ((String)currentMessage).getBytes(),
                               FORM_BYTES );
            }
            currentMessageAsBytes = (byte[]) currentMessage;

            log.debug("Exit: SOAPPart::getAsBytes");
            return (byte[])currentMessage;
        }

        log.error(Messages.getMessage("cantConvert00", ""+currentForm));

        log.debug("Exit: SOAPPart::getAsBytes");
        return null;
    
public org.apache.axis.message.SOAPEnvelopegetAsSOAPEnvelope()
Get the contents of this Part (not the MIME headers!), as a SOAPEnvelope. This will force a complete parse of the message.

return
a SOAPEnvelope containing the message content
throws
AxisFault if the envelope could not be constructed

        if (log.isDebugEnabled()) {
            log.debug("Enter: SOAPPart::getAsSOAPEnvelope()");
            log.debug(Messages.getMessage("currForm", formNames[currentForm]));
        }
        if ( currentForm == FORM_SOAPENVELOPE )
            return (SOAPEnvelope)currentMessage;


        if (currentForm == FORM_BODYINSTREAM) {
            InputStreamBody bodyEl =
                             new InputStreamBody((InputStream)currentMessage);
            SOAPEnvelope env = new SOAPEnvelope();
            env.setOwnerDocument(this);
            env.addBodyElement(bodyEl);
            setCurrentForm(env, FORM_SOAPENVELOPE);
            return env;
        }

        InputSource is;

        if ( currentForm == FORM_INPUTSTREAM ) {
            is = new InputSource( (InputStream) currentMessage );
            String encoding = XMLUtils.getEncoding(msgObject, null, null);
            if (encoding != null) {
                currentEncoding = encoding;
                is.setEncoding(currentEncoding);
            }
        } else {
            is = new InputSource(new StringReader(getAsString()));
        }
        DeserializationContext dser = new DeserializationContext(is,
                                           getMessage().getMessageContext(),
                                           getMessage().getMessageType());
        dser.getEnvelope().setOwnerDocument(this);
        // This may throw a SAXException
        try {
            dser.parse();
        } catch (SAXException e) {
            Exception real = e.getException();
            if (real == null)
                real = e;
            throw AxisFault.makeFault(real);
        }

        SOAPEnvelope nse= dser.getEnvelope();
        if(currentMessageAsEnvelope != null){
          //Need to synchronize back processed header info.
          Vector newHeaders= nse.getHeaders();
          Vector oldHeaders= currentMessageAsEnvelope.getHeaders();
          if( null != newHeaders && null != oldHeaders){
           Iterator ohi= oldHeaders.iterator();
           Iterator nhi= newHeaders.iterator();
           while( ohi.hasNext() && nhi.hasNext()){
             SOAPHeaderElement nhe= (SOAPHeaderElement)nhi.next();
             SOAPHeaderElement ohe= (SOAPHeaderElement)ohi.next();

             if(ohe.isProcessed()) nhe.setProcessed(true);
           }
          }

        }

        setCurrentForm(nse, FORM_SOAPENVELOPE);

        log.debug("Exit: SOAPPart::getAsSOAPEnvelope");
        SOAPEnvelope env = (SOAPEnvelope)currentMessage;
        env.setOwnerDocument(this);
        return env;
    
public java.lang.StringgetAsString()
Get the contents of this Part (not the headers!), as a String. This will force buffering of the message.

return
a String containing the content of this message
throws
AxisFault if there is an error serializing this part

        log.debug("Enter: SOAPPart::getAsString");
        if ( currentForm == FORM_STRING ) {
            if (log.isDebugEnabled()) {
                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
            }
            return (String)currentMessage;
        }

        if ( currentForm == FORM_INPUTSTREAM ||
             currentForm == FORM_BODYINSTREAM ) {
            getAsBytes();
            // Fall thru to "Bytes"
        }

        if ( currentForm == FORM_OPTIMIZED) {
            try {
                currentMessageAsBytes =
                        ((ByteArray) currentMessage).toByteArray();
            } catch (IOException e) {
                throw AxisFault.makeFault(e);
            }

            try{
                setCurrentForm(new String((byte[])currentMessageAsBytes,
                                currentEncoding),
                        FORM_STRING);
            }catch(UnsupportedEncodingException ue){
                setCurrentForm( new String((byte[]) currentMessageAsBytes),
                                   FORM_STRING );
            }
            if (log.isDebugEnabled()) {
                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
            }
            return (String)currentMessage;
        }

        if ( currentForm == FORM_BYTES ) {
            // If the current message was already converted from
            // a String to byte[], return the String representation
            // (this is done to avoid unnecessary conversions)
            if (currentMessage == currentMessageAsBytes &&
                currentMessageAsString != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Exit: SOAPPart::getAsString(): " + currentMessageAsString);
                }
                return currentMessageAsString;
            }
            
            // Save this message in case it is requested later in getAsBytes
            currentMessageAsBytes = (byte[]) currentMessage;
            try{
                setCurrentForm(new String((byte[])currentMessage,
                                currentEncoding),
                        FORM_STRING);
            }catch(UnsupportedEncodingException ue){
                setCurrentForm( new String((byte[]) currentMessage),
                                   FORM_STRING );
            }
            currentMessageAsString = (String) currentMessage;
            if (log.isDebugEnabled()) {
                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
            }
            return (String)currentMessage;
        }

        if ( currentForm == FORM_FAULT ) {
            StringWriter writer = new StringWriter();
            try {
                this.writeTo(writer);
            } catch (Exception e) {
                log.error(Messages.getMessage("exception00"), e);
                return null;
            }
            setCurrentForm(writer.getBuffer().toString(), FORM_STRING);
            if (log.isDebugEnabled()) {
                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
            }
            return (String)currentMessage;
        }

        if ( currentForm == FORM_SOAPENVELOPE ) {
            StringWriter writer = new StringWriter();
            try {
                this.writeTo(writer);
            } catch (Exception e) {
                throw AxisFault.makeFault(e);
            }
            setCurrentForm(writer.getBuffer().toString(), FORM_STRING);
            if (log.isDebugEnabled()) {
                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
            }
            return (String)currentMessage;
        }

        log.error( Messages.getMessage("cantConvert01", ""+currentForm));

        log.debug("Exit: SOAPPart::getAsString()");
        return null;
    
public org.w3c.dom.NamedNodeMapgetAttributes()

        return document.getAttributes();
    
public org.w3c.dom.NodeListgetChildNodes()

        return document.getChildNodes();
    
public javax.xml.transform.SourcegetContent()
Returns the content of the SOAPEnvelope as a JAXP Source object.

return
the content as a javax.xml.transform.Source object
throws
SOAPException if the implementation cannot convert the specified Source object
see
#setContent(javax.xml.transform.Source) setContent(javax.xml.transform.Source)

        if(contentSource == null) {
            switch(currentForm) {
                case FORM_STRING:
                    String s = (String) currentMessage;
                    contentSource = new StreamSource(new StringReader(s));
                    break;
                case FORM_INPUTSTREAM:
                    contentSource =
                            new StreamSource((InputStream) currentMessage);
                    break;
                case FORM_SOAPENVELOPE:
                    SOAPEnvelope se = (SOAPEnvelope) currentMessage;
                    try {
                        contentSource = new DOMSource(se.getAsDocument());
                    } catch (Exception e) {
                        throw new SOAPException(Messages.getMessage("errorGetDocFromSOAPEnvelope"),
                                e);
                    }
                    break;
                case FORM_OPTIMIZED:
                    try {
                        ByteArrayInputStream baos = new ByteArrayInputStream(((ByteArray) currentMessage).toByteArray());
                        contentSource = new StreamSource(baos);
                    } catch (IOException e) {
                        throw new SOAPException(Messages.getMessage("errorGetDocFromSOAPEnvelope"),
                                e);
                    }
                    break;
                case FORM_BYTES:
                    byte[] bytes = (byte[]) currentMessage;
                    contentSource =
                            new StreamSource(new ByteArrayInputStream(bytes));
                    break;
                case FORM_BODYINSTREAM:
                    contentSource =
                            new StreamSource((InputStream) currentMessage);
                    break;
            }
        }
        return contentSource;
    
public java.lang.StringgetContentId()
Content ID.

return
the content ID

        return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
    
public java.lang.StringgetContentIdRef()
Content ID.

return
the contentId reference value that should be used directly as an href in a SOAP element to reference this attachment. Not part of JAX-RPC, JAX-M, SAAJ, etc.

      return org.apache.axis.attachments.Attachments.CIDprefix +
         getContentId();
    
public longgetContentLength()
Get the content length for this SOAPPart. This will force buffering of the SOAPPart, but it will also cache the byte[] form of the SOAPPart.

return
the content length in bytes

        saveChanges();
        if (currentForm == FORM_OPTIMIZED) {
            return ((ByteArray) currentMessage).size();
        } else if (currentForm == FORM_BYTES) {
            return ((byte[]) currentMessage).length;
        }
        byte[] bytes = this.getAsBytes();
        return bytes.length;
    
public java.lang.StringgetContentLocation()
Content location.

return
the content location

        return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION);
    
public java.lang.StringgetContentType()
Content type is always "text/xml" for SOAPParts.

return
the content type

        return "text/xml";
    
public intgetCurrentForm()

        return currentForm;
    
public java.lang.ObjectgetCurrentMessage()
Get the current message, in whatever form it happens to be right now. Will return a String, byte[], InputStream, or SOAPEnvelope, depending on circumstances.

The method name is historical. TODO: rename this for clarity; should be more like getContents.

return
the current content

        return currentMessage;
    
public org.w3c.dom.DocumentTypegetDoctype()

return

        return document.getDoctype();
    
public org.w3c.dom.ElementgetDocumentElement()

        try{
            return getEnvelope();
        }catch(SOAPException se){
            return null;
        }
    
public org.w3c.dom.ElementgetElementById(java.lang.String elementId)

        return document.getElementById(elementId);
    
public org.w3c.dom.NodeListgetElementsByTagName(java.lang.String tagname)

        return document.getElementsByTagName(tagname);
    
public org.w3c.dom.NodeListgetElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)

        return document.getElementsByTagNameNS(namespaceURI,localName);
    
public java.lang.StringgetEncoding()

        return currentEncoding;
    
public javax.xml.soap.SOAPEnvelopegetEnvelope()
Gets the SOAPEnvelope object associated with this SOAPPart object. Once the SOAP envelope is obtained, it can be used to get its contents.

return
the SOAPEnvelope object for this SOAPPart object
throws
SOAPException if there is a SOAP error

        try {
            return getAsSOAPEnvelope();
        } catch (AxisFault af) {
            throw new SOAPException(af);
        }
    
public org.w3c.dom.NodegetFirstChild()

        return document.getFirstChild();
    
private java.lang.StringgetFirstMimeHeader(java.lang.String header)
Get the specified MIME header.

param
header the name of a MIME header
return
the value of the first header named header

        String[] values = mimeHeaders.getHeader(header);
        if(values != null && values.length>0)
            return values[0];
        return null;
    
public org.w3c.dom.DOMImplementationgetImplementation()

return

        return document.getImplementation();
    
public org.w3c.dom.NodegetLastChild()

        return document.getLastChild();
    
public java.lang.StringgetLocalName()

        return document.getLocalName();
    
public java.util.IteratorgetMatchingMimeHeaders(java.lang.String[] match)
Get all headers that match.

param
match an array of Strings giving mime header names
return
an Iterator over all values matching these headers

        return mimeHeaders.getMatchingHeaders(match);
    
public MessagegetMessage()
Get the Message for this Part.

return
the Message for this Part

      return msgObject;
    
public java.lang.String[]getMimeHeader(java.lang.String name)
Gets all the values of the MimeHeader object in this SOAPPart object that is identified by the given String.

param
name the name of the header; example: "Content-Type"
return
a String array giving all the values for the specified header
see
#setMimeHeader(java.lang.String, java.lang.String) setMimeHeader(java.lang.String, java.lang.String)

        return mimeHeaders.getHeader(name);
    
public java.lang.StringgetNamespaceURI()

        return document.getNamespaceURI();
    
public org.w3c.dom.NodegetNextSibling()

        return document.getNextSibling();
    
public java.lang.StringgetNodeName()
Node Implementation

        return document.getNodeName();
    
public shortgetNodeType()

        return document.getNodeType();
    
public java.lang.StringgetNodeValue()

        return document.getNodeValue();
    
public java.util.IteratorgetNonMatchingMimeHeaders(java.lang.String[] match)
Get all headers that do not match.

param
match an array of Strings giving mime header names
return
an Iterator over all values not matching these headers

        return mimeHeaders.getNonMatchingHeaders(match);
    
public org.w3c.dom.DocumentgetOwnerDocument()

        return document.getOwnerDocument();
    
public org.w3c.dom.NodegetParentNode()

        return  document.getParentNode();
    
public java.lang.StringgetPrefix()

        return document.getPrefix();
    
public org.w3c.dom.NodegetPreviousSibling()

        return document.getPreviousSibling();
    
public org.w3c.dom.DocumentgetSOAPDocument()

since
SAAJ 1.2

             
      
        if(document == null){
            document = new SOAPDocumentImpl(this);
        }
        return document;
    
public booleangetStandalone()

        throw new UnsupportedOperationException("Not yet implemented.71");
    
public booleangetStrictErrorChecking()

        throw new UnsupportedOperationException("Not yet implemented.73");
    
public java.lang.StringgetVersion()

        throw new UnsupportedOperationException("Not yet implemented. 75");
    
public booleanhasAttributes()

        return document.hasAttributes();
    
public booleanhasChildNodes()

        return document.hasChildNodes();
    
public org.w3c.dom.NodeimportNode(org.w3c.dom.Node importedNode, boolean deep)

        return document.importNode(importedNode, deep);
    
public org.w3c.dom.NodeinsertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild)

        return document.insertBefore(newChild, refChild);
    
public booleanisBodyStream()

        return (currentForm == SOAPPart.FORM_INPUTSTREAM || currentForm == SOAPPart.FORM_BODYINSTREAM);        
    
private booleanisFormOptimizationAllowed()
check if the allow optimization flag is on

return
form optimization flag

        boolean allowFormOptimization = true;
        Message msg = getMessage();
        if (msg != null) {
            MessageContext ctx = msg.getMessageContext();
            if (ctx != null) {
                Boolean propFormOptimization = (Boolean)ctx.getProperty(ALLOW_FORM_OPTIMIZATION);
                if (propFormOptimization != null) {
                    allowFormOptimization = propFormOptimization.booleanValue();
                }
            }
        }
        return allowFormOptimization;
    
public booleanisSupported(java.lang.String feature, java.lang.String version)

        return document.isSupported(feature, version);
    
public voidnormalize()

        document.normalize();
    
public voidremoveAllMimeHeaders()
Removes all the MimeHeader objects for this SOAPEnvelope object.

        mimeHeaders.removeAllHeaders();
    
public org.w3c.dom.NoderemoveChild(org.w3c.dom.Node oldChild)

        return document.removeChild(oldChild);
    
public voidremoveMimeHeader(java.lang.String header)
Removes all MIME headers that match the given name.

param
header a String giving the name of the MIME header(s) to be removed

        mimeHeaders.removeHeader(header);
    
public org.w3c.dom.NodereplaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild)

        return document.replaceChild(newChild, oldChild);
    
public voidsaveChanges()

        log.debug("Enter: SOAPPart::saveChanges");
        if ( currentForm == FORM_SOAPENVELOPE ||
             currentForm == FORM_FAULT ){
            currentEncoding = XMLUtils.getEncoding(msgObject, null);
            ByteArray array = new ByteArray();
            try {
            	writeTo(array);
                array.flush();
            } catch (Exception e) {
                throw AxisFault.makeFault(e);
            }
            setCurrentForm( array, FORM_OPTIMIZED );
            if (log.isDebugEnabled()) {
                log.debug("Exit: SOAPPart::saveChanges(): " + currentMessage);
            }
        }
    
public voidsetContent(javax.xml.transform.Source source)
Sets the content of the SOAPEnvelope object with the data from the given Source object.

param
source javax.xml.transform.Source object with the data to be set
throws
SOAPException if there is a problem in setting the source
see
#getContent() getContent()

        if(source == null)
            throw new SOAPException(Messages.getMessage("illegalArgumentException00"));

        // override the checks in HandlerChainImpl for JAXRPCHandler kludge
        MessageContext ctx = getMessage().getMessageContext();
        if (ctx != null) {
            ctx.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION,
                Boolean.TRUE);
        }

        contentSource = source;
        InputSource in = org.apache.axis.utils.XMLUtils.sourceToInputSource(contentSource);
        InputStream is = in.getByteStream();
        if(is != null) {
            setCurrentMessage(is, FORM_INPUTSTREAM);
        } else {
            Reader r = in.getCharacterStream();
            if(r == null) {
                throw new SOAPException(Messages.getMessage("noCharacterOrByteStream"));
            }
            BufferedReader br = new BufferedReader(r);
            String line = null;
            StringBuffer sb = new StringBuffer();
            try {
                while((line = br.readLine()) != null) {
                    sb.append(line);
                }
            } catch (IOException e) {
                throw new SOAPException(Messages.getMessage("couldNotReadFromCharStream"), e);
            }
            setCurrentMessage(sb.toString(), FORM_STRING);
        }
    
public voidsetContentId(java.lang.String newCid)
Sets Content-Id of this part. already defined.

param
newCid new Content-Id

        setMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid);
    
public voidsetContentLocation(java.lang.String loc)
Set content location.

param
loc the content location

        setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);
    
private voidsetCurrentForm(java.lang.Object currMsg, int form)
Set the current contents of this Part. The method name is historical. TODO: rename this for clarity to something more like setContents???

param
currMsg the new content of this part
param
form the form of the message

        if (log.isDebugEnabled()) {
            String msgStr;
            if (currMsg instanceof String) {
                msgStr = (String)currMsg;
            } else {
                msgStr = currMsg.getClass().getName();
            }
            log.debug(Messages.getMessage("setMsgForm", formNames[form],
                    "" + msgStr));
        }

        // only change form if allowed
        if (isFormOptimizationAllowed()) {
            currentMessage = currMsg;
            currentForm = form;
            if (currentForm == FORM_SOAPENVELOPE) {
                    currentMessageAsEnvelope = (org.apache.axis.message.SOAPEnvelope) currMsg;
            }
        }
    
public voidsetCurrentMessage(java.lang.Object currMsg, int form)
Set the current message

param
currMsg
param
form

      currentMessageAsString = null; //Get rid of any cached stuff this is new.
      currentMessageAsBytes = null;
      currentMessageAsEnvelope= null;
      setCurrentForm(currMsg, form);
    
public voidsetEncoding(java.lang.String s)

        currentEncoding = s;
    
public voidsetMessage(Message msg)
Set the Message for this Part. Do not call this Directly. Called by Message.

param
msg the Message for this part

        this.msgObject= msg;
    
public voidsetMimeHeader(java.lang.String name, java.lang.String value)
Changes the first header entry that matches the given header name so that its value is the given value, adding a new header with the given name and value if no existing header is a match. If there is a match, this method clears all existing values for the first header that matches and sets the given value instead. If more than one header has the given name, this method removes all of the matching headers after the first one.

Note that RFC822 headers can contain only US-ASCII characters.

param
name a String giving the header name for which to search
param
value a String giving the value to be set. This value will be substituted for the current value(s) of the first header that is a match if there is one. If there is no match, this value will be the value for a new MimeHeader object.
throws java.lang.IllegalArgumentException if there was a problem with the specified mime header name or value
see
#getMimeHeader(java.lang.String) getMimeHeader(java.lang.String)

        mimeHeaders.setHeader(name,value);
    
public voidsetNodeValue(java.lang.String nodeValue)

        document.setNodeValue(nodeValue);
    
public voidsetPrefix(java.lang.String prefix)

        document.setPrefix(prefix);
    
public voidsetSOAPEnvelope(org.apache.axis.message.SOAPEnvelope env)
This set the SOAP Envelope for this part.

Note: It breaks the chicken/egg created. I need a message to create an attachment... From the attachment I should be able to get a reference... I now want to edit elements in the envelope in order to place the attachment reference to it. How do I now update the SOAP envelope with what I've changed?

param
env the SOAPEnvelope for this SOAPPart

       setCurrentMessage(env, FORM_SOAPENVELOPE) ;
    
public voidsetStandalone(boolean flag)

        throw new UnsupportedOperationException("Not yet implemented.72");
    
public voidsetStrictErrorChecking(boolean flag)

        throw new UnsupportedOperationException("Not yet implemented. 74");
    
public voidsetVersion(java.lang.String s)

        throw new UnsupportedOperationException("Not yet implemented.76");
    
public voidwriteTo(java.io.OutputStream os)
Write the contents to the specified stream.

param
os the java.io.OutputStream to write to

        if ( currentForm == FORM_BYTES ) {
            os.write((byte[])currentMessage);
        } else if ( currentForm == FORM_OPTIMIZED ) {
            ((ByteArray) currentMessage).writeTo(os);
        } else {
            Writer writer = new OutputStreamWriter(os, currentEncoding);
            writer = new BufferedWriter(new PrintWriter(writer));
            writeTo(writer);
            writer.flush();
        }
    
public voidwriteTo(java.io.Writer writer)
Write the contents to the specified writer.

param
writer the Writer to write to

        boolean inclXmlDecl = false;         
        
        if (msgObject.getMessageContext() != null) {    // if we have message context (JAX-RPC), write xml decl always. 
            inclXmlDecl = true;            
        } else {    // if we have no message context (SAAJ), write xml decl according to property.
            try {
                String xmlDecl = (String)msgObject.getProperty(SOAPMessage.WRITE_XML_DECLARATION);
                if (xmlDecl != null && xmlDecl.equals("true")) {
                    inclXmlDecl = true;                    
                }                
            } catch (SOAPException e) {
                throw new IOException(e.getMessage());
            }
        }
        
        if ( currentForm == FORM_FAULT ) {
            AxisFault env = (AxisFault)currentMessage;
            try {
                SerializationContext serContext = new SerializationContext(writer, getMessage().getMessageContext()); 
                serContext.setSendDecl(inclXmlDecl);
                serContext.setEncoding(currentEncoding);
                env.output(serContext);
            } catch (Exception e) {
                log.error(Messages.getMessage("exception00"), e);
                throw env;
            }
            return;
        }

        if ( currentForm == FORM_SOAPENVELOPE ) {
            SOAPEnvelope env = (SOAPEnvelope)currentMessage;
            try {
                SerializationContext serContext = new SerializationContext(writer, getMessage().getMessageContext());
                serContext.setSendDecl(inclXmlDecl);
                serContext.setEncoding(currentEncoding);
                env.output(serContext);
            } catch (Exception e) {
                throw AxisFault.makeFault(e);
            }
            return;
        }

        String xml = this.getAsString();
        if(inclXmlDecl){
            if(!xml.startsWith("<?xml")){
                writer.write("<?xml version=\"1.0\" encoding=\"");
                writer.write(currentEncoding);
                writer.write("\"?>");
            }
        }
        writer.write(xml);