1 /* ======================================================================== 2 * JCommon : a free general purpose class library for the Java(tm) platform 3 * ======================================================================== 4 * 5 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. 6 * 7 * Project Info: http://www.jfree.org/jcommon/index.html 8 * 9 * This library is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU Lesser General Public License as published by 11 * the Free Software Foundation; either version 2.1 of the License, or 12 * (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 * License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this library; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22 * USA. 23 * 24 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25 * in the United States and other countries.] 26 * 27 * ---------------------- 28 * DefaultModuleInfo.java 29 * ---------------------- 30 * (C)opyright 2003, 2004, by Thomas Morgner and Contributors. 31 * 32 * Original Author: Thomas Morgner; 33 * Contributor(s): David Gilbert (for Object Refinery Limited); 34 * 35 * $Id: DefaultModuleInfo.java,v 1.2 2005/10/18 13:14:50 mungady Exp $ 36 * 37 * Changes 38 * ------- 39 * 05-Jul-2003 : Initial version 40 * 07-Jun-2004 : Added JCommon header (DG); 41 * 42 */ 43 44 package org.jfree.base.modules; 45 46 /** 47 * Provides a default implementation of the module info interface. 48 * 49 * @author Thomas Morgner 50 */ 51 public class DefaultModuleInfo implements ModuleInfo 52 { 53 /** The name of the module class. */ 54 private String moduleClass; 55 /** The major version of the described module. */ 56 private String majorVersion; 57 /** The minor version of the described module. */ 58 private String minorVersion; 59 /** The patchlevel version of the described module. */ 60 private String patchLevel; 61 62 /** 63 * DefaultConstructor. 64 */ DefaultModuleInfo()65 public DefaultModuleInfo() { 66 // nothing required 67 } 68 69 /** 70 * Creates a new module info an initalizes it with the given values. 71 * 72 * @param moduleClass the class name of the module implementation holding the module 73 * description. 74 * @param majorVersion the modules major version. 75 * @param minorVersion the modules minor version. 76 * @param patchLevel the modules patchlevel. 77 * @throws NullPointerException if the moduleClass is null. 78 */ DefaultModuleInfo(final String moduleClass, final String majorVersion, final String minorVersion, final String patchLevel)79 public DefaultModuleInfo(final String moduleClass, final String majorVersion, 80 final String minorVersion, final String patchLevel) 81 { 82 if (moduleClass == null) 83 { 84 throw new NullPointerException("Module class must not be null."); 85 } 86 this.moduleClass = moduleClass; 87 this.majorVersion = majorVersion; 88 this.minorVersion = minorVersion; 89 this.patchLevel = patchLevel; 90 } 91 92 /** 93 * Returns the class name of the module described implementation. 94 * 95 * @see ModuleInfo#getModuleClass() 96 * 97 * @return the module class name. 98 */ getModuleClass()99 public String getModuleClass() 100 { 101 return this.moduleClass; 102 } 103 104 /** 105 * Defines the module class name. 106 * 107 * @param moduleClass the class name of the module implementation. 108 */ setModuleClass(final String moduleClass)109 public void setModuleClass(final String moduleClass) 110 { 111 if (moduleClass == null) 112 { 113 throw new NullPointerException(); 114 } 115 this.moduleClass = moduleClass; 116 } 117 118 /** 119 * Returns the major version of the module. This property may be 120 * null to indicate that the module version is not specified. 121 * @see ModuleInfo#getMajorVersion() 122 * 123 * @return the major version. 124 */ getMajorVersion()125 public String getMajorVersion() 126 { 127 return this.majorVersion; 128 } 129 130 /** 131 * Defines the major version of the module. This property may be 132 * null to indicate that the module version is not specified. 133 * @see ModuleInfo#getMajorVersion() 134 * 135 * @param majorVersion the major version. 136 */ setMajorVersion(final String majorVersion)137 public void setMajorVersion(final String majorVersion) 138 { 139 this.majorVersion = majorVersion; 140 } 141 142 /** 143 * Returns the minor version of the module. This property may be 144 * null to indicate that the module version is not specified. 145 * @see ModuleInfo#getMajorVersion() 146 * 147 * @return the minor version. 148 */ getMinorVersion()149 public String getMinorVersion() 150 { 151 return this.minorVersion; 152 } 153 154 /** 155 * Defines the minor version of the module. This property may be 156 * null to indicate that the module version is not specified. 157 * @see ModuleInfo#getMajorVersion() 158 * 159 * @param minorVersion the minor version. 160 */ setMinorVersion(final String minorVersion)161 public void setMinorVersion(final String minorVersion) 162 { 163 this.minorVersion = minorVersion; 164 } 165 166 /** 167 * Returns the patch level version of the module. This property may be 168 * null to indicate that the module version is not specified. 169 * @see ModuleInfo#getMajorVersion() 170 * 171 * @return the patch level version. 172 */ getPatchLevel()173 public String getPatchLevel() 174 { 175 return this.patchLevel; 176 } 177 178 /** 179 * Defines the patch level version of the module. This property may be 180 * null to indicate that the module version is not specified. 181 * @see ModuleInfo#getMajorVersion() 182 * 183 * @param patchLevel the patch level version. 184 */ setPatchLevel(final String patchLevel)185 public void setPatchLevel(final String patchLevel) 186 { 187 this.patchLevel = patchLevel; 188 } 189 190 /** 191 * Two moduleinfos are equal,if they have the same module class. 192 * 193 * @param o the other object to compare. 194 * @return true, if the module points to the same module, false otherwise. 195 */ equals(final Object o)196 public boolean equals(final Object o) 197 { 198 if (this == o) 199 { 200 return true; 201 } 202 if (!(o instanceof DefaultModuleInfo)) 203 { 204 return false; 205 } 206 207 final ModuleInfo defaultModuleInfo = (ModuleInfo) o; 208 209 if (!this.moduleClass.equals(defaultModuleInfo.getModuleClass())) 210 { 211 return false; 212 } 213 return true; 214 } 215 216 /** 217 * Computes an hashcode for this module information. 218 * @see java.lang.Object#hashCode() 219 * 220 * @return the hashcode. 221 */ hashCode()222 public int hashCode() 223 { 224 final int result; 225 result = this.moduleClass.hashCode(); 226 return result; 227 } 228 229 /** 230 * Returns a string representation of this module information. 231 * 232 * @see java.lang.Object#toString() 233 * 234 * @return a string describing this class. 235 */ toString()236 public String toString() 237 { 238 final StringBuffer buffer = new StringBuffer(); 239 buffer.append(getClass().getName()); 240 buffer.append("={ModuleClass="); 241 buffer.append(getModuleClass()); 242 if (getMajorVersion() != null) 243 { 244 buffer.append("; Version="); 245 buffer.append(getMajorVersion()); 246 if (getMinorVersion() != null) 247 { 248 buffer.append("-"); 249 buffer.append(getMinorVersion()); 250 if (getPatchLevel() != null) 251 { 252 buffer.append("_"); 253 buffer.append(getPatchLevel()); 254 } 255 } 256 } 257 buffer.append("}"); 258 return buffer.toString(); 259 } 260 } 261