net.sourceforge.esw.collection
Class MailTransducer

java.lang.Object
  |
  +--net.sourceforge.esw.collection.ATransducer
        |
        +--net.sourceforge.esw.collection.MailTransducer
All Implemented Interfaces:
ITransducer, java.io.Serializable

public class MailTransducer
extends ATransducer
implements ITransducer

Performs Transduction between a mail data source and an IMetaCollection instance.

This transduction occurs both ways; put() takes data from the IMetaCollection instance to which this ITransducer instance is attached and places it into the data source represented by this ITransducer instance. The get() method takes data from the data source represented by this ITransducer instance and places it into the IMetaCollection instance to which this ITransducer instance is attached.

For proper put transduction to occur, three variables are needed. These are:

Only get is implemented for this MailTransducer instance.

For this MailTransducer instance, the INode instance's of the containing IMetaCollection provide the data elements of the Mail message being sent. Those elements are:

Mail Element Description
From (net.sourceforge.esw.collection.MailTransducer.FROM) The Mail Address of the user sending a message.
To (net.sourceforge.esw.collection.MailTransducer.TO) The Mail Addresses of the receipient of the message. Multiple recipients each require their own INode instance within the IMetaCollection instance.
CC (net.sourceforge.esw.collection.MailTransducer.CC) The Mail Addresses of the CC of the message. Multiple recipients each require their own INode instance within the IMetaCollection instance.
BCC (net.sourceforge.esw.collection.MailTransducer.BCC) The Mail Addresses of the BCC of the message. Multiple recipients each require their own INode instance within the IMetaCollection instance.
Text (net.sourceforge.esw.collection.MailTransducer.TEXT) The message text.
Subject (net.sourceforge.esw.collection.MailTransducer.SUBJECT) The message subject.

 

 

 

 

 

 

 

 

 

Example:
    IMetaCollection meta = MetaFactory.createMetaCollection();
    MailTransducer trans = new MailTransducer();

    StringBuffer sb = new StringBuffer();
    sb.append("Hello TEST!\n\n");
    sb.append("This is a \"Hello World\" from TestMailTransducer.\n\n");
    sb.append("Sincerly,\n");
    sb.append("TestMailTransducer");

    meta.add( NodeFactory.createNode( MailTransducer.TEXT,    sb.toString() ) );
    meta.add( NodeFactory.createNode( MailTransducer.SUBJECT, "This message is from your friendly TestMailTransducer!" ) );
    meta.add( NodeFactory.createNode( MailTransducer.TO,      "blah@abcblah.com" ) );
    meta.add( NodeFactory.createNode( MailTransducer.FROM,    "meblah@abcblah.com" ) );

    trans.setSMTPHost( smtpHost );
    meta.setTransducer( trans );

    try {
      meta.put();
    }
    catch ( TransducerException te ) {
      te.printStackTrace();
    }
 

See Also:
IMetaCollection, Serialized Form

Field Summary
static java.lang.String BCC
          The INode instance name for the BCC element of a Mail Message.
static java.lang.String CC
          The INode instance name for the CC element of a Mail Message.
protected  boolean debug
          Sets if debugging for the Mail API should be turned on or off.
static java.lang.String FROM
          The INode instance name for the From element of a Mail Message.
protected  java.lang.String password
          The password for access to the SMTP server through which this MailTransducer instance will send its message.
static java.lang.String REPLY_TO
          The INode instance name for the ReplyTo element of a Mail Message.
protected static java.lang.String SMTP
          The constant for the SMTP protocol type.
protected  java.lang.String smtpHost
          The hostname of the SMTP server through which this MailTransducer instance will send it's message.
static java.lang.String SUBJECT
          The INode instance name for the Subject element of a Mail Message.
static java.lang.String TEXT
          The INode instance name for the From element of a Mail Message.
static java.lang.String TO
          The INode instance name for the To element of a Mail Message.
protected  java.lang.String username
          The username for access to the SMTP server through which this MailTransducer instance will send its message.
 
Fields inherited from class net.sourceforge.esw.collection.ATransducer
contextFactory
 
Constructor Summary
MailTransducer()
          Creates a new MailTransducer instance.
