Class AttachmentPart
- java.lang.Object
-
- javax.xml.soap.AttachmentPart
-
- org.apache.axis.attachments.AttachmentPart
-
- All Implemented Interfaces:
java.io.Serializable,Part
public class AttachmentPart extends AttachmentPart implements Part
An attachment part.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.commons.logging.LoglogField log
-
Constructor Summary
Constructors Constructor Description AttachmentPart()Bulds a newAttachmentPart.AttachmentPart(javax.activation.DataHandler dh)Bulds a newAttachmentPartwith aDataHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMimeHeader(java.lang.String header, java.lang.String value)Add the specified MIME header, as per JAXM.voidclearContent()Clears out the content of thisAttachmentPartobject.voiddetachAttachmentFile()Detach the attachment file from this class, so it is not cleaned up.voiddispose()when an attachment part is disposed, any associated files are deleted, and the datahandler itself nulled.protected voidfinalize()On death, we clean up our file.javax.activation.DataHandlergetActivationDataHandler()Get the data handler.java.util.IteratorgetAllMimeHeaders()Retrieves all the headers for thisAttachmentPartobject as an iterator over theMimeHeaderobjects.java.lang.StringgetAttachmentFile()Get the filename of this attachment.java.lang.ObjectgetContent()Gets the content of thisAttachmentPartobject as a Java object.java.lang.StringgetContentId()Gets the value of the MIME header whose name is "Content-Id".java.lang.StringgetContentIdRef()Content ID.java.lang.StringgetContentLocation()Gets the value of the MIME header "Content-Location".java.lang.StringgetContentType()getContentTypejavax.activation.DataHandlergetDataHandler()Gets theDataHandlerobject for thisAttachmentPartobject.java.lang.StringgetFirstMimeHeader(java.lang.String header)Get the specified MIME header.java.util.IteratorgetMatchingMimeHeaders(java.lang.String[] match)Retrieves allMimeHeaderobjects that match a name in the given array.java.lang.String[]getMimeHeader(java.lang.String name)Gets all the values of the header identified by the givenString.java.util.IteratorgetNonMatchingMimeHeaders(java.lang.String[] match)Retrieves allMimeHeaderobjects whose name does not match a name in the given array.intgetSize()Returns the number of bytes in thisAttachmentPartobject.booleanmatches(MimeHeaders headers)check if this Part's mimeheaders matches the one passed in.voidremoveAllMimeHeaders()Removes all the MIME header entries.voidremoveMimeHeader(java.lang.String header)Removes all MIME headers that match the given name.protected voidsetAttachmentFile(java.lang.String path)Set the filename of this attachment part.voidsetContent(java.lang.Object object, java.lang.String contentType)Sets the content of this attachment part to that of the givenObjectand sets the value of theContent-Typeheader to the given type.voidsetContentId(java.lang.String newCid)Sets the MIME header "Content-Id" with the given value.voidsetContentLocation(java.lang.String loc)Sets the MIME header "Content-Location" with the given value.voidsetDataHandler(javax.activation.DataHandler datahandler)Sets the givenDataHandlerobject as the data handler for thisAttachmentPartobject.voidsetMimeHeader(java.lang.String name, java.lang.String value)Changes the first header entry that matches the given name to the given value, adding a new header if no existing header matches.-
Methods inherited from class javax.xml.soap.AttachmentPart
setContentType
-
-
-
-
Method Detail
-
finalize
protected void finalize() throws java.lang.ThrowableOn death, we clean up our file.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable- if anything went wrong during finalization
-
getActivationDataHandler
public javax.activation.DataHandler getActivationDataHandler()
Get the data handler.- Returns:
- the activation
DataHandler
-
getContentType
public java.lang.String getContentType()
getContentType- Specified by:
getContentTypein interfacePart- Overrides:
getContentTypein classAttachmentPart- Returns:
- content type
-
addMimeHeader
public void addMimeHeader(java.lang.String header, java.lang.String value)Add the specified MIME header, as per JAXM.- Specified by:
addMimeHeaderin interfacePart- Specified by:
addMimeHeaderin classAttachmentPart- Parameters:
header-value-
-
getFirstMimeHeader
public java.lang.String getFirstMimeHeader(java.lang.String header)
Get the specified MIME header.- Parameters:
header-- Returns:
-
matches
public boolean matches(MimeHeaders headers)
check if this Part's mimeheaders matches the one passed in. TODO: Am not sure about the logic.- Parameters:
headers- theMimeHeadersto check- Returns:
- true if all header name, values in
headersare found, false otherwise
-
getContentLocation
public java.lang.String getContentLocation()
Description copied from class:AttachmentPartGets the value of the MIME header "Content-Location".- Specified by:
getContentLocationin interfacePart- Overrides:
getContentLocationin classAttachmentPart- Returns:
- a
Stringgiving the value of the "Content-Location" header ornullif there is none
-
setContentLocation
public void setContentLocation(java.lang.String loc)
Description copied from class:AttachmentPartSets the MIME header "Content-Location" with the given value.- Specified by:
setContentLocationin interfacePart- Overrides:
setContentLocationin classAttachmentPart- Parameters:
loc- aStringgiving the value of the "Content-Location" header
-
setContentId
public void setContentId(java.lang.String newCid)
Description copied from class:AttachmentPartSets the MIME header "Content-Id" with the given value.- Specified by:
setContentIdin interfacePart- Overrides:
setContentIdin classAttachmentPart- Parameters:
newCid- aStringgiving the value of the "Content-Id" header- See Also:
getContentId()
-
getContentId
public java.lang.String getContentId()
Description copied from class:AttachmentPartGets the value of the MIME header whose name is "Content-Id".- Specified by:
getContentIdin interfacePart- Overrides:
getContentIdin classAttachmentPart- Returns:
- a
Stringgiving the value of the "Content-Id" header ornullif there is none - See Also:
setContentId(java.lang.String)
-
getMatchingMimeHeaders
public java.util.Iterator getMatchingMimeHeaders(java.lang.String[] match)
Description copied from class:AttachmentPartRetrieves allMimeHeaderobjects that match a name in the given array.- Specified by:
getMatchingMimeHeadersin interfacePart- Specified by:
getMatchingMimeHeadersin classAttachmentPart- Parameters:
match- aStringarray with the name(s) of the MIME headers to be returned- Returns:
- all of the MIME headers that match one of the names
in the given array as an
Iteratorobject
-
getNonMatchingMimeHeaders
public java.util.Iterator getNonMatchingMimeHeaders(java.lang.String[] match)
Description copied from class:AttachmentPartRetrieves allMimeHeaderobjects whose name does not match a name in the given array.- Specified by:
getNonMatchingMimeHeadersin interfacePart- Specified by:
getNonMatchingMimeHeadersin classAttachmentPart- Parameters:
match- aStringarray with the name(s) of the MIME headers not to be returned- Returns:
- all of the MIME headers in this
AttachmentPartobject except those that match one of the names in the given array. The nonmatching MIME headers are returned as anIteratorobject.
-
getAllMimeHeaders
public java.util.Iterator getAllMimeHeaders()
Description copied from class:AttachmentPartRetrieves all the headers for thisAttachmentPartobject as an iterator over theMimeHeaderobjects.- Specified by:
getAllMimeHeadersin classAttachmentPart- Returns:
- an
Iteratorobject with all of the Mime headers for thisAttachmentPartobject
-
setMimeHeader
public void setMimeHeader(java.lang.String name, java.lang.String value)Changes the first header entry that matches the given name to the given value, adding a new header if no existing header matches. This method also removes all matching headers but the first.Note that RFC822 headers can only contain US-ASCII characters.
- Specified by:
setMimeHeaderin classAttachmentPart- Parameters:
name- aStringgiving the name of the header for which to searchvalue- aStringgiving the value to be set for the header whose name matches the given name- Throws:
java.lang.IllegalArgumentException- if there was a problem with the specified mime header name or value
-
removeAllMimeHeaders
public void removeAllMimeHeaders()
Removes all the MIME header entries.- Specified by:
removeAllMimeHeadersin classAttachmentPart
-
removeMimeHeader
public void removeMimeHeader(java.lang.String header)
Removes all MIME headers that match the given name.- Specified by:
removeMimeHeaderin classAttachmentPart- Parameters:
header- - the string name of the MIME header/s to be removed
-
getDataHandler
public javax.activation.DataHandler getDataHandler() throws SOAPExceptionGets theDataHandlerobject for thisAttachmentPartobject.- Specified by:
getDataHandlerin classAttachmentPart- Returns:
- the
DataHandlerobject associated with thisAttachmentPartobject - Throws:
SOAPException- if there is no data in thisAttachmentPartobject
-
setDataHandler
public void setDataHandler(javax.activation.DataHandler datahandler)
Sets the givenDataHandlerobject as the data handler for thisAttachmentPartobject. Typically, on an incoming message, the data handler is automatically set. When a message is being created and populated with content, thesetDataHandlermethod can be used to get data from various data sources into the message.- Specified by:
setDataHandlerin classAttachmentPart- Parameters:
datahandler-DataHandlerobject to be set- Throws:
java.lang.IllegalArgumentException- if there was a problem with the specifiedDataHandlerobject
-
getContent
public java.lang.Object getContent() throws SOAPExceptionGets the content of thisAttachmentPartobject as a Java object. The type of the returned Java object depends on (1) theDataContentHandlerobject that is used to interpret the bytes and (2) theContent-Typegiven in the header.For the MIME content types "text/plain", "text/html" and "text/xml", the
DataContentHandlerobject does the conversions to and from the Java types corresponding to the MIME types. For other MIME types,theDataContentHandlerobject can return anInputStreamobject that contains the content data as raw bytes.A JAXM-compliant implementation must, as a minimum, return a
java.lang.Stringobject corresponding to any content stream with aContent-Typevalue oftext/plainand ajavax.xml.transform.StreamSourceobject corresponding to a content stream with aContent-Typevalue oftext/xml. For those content types that an installedDataContentHandlerobject does not understand, theDataContentHandlerobject is required to return ajava.io.InputStreamobject with the raw bytes.- Specified by:
getContentin classAttachmentPart- Returns:
- a Java object with the content of this
AttachmentPartobject - Throws:
SOAPException- if there is no content set into thisAttachmentPartobject or if there was a data transformation error
-
setContent
public void setContent(java.lang.Object object, java.lang.String contentType)Sets the content of this attachment part to that of the givenObjectand sets the value of theContent-Typeheader to the given type. The type of theObjectshould correspond to the value given for theContent-Type. This depends on the particular set ofDataContentHandlerobjects in use.- Specified by:
setContentin classAttachmentPart- Parameters:
object- the Java object that makes up the content for this attachment partcontentType- the MIME string that specifies the type of the content- Throws:
java.lang.IllegalArgumentException- if the contentType does not match the type of the content object, or if there was noDataContentHandlerobject for this content object- See Also:
getContent()
-
clearContent
public void clearContent()
Clears out the content of thisAttachmentPartobject. The MIME header portion is left untouched.- Specified by:
clearContentin classAttachmentPart
-
getSize
public int getSize() throws SOAPExceptionReturns the number of bytes in thisAttachmentPartobject.- Specified by:
getSizein classAttachmentPart- Returns:
- the size of this
AttachmentPartobject in bytes or -1 if the size cannot be determined - Throws:
SOAPException- if the content of this attachment is corrupted of if there was an exception while trying to determine the size.
-
getMimeHeader
public java.lang.String[] getMimeHeader(java.lang.String name)
Gets all the values of the header identified by the givenString.- Specified by:
getMimeHeaderin interfacePart- Specified by:
getMimeHeaderin classAttachmentPart- Parameters:
name- the name of the header; example: "Content-Type"- Returns:
- a
Stringarray giving the value for the specified header - See Also:
setMimeHeader(java.lang.String, java.lang.String)
-
getContentIdRef
public java.lang.String getContentIdRef()
Content ID.- Specified by:
getContentIdRefin interfacePart- Returns:
- 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.
-
setAttachmentFile
protected void setAttachmentFile(java.lang.String path)
Set the filename of this attachment part.- Parameters:
path- the new file path
-
detachAttachmentFile
public void detachAttachmentFile()
Detach the attachment file from this class, so it is not cleaned up. This has the side-effect of making subsequent calls to getAttachmentFile() returnnull.
-
getAttachmentFile
public java.lang.String getAttachmentFile()
Get the filename of this attachment.- Returns:
- the filename or null for an uncached file
-
dispose
public void dispose()
when an attachment part is disposed, any associated files are deleted, and the datahandler itself nulled. The object is no longer completely usable, at this point
-
-