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