MailTransducer(java.lang.String aSMTPHost)
          Creates a new MailTransducer instance with the specified SMTP host.
MailTransducer(java.lang.String aSMTPHost, java.lang.String aUsername, java.lang.String aPassword)
          Creates a new MailTransducer instance with the specified values.
 
Method Summary
protected  void checkPasswordExists()
          Checks to make sure that the password has been set on this MailTransducer instance.
protected  void checkSMTPHostExists()
          Checks to make sure that the SMTP host server name has been set on this MailTransducer instance.
protected  void checkToFromSubjectText(IMetaCollection aCollection)
          Checks to make sure that the IMetaCollection instance contains a TO, FROM, SUBJECT, and TEXT INode children instances that have a non-null value.
protected  void checkUsernameExists()
          Checks to make sure that the username has been set on this MailTransducer instance.
 void get(IMetaCollection aCollection)
          Gets the data source's data represented by this ITransducer instance into the referenced IMetaCollection instance.
protected  javax.mail.internet.InternetAddress[] getAddresses(IMetaCollection aCollection, java.lang.String aType)
          Returns the addresses from the IMetaCollection instance based on the specified type of address (to, cc, bcc...).
 java.lang.String getPassword()
          Returns the Password for access to the SMTP server that this MailTransducer instance will use to send the mail message.
 java.lang.String getSMTPHost()
          Returns the SMTP hostname for this MailTransducer instance to which to send the mail message.
 java.lang.String getUsername()
          Returns the username for access to the SMTP server that this MailTransducer instance will use to send the mail message.
 boolean isDebug()
          Returns if the bebug flag for the Mail API should be turned on or off.
 void put(IMetaCollection aCollection)
          Puts the referenced IMetaCollection instance's data into the data source represented by this ITransducer instance.
 void setDebug(boolean aDebug)
          Sets if the bebug flag for the Mail API should be turned on or off.
 void setPassword(java.lang.String aPassword)
          Sets the Password for access to the SMTP server that this MailTransducer instance will use to send the mail message.
 void setSMTPHost(java.lang.String aSMTPHost)
          Sets the SMTP hostname for this MailTransducer instance to which to send the mail message.
 void setUsername(java.lang.String aUsername)
          Sets the username for access to the SMTP server that this MailTransducer instance will use to send the mail message.
 
Methods inherited from class net.sourceforge.esw.collection.ATransducer
getContextFactory, setContextFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.esw.collection.ITransducer
getContextFactory, setContextFactory
 

Field Detail

smtpHost

protected java.lang.String smtpHost
The hostname of the SMTP server through which this MailTransducer instance will send it's message.

username

protected java.lang.String username
The username for access to the SMTP server through which this MailTransducer instance will send its message.

password

protected java.lang.String password
The password for access to the SMTP server through which this MailTransducer instance will send its message.

debug

protected boolean debug
Sets if debugging for the Mail API should be turned on or off.

SMTP

protected static final java.lang.String SMTP
The constant for the SMTP protocol type.

FROM

public static final java.lang.String FROM
The INode instance name for the From element of a Mail Message.

REPLY_TO

public static final java.lang.String REPLY_TO
The INode instance name for the ReplyTo element of a Mail Message.

TO

public static final java.lang.String TO
The INode instance name for the To element of a Mail Message.

CC

public static final java.lang.String CC
The INode instance name for the CC element of a Mail Message.

BCC

public static final java.lang.String BCC
The INode instance name for the BCC element of a Mail Message.

SUBJECT

public static final java.lang.String SUBJECT
The INode instance name for the Subject element of a Mail Message.

TEXT

public static final java.lang.String TEXT
The INode instance name for the From element of a Mail Message.
Constructor Detail

MailTransducer

public MailTransducer()
Creates a new MailTransducer instance.

MailTransducer

public MailTransducer(java.lang.String aSMTPHost)
Creates a new MailTransducer instance with the specified SMTP host.

Parameters:
aSMTPHost - the hostname of the SMTP server.

MailTransducer

public MailTransducer(java.lang.String aSMTPHost,
                      java.lang.String aUsername,
                      java.lang.String aPassword)
Creates a new MailTransducer instance with the specified values.

Parameters:
aSMTPHost - the hostname of the SMTP server.
aUSername - the username for the SMTP server.
aPassword - the password for the SMTP server.
Method Detail

put

public void put(IMetaCollection aCollection)
         throws TransducerException
Puts the referenced IMetaCollection instance's data into the data source represented by this ITransducer instance.
Specified by:
put in interface ITransducer
Parameters:
aCollection - the IMetaCollection instance from which to take data.
Throws:
TransducerException - if an error occurs during transduction.
See Also:
get( IMetaCollection )

get

public void get(IMetaCollection aCollection)
         throws TransducerException
Gets the data source's data represented by this ITransducer instance into the referenced IMetaCollection instance.
Specified by:
get in interface ITransducer
Parameters:
aCollection - the IMetaCollection instance into which to read.
Throws:
TransducerException - if an error occurs during transduction.
See Also:
put( IMetaCollection )

setSMTPHost

public void setSMTPHost(java.lang.String aSMTPHost)
Sets the SMTP hostname for this MailTransducer instance to which to send the mail message.
Parameters:
aSMTPHost - the hostname of the SMTP server.
See Also:
getSMTPHost()

getSMTPHost

public java.lang.String getSMTPHost()
Returns the SMTP hostname for this MailTransducer instance to which to send the mail message.
Returns:
the SMTP server's hostname.
See Also:
setSMTPHost( String )

setUsername

public void setUsername(java.lang.String aUsername)
Sets the username for access to the SMTP server that this MailTransducer instance will use to send the mail message.
Parameters:
aUsername - the username for access to the SMTP server.
See Also:
getUsername()

getUsername

public java.lang.String getUsername()
Returns the username for access to the SMTP server that this MailTransducer instance will use to send the mail message.
Returns:
the username for access to the SMTP server.
See Also:
setUsername( String )

setPassword

public void setPassword(java.lang.String aPassword)
Sets the Password for access to the SMTP server that this MailTransducer instance will use to send the mail message.
Parameters:
aPassword - the Password for access to the SMTP server.
See Also:
getPassword()

getPassword

public java.lang.String getPassword()
Returns the Password for access to the SMTP server that this MailTransducer instance will use to send the mail message.
Returns:
the Password for access to the SMTP server.
See Also:
setPassword( String )

setDebug

public void setDebug(boolean aDebug)
Sets if the bebug flag for the Mail API should be turned on or off.
Parameters:
aDebug - the bebug flag for the Mail API.
See Also:
isDebug()

isDebug

public boolean isDebug()
Returns if the bebug flag for the Mail API should be turned on or off.
Returns:
the bebug flag for the Mail API.
See Also:
setDebug( boolean )

checkSMTPHostExists

protected void checkSMTPHostExists()
                            throws TransducerException
Checks to make sure that the SMTP host server name has been set on this MailTransducer instance.
Throws:
TransducerException - if the SMTPHost parameters does not exist.

checkUsernameExists

protected void checkUsernameExists()
                            throws TransducerException
Checks to make sure that the username has been set on this MailTransducer instance.
Returns:
if the username exists.
Throws:
TransducerException - if the SMTPHost parameters does not exist.

checkPasswordExists

protected void checkPasswordExists()
                            throws TransducerException
Checks to make sure that the password has been set on this MailTransducer instance.
Returns:
if the password exists.

checkToFromSubjectText

protected void checkToFromSubjectText(IMetaCollection aCollection)
                               throws TransducerException
Checks to make sure that the IMetaCollection instance contains a TO, FROM, SUBJECT, and TEXT INode children instances that have a non-null value.
Parameters:
aCollection - the IMetaCollection instance to check.
Throws:
TransducerException - if any of the listed parameters do not exist.

getAddresses

protected javax.mail.internet.InternetAddress[] getAddresses(IMetaCollection aCollection,
                                                             java.lang.String aType)
                                                      throws java.lang.Exception
Returns the addresses from the IMetaCollection instance based on the specified type of address (to, cc, bcc...).
Parameters:
aCollection - the IMetaCollection instance to pull the addresses from.
aType - the type of address to pull (to, cc, bcc...).
Returns:
the specified addresses.


Copyright 2002 Free Software Foundation. All Rights Reserved.