Hi,
First: Serge sorry for mailing you directly. It won't happen again!!
Second: As Mail is Serializable it is of course necessary for the added
attributes to be Serializable as well. As you can see in the migration
document below. I have changed the method signatures orignally proposed so
this demand is better supported to:
void setAttribute (String, Serializable)
Serializable getAttribute (String)
Serializable removeAttribute (String)
What do you think of this change?
Should setAttribute also return the previous set value like removeAttribute?
Third: this is what I have cooked up for a migration document, Does this match
what is needed?
"
This is a description of how to migrate previous versions of the
Mailet API and James implementation of it, to support attributes on
Mail instances.
NOTE: As Mail is Serializable, it is necessary for attribute value objects
to be Serializable as well.
First: changes to src/java/org/apache/james/core/MailImpl.java
add following import statements:
import java.util.HashMap;
import java.io.Serializable;
add this attribute declaration:
/**
* Attributes added to this MailImpl instance
*/
private HashMap attributes;
add this statement to the default constructor (MailImpl()):
attributes = new HashMap();
add the following methods to the class:
/**
* @see org.apache.mailet.Mail#getAttribute(String)
*/
public Serializable getAttribute(String key) {
return attributes.get(key);
}
/**
* @see org.apache.mailet.Mail#setAttribute(String,Serializable)
*/
public void setAttribute(String key, Serializable object) {
attributes.put(key, object);
}
/**
* @see org.apache.mailet.Mail#removeAttribute(String)
*/
public Serializable removeAttribute(String key) {
attributes.remove(key);
}
/**
* @see org.apache.mailet.Mail#getAttributeNames()
*/
public Iterator getAttributeNames() {
return attributes.keySet().iterator();
}
add this statement to the end of the readObject method:
attributes = in.readObject();
add this statement to the end of the writeObject method:
out.writeObject(attributes);
Second: changes to src/java/org/apache/mailet/Mail
add the following method declarations:
/**
* 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.
*/
void 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
*/
void setAttribute(String name, Serializable object);
"
regards
S�ren
--
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: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]