james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Soeren Hilmer <soren.hil...@tietoenator.com>
Subject [PATCH] for Bug 18471 missing attributes on mail
Date Mon, 07 Apr 2003 10:20:52 GMT
This patch enhances the Mail interface and its implementation in James, with 
the possibility to add attributes. This feature can be used to make pr. Mail 
processing directives.
This patch is a fix for Bug 18471.
Migration from existing mail repositories are done on the fly, in the 
readObject method, by checking the actual type of object deserialized.
A Hashmap for holding the attributes, has been chosen, as only one Thread will 
have its hands on a Mail instance at the time.

--- ../jakarta-james-modified/src/java/org/apache/james/core/MailImpl.java	
2003-04-07 10:48:39.000000000 +0200
+++ src/java/org/apache/james/core/MailImpl.java	2003-03-08 22:14:01.000000000 
+0100
@@ -63,14 +63,12 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
-import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.HashMap;
 
 import javax.mail.Address;
 import javax.mail.Message;
@@ -132,15 +130,10 @@
      */
     private Date lastUpdated = new Date();
     /**
-     * Attributes added to this MailImpl instance
-     */
-    private HashMap attributes;
-    /**
      * A constructor that creates a new, uninitialized MailImpl
      */
     public MailImpl() {
         setState(Mail.DEFAULT);
-        attributes = new HashMap();
     }
     /**
      * A constructor that creates a MailImpl with the specified name,
@@ -523,15 +516,7 @@
         name = (String) in.readObject();
         remoteHost = (String) in.readObject();
         remoteAddr = (String) in.readObject();
-        Object o = in.readObject();
-        //this check is done to be backwards compatible with mail 
repositories
-        if (o instanceof Date) {
-            setLastUpdated ((Date)o);
-            attributes = new HashMap();
-        } else {
-            attributes = (HashMap)o;
-            setLastUpdated((Date) in.readObject());
-        }
+        setLastUpdated((Date) in.readObject());
     }
     /**
      * Write the MailImpl to an <code>ObjectOutputStream</code>.
@@ -549,9 +534,9 @@
         out.writeObject(name);
         out.writeObject(remoteHost);
         out.writeObject(remoteAddr);
-        out.writeObject(attributes);
         out.writeObject(lastUpdated);
     }
+
     /**
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
@@ -566,28 +551,5 @@
             // Ignored
         }
     }
-    /**
-     * @see org.apache.mailet.Mail#getAttribute(String)
-     */
-    public Serializable getAttribute(String key) {
-        return (Serializable)attributes.get(key);
-    }
-    /**
-     * @see org.apache.mailet.Mail#setAttribute(String,Serializable)
-     */
-    public Serializable setAttribute(String key, Serializable object) {
-        return (Serializable)attributes.put(key, object);
-    }
-    /**
-     * @see org.apache.mailet.Mail#removeAttribute(String)
-     */
-    public Serializable removeAttribute(String key) {
-        return (Serializable)attributes.remove(key);
-    }
-    /**
-     * @see org.apache.mailet.Mail#getAttributeNames()
-     */
-    public Iterator getAttributeNames() {
-        return attributes.keySet().iterator();
-    }
+
 }
--- ../jakarta-james-modified/src/java/org/apache/mailet/Mail.java	2003-04-07 
10:48:00.000000000 +0200
+++ src/java/org/apache/mailet/Mail.java	2003-03-08 22:14:14.000000000 +0100
@@ -61,7 +61,6 @@
 import javax.mail.internet.MimeMessage;
 import java.io.Serializable;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.Date;
 /**
  * Wrap a MimeMessage with routing information (from SMTP) such
@@ -164,55 +163,4 @@
      * @return Date. timestamp of the last action which changed this Mail
      */
     Date getLastUpdated();
-    /**
-     * Returns the Mail session attribute with the given name, or null
-     * if there is no attribute by that name.
-     * An attribute allows a mailet to give this Mail instance additional 
information
-     * not already provided by this interface.<p>
-     * A list of currently set attributes can be retrieved using 
getAttributeNames.
-     * <p>
-     * The attribute is returned as a java.lang.Object or some subclass. 
Attribute
-     * names should follow the same convention as package names. The Java 
Mailet API
-     * specification reserves names matching java.*, javax.*, and sun.*
-     *
-     * @param name - a String specifying the name of the attribute
-     * @return an Object containing the value of the attribute, or null if no 
attribute
-     *      exists matching the given name
-     */
-    Serializable getAttribute(String name);
-    /**
-     * Returns an Iterator containing the attribute names currently available 
within
-     * this Mail instance.  Use the getAttribute(java.lang.String) method 
with an
-     * attribute name to get the value of an attribute.
-     *
-     * @return an Iterator of attribute names
-     */
-    Iterator getAttributeNames();
-    /**
-     * Removes the attribute with the given name from this Mail instance. 
After
-     * removal, subsequent calls to getAttribute(java.lang.String) to 
retrieve
-     * the attribute's value will return null.
-     *
-     * @param name - a String specifying the name of the attribute to be 
removed
-     * @return previous attribute value associated with specified name, or 
null
-     * if there was no mapping for name (null can also mean that null
-     * was bound to the name)
-     */
-    Serializable removeAttribute(String name);
-    /**
-     * Binds an object to a given attribute name in this Mail instance. If 
the name
-     * specified is already used for an attribute, this method will remove 
the old
-     * attribute and bind the name to the new attribute.
-     * As instances of Mail is Serializable, it is necessary that the 
attributes being
-     * Serializable as well
-     * <p>
-     * Attribute names should follow the same convention as package names. 
The Java
-     * Mailet API specification reserves names matching java.*, javax.*, and 
sun.*.
-     *
-     * @param name - a String specifying the name of the attribute
-     * @param object - a Serializable Object representing the attribute to be 
bound
-     * @return the object previously bound to the name, null if the name was
-     * not bound (null can also mean that null was bound to the name)
-     */
-    Serializable setAttribute(String name, Serializable object);
 }




-- 
Søren Hilmer, M.Sc.
R&D manager		Phone:	+45 70 27 64 00
TietoEnator IT+ A/S	Fax:	+45 70 27 64 40
Ved Lunden 12		Direct:	+45 87 46 64 57
DK-8230 Åbyhøj		Email:	soren.hilmer@tietoenator.com


---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org


Mime
View raw message