1 /*
2 * jDTAUS Core API
3 * Copyright (C) 2005 Christian Schulte
4 * <cs@schulte.it>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21 package org.jdtaus.core.container;
22
23 import java.io.Serializable;
24
25 /**
26 * Property meta-data.
27 * <p>A property consists of the properties {@code name}, {@code type} and
28 * {@code value}. Property {@code name} holds the name uniquely identifying the
29 * property in a collection of properties. Property {@code type} holds the type
30 * of the property. Property {@code value} holds the properties value which is
31 * of type {@code type}. The {@code api} flag indicates if the property is part
32 * of a public API.</p>
33 *
34 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
35 * @version $JDTAUS: Property.java 8743 2012-10-07 03:06:20Z schulte $
36 */
37 public class Property extends ModelObject implements Cloneable, Serializable
38 {
39 //--Constants---------------------------------------------------------------
40
41 /** Serial version UID for backwards compatibility with 1.0.x classes. */
42 private static final long serialVersionUID = -5450366074586725711L;
43
44 //---------------------------------------------------------------Constants--
45 //--Property----------------------------------------------------------------
46
47 /**
48 * The name of the property.
49 * @serial
50 */
51 private String name;
52
53 /**
54 * The type of the property.
55 * @serial
56 */
57 private Class type;
58
59 /**
60 * The value of the property.
61 * @serial
62 */
63 private Object value;
64
65 /**
66 * Flag indicating that the property is part of a public API.
67 * @serial
68 */
69 private boolean api;
70
71 /** Creates a new {@code Property} instance. */
72 public Property()
73 {
74 super();
75 }
76
77 /**
78 * Gets the name of the property.
79 *
80 * @return the name of the property.
81 */
82 public String getName()
83 {
84 if ( this.name == null )
85 {
86 this.name = "";
87 }
88
89 return this.name;
90 }
91
92 /**
93 * Setter for property {@code name}.
94 *
95 * @param value the new name of the property.
96 */
97 public void setName( final String value )
98 {
99 this.name = value;
100 }
101
102 /**
103 * Gets the type of the property.
104 *
105 * @return the type of the property.
106 */
107 public Class getType()
108 {
109 if ( this.type == null )
110 {
111 this.type = String.class;
112 }
113
114 return this.type;
115 }
116
117 /**
118 * Setter for property {@code type}.
119 *
120 * @param value the new type of the property.
121 */
122 public void setType( final Class value )
123 {
124 this.type = value;
125 }
126
127 /**
128 * Gets the value of the property.
129 *
130 * @return the value of the property or {@code null}.
131 */
132 public Object getValue()
133 {
134 return this.value;
135 }
136
137 /**
138 * Setter for property {@code value}.
139 *
140 * @param value the new value of the property.
141 */
142 public void setValue( final Object value )
143 {
144 this.value = value;
145 }
146
147 /**
148 * Gets the flag indicating if the property is part of a public API.
149 *
150 * @return {@code true} if the property is part of a public API.
151 */
152 public boolean isApi()
153 {
154 return this.api;
155 }
156
157 /**
158 * Setter for property {@code api}.
159 *
160 * @param value {@code true} if the property is part of a public API.
161 */
162 public void setApi( final boolean value )
163 {
164 this.api = value;
165 }
166
167 /**
168 * Creates a string representing the properties of the instance.
169 *
170 * @return a string representing the properties of the instance.
171 */
172 private String internalString()
173 {
174 return new StringBuffer( 500 ).append( '{' ).
175 append( super.internalString( this ) ).
176 append( ", api=" ).append( this.api ).
177 append( ", name=" ).append( this.name ).
178 append( ", type=" ).append( this.type ).
179 append( ", value=" ).append( this.value ).
180 append( '}' ).toString();
181
182 }
183
184 //----------------------------------------------------------------Property--
185 //--Object------------------------------------------------------------------
186
187 /**
188 * Returns a string representation of the object.
189 *
190 * @return a string representation of the object.
191 */
192 public String toString()
193 {
194 return super.toString() + this.internalString();
195 }
196
197 /**
198 * Indicates whether some other object is equal to this one by comparing
199 * the values of all properties.
200 *
201 * @param o the reference object with which to compare.
202 *
203 * @return {@code true} if this object is the same as {@code o};
204 * {@code false} otherwise.
205 */
206 public boolean equals( final Object o )
207 {
208 boolean equal = this == o;
209
210 if ( !equal && o instanceof Property )
211 {
212 final Property that = (Property) o;
213 equal = this.getName().equals( that.getName() ) &&
214 this.getType().equals( that.getType() ) &&
215 ( this.getValue() == null
216 ? that.getValue() == null
217 : this.getValue().equals( that.getValue() ) );
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 return this.getName().hashCode() +
232 this.getType().hashCode() +
233 ( this.getValue() == null ? 0 : this.getValue().hashCode() );
234
235 }
236
237 /**
238 * Creates and returns a copy of this object. This method performs a
239 * "shallow copy" of this object, not a "deep copy" operation.
240 *
241 * @return a clone of this instance.
242 */
243 public Object clone()
244 {
245 try
246 {
247 return super.clone();
248 }
249 catch ( final CloneNotSupportedException e )
250 {
251 throw new AssertionError( e );
252 }
253 }
254
255 //------------------------------------------------------------------Object--
256 }