dims        02/05/29 06:05:54

  Modified:    java/src/org/apache/axis/attachments AttachmentPart.java
                        AttachmentsImpl.java AttachmentUtils.java
                        MimeUtils.java
               java/src/org/apache/axis/encoding/ser
                        JAFDataHandlerDeserializer.java
               java/src/org/apache/axis/handlers MD5AttachHandler.java
               java/src/org/apache/axis Part.java SOAPPart.java
  Added:       java/src/org/apache/axis/utils SOAPUtils.java
  Log:
  - Convert org.apache.axis.Part into an interface from an abstract class.
  - org.apache.axis.SOAPPart extends javax.xml.soap.SOAPPart
  - org.apache.axis.attachments.AttachmentPart extends javax.xml.soap.AttachmentPart
  - Fix typo getActiviationDataHandler->getActivationDataHandler
  - Extract static code previously in org.apache.axis.Part into SOAPUtils.java
  
  TODO:
  - Implement/cleanup the methods in org.apache.axis.SOAPPart and 
org.apache.axis.attachments.AttachmentPart
  
  Revision  Changes    Path
  1.8       +314 -9    
xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java
  
  Index: AttachmentPart.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AttachmentPart.java       24 May 2002 18:20:41 -0000      1.7
  +++ AttachmentPart.java       29 May 2002 13:05:54 -0000      1.8
  @@ -56,28 +56,41 @@
   package org.apache.axis.attachments;
   
   import org.apache.axis.Part;
  +import org.apache.axis.utils.JavaUtils;
  +import org.apache.axis.utils.SOAPUtils;
   import org.apache.axis.transport.http.HTTPConstants;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -public class AttachmentPart extends Part {
  +import javax.activation.DataHandler;
  +import javax.xml.soap.SOAPException;
  +import java.util.Hashtable;
  +import java.util.Iterator;
  +
  +public class AttachmentPart extends javax.xml.soap.AttachmentPart implements Part {
       protected static Log log =
           LogFactory.getLog(AttachmentPart.class.getName());
   
       javax.activation.DataHandler datahandler= null;
  -    
  +
  +    private Hashtable headers = new Hashtable();
  +    private String contentId;
  +    private String contentLocation;
  +
   
       public AttachmentPart() {
  -        super();
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , 
SOAPUtils.getNewContentIdValue());
  +
       }
   
       public AttachmentPart(javax.activation.DataHandler dh ) {
  -        super();
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , 
SOAPUtils.getNewContentIdValue());
  +
           datahandler= dh;
           addMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE , dh.getContentType());
       }
   
  -    public javax.activation.DataHandler getActiviationDataHandler(){
  +    public javax.activation.DataHandler getActivationDataHandler(){
         return datahandler;
       }
   
  @@ -86,13 +99,13 @@
       public int getContentLength() {
           return 0;
       }
  -    */ 
  +    */
   
       /**
        * TODO: everything!
  -     */ 
  +     */
       public String getContentType() {
  -        return getMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE);
  +        return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_TYPE);
       }
   
       /**
  @@ -100,7 +113,299 @@
       public int getSize() {
           return 0;
       }
  -     */ 
  +     */
  +
  +    /**
  +     * Add the specified MIME header, as per JAXM.
  +     */
  +    public void addMimeHeader (String header, String value) {
  +
  +        if(null == header) {
  +            throw new 
IllegalArgumentException(JavaUtils.getMessage("headerNotNull"));
  +        }
  +
  +        header = header.trim();
  +
  +        if(header.length() == 0) {
  +            throw new IllegalArgumentException(
  +                    JavaUtils.getMessage("headerNotEmpty"));
  +        }
  +
  +        if(null == value) {
  +            throw new IllegalArgumentException(
  +                    JavaUtils.getMessage("headerValueNotNull"));
  +        }
  +        headers.put(header.toLowerCase(), value);
  +    }
  +
  +    /**
  +     * Get the specified MIME header.
  +     */
  +    public String getFirstMimeHeader (String header) {
  +        return (String) headers.get(header.toLowerCase());
  +    }
  +
  +    /**
  +     * Total size in bytes (of all content and headers, as encoded).
  +    public abstract int getSize();
  +     */
  +
  +    /**
  +     * Content location.
  +     */
  +    public String getContentLocation() {
  +        return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION);
  +    }
  +
  +    /**
  +     * Set content location.
  +     */
  +    public void setContentLocation(String loc) {
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);
  +    }
  +
  +    /**
  +         * Sets Content-Id of this part. "cid:"; prefix will be added if one wan't
  +         *  already defined.
  +         * @param newCid new Content-Id
  +         * @returns void
  +         */
  +        public void setContentId(String newCid){
  +                if(!newCid.toLowerCase().startsWith("cid:";)){
  +                        newCid="cid:"+newCid;
  +                }
  +                addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid);
  +        }
  +
  +    /**
  +     * Content ID.
  +     */
  +    public String getContentId() {
  +        String ret= getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
  +        //Do not let the contentID ever be empty.
  +        if(ret == null){
  +            ret=SOAPUtils.getNewContentIdValue();
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  +        }
  +        ret= ret.trim();
  +        if(ret.length() ==0){
  +            ret=SOAPUtils.getNewContentIdValue();
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  +        }
  +        return ret;
  +    }
  +
  +
  +    /**
  +     * Get all headers that match
  +     */
  +    public java.util.Iterator getMatchingMimeHeaders( final String[] match){
  +        java.util.LinkedList retList= new java.util.LinkedList();
  +        if(null != match && 0 != match.length ){
  +            for(int i= match.length-1 ; i > -1 ; --i){
  +                    if(match[i] != null){
  +                      String key= match[i].toLowerCase();
  +                      if(headers.containsKey(key))
  +                         retList.add(match[i]);
  +                }
  +            }
  +        }
  +        return retList.iterator();
  +    }
  +
  +    /**
  +     * Get all headers that do not match
  +     */
  +    public java.util.Iterator getNonMatchingMimeHeaders( final String[] match){
  +        java.util.LinkedList retList= new java.util.LinkedList(headers.keySet());
  +        if(null != match && 0 != match.length && !headers.isEmpty()){
  +            for(int i= match.length-1 ; i > -1 ; --i){
  +                    if(match[i] != null){
  +                        String remItem= match[i].toLowerCase();
  +                        if(headers.containsKey(remItem)){
  +                            retList.remove(remItem);
  +                    }
  +                }
  +            }
  +        }
  +        return retList.iterator();
  +    }
  +
  +    /**
  +     * Retrieves all the headers for this <CODE>
  +     * AttachmentPart</CODE> object as an iterator over the <CODE>
  +     * MimeHeader</CODE> objects.
  +     * @return  an <CODE>Iterator</CODE> object with all of the Mime
  +     *     headers for this <CODE>AttachmentPart</CODE> object
  +     */
  +    public Iterator getAllMimeHeaders() {
  +        //TODO: Implement this.
  +        return null;
  +    }
   
  +    /**
  +     * 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.
  +     *
  +     *   <P>Note that RFC822 headers can only contain US-ASCII
  +     *   characters.</P>
  +     * @param  name   a <CODE>String</CODE> giving the
  +     *     name of the header for which to search
  +     * @param  value  a <CODE>String</CODE> giving 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
  +     */
  +    public void setMimeHeader(String name, String value){
  +        //TODO: Implement this.
  +    }
  +
  +    /** Removes all the MIME header entries. */
  +    public void removeAllMimeHeaders() {
  +        //TODO: Implement this.
  +    }
  +
  +    /**
  +     * Removes all MIME headers that match the given name.
  +     * @param  header - the string name of the MIME
  +     *     header/s to be removed
  +     */
  +    public void removeMimeHeader(String header) {
  +        //TODO: Implement this.
  +    }
  +
  +    /**
  +     * Gets the <CODE>DataHandler</CODE> object for this <CODE>
  +     * AttachmentPart</CODE> object.
  +     * @return the <CODE>DataHandler</CODE> object associated with
  +     *     this <CODE>AttachmentPart</CODE> object
  +     * @throws  SOAPException  if there is
  +     *     no data in this <CODE>AttachmentPart</CODE> object
  +     */
  +    public DataHandler getDataHandler() throws SOAPException {
  +        //TODO: Implement this.
  +        return null;
  +    }
  +
  +    /**
  +     * Sets the given <CODE>DataHandler</CODE> object as the
  +     * data handler for this <CODE>AttachmentPart</CODE> object.
  +     * Typically, on an incoming message, the data handler is
  +     * automatically set. When a message is being created and
  +     * populated with content, the <CODE>setDataHandler</CODE>
  +     * method can be used to get data from various data sources into
  +     * the message.
  +     * @param  datahandler  <CODE>DataHandler</CODE> object to
  +     *     be set
  +     * @throws java.lang.IllegalArgumentException if
  +     *     there was a problem with the specified <CODE>
  +     *     DataHandler</CODE> object
  +     */
  +    public void setDataHandler(DataHandler datahandler) {
  +        //TODO: Implement this.
  +    }
  +
  +    /**
  +     * Gets the content of this <CODE>AttachmentPart</CODE> object
  +     *   as a Java object. The type of the returned Java object
  +     *   depends on (1) the <CODE>DataContentHandler</CODE> object
  +     *   that is used to interpret the bytes and (2) the <CODE>
  +     *   Content-Type</CODE> given in the header.
  +     *
  +     *   <P>For the MIME content types "text/plain", "text/html" and
  +     *   "text/xml", the <CODE>DataContentHandler</CODE> object does
  +     *   the conversions to and from the Java types corresponding to
  +     *   the MIME types. For other MIME types,the <CODE>
  +     *   DataContentHandler</CODE> object can return an <CODE>
  +     *   InputStream</CODE> object that contains the content data as
  +     *   raw bytes.</P>
  +     *
  +     *   <P>A JAXM-compliant implementation must, as a minimum,
  +     *   return a <CODE>java.lang.String</CODE> object corresponding
  +     *   to any content stream with a <CODE>Content-Type</CODE>
  +     *   value of <CODE>text/plain</CODE> and a <CODE>
  +     *   javax.xml.transform.StreamSource</CODE> object
  +     *   corresponding to a content stream with a <CODE>
  +     *   Content-Type</CODE> value of <CODE>text/xml</CODE>. For
  +     *   those content types that an installed <CODE>
  +     *   DataContentHandler</CODE> object does not understand, the
  +     *   <CODE>DataContentHandler</CODE> object is required to
  +     *   return a <CODE>java.io.InputStream</CODE> object with the
  +     *   raw bytes.</P>
  +     * @return a Java object with the content of this <CODE>
  +     *     AttachmentPart</CODE> object
  +     * @throws  SOAPException  if there is no content set
  +     *     into this <CODE>AttachmentPart</CODE> object or if there
  +     *     was a data transformation error
  +     */
  +    public Object getContent() throws SOAPException {
  +        //TODO: Implement this.
  +        return null;
  +    }
  +
  +    /**
  +     * Sets the content of this attachment part to that of the
  +     * given <CODE>Object</CODE> and sets the value of the <CODE>
  +     * Content-Type</CODE> header to the given type. The type of the
  +     * <CODE>Object</CODE> should correspond to the value given for
  +     * the <CODE>Content-Type</CODE>. This depends on the particular
  +     * set of <CODE>DataContentHandler</CODE> objects in use.
  +     * @param  object  the Java object that makes up
  +          the content for this attachment part
  +     * @param  contentType 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 no <CODE>
  +     *     DataContentHandler</CODE> object for this content
  +     *     object
  +     * @see #getContent() getContent()
  +     */
  +    public void setContent(Object object, String contentType) {
  +        //TODO: Implement this.
  +    }
  +
  +    /**
  +     * Clears out the content of this <CODE>
  +     * AttachmentPart</CODE> object. The MIME header portion is left
  +     * untouched.
  +     */
  +    public void clearContent() {
  +        //TODO: Implement this.
  +    }
  +
  +    /**
  +     * Returns the number of bytes in this <CODE>
  +     * AttachmentPart</CODE> object.
  +     * @return the size of this <CODE>AttachmentPart</CODE> object
  +     *     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.
  +     */
  +    public int getSize() throws SOAPException {
  +        //TODO: Implement this.
  +        return -1;
  +    }
  +
  +    /**
  +     * Gets all the values of the header identified by the given
  +     * <CODE>String</CODE>.
  +     * @param   name  the name of the header; example:
  +     *     "Content-Type"
  +     * @return a <CODE>String</CODE> array giving the value for the
  +     *     specified header
  +     * @see #setMimeHeader(java.lang.String, java.lang.String) 
setMimeHeader(java.lang.String, java.lang.String)
  +     */
  +    public String[] getMimeHeader(String name) {
  +        //TODO: Flesh this out.
  +        String[] strings = new String[1];
  +        strings[0] = getFirstMimeHeader(name);
  +        return strings;
  +    }
   }
   
  
  
  
  1.14      +1 -1      
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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- AttachmentsImpl.java      15 Mar 2002 01:14:10 -0000      1.13
  +++ AttachmentsImpl.java      29 May 2002 13:05:54 -0000      1.14
  @@ -320,7 +320,7 @@
                                                                            (multipart 
= org.apache.axis.attachments.MimeUtils.createMP(soapPart.getAsString(), 
orderedAttachments)));
           for( java.util.Iterator i= orderedAttachments.iterator(); i.hasNext(); ){
             AttachmentPart part= (AttachmentPart)i.next();
  -              DataHandler dh= AttachmentUtils.getActiviationDataHandler(part);
  +              DataHandler dh= AttachmentUtils.getActivationDataHandler(part);
                 DataSource ds= dh.getDataSource();
                 if( ds != null && ds instanceof ManagedMemoryDataSource ){
                     ((ManagedMemoryDataSource) ds).delete();
  
  
  
  1.5       +2 -2      
xml-axis/java/src/org/apache/axis/attachments/AttachmentUtils.java
  
  Index: AttachmentUtils.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AttachmentUtils.java      15 Mar 2002 01:14:10 -0000      1.4
  +++ AttachmentUtils.java      29 May 2002 13:05:54 -0000      1.5
  @@ -75,7 +75,7 @@
        * @return The Java activiation data handler.
        */
   
  -    public static DataHandler getActiviationDataHandler(Part part) throws AxisFault{
  +    public static DataHandler getActivationDataHandler(Part part) throws AxisFault{
          if( null == part) {
           throw new AxisFault(JavaUtils.getMessage("gotNullPart"));
          }
  @@ -84,7 +84,7 @@
           throw new AxisFault(JavaUtils.getMessage("unsupportedAttach",
                   part.getClass().getName(), AttachmentPart.class.getName()));
          }
  -       return ((AttachmentPart) part).getActiviationDataHandler();
  +       return ((AttachmentPart) part).getActivationDataHandler();
       }
   
       /**
  
  
  
  1.14      +2 -2      xml-axis/java/src/org/apache/axis/attachments/MimeUtils.java
  
  Index: MimeUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/MimeUtils.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- MimeUtils.java    25 Mar 2002 23:55:30 -0000      1.13
  +++ MimeUtils.java    29 May 2002 13:05:54 -0000      1.14
  @@ -242,7 +242,7 @@
               for (java.util.Iterator it = parts.iterator(); it.hasNext(); ) {
                   org.apache.axis.Part part=  (org.apache.axis.Part) it.next();
                   javax.activation.DataHandler dh =
  -                    
org.apache.axis.attachments.AttachmentUtils.getActiviationDataHandler(part);
  +                    
org.apache.axis.attachments.AttachmentUtils.getActivationDataHandler(part);
                   String contentID = part.getContentId();
   
                   if (contentID.startsWith("cid:";)) contentID = 
contentID.substring(4);
  @@ -262,7 +262,7 @@
                      HTTPConstants.HEADER_CONTENT_TYPE, 
HTTPConstants.HEADER_CONTENT_ID,
                      HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING }); i.hasNext(); 
){
                          String header= (String) i.next();
  -                       messageBodyPart.setHeader(header, 
part.getMimeHeader(header)); 
  +                       messageBodyPart.setHeader(header, 
part.getFirstMimeHeader(header)); 
                   }
                   multipart.addBodyPart(messageBodyPart);
               }
  
  
  
  1.7       +1 -1      
xml-axis/java/src/org/apache/axis/encoding/ser/JAFDataHandlerDeserializer.java
  
  Index: JAFDataHandlerDeserializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/JAFDataHandlerDeserializer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JAFDataHandlerDeserializer.java   25 May 2002 03:46:46 -0000      1.6
  +++ JAFDataHandlerDeserializer.java   29 May 2002 13:05:54 -0000      1.7
  @@ -101,7 +101,7 @@
           if (href != null) {
               Object ref = context.getObjectByRef(href);
               try{
  -                ref = 
AttachmentUtils.getActiviationDataHandler((org.apache.axis.Part)ref); 
  +                ref = 
AttachmentUtils.getActivationDataHandler((org.apache.axis.Part)ref); 
               }catch(org.apache.axis.AxisFault e){;}
               
               setValue(ref);
  
  
  
  1.10      +1 -1      xml-axis/java/src/org/apache/axis/handlers/MD5AttachHandler.java
  
  Index: MD5AttachHandler.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/handlers/MD5AttachHandler.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- MD5AttachHandler.java     9 May 2002 18:25:17 -0000       1.9
  +++ MD5AttachHandler.java     29 May 2002 13:05:54 -0000      1.10
  @@ -93,7 +93,7 @@
               //Get the href associated with the attachment.
               String href = 
paramElement.getAttribute(org.apache.axis.Constants.ATTR_HREF);
               org.apache.axis.Part ap = 
msg.getAttachments().getAttachmentByReference(href);
  -            javax.activation.DataHandler dh = 
org.apache.axis.attachments.AttachmentUtils.getActiviationDataHandler(ap);
  +            javax.activation.DataHandler dh = 
org.apache.axis.attachments.AttachmentUtils.getActivationDataHandler(ap);
               org.w3c.dom.Node timeNode = paramElement.getFirstChild();
               long startTime = -1;
   
  
  
  
  1.8       +21 -139   xml-axis/java/src/org/apache/axis/Part.java
  
  Index: Part.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/Part.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Part.java 15 Mar 2002 01:14:09 -0000      1.7
  +++ Part.java 29 May 2002 13:05:54 -0000      1.8
  @@ -81,172 +81,54 @@
   
   import org.apache.axis.transport.http.HTTPConstants;
   
  -public abstract class Part
  +public interface Part
   {
  -    protected static Log log =
  -        LogFactory.getLog(Part.class.getName());
  -
  -    private Hashtable headers = new Hashtable();
  -    private String contentId;
  -    private String contentLocation;
  -    
  -    /**
  -     * Fill in the Message field.  (Of course this can only be called by
  -     * subclass constructors since Part itself is abstract.)
  -     */
  -    public Part () {
  -        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , getNewContentIdValue());
  -
  -    }
  -
       /**
        * Add the specified MIME header, as per JAXM.
        */
  -    public void addMimeHeader (String header, String value) {
  -
  -        if(null == header) {
  -            throw new 
IllegalArgumentException(JavaUtils.getMessage("headerNotNull"));
  -        }
  -
  -        header = header.trim();
  -
  -        if(header.length() == 0) {
  -            throw new IllegalArgumentException(
  -                    JavaUtils.getMessage("headerNotEmpty"));
  -        }
  -
  -        if(null == value) {
  -            throw new IllegalArgumentException(
  -                    JavaUtils.getMessage("headerValueNotNull"));
  -        }
  -        headers.put(header.toLowerCase(), value);
  -    }
  +    public void addMimeHeader (String header, String value);
   
       /**
        * Get the specified MIME header.
        */
  -    public String getMimeHeader (String header) {
  -        return (String) headers.get(header.toLowerCase());
  -    }
  -    
  -    /**
  -     * Total size in bytes (of all content and headers, as encoded).
  -    public abstract int getSize();
  -     */
  +    public String getFirstMimeHeader (String header);
   
       /**
        * Content location.
        */
  -    public String getContentLocation() {
  -        return getMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION);
  -    }
  +    public String getContentLocation();
   
       /**
        * Set content location.
        */
  -    public void setContentLocation(String loc) {
  -        addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);
  -    }
  -
  -    /**
  -         * Sets Content-Id of this part. "cid:"; prefix will be added if one wan't
  -         *  already defined.
  -         * @param newCid new Content-Id
  -         * @returns void
  -         */
  -        public void setContentId(String newCid){
  -                if(!newCid.toLowerCase().startsWith("cid:";)){
  -                        newCid="cid:"+newCid;
  -                }
  -                addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid);
  -        }
  +    public void setContentLocation(String loc);
  +
  +    /**
  +     * Sets Content-Id of this part. "cid:"; prefix will be added if one wan't
  +     *  already defined.
  +     * @param newCid new Content-Id
  +     * @returns void
  +     */
  +    public void setContentId(String newCid);
   
       /**
        * Content ID.
        */
  -    public String getContentId() {
  -        String ret= getMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
  -        //Do not let the contentID ever be empty.
  -        if(ret == null){
  -            ret=getNewContentIdValue();
  -            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  -        }
  -        ret= ret.trim();
  -        if(ret.length() ==0){
  -            ret=getNewContentIdValue();
  -            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  -        }
  -        return ret;
  -    }
  +    public String getContentId();
   
  +    /**
  +     * Get all headers that match
  +     */
  +    public java.util.Iterator getMatchingMimeHeaders( final String[] match);
   
       /**
  -     * Get all headers that match 
  -     */
  -    public java.util.Iterator getMatchingMimeHeaders( final String[] match){
  -        java.util.LinkedList retList= new java.util.LinkedList();
  -        if(null != match && 0 != match.length ){
  -            for(int i= match.length-1 ; i > -1 ; --i){
  -                    if(match[i] != null){
  -                      String key= match[i].toLowerCase();
  -                      if(headers.containsKey(key))
  -                         retList.add(match[i]); 
  -                }
  -            }
  -        }
  -        return retList.iterator();
  -    }
  -
  -    /**
  -     * Get all headers that do not match 
  -     */
  -    public java.util.Iterator getNonMatchingMimeHeaders( final String[] match){
  -        java.util.LinkedList retList= new java.util.LinkedList(headers.keySet());
  -        if(null != match && 0 != match.length && !headers.isEmpty()){
  -            for(int i= match.length-1 ; i > -1 ; --i){
  -                    if(match[i] != null){
  -                        String remItem= match[i].toLowerCase();
  -                        if(headers.containsKey(remItem)){
  -                            retList.remove(remItem); 
  -                    }
  -                }
  -            }
  -        }
  -        return retList.iterator();
  -    }
  +     * Get all headers that do not match
  +     */
  +    public java.util.Iterator getNonMatchingMimeHeaders( final String[] match);
   
       /**
        * Content type.
        */
       public abstract String getContentType();
  -
  -
  -    static String thisHost = null;
  -
  -    private static int count = (int) (Math.random() * 100);
  -
  -    public static String getNewContentIdValue() {
  -        int lcount;
  -
  -        synchronized (org.apache.axis.Part.class  ) {
  -            lcount = ++count;
  -        }
  -        if (null == thisHost) {
  -            try {
  -                thisHost = java.net.InetAddress.getLocalHost().getHostName();
  -            } 
  -            catch (java.net.UnknownHostException e) {
  -                log.error(JavaUtils.getMessage("javaNetUnknownHostException00"), e);
  -
  -                thisHost = "localhost";
  -            }
  -        }
  -
  -        StringBuffer s = new StringBuffer();
  -
  -        // Unique string is <hashcode>.<currentTime>.apache-soap.<hostname>
  -        s.append("cid:";).append( 
lcount).append(s.hashCode()).append('.').append(System.currentTimeMillis()).append(".AXIS@").append(thisHost);
  -        return s.toString();
  -    }
   }
   
  
  
  
  1.22      +243 -2    xml-axis/java/src/org/apache/axis/SOAPPart.java
  
  Index: SOAPPart.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/SOAPPart.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- SOAPPart.java     24 May 2002 18:20:41 -0000      1.21
  +++ SOAPPart.java     29 May 2002 13:05:54 -0000      1.22
  @@ -62,6 +62,8 @@
   import org.apache.axis.message.InputStreamBody;
   import org.apache.axis.message.SOAPEnvelope;
   import org.apache.axis.utils.JavaUtils;
  +import org.apache.axis.utils.SOAPUtils;
  +import org.apache.axis.transport.http.HTTPConstants;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -69,7 +71,11 @@
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   
  +import javax.xml.soap.SOAPException;
  +import javax.xml.transform.Source;
   import java.io.*;
  +import java.util.Hashtable;
  +import java.util.Iterator;
   
   /**
    * The SOAPPart provides access to the root part of the Message which
  @@ -86,7 +92,7 @@
    * @author Doug Davis ([EMAIL PROTECTED])
    * @author Glen Daniels ([EMAIL PROTECTED])
    */
  -public class SOAPPart extends Part
  +public class SOAPPart extends javax.xml.soap.SOAPPart implements Part
   {
       protected static Log log =
           LogFactory.getLog(SOAPPart.class.getName());
  @@ -99,6 +105,11 @@
       private static final int FORM_FAULT        = 6;
       private int currentForm;
   
  +    private Hashtable headers = new Hashtable();
  +    private String contentId;
  +    private String contentLocation;
  +
  +
       private static final String[] formNames =
       { "", "FORM_STRING", "FORM_INPUTSTREAM", "FORM_SOAPENVELOPE",
         "FORM_BYTES", "FORM_BODYINSTREAM", "FORM_FAULT" };
  @@ -132,7 +143,8 @@
        * "Just something to us working..."
        */
       public SOAPPart(Message parent, Object initialContents, boolean isBodyStream) {
  -        super();
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , 
SOAPUtils.getNewContentIdValue());
  +
   
           msgObject=parent;
           // originalMessage = initialContents;
  @@ -454,5 +466,234 @@
           return (SOAPEnvelope)currentMessage;
       }
   
  +    /**
  +     * Add the specified MIME header, as per JAXM.
  +     */
  +    public void addMimeHeader (String header, String value) {
  +
  +        if(null == header) {
  +            throw new 
IllegalArgumentException(JavaUtils.getMessage("headerNotNull"));
  +        }
  +
  +        header = header.trim();
  +
  +        if(header.length() == 0) {
  +            throw new IllegalArgumentException(
  +                    JavaUtils.getMessage("headerNotEmpty"));
  +        }
  +
  +        if(null == value) {
  +            throw new IllegalArgumentException(
  +                    JavaUtils.getMessage("headerValueNotNull"));
  +        }
  +        headers.put(header.toLowerCase(), value);
  +    }
  +
  +    /**
  +     * Get the specified MIME header.
  +     */
  +    public String getFirstMimeHeader (String header) {
  +        return (String) headers.get(header.toLowerCase());
  +    }
  +
  +    /**
  +     * Total size in bytes (of all content and headers, as encoded).
  +    public abstract int getSize();
  +     */
  +
  +    /**
  +     * Content location.
  +     */
  +    public String getContentLocation() {
  +        return getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION);
  +    }
  +
  +    /**
  +     * Set content location.
  +     */
  +    public void setContentLocation(String loc) {
  +        addMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION, loc);
  +    }
  +
  +    /**
  +         * Sets Content-Id of this part. "cid:"; prefix will be added if one wan't
  +         *  already defined.
  +         * @param newCid new Content-Id
  +         * @returns void
  +         */
  +        public void setContentId(String newCid){
  +                if(!newCid.toLowerCase().startsWith("cid:";)){
  +                        newCid="cid:"+newCid;
  +                }
  +                addMimeHeader(HTTPConstants.HEADER_CONTENT_ID,newCid);
  +        }
  +
  +    /**
  +     * Content ID.
  +     */
  +    public String getContentId() {
  +        String ret= getFirstMimeHeader(HTTPConstants.HEADER_CONTENT_ID);
  +        //Do not let the contentID ever be empty.
  +        if(ret == null){
  +            ret=SOAPUtils.getNewContentIdValue();
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  +        }
  +        ret= ret.trim();
  +        if(ret.length() ==0){
  +            ret=SOAPUtils.getNewContentIdValue();
  +            addMimeHeader(HTTPConstants.HEADER_CONTENT_ID , ret);
  +        }
  +        return ret;
  +    }
  +
  +
  +    /**
  +     * Get all headers that match
  +     */
  +    public java.util.Iterator getMatchingMimeHeaders( final String[] match){
  +        java.util.LinkedList retList= new java.util.LinkedList();
  +        if(null != match && 0 != match.length ){
  +            for(int i= match.length-1 ; i > -1 ; --i){
  +                    if(match[i] != null){
  +                      String key= match[i].toLowerCase();
  +                      if(headers.containsKey(key))
  +                         retList.add(match[i]);
  +                }
  +            }
  +        }
  +        return retList.iterator();
  +    }
  +
  +    /**
  +     * Get all headers that do not match
  +     */
  +    public java.util.Iterator getNonMatchingMimeHeaders( final String[] match){
  +        java.util.LinkedList retList= new java.util.LinkedList(headers.keySet());
  +        if(null != match && 0 != match.length && !headers.isEmpty()){
  +            for(int i= match.length-1 ; i > -1 ; --i){
  +                    if(match[i] != null){
  +                        String remItem= match[i].toLowerCase();
  +                        if(headers.containsKey(remItem)){
  +                            retList.remove(remItem);
  +                    }
  +                }
  +            }
  +        }
  +        return retList.iterator();
  +    }
  +
  +    /**
  +     * Sets the content of the <CODE>SOAPEnvelope</CODE> object
  +     * with the data from the given <CODE>Source</CODE> object.
  +     * @param   source javax.xml.transform.Source</CODE> object with the data to
  +     *     be set
  +     * @throws  SOAPException if there is a problem in
  +     *     setting the source
  +     * @see #getContent() getContent()
  +     */
  +    public void setContent(Source source) throws SOAPException {
  +        //TODO: Flesh this out.
  +    }
  +
  +    /**
  +     * Returns the content of the SOAPEnvelope as a JAXP <CODE>
  +     * Source</CODE> object.
  +     * @return the content as a <CODE>
  +     *     javax.xml.transform.Source</CODE> object
  +     * @throws  SOAPException  if the implementation cannot
  +     *     convert the specified <CODE>Source</CODE> object
  +     * @see #setContent(javax.xml.transform.Source) 
setContent(javax.xml.transform.Source)
  +     */
  +    public Source getContent() throws SOAPException {
  +        //TODO: Flesh this out.
  +        return null;
  +    }
  +
  +    /**
  +     * Retrieves all the headers for this <CODE>SOAPPart</CODE>
  +     * object as an iterator over the <CODE>MimeHeader</CODE>
  +     * objects.
  +     * @return an <CODE>Iterator</CODE> object with all of the Mime
  +     *     headers for this <CODE>SOAPPart</CODE> object
  +     */
  +    public Iterator getAllMimeHeaders() {
  +        //TODO: Flesh this out.
  +        return null;
  +    }
  +
  +    /**
  +     * 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.
  +     *
  +     *   <P>Note that RFC822 headers can contain only US-ASCII
  +     *   characters.</P>
  +     * @param  name a <CODE>String</CODE> giving the
  +     *     header name for which to search
  +     * @param  value a <CODE>String</CODE> 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 <CODE>MimeHeader</CODE> 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)
  +     */
  +    public void setMimeHeader(String name, String value) {
  +        //TODO: Flesh this out.
  +    }
  +
  +    /**
  +     * Gets all the values of the <CODE>MimeHeader</CODE> object
  +     * in this <CODE>SOAPPart</CODE> object that is identified by
  +     * the given <CODE>String</CODE>.
  +     * @param   name  the name of the header; example:
  +     *     "Content-Type"
  +     * @return a <CODE>String</CODE> array giving all the values for
  +     *     the specified header
  +     * @see #setMimeHeader(java.lang.String, java.lang.String) 
setMimeHeader(java.lang.String, java.lang.String)
  +     */
  +    public String[] getMimeHeader(String name) {
  +        //TODO: Flesh this out.
  +        String[] strings = new String[1];
  +        strings[0] = getFirstMimeHeader(name);
  +        return strings;
  +    }
  +
  +    /**
  +     * Removes all the <CODE>MimeHeader</CODE> objects for this
  +     * <CODE>SOAPEnvelope</CODE> object.
  +     */
  +    public void removeAllMimeHeaders() {
  +        //TODO: Flesh this out.
  +    }
  +
  +    /**
  +     * Removes all MIME headers that match the given name.
  +     * @param  header  a <CODE>String</CODE> giving
  +     *     the name of the MIME header(s) to be removed
  +     */
  +    public void removeMimeHeader(String header) {
  +        //TODO: Flesh this out.
  +    }
  +
  +    /**
  +     * Gets the <CODE>SOAPEnvelope</CODE> object associated with
  +     * this <CODE>SOAPPart</CODE> object. Once the SOAP envelope is
  +     * obtained, it can be used to get its contents.
  +     * @return the <CODE>SOAPEnvelope</CODE> object for this <CODE>
  +     *     SOAPPart</CODE> object
  +     * @throws  SOAPException if there is a SOAP error
  +     */
  +    public javax.xml.soap.SOAPEnvelope getEnvelope() throws SOAPException {
  +        //TODO: Flesh this out.
  +        return null;
  +    }
   }
   
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/utils/SOAPUtils.java
  
  Index: SOAPUtils.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.axis.utils;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.axis.SOAPPart;
  
  public class SOAPUtils {
      protected static Log log =
          LogFactory.getLog(SOAPUtils.class.getName());
  
      static String thisHost = null;
  
      private static int count = (int) (Math.random() * 100);
  
      public static String getNewContentIdValue() {
          int lcount;
  
          synchronized (org.apache.axis.utils.SOAPUtils.class  ) {
              lcount = ++count;
          }
          if (null == thisHost) {
              try {
                  thisHost = java.net.InetAddress.getLocalHost().getHostName();
              }
              catch (java.net.UnknownHostException e) {
                  log.error(JavaUtils.getMessage("javaNetUnknownHostException00"), e);
  
                  thisHost = "localhost";
              }
          }
  
          StringBuffer s = new StringBuffer();
  
          // Unique string is <hashcode>.<currentTime>.apache-soap.<hostname>
          s.append("cid:";).append( 
lcount).append(s.hashCode()).append('.').append(System.currentTimeMillis()).append(".AXIS@").append(thisHost);
          return s.toString();
      }
  }
  
  
  


Reply via email to