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 * Argument meta-data.
029 * <p>An argument consists of the properties {@code index}, {@code name} and
030 * {@code type}. Property {@code index} holds the index of the argument in a
031 * list of arguments. Property {@code name} holds the name uniquely identifying
032 * the argument in a set of arguments. Property {@code type} holds the type
033 * of the argument.</p>
034 *
035 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
036 * @version $Id: Argument.java 8044 2009-07-02 01:29:05Z schulte2005 $
037 */
038 public class Argument extends ModelObject implements Cloneable, Serializable
039 {
040 //--Constants---------------------------------------------------------------
041
042 /** Constant for property {@code type}. */
043 public static final int TYPE_NUMBER = 27000;
044
045 /** Constant for property {@code type}. */
046 public static final int TYPE_DATE = 27001;
047
048 /** Constant for property {@code type}. */
049 public static final int TYPE_TIME = 27002;
050
051 /** Constant for property {@code type}. */
052 public static final int TYPE_TEXT = 27003;
053
054 /** Serial version UID for backwards compatibility with 1.5.x classes. */
055 private static final long serialVersionUID = 5250117542077493369L;
056
057 //---------------------------------------------------------------Constants--
058 //--Argument----------------------------------------------------------------
059
060 /**
061 * The index of the argument.
062 * @serial
063 */
064 private int index;
065
066 /**
067 * The name of the argument.
068 * @serial
069 */
070 private String name;
071
072 /**
073 * The type of the argument.
074 * @serial
075 */
076 private int type;
077
078 /**
079 * Gets the index of the argument.
080 *
081 * @return the index of the argument.
082 */
083 public int getIndex()
084 {
085 return this.index;
086 }
087
088 /**
089 * Setter for property {@code index}.
090 *
091 * @param value the new index of the argument.
092 */
093 public void setIndex( final int value )
094 {
095 this.index = value;
096 }
097
098 /**
099 * Gets the name of the argument.
100 *
101 * @return the name of the argument.
102 */
103 public String getName()
104 {
105 if ( this.name == null )
106 {
107 this.name = "";
108 }
109
110 return this.name;
111 }
112
113 /**
114 * Setter for property {@code name}.
115 *
116 * @param value the new name of the argument.
117 */
118 public void setName( final String value )
119 {
120 this.name = value;
121 }
122
123 /**
124 * Gets the type of the argument.
125 *
126 * @return the type of the argument.
127 */
128 public int getType()
129 {
130 return this.type;
131 }
132
133 /**
134 * Setter for property {@code type}.
135 *
136 * @param value the new type of the argument.
137 *
138 * @throws IllegalArgumentException if {@code value} is not equal to one of
139 * the constants {@code TYPE_NUMBER}, {@code TYPE_DATE}, {@code TYPE_TIME}
140 * or {@code TYPE_TEXT}.
141 */
142 public void setType( final int value )
143 {
144 if ( value != TYPE_NUMBER && value != TYPE_DATE &&
145 value != TYPE_TIME && value != TYPE_TEXT )
146 {
147 throw new IllegalArgumentException( Integer.toString( value ) );
148 }
149
150 this.type = value;
151 }
152
153 /**
154 * Creates a string representing the properties of the instance.
155 *
156 * @return a string representing the properties of the instance.
157 */
158 private String internalString()
159 {
160 final StringBuffer buf = new StringBuffer( 500 ).append( '{' ).
161 append( this.internalString( this ) ).
162 append( ", index=" ).append( this.index ).
163 append( ", name=" ).append( this.name ).
164 append( ", type=" );
165
166 if ( this.type == TYPE_NUMBER )
167 {
168 buf.append( "number" );
169 }
170 else if ( this.type == TYPE_DATE )
171 {
172 buf.append( "date" );
173 }
174 else if ( this.type == TYPE_TIME )
175 {
176 buf.append( "time" );
177 }
178 else if ( this.type == TYPE_TEXT )
179 {
180 buf.append( "text" );
181 }
182
183 return buf.append( '}' ).toString();
184 }
185
186 //----------------------------------------------------------------Argument--
187 //--Object------------------------------------------------------------------
188
189 /**
190 * Returns a string representation of the object.
191 *
192 * @return a string representation of the object.
193 */
194 public String toString()
195 {
196 return super.toString() + this.internalString();
197 }
198
199 /**
200 * Indicates whether some other object is equal to this one by comparing
201 * the values of all properties.
202 *
203 * @param o the reference object with which to compare.
204 *
205 * @return {@code true} if this object is the same as {@code o};
206 * {@code false} otherwise.
207 */
208 public boolean equals( final Object o )
209 {
210 boolean equal = this == o;
211
212 if ( !equal && o instanceof Argument )
213 {
214 final Argument that = (Argument) o;
215 equal = this.getIndex() == that.getIndex() &&
216 this.getType() == that.getType() &&
217 this.getName().equals( that.getName() );
218
219 }
220
221 return equal;
222 }
223
224 /**
225 * Returns a hash code value for this object.
226 *
227 * @return a hash code value for this object.
228 */
229 public int hashCode()
230 {
231 int hc = 23;
232 hc = 37 * hc + this.getIndex();
233 hc = 37 * hc + this.getName().hashCode();
234 hc = 37 * hc + this.getType();
235 return hc;
236 }
237
238 /**
239 * Creates and returns a copy of this object. This method performs a
240 * "shallow copy" of this object, not a "deep copy" operation.
241 *
242 * @return a clone of this instance.
243 */
244 public Object clone()
245 {
246 try
247 {
248 return super.clone();
249 }
250 catch ( CloneNotSupportedException e )
251 {
252 throw new AssertionError( e );
253 }
254 }
255
256 //------------------------------------------------------------------Object--
257 }