001/* 002 * jDTAUS Core API 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.core.container; 022 023import java.io.ObjectStreamException; 024import java.io.Serializable; 025 026/** 027 * Module meta-data. 028 * <p>A module consists of the properties {@code name}, {@code description} 029 * and {@code version}. Property {@code name} holds the name of the module 030 * uniquely identifying the module in a collection of modules. Property 031 * {@code description} holds a textual description, property {@code version} 032 * a textual version of the module. A module defines specifications, 033 * implementations and properties.</p> 034 * 035 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 036 * @version $JDTAUS: Module.java 8743 2012-10-07 03:06:20Z schulte $ 037 */ 038public class Module extends ModelObject implements Cloneable, Serializable 039{ 040 //--Constants--------------------------------------------------------------- 041 042 /** Serial version UID for backwards compatibility with 1.0.x classes. */ 043 private static final long serialVersionUID = 2518888867819463746L; 044 045 //---------------------------------------------------------------Constants-- 046 //--Module------------------------------------------------------------------ 047 048 /** 049 * The specifications of the module. 050 * @serial 051 */ 052 private Specifications specifications; 053 054 /** 055 * The implementations of the module. 056 * @serial 057 */ 058 private Implementations implementations; 059 060 /** 061 * The properties of the module. 062 * @serial 063 */ 064 private Properties properties; 065 066 /** 067 * The messages of the module. 068 * @serial 069 */ 070 private Messages messages; 071 072 /** 073 * The description of the module. 074 * @serial 075 * @deprecated Replaced by property {@code documentation}. 076 */ 077 private String description; 078 079 /** 080 * The name of the module. 081 * @serial 082 */ 083 private String name; 084 085 /** 086 * The version of the module. 087 * @serial 088 */ 089 private String version; 090 091 /** Creates a new {@code Module} instance. */ 092 public Module() 093 { 094 super(); 095 } 096 097 /** 098 * Gets the specifications of the module. 099 * 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}