001/* 002 * jDTAUS Core API 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.core.container; 022 023import java.io.Serializable; 024 025/** 026 * Message meta-data. 027 * <p>A message consists of the properties {@code name}, {@code template} and 028 * {@code arguments}. Property {@code name} holds a name uniquely identifying 029 * the message in a set of messages. Property {@code template} holds the 030 * template of the message. Property {@code arguments} holds meta-data 031 * describing arguments to format the message with.</p> 032 * 033 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 034 * @version $JDTAUS: Message.java 8743 2012-10-07 03:06:20Z schulte $ 035 */ 036public class Message extends ModelObject implements Cloneable, Serializable 037{ 038 //--Constants--------------------------------------------------------------- 039 040 /** Serial version UID for backwards compatibility with 1.5.x classes. */ 041 private static final long serialVersionUID = 8433823757935477327L; 042 043 //---------------------------------------------------------------Constants-- 044 //--Message.---------------------------------------------------------------- 045 046 /** 047 * The name of the message. 048 * @serial 049 */ 050 private String name; 051 052 /** 053 * The name of the module holding the message. 054 * @serial 055 */ 056 private String moduleName; 057 058 /** 059 * The template of the message. 060 * @serial 061 */ 062 private Text template; 063 064 /** 065 * The arguments of the message. 066 * @serial 067 */ 068 private Arguments arguments; 069 070 /** Creates a new {@code Message} instance. */ 071 public Message() 072 { 073 super(); 074 } 075 076 /** 077 * Gets the name of the message. 078 * 079 * @return the name of the message. 080 */ 081 public String getName() 082 { 083 if ( this.name == null ) 084 { 085 this.name = ""; 086 } 087 088 return this.name; 089 } 090 091 /** 092 * Setter for property {@code name}. 093 * 094 * @param value the new name of the message. 095 */ 096 public void setName( final String value ) 097 { 098 this.name = value; 099 } 100 101 /** 102 * Gets the name of the module holding the message. 103 * 104 * @return the name of the module holding the message. 105 */ 106 public String getModuleName() 107 { 108 if ( this.moduleName == null ) 109 { 110 this.moduleName = ""; 111 } 112 113 return this.moduleName; 114 } 115 116 /** 117 * Setter for property {@code moduleName}. 118 * 119 * @param value the new name of the module holding the message. 120 */ 121 public void setModuleName( final String value ) 122 { 123 this.moduleName = value; 124 } 125 126 /** 127 * Gets the template of the message. 128 * 129 * @return the template of the message. 130 */ 131 public Text getTemplate() 132 { 133 if ( this.template == null ) 134 { 135 this.template = new Text(); 136 } 137 138 return this.template; 139 } 140 141 /** 142 * Setter for property {@code template}. 143 * 144 * @param value the new template of the message. 145 */ 146 public void setTemplate( final Text value ) 147 { 148 this.template = value; 149 } 150 151 /** 152 * Gets the arguments of the message. 153 * 154 * @return the arguments of the message. 155 */ 156 public Arguments getArguments() 157 { 158 if ( this.arguments == null ) 159 { 160 this.arguments = new Arguments(); 161 } 162 163 return this.arguments; 164 } 165 166 /** 167 * Setter for property {@code arguments}. 168 * 169 * @param value the new arguments of the message. 170 */ 171 public void setArguments( final Arguments value ) 172 { 173 this.arguments = value; 174 } 175 176 /** 177 * Creates a string representing the properties of the instance. 178 * 179 * @return a string representing the properties of the instance. 180 */ 181 private String internalString() 182 { 183 final StringBuffer buf = new StringBuffer( 500 ).append( '{' ). 184 append( this.internalString( this ) ). 185 append( ", name=" ).append( this.name ). 186 append( ", moduleName=" ).append( this.moduleName ). 187 append( ", template=" ).append( this.template ). 188 append( ", arguments=" ).append( this.arguments ); 189 190 buf.append( '}' ); 191 return buf.toString(); 192 } 193 194 //----------------------------------------------------------------Template-- 195 //--Object------------------------------------------------------------------ 196 197 /** 198 * Returns a string representation of the object. 199 * 200 * @return a string representation of the object. 201 */ 202 public String toString() 203 { 204 return super.toString() + this.internalString(); 205 } 206 207 /** 208 * Creates and returns a copy of this object. This method performs a 209 * "shallow copy" of this object, not a "deep copy" operation. 210 * 211 * @return a clone of this instance. 212 */ 213 public Object clone() 214 { 215 try 216 { 217 return super.clone(); 218 } 219 catch ( final CloneNotSupportedException e ) 220 { 221 throw new AssertionError( e ); 222 } 223 } 224 225 /** 226 * Indicates whether some other object is equal to this one by comparing 227 * properties {@code name} and {@code moduleName}. 228 * 229 * @param o the reference object with which to compare. 230 * 231 * @return {@code true} if this object is the same as {@code o}; 232 * {@code false} otherwise. 233 */ 234 public final boolean equals( final Object o ) 235 { 236 boolean equal = o == this; 237 if ( !equal && o instanceof Message ) 238 { 239 final Message that = (Message) o; 240 equal = this.getName().equals( that.getName() ) && 241 this.getModuleName().equals( that.getModuleName() ); 242 243 } 244 245 return equal; 246 } 247 248 /** 249 * Returns a hash code value for this object. 250 * 251 * @return a hash code value for this object. 252 */ 253 public final int hashCode() 254 { 255 return this.getName().hashCode() + this.getModuleName().hashCode(); 256 } 257 258 //------------------------------------------------------------------Object-- 259}