001    /*
002     *  jDTAUS - DTAUS fileformat.
003     *  Copyright (c) 2005 Christian Schulte <cs@schulte.it>
004     *
005     *  This library is free software; you can redistribute it and/or
006     *  modify it under the terms of the GNU Lesser General Public
007     *  License as published by the Free Software Foundation; either
008     *  version 2.1 of the License, or any later version.
009     *
010     *  This library is distributed in the hope that it will be useful,
011     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
012     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013     *  Lesser General Public License for more details.
014     *
015     *  You should have received a copy of the GNU Lesser General Public
016     *  License along with this library; if not, write to the Free Software
017     *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
018     *
019     */
020    package org.jdtaus.core.container;
021    
022    import java.io.Serializable;
023    
024    /**
025     * Module meta-data.
026     * <p>A module consists of the properties {@code name}, {@code description}
027     * and {@code version}. Property {@code name} holds the name of the module
028     * uniquely identifying the module in a collection of modules. Property
029     * {@code description} holds a textual description, property {@code version}
030     * a textual version of the module. A module defines specifications and
031     * implementations. Properties can be additionally defined.</p>
032     *
033     * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
034     * @version $Id: Module.java 2201 2007-03-21 23:59:00Z schulte2005 $
035     */
036    public class Module implements Cloneable, Serializable
037    {
038    
039        //--Module------------------------------------------------------------------
040    
041        /**
042         * The specifications of the module.
043         * @serial
044         */
045        private Specifications specifications;
046    
047        /**
048         * The implementations of the module.
049         * @serial
050         */
051        private Implementations implementations;
052    
053        /**
054         * The properties of the module.
055         * @serial
056         */
057        private Properties properties;
058    
059        /**
060         * The description of the module.
061         * @serial
062         */
063        private String description;
064    
065        /**
066         * The name of the module.
067         * @serial
068         */
069        private String name;
070    
071        /**
072         * The version of the module.
073         * @serial
074         */
075        private String version;
076    
077        /**
078         * Gets the specifications of the module.
079         *
080         * @return the specifications of the module.
081         */
082        public Specifications getSpecifications()
083        {
084            if(this.specifications == null)
085            {
086                this.specifications = new Specifications();
087            }
088    
089            return this.specifications;
090        }
091    
092        /**
093         * Setter for property {@code specifications}.
094         *
095         * @param value the new specifications of the module.
096         */
097        public void setSpecifications(final Specifications value)
098        {
099            this.specifications = value;
100        }
101    
102        /**
103         * Gets the implementations of the module.
104         *
105         * @return implementations of the module.
106         */
107        public Implementations getImplementations()
108        {
109            if(this.implementations == null)
110            {
111                this.implementations = new Implementations();
112            }
113    
114            return this.implementations;
115        }
116    
117        /**
118         * Setter for property {@code implementations}.
119         *
120         * @param value the new implementations of the module.
121         */
122        public void setImplementations(final Implementations value)
123        {
124            this.implementations = value;
125        }
126    
127        /**
128         * Gets the properties of the module.
129         *
130         * @return the properties of the module.
131         */
132        public Properties getProperties()
133        {
134            if(this.properties == null)
135            {
136                this.properties = new Properties();
137            }
138    
139            return this.properties;
140        }
141    
142        /**
143         * Setter for property {@code properties}.
144         *
145         * @param value the new properties of the module.
146         */
147        public void setProperties(final Properties value)
148        {
149            this.properties = value;
150        }
151    
152        /**
153         * Gets the description of the module.
154         *
155         * @return the description of the module.
156         */
157        public String getDescription()
158        {
159            if(this.description == null)
160            {
161                this.description = "";
162            }
163    
164            return this.description;
165        }
166    
167        /**
168         * Setter for property {@code description}.
169         *
170         * @param value the new description of the module.
171         */
172        public void setDescription(final String value)
173        {
174            this.description = value;
175        }
176    
177        /**
178         * Gets the name of the module.
179         *
180         * @return the unique name of the module.
181         */
182        public String getName()
183        {
184            if(this.name == null)
185            {
186                this.name = "";
187            }
188    
189            return this.name;
190        }
191    
192        /**
193         * Setter for property {@code name}.
194         *
195         * @param value the new name of the module.
196         */
197        public void setName(final String value)
198        {
199            this.name = value;
200        }
201    
202        /**
203         * Gets the version of the module.
204         *
205         * @return the version of the module.
206         */
207        public String getVersion()
208        {
209            if(this.version == null)
210            {
211                this.version = "";
212            }
213    
214            return this.version;
215        }
216    
217        /**
218         * Setter for property {@code version}.
219         *
220         * @param value the new version of the module.
221         */
222        public void setVersion(final String value)
223        {
224            this.version = value;
225        }
226    
227        /**
228         * Creates a string representing the properties of the instance.
229         *
230         * @return a string representing the properties of the instance.
231         */
232        private String internalString()
233        {
234            return new StringBuffer(500).
235                append("\n\tdescription=").append(this.description).
236                append("\n\timplementations=").append(this.implementations).
237                append("\n\tname=").append(this.name).
238                append("\n\tproperties=").append(this.properties).
239                append("\n\tspecifications=").append(this.specifications).
240                append("\n\tversion=").append(this.version).
241                toString();
242    
243        }
244    
245        //------------------------------------------------------------------Module--
246        //--Object------------------------------------------------------------------
247    
248        /**
249         * Returns a string representation of the object.
250         *
251         * @return a string representation of the object.
252         */
253        public String toString()
254        {
255            return super.toString() + this.internalString();
256        }
257    
258        /**
259         * Creates and returns a deep copy of this object.
260         *
261         * @return a clone of this instance.
262         */
263        public Object clone()
264        {
265            try
266            {
267                final Module ret = (Module) super.clone();
268                ret.properties = (Properties) this.getProperties().clone();
269                ret.implementations =
270                    (Implementations) this.getImplementations().clone();
271    
272                ret.specifications =
273                    (Specifications) this.getSpecifications().clone();
274    
275                return ret;
276            }
277            catch(CloneNotSupportedException e)
278            {
279                throw new AssertionError(e);
280            }
281        }
282    
283        /**
284         * Indicates whether some other object is equal to this one by comparing
285         * property {@code name}.
286         *
287         * @param o the reference object with which to compare.
288         *
289         * @return {@code true} if this object is the same as {@code o};
290         * {@code false} otherwise.
291         */
292        public final boolean equals(final Object o)
293        {
294            return o == this || (o != null && o instanceof Module &&
295                ((Module)o).getName().equals(this.getName()));
296    
297        }
298    
299        /**
300         * Returns a hash code value for this object.
301         *
302         * @return a hash code value for this object.
303         */
304        public final int hashCode()
305        {
306            return this.getName().hashCode();
307        }
308    
309        //------------------------------------------------------------------Object--
310    
311    }