001: /*
002: * Created on Nov 23, 2004
003: */
004: package uk.org.ponder.messageutil;
005:
006: import java.io.Serializable;
007:
008: /**
009: * Represents a single message, for presentation to the user, targetted at a
010: * particular field or part of an interface. The message has not yet been
011: * resolved onto its localised representation (generally to be performed via
012: * {@link MessageLocator}, and has an associated severity level.
013: * @author Antranig Basman (antranig@caret.cam.ac.uk)
014: *
015: */
016: public class TargettedMessage implements Serializable {
017: public static final String TARGET_NONE = "No specific target";
018: /**
019: * A list of possible message codes, in descending order of specificity. This
020: * is the same semantics as Spring's "MessageSourceResolvable" system.
021: */
022: public String[] messagecodes;
023: public Object[] args = null;
024: public String targetid = TARGET_NONE;
025: public Exception exception;
026:
027: public static final int SEVERITY_INFO = 0;
028: public static final int SEVERITY_ERROR = 1;
029: public int severity = SEVERITY_ERROR;
030:
031: public void updateMessageCode(String messagecode) {
032: messagecodes = new String[] { messagecode };
033: }
034:
035: public void updateTarget(String targetid) {
036: this .targetid = targetid == null ? TARGET_NONE : targetid;
037: }
038:
039: public String acquireMessageCode() {
040: return messagecodes == null ? null
041: : messagecodes[messagecodes.length - 1];
042: }
043:
044: public TargettedMessage() {
045: }
046:
047: /** Construct a simple targetted message
048: * @param messagecode The message key for resolving the message text.
049: * @param targetid The target field or path of the message, if <code>null</code>
050: * will be substituted with {@link #TARGET_NONE}.
051: */
052: public TargettedMessage(String messagecode, String targetid) {
053: updateMessageCode(messagecode);
054: this .targetid = targetid == null ? TARGET_NONE : targetid;
055: }
056:
057: public TargettedMessage(String messagecode, Object[] args,
058: String targetid) {
059: updateMessageCode(messagecode);
060: updateTarget(targetid);
061: this .args = args;
062: }
063:
064: public TargettedMessage(String messagecode) {
065: updateMessageCode(messagecode);
066: }
067:
068: public TargettedMessage(String messagecode, Exception exception) {
069: updateMessageCode(messagecode);
070: this .exception = exception;
071: }
072:
073: public TargettedMessage(String messagecode, Exception exception,
074: String targetid) {
075: updateMessageCode(messagecode);
076: updateTarget(targetid);
077: this .exception = exception;
078: }
079:
080: public TargettedMessage(String messagecode, Object[] args) {
081: updateMessageCode(messagecode);
082: this .args = args;
083: }
084:
085: public TargettedMessage(String messagecode, Object[] args,
086: int severity) {
087: updateMessageCode(messagecode);
088: this .args = args;
089: this .severity = severity;
090: }
091:
092: public TargettedMessage(String[] messagecodes, Object[] args,
093: String targetid) {
094: updateTarget(targetid);
095: this .messagecodes = messagecodes;
096: this .args = args;
097: }
098:
099: /** The fullest constructor for TargettedMessage.
100: * @param messagecodes Message codes to be used for resolution, in descending
101: * order of priority. See {@link MessageLocator}
102: * @param args Any arguments required for substitution in the resolved message.
103: * @param targetid The ID or path that the message is to be targetted at.
104: * @param severity The severity of the message, either {@link #SEVERITY_INFO} or
105: * {@link #SEVERITY_ERROR}
106: */
107: public TargettedMessage(String[] messagecodes, Object[] args,
108: String targetid, int severity) {
109: updateTarget(targetid);
110: this.messagecodes = messagecodes;
111: this.args = args;
112: this.severity = severity;
113: }
114: }
|