Class MessageContext

java.lang.Object
org.deltava.mail.MessageContext

public class MessageContext extends Object
A class to store and retrieve message context data.
Since:
1.0
Version:
11.1
Author:
Luke
  • Constructor Details

    • MessageContext

      public MessageContext()
      Initializes the Message Context, and sets any pre-defined context elements.
    • MessageContext

      public MessageContext(String aCode)
      Initializes the Message Context, and sets any pre-defined context elements.
      Parameters:
      aCode - the airline code
  • Method Details

    • addData

      public void addData(String name, Object obj)
      Adds an object to the context data.
      Parameters:
      name - the name of the object
      obj - the object
      Throws:
      NullPointerException - if name is null
    • setSubject

      public void setSubject(String subj)
      Overrides the subject used in the message, instead of using the Message Template subject.
      Parameters:
      subj - the new subject
    • getSubject

      public String getSubject()
      Returns the message subject.
      Returns:
      the subject prepended by the Airline Name
    • getBody

      public String getBody()
      Formats the message by replacing arguments in the message template with values from the context.
      Returns:
      the formatted message body text
      Throws:
      IllegalStateException - if no template exists
    • hasData

      boolean hasData(String name)
      Checks if a particular named object exists within this context.
      Parameters:
      name - the name of the object
      Returns:
      TRUE if the object exists within this context, otherwise false
      Throws:
      NullPointerException - if name is null
    • setRecipient

      public void setRecipient(EMailAddress to)
      Sets the recipient of this email message.
      Parameters:
      to - an EMailAddress
    • setBody

      public void setBody(String body)
      Sets the message body to use, if no template is used.
      Parameters:
      body - the message body
    • setTemplate

      public void setTemplate(MessageTemplate mt)
      Sets the message template to use.
      Parameters:
      mt - the Message Template
      See Also:
    • getTemplate

      public MessageTemplate getTemplate()
      Returns the Message template in use.
      Returns:
      a MessageTemplate object
      See Also:
    • execute

      String execute(String arg)
      Evalutes and formats a given macro argument.
      Parameters:
      arg - the argument macro
      Returns:
      the formatting String result
    • evaluate

      Object evaluate(String arg)
      Determines the value of a given macro argument via recursive reflection. The argument is in the following format: name.[method OR field ...] which can be repeated numerous times. For example the macro pirep.getAirportA.getIATA will get the named object called "pirep", and then execute the getAirportA() method on this object. The method getIATA() method will be returned on the result of the first method call. If no method matching a given name is found, a field with this name will be used if present. If no method or field matching a given component is found, then execution fails.
      Parameters:
      arg - the argument macro
      Returns:
      the value of the argument macro, or an empty String ("") if execution fails
      See Also: