org.iscreen.ognl
Class OgnlMessage

java.lang.Object
  extended by org.iscreen.ognl.OgnlMessage
All Implemented Interfaces:
FailureMessage
Direct Known Subclasses:
OgnlResourceMessage

public class OgnlMessage
extends java.lang.Object
implements FailureMessage

An OGNL message wraps a "template" that is a String of characters. This template may contain "OGNL tags" that look like this: ${some ognl}. When a ${} is found within the template, it's removed, and the contents are considered an OGNL expression, which is evaluated based upon an OGNL root (either set separately or passed in when generating the message).

Author:
Shellman, Dan

Field Summary
protected  java.util.Map extraMessages
           
protected  java.lang.Object root
           
protected  int severityLevel
           
protected  java.lang.String template
           
 
Constructor Summary
protected OgnlMessage()
          For sub-classes to over-ride how this works.
  OgnlMessage(java.lang.String theTemplate, int severity)
          Constructor taking the template of this message.
 
Method Summary
 void addMessage(java.lang.String name, OgnlMessage extraMessage)
          Adds an additional message.
static java.lang.String constructMessage(java.lang.String theTemplate, java.lang.Object ognlRoot)
          Searches through the template and replaces all ${} with the evaluation of their OGNL expressions.
 java.util.Map getExtraMessages()
          Retrieves additional messages that are associated with the failure.
 java.lang.String getMessage()
          Generates a message based upon the template of this message and the OGNL root passed in to the setOgnlRoot() method.
 java.lang.String getMessage(java.lang.Object ognlRoot, java.util.Locale locale)
          Generates a message based upon the template of this message and the OGNL root passed in.
 java.lang.Object getOgnlRoot()
          Returns the OGNL root previously set using the setOgnlRoot() method.
 int getSeverity()
          Retrieves the failure's severity level.
 java.lang.String getTemplate(java.util.Locale locale)
          Returns the template previously set during construction.
 void setOgnlRoot(java.lang.Object ognlRoot)
          Sets the OGNL root to be used when getMessage() is called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

template

protected java.lang.String template

root

protected java.lang.Object root

severityLevel

protected int severityLevel

extraMessages

protected java.util.Map extraMessages
Constructor Detail

OgnlMessage

public OgnlMessage(java.lang.String theTemplate,
                   int severity)
Constructor taking the template of this message. The template should never be null.

Parameters:
theTemplate - The template (which may or may not contain OGNL tags)

OgnlMessage

protected OgnlMessage()
For sub-classes to over-ride how this works.

Method Detail

getExtraMessages

public java.util.Map getExtraMessages()
Description copied from interface: FailureMessage
Retrieves additional messages that are associated with the failure. These additional messages are based upon a name and can be found in the config as sub-elements to the 'failure' element.

Specified by:
getExtraMessages in interface FailureMessage
Returns:
Returns a map of message names to messages. The messages are, themselves, FailureMessage objects.

addMessage

public void addMessage(java.lang.String name,
                       OgnlMessage extraMessage)
Adds an additional message.

Parameters:
name - The name of the message.
extraMessage - The extra message.

setOgnlRoot

public void setOgnlRoot(java.lang.Object ognlRoot)
Sets the OGNL root to be used when getMessage() is called.

Parameters:
ognlRoot - The OGNL root object.

getMessage

public java.lang.String getMessage()
Generates a message based upon the template of this message and the OGNL root passed in to the setOgnlRoot() method. If the OGNL root object is null, then this method will return the template unchanged.

Returns:
Returns the message, which is constructed based upon the OGNL root and the template.

getMessage

public java.lang.String getMessage(java.lang.Object ognlRoot,
                                   java.util.Locale locale)
Generates a message based upon the template of this message and the OGNL root passed in. If the OGNL root is null, then the OGNL root passed in to the setOgnlRoot() method is used. If that's null, then the template is returned unchanged.

Specified by:
getMessage in interface FailureMessage
Parameters:
ognlRoot - The OGNL root to use for generating the message.
locale - The locale use for localizing the message.
Returns:
Returns the message, which is constructed based upon the OGNL root passed in and the template.

getSeverity

public int getSeverity()
Description copied from interface: FailureMessage
Retrieves the failure's severity level. The higher the severity level (numerically), the "worse" the failure. See the constants defined in this interface for "standard" severity levels.

Specified by:
getSeverity in interface FailureMessage
Returns:
Returns the failure's severity level.

getOgnlRoot

public java.lang.Object getOgnlRoot()
Returns the OGNL root previously set using the setOgnlRoot() method.

Returns:
Returns the OGNL root for this message.

getTemplate

public java.lang.String getTemplate(java.util.Locale locale)
Returns the template previously set during construction.

Parameters:
locale - The locale to use.
Returns:
Returns the template.

constructMessage

public static java.lang.String constructMessage(java.lang.String theTemplate,
                                                java.lang.Object ognlRoot)
Searches through the template and replaces all ${} with the evaluation of their OGNL expressions.

Parameters:
theTemplate - The template to use.
ognlRoot - The OGNL root.
Returns:
Returns the constructed String.