Email Answering System
Version 1.0

com.ninecode.email.connector
Class EmailInteraction

java.lang.Object
  |
  +--com.ninecode.email.connector.EmailInteraction
All Implemented Interfaces:
Interaction

public class EmailInteraction
extends Object
implements Interaction

A Common Client Interface interaction to an underlying email system.

Author:
Derrick Oswald

Field Summary
protected  EmailConnection mConnection
          The connection that created this interacation.
protected  Integer mPollDelay
          Cached poll delay.
protected  ResourceWarning mWarning
          The first warning in the chain.
 
Constructor Summary
EmailInteraction()
          Create a new instance of an EmailInteraction.
 
Method Summary
protected  void chainWarning(ResourceWarning warning)
          Add a warning onto the chain.
protected  void checkConnection()
          Check the connection associated with this interaction.
protected  void checkForMe(Session session, Address[] recipients)
          Test to eliminate sending to our own self.
 void clearWarnings()
          Clears all the warning reported by this Interaction instance.
 void close()
          Closes the current Interaction and release all the resources held for this instance by the resource adapter.
 Record execute(InteractionSpec ispec, Record record)
          Executes an interaction represented by the InteractionSpec.
 boolean execute(InteractionSpec ispec, Record input, Record output)
          Executes an interaction represented by the InteractionSpec.
 Connection getConnection()
          Gets the Connection associated with the Interaction.
protected  MimeMessage getMessage(Record record)
           
 ResourceWarning getWarnings()
          Gets the first ResourceWarning from the chain of warnings associated with this Interaction instance.
protected  void setConnection(EmailConnection connection)
          Sets the connection associated with this interaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mConnection

protected EmailConnection mConnection
The connection that created this interacation.


mWarning

protected ResourceWarning mWarning
The first warning in the chain.


mPollDelay

protected Integer mPollDelay
Cached poll delay.

Constructor Detail

EmailInteraction

public EmailInteraction()
Create a new instance of an EmailInteraction.

Method Detail

getMessage

protected MimeMessage getMessage(Record record)
                          throws ResourceException
ResourceException

chainWarning

protected void chainWarning(ResourceWarning warning)
Add a warning onto the chain.


checkForMe

protected void checkForMe(Session session,
                          Address[] recipients)
                   throws ResourceException
Test to eliminate sending to our own self. It does a simple string comparison between the recipient and the local address (according to the session). This is not sufficient, because the "mail.from" property can override the local address but the recipient can still be the Store the adapter is listening to. It's just a simple test that eliminates 90% of the 'oops, now it's in an infinite loop' problems.

Parameters:
session - The mail session.
recipients - The list of recipients to check.
Throws:
ResourceException - if there is a match between the local address and any recipient.

setConnection

protected void setConnection(EmailConnection connection)
Sets the connection associated with this interaction.

Parameters:
connection - The connection to associate with this Interaction.

checkConnection

protected void checkConnection()
                        throws ResourceException
Check the connection associated with this interaction.

Throws:
ResourceException - If this is a closed interaction.

clearWarnings

public void clearWarnings()
                   throws ResourceException
Clears all the warning reported by this Interaction instance. After a call to this method, the method getWarnings() will return null until a new warning is reported for this Interaction.

Specified by:
clearWarnings in interface Interaction
Throws:
ResourceException - Failed to clear ResourceWarnings associated with Interaction.

close

public void close()
           throws ResourceException
Closes the current Interaction and release all the resources held for this instance by the resource adapter. The close of an Interaction instance does not close the associated Connection instance. It is recommended that Interaction instances be closed explicitly to free any held resources.

Specified by:
close in interface Interaction
Throws:
ResourceException - Failed to close the Interaction instance. Invoking close on an already closed Interaction should also throw this exception.

execute

public Record execute(InteractionSpec ispec,
                      Record record)
               throws ResourceException
Executes an interaction represented by the InteractionSpec. This form of invocation takes an input Record and returns an output Record if the execution of the Interaction has been successfull.

Specified by:
execute in interface Interaction
Parameters:
ispec - - InteractionSpec representing a target EIS data/function module.
Returns:
Output Record if execution of the EIS function has been successful; null otherwise.
Throws:
ResourceException - Exception if execute operation fails. Examples of error cases are: Resource adapter internal, EIS-specific or communication error. Invalid specification of an InteractionSpec or input record structure. Errors in use of input Record or creation of an output Record. Invalid connection associated with this Interaction
NotSupportedException - Operation not supported.

execute

public boolean execute(InteractionSpec ispec,
                       Record input,
                       Record output)
                throws ResourceException
Executes an interaction represented by the InteractionSpec. This form of invocation takes an input Record and updates the output Record.

Specified by:
execute in interface Interaction
Parameters:
ispec - - InteractionSpec representing a target EIS data/function module.
input - Input Record.
output - Output Record.
Returns:
true if execution of the EIS function has been successful and output Record has been updated; false otherwise
Throws:
ResourceException - Exception if execute operation fails. Examples of error cases are: Resource adapter internal, EIS-specific or communication error. Invalid specification of an InteractionSpec, input or output record structure. Errors in use of input or output Record. Invalid connection associated with this Interaction.
NotSupportedException - Operation not supported.

getConnection

public Connection getConnection()
Gets the Connection associated with the Interaction.

Specified by:
getConnection in interface Interaction
Returns:
Connection instance associated with the Interaction.

Note: This will be null if the interaction has been closed, although this is not mentioned in the API. The other alternative would be to throw a ResourceException since that is the defined behaviour for other operations on a closed interaction.


getWarnings

public ResourceWarning getWarnings()
                            throws ResourceException
Gets the first ResourceWarning from the chain of warnings associated with this Interaction instance.

Specified by:
getWarnings in interface Interaction
Returns:
ResourceWarning at top of the warning chain.
Throws:
ResourceException - Failed to get ResourceWarnings associated with Interaction.

Email Answering System
Version 1.0

Copyright © 2003 Derrick Oswald. All rights reserved.