You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by gd...@apache.org on 2001/12/04 23:12:10 UTC
cvs commit: xml-axis/java/src/org/apache/axis/attachments AttachmentsImpl.java
gdaniels 01/12/04 14:12:10
Modified: java/src/org/apache/axis/attachments AttachmentsImpl.java
Log:
Clean up code.
Why are 95% of the classes in this file fully-qualified? Doesn't make for particularly readable code...
Revision Changes Path
1.10 +145 -127 xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java
Index: AttachmentsImpl.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AttachmentsImpl.java 2001/12/03 22:49:23 1.9
+++ AttachmentsImpl.java 2001/12/04 22:12:10 1.10
@@ -53,14 +53,14 @@
* <http://www.apache.org/>.
*/
- /* @author Rob Jellinghaus (robj@unrealities.com) */
- /* @author Rick Rineholt */
+/* @author Rob Jellinghaus (robj@unrealities.com) */
+/* @author Rick Rineholt */
package org.apache.axis.attachments;
+import org.apache.axis.AxisFault;
import org.apache.axis.Message;
import org.apache.axis.Part;
-import org.apache.axis.AxisFault;
/**
@@ -70,189 +70,207 @@
public class AttachmentsImpl implements Attachments {
private Message msg;
-
-
private java.util.HashMap attachments = new java.util.HashMap();
-
- protected org.apache.axis.SOAPPart soapPart= null;
+ protected org.apache.axis.SOAPPart soapPart = null;
/**
* The actual stream to manage the multi-related input stream.
*/
- protected org.apache.axis.attachments.MultiPartRelatedInputStream mpartStream= null;
+ protected org.apache.axis.attachments.MultiPartRelatedInputStream mpartStream = null;
/**
* This is the content location as specified in SOAP with Attachments.
* This maybe null if the message had no Content-Location specifed.
*/
+ protected String contentLocation = null;
- protected String contentLocation= null;
-
/**
* Construct one of these on a parent Message.
* Should only ever be called by Message constructor!
* @param msg the message associated
- * @param initialContents should be anything but today only a stream is supported.
- * @param The mime content type of the stream for transports that provide it.
- */
- public AttachmentsImpl(Message msg, Object intialContents, String contentType,
- String contentLocation) throws org.apache.axis.AxisFault {
- if(contentLocation != null){
- contentLocation= contentLocation.trim();
- if(contentLocation.length()==0) contentLocation= null;
- }
- this.contentLocation= contentLocation;
-
- this.msg= msg;
- if(contentType != null) {
- if(contentType.equals(org.apache.axis.Message.MIME_UNKNOWN)){
- //Process the input stream for headers to determine the mime type.
- //TODO
- }
- else{
- java.util.StringTokenizer st = new java.util.StringTokenizer(contentType, " \t;");
- if(st.hasMoreTokens()) {
- String mimetype= st.nextToken();
- if(mimetype.equalsIgnoreCase(org.apache.axis.Message.MIME_MULTIPART_RELATED)){
- mpartStream= new org.apache.axis.attachments.MultiPartRelatedInputStream(contentType,
- (java.io.InputStream)intialContents);
- if(null == contentLocation){ //If the content location is not specified as
- //of the main message use the SOAP content location.
- contentLocation= mpartStream.getContentLocation();
-
- if(contentLocation != null){
- contentLocation= contentLocation.trim();
- if(contentLocation.length()==0) contentLocation= null;
- }
- }
-
- soapPart= new org.apache.axis.SOAPPart(msg, mpartStream, false);
- }
- else if(mimetype.equalsIgnoreCase(org.apache.axis.Message.MIME_APPLICATION_DIME)){ //do nothing today.
- //is= new DIMEInputStreamManager(is);
- }
- }
- }
- }
+ * @param initialContents should be anything but today only a stream is
+ * supported.
+ * @param The mime content type of the stream for transports that provide
+ * it.
+ */
+ public AttachmentsImpl(Message msg,
+ Object intialContents,
+ String contentType,
+ String contentLocation)
+ throws org.apache.axis.AxisFault
+ {
+ if (contentLocation != null) {
+ contentLocation = contentLocation.trim();
+ if (contentLocation.length() == 0) contentLocation = null;
+ }
+ this.contentLocation = contentLocation;
+
+ this.msg = msg;
+ if (contentType != null) {
+ if (contentType.equals(org.apache.axis.Message.MIME_UNKNOWN)) {
+ //Process the input stream for headers to determine the mime
+ //type.
+ //TODO
+ } else {
+ java.util.StringTokenizer st =
+ new java.util.StringTokenizer(contentType, " \t;");
+ if (st.hasMoreTokens()) {
+ String mimetype = st.nextToken();
+ if (mimetype.equalsIgnoreCase(
+ org.apache.axis.Message.MIME_MULTIPART_RELATED)) {
+ mpartStream =
+ new org.apache.axis.attachments.MultiPartRelatedInputStream(contentType,
+ (java.io.InputStream) intialContents);
+ if (null == contentLocation) {
+ //If the content location is not specified as
+ //of the main message use the SOAP content location.
+ contentLocation = mpartStream.getContentLocation();
+
+ if (contentLocation != null) {
+ contentLocation = contentLocation.trim();
+ if (contentLocation.length() == 0)
+ contentLocation = null;
+ }
+ }
+
+ soapPart = new org.apache.axis.SOAPPart(msg,
+ mpartStream,
+ false);
+ } else if (mimetype.equalsIgnoreCase(org.apache.axis.Message.MIME_APPLICATION_DIME)) { //do nothing today.
+ //is= new DIMEInputStreamManager(is);
+ }
+ }
+ }
+ }
}
/**
* Create an attachment part with a buried JAF data handler.
*/
- public Part createAttachmentPart(Object datahandler ) throws org.apache.axis.AxisFault{
- if(!( datahandler instanceof javax.activation.DataHandler )){
- throw new org.apache.axis.AxisFault( "Unsupported attachment type \"" + datahandler.getClass().getName()
- + "\" only supporting \"" + javax.activation.DataHandler.class.getName() +"\".");
- }
- Part ret= new AttachmentPart(msg, (javax.activation.DataHandler)datahandler);
- attachments.put(ret.getContentId(), ret);
+ public Part createAttachmentPart(Object datahandler)
+ throws org.apache.axis.AxisFault {
+ if (!(datahandler instanceof javax.activation.DataHandler)) {
+ throw new org.apache.axis.AxisFault("Unsupported attachment type \"" +
+ datahandler.getClass().getName() +
+ "\" only supporting \"" +
+ javax.activation.DataHandler.class.getName() + "\".");
+ }
+ Part ret = new AttachmentPart(msg,
+ (javax.activation.DataHandler)datahandler);
+ attachments.put(ret.getContentId(), ret);
return ret;
}
/**
* Add the collection of parts.
*/
- public void setAttachmentParts( java.util.Collection parts) throws org.apache.axis.AxisFault{
- attachments.clear();
- if(parts != null && !parts.isEmpty()){
- for(java.util.Iterator i= parts.iterator(); i.hasNext();){
- Part part= (Part ) i.next();
- if(null != part){
- part.setMessage(msg);
- attachments.put(part.getContentId(), part);
- }
- }
- }
+ public void setAttachmentParts(java.util.Collection parts)
+ throws org.apache.axis.AxisFault {
+ attachments.clear();
+ if (parts != null && !parts.isEmpty()) {
+ for (java.util.Iterator i = parts.iterator(); i.hasNext();) {
+ Part part = (Part) i.next();
+ if (null != part) {
+ part.setMessage(msg);
+ attachments.put(part.getContentId(), part);
+ }
+ }
+ }
}
/**
- * This method should look at a refernce and determine if it is a CID: or url
- * to look for attachment.
+ * This method should look at a refernce and determine if it is a CID: or
+ * url to look for attachment.
* @param The reference in the xml that referers to an attachment.
* @return The part associated with the attachment.
- */
- public Part getAttachmentByReference(String reference) throws org.apache.axis.AxisFault {
- if(null == reference ) return null;
- reference= reference.trim();
- if(0== reference.length()) return null;
-
- String[]id= null;
- String referenceLC= reference.toLowerCase();
- if(!referenceLC.startsWith("cid:") && null != contentLocation){
- String fqreference= contentLocation;
- if(!fqreference.endsWith("/")) fqreference += "/";
- if(reference.startsWith("/")) fqreference += reference.substring(1);
- else fqreference += reference;
- id= new String[]{reference, fqreference };
- }else{
- id= new String[]{reference};
- }
- Part ret= (AttachmentPart)attachments.get(id);
- if(ret == null && mpartStream != null ){
- //We need to still check if this coming in the input stream;
- ret= mpartStream.getAttachmentByReference(id);
+ */
+ public Part getAttachmentByReference(String reference)
+ throws org.apache.axis.AxisFault {
+ if (null == reference) return null;
+ reference = reference.trim();
+ if (0 == reference.length()) return null;
+
+ String[] id = null;
+ String referenceLC = reference.toLowerCase();
+ if (!referenceLC.startsWith("cid:") && null != contentLocation) {
+ String fqreference = contentLocation;
+ if (!fqreference.endsWith("/")) fqreference += "/";
+ if (reference.startsWith("/"))
+ fqreference += reference.substring(1);
+ else
+ fqreference += reference;
+ id = new String[]{reference, fqreference};
+ } else {
+ id = new String[]{reference};
}
- return ret;
+ Part ret = (AttachmentPart) attachments.get(id);
+ if (ret == null && mpartStream != null) {
+ //We need to still check if this coming in the input stream;
+ ret = mpartStream.getAttachmentByReference(id);
+ }
+ return ret;
}
-
+
/**
* This method will return all attachments as a collection.
*
* @return A collection of attachments.
- */
- public java.util.Collection getAttachments() throws org.apache.axis.AxisFault{
- java.util.Collection ret= new java.util.LinkedList();
-
- if(null != mpartStream){
- java.util.Collection mc= mpartStream.getAttachments();
- ret= new java.util.LinkedList( mc); // make a copy.
+ */
+ public java.util.Collection getAttachments()
+ throws org.apache.axis.AxisFault {
+ java.util.Collection ret = new java.util.LinkedList();
+
+ if (null != mpartStream) {
+ java.util.Collection mc = mpartStream.getAttachments();
+ ret = new java.util.LinkedList(mc); // make a copy.
}
- return ret;
+ return ret;
}
/**
* From the complex stream return the root part.
* Today this is SOAP.
- */
- public Part getRootPart(){
- return soapPart;
+ */
+ public Part getRootPart() {
+ return soapPart;
}
- public javax.mail.internet.MimeMultipart multipart= null;
-
+ public javax.mail.internet.MimeMultipart multipart = null;
+
/**
* Get the content length of the stream.
- */
+ */
public int getContentLength() throws org.apache.axis.AxisFault {
- try{
- return (int) org.apache.axis.attachments.MimeUtils.getContentLength( multipart !=null ? multipart :
- (multipart= org.apache.axis.attachments.MimeUtils.createMP(msg.getSOAPPart().getAsString(), attachments )));
- }
- catch(Exception e){
- throw AxisFault.makeFault(e);
- }
+ try {
+ return (int)org.apache.axis.attachments.MimeUtils.getContentLength(
+ multipart != null ? multipart : (multipart = org.apache.axis.attachments.MimeUtils.createMP(msg.getSOAPPart().getAsString(), attachments)));
+ } catch (Exception e) {
+ throw AxisFault.makeFault(e);
+ }
}
/**
* Write the content to the stream.
- */
- public void writeContentToStream(java.io.OutputStream os) throws org.apache.axis.AxisFault {
- org.apache.axis.attachments.MimeUtils.writeToMultiPartStream(os, multipart !=null ? multipart :
- (multipart= org.apache.axis.attachments.MimeUtils.createMP(msg.getSOAPPart().getAsString(), attachments )));
+ */
+ public void writeContentToStream(java.io.OutputStream os)
+ throws org.apache.axis.AxisFault {
+ org.apache.axis.attachments.MimeUtils.writeToMultiPartStream(os, multipart != null ? multipart :
+ (multipart = org.apache.axis.attachments.MimeUtils.createMP(msg.getSOAPPart().getAsString(), attachments)));
}
+
/**
* Gets the content type for the whole stream.
*/
- public String getContentType()throws org.apache.axis.AxisFault {
- return org.apache.axis.attachments.MimeUtils.getContentType( multipart !=null ? multipart :
- (multipart= org.apache.axis.attachments.MimeUtils.createMP(msg.getSOAPPart().getAsString(), attachments )));
+ public String getContentType() throws org.apache.axis.AxisFault {
+ return org.apache.axis.attachments.MimeUtils.getContentType(multipart != null ? multipart :
+ (multipart = org.apache.axis.attachments.MimeUtils.createMP(msg.getSOAPPart().getAsString(), attachments)));
}
/**
*This is the number of attachments.
**/
- public int getAttachmentCount(){
- return attachments.size();
+ public int getAttachmentCount() {
+ return attachments.size();
}
/**
@@ -264,7 +282,7 @@
* @return True if value should be treated as an attchment.
*/
- public boolean isAttachment( Object value){
- return AttachmentUtils.isAttachment(value);
+ public boolean isAttachment(Object value) {
+ return AttachmentUtils.isAttachment(value);
}
}