TagLib documentation

org.alweb.doff.util.error
Class ErrorMessage

java.lang.Object
  extended by org.alweb.doff.util.error.ErrorMessage

public final class ErrorMessage
extends Object

Represents an error message with optionnal parameters. ErrorMessage instances are often created by ErrorContainer subclasses. Your model classes can extends this class or implements ErrorProducer in order to raise errors. Error messages can be internationalized keys or not.

Since:
1.4
Author:
Alexis Toulotte
See Also:
ErrorContainer, ErrorProducer

Constructor Summary
ErrorMessage(String message, Object... params)
          Constructs a new error message with the specified message as string format and optional parameters.
 
Method Summary
 void addParam(Object param)
          Adds specified parameter into the internal parameter list.
 void addParams(Collection<Object> params)
          Adds specified parameters into the internal parameter list.
 void addParams(Object... params)
          Adds specified parameters into the internal parameter list.
 boolean equals(Object object)
           
 String format(ResourceBundle bundle)
           Format this error message thanks to specified bundle.
 Object getCause()
          Returns the cause of this error or null if not specified.
 String getMessage()
          Returns the message specified at constructor.
 Collection<Object> getParams()
          Returns a read-only collection of all parameters.
 boolean hasParam()
          Determines if this error message has at least one parameter.
 ErrorMessage setCause(Object cause)
          Sets the cause of this message.
 String toString()
          Provides a string representation of this error message.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ErrorMessage

public ErrorMessage(String message,
                    Object... params)
Constructs a new error message with the specified message as string format and optional parameters. The specified message can be a key into i18n files. The specified message is trimmed.

See Also:
addParams(Object[])
Method Detail

addParam

public void addParam(Object param)
Adds specified parameter into the internal parameter list.


addParams

public void addParams(Collection<Object> params)
Adds specified parameters into the internal parameter list.


addParams

public void addParams(Object... params)
Adds specified parameters into the internal parameter list.


equals

public boolean equals(Object object)
Overrides:
equals in class Object

format

public String format(ResourceBundle bundle)

Format this error message thanks to specified bundle. The message is supposed to be a key into the specified bundle. This method uses ResourceBundle.getString(String) method and if this error message has parameters, it formats the message thanks to MessageFormat.format(String, Object[]) method.

If string can't be retrieved, this method doesn't throws a MissingResourceException but returns the message surrounded with two !.

Throws:
NullPointerException - if specified bundle is null.
See Also:
getMessage(), MessageFormat

getCause

public Object getCause()
Returns the cause of this error or null if not specified.

Since:
1.6.3
See Also:
getCause()

getMessage

public String getMessage()
Returns the message specified at constructor.


getParams

public Collection<Object> getParams()
Returns a read-only collection of all parameters.

See Also:
Collections.unmodifiableCollection(Collection)

hasParam

public boolean hasParam()
Determines if this error message has at least one parameter.

See Also:
getParams(), Collection.isEmpty()

setCause

public ErrorMessage setCause(Object cause)
Sets the cause of this message.

Returns:
This error message for chaining.
Since:
1.6.3

toString

public String toString()
Provides a string representation of this error message.

Overrides:
toString in class Object
Returns:
The message specified at constructor.
See Also:
getMessage()

TagLib documentation