001: package nl.knowlogy.validation;
002:
003: import org.apache.commons.lang.builder.ToStringBuilder;
004: import org.apache.commons.lang.builder.ToStringStyle;
005:
006: /**
007: * MessageImpl is the default implementation for the <tt>Message</tt> interface.
008: *
009: * @author <a href="mailto:robert.hofstra@knowlogy.nl">Robert Hofstra, Knowlogy</a>
010: *
011: */
012: public class MessageImpl implements Message {
013:
014: private Object objectPertainingMessage;
015:
016: private String propertyName;
017:
018: private String message;
019:
020: private String messageCode;
021:
022: private Object[] messageArgs;
023:
024: private MessageType messageType;
025:
026: private boolean rendered = false;
027:
028: public MessageImpl(MessageType messageType,
029: Object objectPertainingMessage, String propertyName,
030: String messageCode) {
031: this (messageType, objectPertainingMessage, propertyName,
032: messageCode, null, null);
033: }
034:
035: public MessageImpl(MessageType messageType,
036: Object objectPertainingMessage, String propertyName,
037: String messageCode, String message) {
038: this (messageType, objectPertainingMessage, propertyName,
039: messageCode, null, message);
040: }
041:
042: public MessageImpl(MessageType messageType,
043: Object objectPertainingMessage, String propertyName,
044: String messageCode, Object[] errorArgs, String message) {
045: this .messageType = messageType;
046: this .objectPertainingMessage = objectPertainingMessage;
047: this .propertyName = propertyName;
048: this .messageCode = messageCode;
049: this .messageArgs = errorArgs;
050: // if (errorArgs != null){
051: // this.messageArgs = new Object[errorArgs.length];
052: // this.messageArgs[0] = propertyName;
053: // for(int i = 0; i < errorArgs.length; i++){
054: // this.messageArgs[i + 1] = errorArgs[i];
055: // }
056: // }
057: this .message = message;
058:
059: }
060:
061: public Object getRelatedObject() {
062: return objectPertainingMessage;
063: }
064:
065: /**
066: * @return Returns the message.
067: */
068: public String getMessage() {
069: return message;
070: }
071:
072: public void setMessage(String message) {
073:
074: this .message = message;
075: }
076:
077: /**
078: * @return Returns the propertyName.
079: */
080: public String getPropertyName() {
081: return propertyName;
082: }
083:
084: public String getMessageCode() {
085: return messageCode;
086: }
087:
088: /**
089: * @return Returns the messageArgs.
090: */
091: public Object[] getMessageArgs() {
092: return messageArgs;
093: }
094:
095: /* (non-Javadoc)
096: * @see nl.knowlogy.validation.errors.PropertyError#toString()
097: */
098: public String toString() {
099: return new ToStringBuilder(this , ToStringStyle.DEFAULT_STYLE)
100: .append("propertyName", this .getPropertyName()).append(
101: "messageCode", this .getMessageCode()).append(
102: "message", this .getMessage()).append(
103: "messageArgs", this .getMessageArgs())
104: .toString();
105: }
106:
107: public MessageType getMessageType() {
108: return messageType;
109: }
110:
111: public boolean isRendered() {
112: return rendered;
113: }
114:
115: public void setRendered(boolean rendered) {
116: this.rendered = rendered;
117: }
118: }
|