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.ObjectStreamException;
026 import java.io.Serializable;
027
028 /**
029 * Module meta-data.
030 * <p>A module consists of the properties {@code name}, {@code description}
031 * and {@code version}. Property {@code name} holds the name of the module
032 * uniquely identifying the module in a collection of modules. Property
033 * {@code description} holds a textual description, property {@code version}
034 * a textual version of the module. A module defines specifications,
035 * implementations and properties.</p>
036 *
037 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
038 * @version $Id: Module.java 8044 2009-07-02 01:29:05Z schulte2005 $
039 */
040 public class Module extends ModelObject implements Cloneable, Serializable
041 {
042 //--Constants---------------------------------------------------------------
043
044 /** Serial version UID for backwards compatibility with 1.0.x classes. */
045 private static final long serialVersionUID = 2518888867819463746L;
046
047 //---------------------------------------------------------------Constants--
048 //--Module------------------------------------------------------------------
049
050 /**
051 * The specifications of the module.
052 * @serial
053 */
054 private Specifications specifications;
055
056 /**
057 * The implementations of the module.
058 * @serial
059 */
060 private Implementations implementations;
061
062 /**
063 * The properties of the module.
064 * @serial
065 */
066 private Properties properties;
067
068 /**
069 * The messages of the module.
070 * @serial
071 */
072 private Messages messages;
073
074 /**
075 * The description of the module.
076 * @serial
077 * @deprecated Replaced by property {@code documentation}.
078 */
079 private String description;
080
081 /**
082 * The name of the module.
083 * @serial
084 */
085 private String name;
086
087 /**
088 * The version of the module.
089 * @serial
090 */
091 private String version;
092
093 /**
094 * Gets the specifications of the module.
095 *
096 * @return the specifications of the module.
097 */
098 public Specifications getSpecifications()
099 {
100 if ( this.specifications == null )
101 {
102 this.specifications = new Specifications();
103 }
104
105 return this.specifications;
106 }
107
108 /**
109 * Setter for property {@code specifications}.
110 *
111 * @param value the new specifications of the module.
112 */
113 public void setSpecifications( final Specifications value )
114 {
115 this.specifications = value;
116 }
117
118 /**
119 * Gets the implementations of the module.
120 *
121 * @return implementations of the module.
122 */
123 public Implementations getImplementations()
124 {
125 if ( this.implementations == null )
126 {
127 this.implementations = new Implementations();
128 }
129
130 return this.implementations;
131 }
132
133 /**
134 * Setter for property {@code implementations}.
135 *
136 * @param value the new implementations of the module.
137 */
138 public void setImplementations( final Implementations value )
139 {
140 this.implementations = value;
141 }
142
143 /**
144 * Gets the properties of the module.
145 *
146 * @return the properties of the module.
147 */
148 public Properties getProperties()
149 {
150 if ( this.properties == null )
151 {
152 this.properties = new Properties();
153 }
154
155 return this.properties;
156 }
157
158 /**
159 * Setter for property {@code properties}.
160 *
161 * @param value the new properties of the module.
162 */
163 public void setProperties( final Properties value )
164 {
165 this.properties = value;
166 }
167
168 /**
169 * Gets the messages of the module.
170 *
171 * @return the messages of the module.
172 */
173 public Messages getMessages()
174 {
175 if ( this.messages == null )
176 {
177 this.messages = new Messages();
178 }
179
180 return this.messages;
181 }
182
183 /**
184 * Setter for property {@code messages}.
185 *
186 * @param value new messages of the module.
187 */
188 public void setMessages( final Messages value )
189 {
190 this.messages = value;
191 }
192
193 /**
194 * Gets the description of the module.
195 *
196 * @return the description of the module or {@code null}.
197 * @deprecated Replaced by {@link #getDocumentation() getDocumentation().getValue()}.
198 */
199 public String getDescription()
200 {
201 return this.getDocumentation().getValue();
202 }
203
204 /**
205 * Setter for property {@code description}.
206 *
207 * @param value the new description of the module.
208 * @deprecated Replaced by {@link #setDocumentation(org.jdtaus.core.container.Text) getDocumentation().setValue( value )}.
209 */
210 public void setDescription( final String value )
211 {
212 this.getDocumentation().setValue( value );
213 }
214
215 /**
216 * Gets the name of the module.
217 *
218 * @return the unique name of the module.
219 */
220 public String getName()
221 {
222 if ( this.name == null )
223 {
224 this.name = "";
225 }
226
227 return this.name;
228 }
229
230 /**
231 * Setter for property {@code name}.
232 *
233 * @param value the new name of the module.
234 */
235 public void setName( final String value )
236 {
237 this.name = value;
238 }
239
240 /**
241 * Gets the version of the module.
242 *
243 * @return the version of the module or {@code null}.
244 */
245 public String getVersion()
246 {
247 return this.version;
248 }
249
250 /**
251 * Setter for property {@code version}.
252 *
253 * @param value the new version of the module.
254 */
255 public void setVersion( final String value )
256 {
257 this.version = value;
258 }
259
260 /**
261 * Creates a string representing the properties of the instance.
262 *
263 * @return a string representing the properties of the instance.
264 */
265 private String internalString()
266 {
267 final StringBuffer buf = new StringBuffer( 500 ).append( '{' ).
268 append( this.internalString( this ) ).
269 append( ", name=" ).append( this.name ).
270 append( ", version=" ).append( this.version ).
271 append( ", properties=" ).append( this.properties ).
272 append( ", messages=" ).append( this.messages ).
273 append( ", specifications=" ).append( this.getSpecifications() ).
274 append( ", implementations=" ).append( this.getImplementations() );
275
276 buf.append( '}' ).toString();
277 return buf.toString();
278 }
279
280 //------------------------------------------------------------------Module--
281 //--Serializable------------------------------------------------------------
282
283 /**
284 * Takes care of initializing fields when constructed from an 1.0.x object
285 * stream.
286 *
287 * @throws ObjectStreamException if no scope can be resolved.
288 */
289 private Object readResolve() throws ObjectStreamException
290 {
291 if ( this.getDocumentation().getValue() == null &&
292 this.description != null )
293 {
294 this.getDocumentation().setValue( this.description );
295 }
296 if ( "".equals( this.version ) )
297 {
298 this.version = null;
299 }
300
301 return this;
302 }
303
304 //------------------------------------------------------------Serializable--
305 //--Object------------------------------------------------------------------
306
307 /**
308 * Returns a string representation of the object.
309 *
310 * @return a string representation of the object.
311 */
312 public String toString()
313 {
314 return super.toString() + this.internalString();
315 }
316
317 /**
318 * Creates and returns a copy of this object. This method performs a
319 * "shallow copy" of this object, not a "deep copy" operation.
320 *
321 * @return a clone of this instance.
322 */
323 public Object clone()
324 {
325 try
326 {
327 return super.clone();
328 }
329 catch ( CloneNotSupportedException e )
330 {
331 throw new AssertionError( e );
332 }
333 }
334
335 /**
336 * Indicates whether some other object is equal to this one by comparing
337 * properties {@code name} and {@code version}.
338 *
339 * @param o the reference object with which to compare.
340 *
341 * @return {@code true} if this object is the same as {@code o};
342 * {@code false} otherwise.
343 */
344 public final boolean equals( final Object o )
345 {
346 boolean equal = this == o;
347
348 if ( !equal && o instanceof Module )
349 {
350 final Module that = (Module) o;
351 equal = this.getName().equals( that.getName() ) &&
352 ( this.getVersion() == null ? that.getVersion() == null
353 : this.getVersion().equals( that.getVersion() ) );
354
355 }
356
357 return equal;
358 }
359
360 /**
361 * Returns a hash code value for this object.
362 *
363 * @return a hash code value for this object.
364 */
365 public final int hashCode()
366 {
367 return this.getName().hashCode() +
368 ( this.getVersion() == null ? 0 : this.getVersion().hashCode() );
369
370 }
371
372 //------------------------------------------------------------------Object--
373 }