View Javadoc

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.ObjectStreamException;
24  import java.io.Serializable;
25  
26  /**
27   * Module meta-data.
28   * <p>A module consists of the properties {@code name}, {@code description}
29   * and {@code version}. Property {@code name} holds the name of the module
30   * uniquely identifying the module in a collection of modules. Property
31   * {@code description} holds a textual description, property {@code version}
32   * a textual version of the module. A module defines specifications,
33   * implementations and properties.</p>
34   *
35   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
36   * @version $JDTAUS: Module.java 8743 2012-10-07 03:06:20Z schulte $
37   */
38  public class Module extends ModelObject implements Cloneable, Serializable
39  {
40      //--Constants---------------------------------------------------------------
41  
42      /** Serial version UID for backwards compatibility with 1.0.x classes. */
43      private static final long serialVersionUID = 2518888867819463746L;
44  
45      //---------------------------------------------------------------Constants--
46      //--Module------------------------------------------------------------------
47  
48      /**
49       * The specifications of the module.
50       * @serial
51       */
52      private Specifications specifications;
53  
54      /**
55       * The implementations of the module.
56       * @serial
57       */
58      private Implementations implementations;
59  
60      /**
61       * The properties of the module.
62       * @serial
63       */
64      private Properties properties;
65  
66      /**
67       * The messages of the module.
68       * @serial
69       */
70      private Messages messages;
71  
72      /**
73       * The description of the module.
74       * @serial
75       * @deprecated Replaced by property {@code documentation}.
76       */
77      private String description;
78  
79      /**
80       * The name of the module.
81       * @serial
82       */
83      private String name;
84  
85      /**
86       * The version of the module.
87       * @serial
88       */
89      private String version;
90  
91      /** Creates a new {@code Module} instance. */
92      public Module()
93      {
94          super();
95      }
96  
97      /**
98       * Gets the specifications of the module.
99       *
100      * @return the specifications of the module.
101      */
102     public Specifications getSpecifications()
103     {
104         if ( this.specifications == null )
105         {
106             this.specifications = new Specifications();
107         }
108 
109         return this.specifications;
110     }
111 
112     /**
113      * Setter for property {@code specifications}.
114      *
115      * @param value the new specifications of the module.
116      */
117     public void setSpecifications( final Specifications value )
118     {
119         this.specifications = value;
120     }
121 
122     /**
123      * Gets the implementations of the module.
124      *
125      * @return implementations of the module.
126      */
127     public Implementations getImplementations()
128     {
129         if ( this.implementations == null )
130         {
131             this.implementations = new Implementations();
132         }
133 
134         return this.implementations;
135     }
136 
137     /**
138      * Setter for property {@code implementations}.
139      *
140      * @param value the new implementations of the module.
141      */
142     public void setImplementations( final Implementations value )
143     {
144         this.implementations = value;
145     }
146 
147     /**
148      * Gets the properties of the module.
149      *
150      * @return the properties of the module.
151      */
152     public Properties getProperties()
153     {
154         if ( this.properties == null )
155         {
156             this.properties = new Properties();
157         }
158 
159         return this.properties;
160     }
161 
162     /**
163      * Setter for property {@code properties}.
164      *
165      * @param value the new properties of the module.
166      */
167     public void setProperties( final Properties value )
168     {
169         this.properties = value;
170     }
171 
172     /**
173      * Gets the messages of the module.
174      *
175      * @return the messages of the module.
176      */
177     public Messages getMessages()
178     {
179         if ( this.messages == null )
180         {
181             this.messages = new Messages();
182         }
183 
184         return this.messages;
185     }
186 
187     /**
188      * Setter for property {@code messages}.
189      *
190      * @param value new messages of the module.
191      */
192     public void setMessages( final Messages value )
193     {
194         this.messages = value;
195     }
196 
197     /**
198      * Gets the description of the module.
199      *
200      * @return the description of the module or {@code null}.
201      * @deprecated Replaced by {@link #getDocumentation() getDocumentation().getValue()}.
202      */
203     public String getDescription()
204     {
205         return this.getDocumentation().getValue();
206     }
207 
208     /**
209      * Setter for property {@code description}.
210      *
211      * @param value the new description of the module.
212      * @deprecated Replaced by {@link #setDocumentation(org.jdtaus.core.container.Text) getDocumentation().setValue( value )}.
213      */
214     public void setDescription( final String value )
215     {
216         this.getDocumentation().setValue( value );
217     }
218 
219     /**
220      * Gets the name of the module.
221      *
222      * @return the unique name of the module.
223      */
224     public String getName()
225     {
226         if ( this.name == null )
227         {
228             this.name = "";
229         }
230 
231         return this.name;
232     }
233 
234     /**
235      * Setter for property {@code name}.
236      *
237      * @param value the new name of the module.
238      */
239     public void setName( final String value )
240     {
241         this.name = value;
242     }
243 
244     /**
245      * Gets the version of the module.
246      *
247      * @return the version of the module or {@code null}.
248      */
249     public String getVersion()
250     {
251         return this.version;
252     }
253 
254     /**
255      * Setter for property {@code version}.
256      *
257      * @param value the new version of the module.
258      */
259     public void setVersion( final String value )
260     {
261         this.version = value;
262     }
263 
264     /**
265      * Creates a string representing the properties of the instance.
266      *
267      * @return a string representing the properties of the instance.
268      */
269     private String internalString()
270     {
271         final StringBuffer buf = new StringBuffer( 500 ).append( '{' ).
272             append( this.internalString( this ) ).
273             append( ", name=" ).append( this.name ).
274             append( ", version=" ).append( this.version ).
275             append( ", properties=" ).append( this.properties ).
276             append( ", messages=" ).append( this.messages ).
277             append( ", specifications=" ).append( this.getSpecifications() ).
278             append( ", implementations=" ).append( this.getImplementations() );
279 
280         buf.append( '}' ).toString();
281         return buf.toString();
282     }
283 
284     //------------------------------------------------------------------Module--
285     //--Serializable------------------------------------------------------------
286 
287     /**
288      * Takes care of initializing fields when constructed from an 1.0.x object
289      * stream.
290      *
291      * @throws ObjectStreamException if no scope can be resolved.
292      */
293     private Object readResolve() throws ObjectStreamException
294     {
295         if ( this.getDocumentation().getValue() == null &&
296             this.description != null )
297         {
298             this.getDocumentation().setValue( this.description );
299         }
300         if ( "".equals( this.version ) )
301         {
302             this.version = null;
303         }
304 
305         return this;
306     }
307 
308     //------------------------------------------------------------Serializable--
309     //--Object------------------------------------------------------------------
310 
311     /**
312      * Returns a string representation of the object.
313      *
314      * @return a string representation of the object.
315      */
316     public String toString()
317     {
318         return super.toString() + this.internalString();
319     }
320 
321     /**
322      * Creates and returns a copy of this object. This method  performs a
323      * "shallow copy" of this object, not a "deep copy" operation.
324      *
325      * @return a clone of this instance.
326      */
327     public Object clone()
328     {
329         try
330         {
331             return super.clone();
332         }
333         catch ( final CloneNotSupportedException e )
334         {
335             throw new AssertionError( e );
336         }
337     }
338 
339     /**
340      * Indicates whether some other object is equal to this one by comparing
341      * properties {@code name} and {@code version}.
342      *
343      * @param o the reference object with which to compare.
344      *
345      * @return {@code true} if this object is the same as {@code o};
346      * {@code false} otherwise.
347      */
348     public final boolean equals( final Object o )
349     {
350         boolean equal = this == o;
351 
352         if ( !equal && o instanceof Module )
353         {
354             final Module that = (Module) o;
355             equal = this.getName().equals( that.getName() ) &&
356                 ( this.getVersion() == null ? that.getVersion() == null
357                 : this.getVersion().equals( that.getVersion() ) );
358 
359         }
360 
361         return equal;
362     }
363 
364     /**
365      * Returns a hash code value for this object.
366      *
367      * @return a hash code value for this object.
368      */
369     public final int hashCode()
370     {
371         return this.getName().hashCode() +
372             ( this.getVersion() == null ? 0 : this.getVersion().hashCode() );
373 
374     }
375 
376     //------------------------------------------------------------------Object--
377 }