DefaultModuleInfo.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. package org.jfree.base.modules;
  44. /**
  45. * Provides a default implementation of the module info interface.
  46. *
  47. * @author Thomas Morgner
  48. */
  49. public class DefaultModuleInfo implements ModuleInfo
  50. {
  51. /** The name of the module class. */
  52. private String moduleClass;
  53. /** The major version of the described module. */
  54. private String majorVersion;
  55. /** The minor version of the described module. */
  56. private String minorVersion;
  57. /** The patchlevel version of the described module. */
  58. private String patchLevel;
  59. /**
  60. * DefaultConstructor.
  61. */
  62. public DefaultModuleInfo() {
  63. // nothing required
  64. }
  65. /**
  66. * Creates a new module info an initalizes it with the given values.
  67. *
  68. * @param moduleClass the class name of the module implementation holding the module
  69. * description.
  70. * @param majorVersion the modules major version.
  71. * @param minorVersion the modules minor version.
  72. * @param patchLevel the modules patchlevel.
  73. * @throws NullPointerException if the moduleClass is null.
  74. */
  75. public DefaultModuleInfo(final String moduleClass, final String majorVersion,
  76. final String minorVersion, final String patchLevel)
  77. {
  78. if (moduleClass == null)
  79. {
  80. throw new NullPointerException("Module class must not be null.");
  81. }
  82. this.moduleClass = moduleClass;
  83. this.majorVersion = majorVersion;
  84. this.minorVersion = minorVersion;
  85. this.patchLevel = patchLevel;
  86. }
  87. /**
  88. * Returns the class name of the module described implementation.
  89. *
  90. * @see ModuleInfo#getModuleClass()
  91. *
  92. * @return the module class name.
  93. */
  94. public String getModuleClass()
  95. {
  96. return this.moduleClass;
  97. }
  98. /**
  99. * Defines the module class name.
  100. *
  101. * @param moduleClass the class name of the module implementation.
  102. */
  103. public void setModuleClass(final String moduleClass)
  104. {
  105. if (moduleClass == null)
  106. {
  107. throw new NullPointerException();
  108. }
  109. this.moduleClass = moduleClass;
  110. }
  111. /**
  112. * Returns the major version of the module. This property may be
  113. * null to indicate that the module version is not specified.
  114. * @see ModuleInfo#getMajorVersion()
  115. *
  116. * @return the major version.
  117. */
  118. public String getMajorVersion()
  119. {
  120. return this.majorVersion;
  121. }
  122. /**
  123. * Defines the major version of the module. This property may be
  124. * null to indicate that the module version is not specified.
  125. * @see ModuleInfo#getMajorVersion()
  126. *
  127. * @param majorVersion the major version.
  128. */
  129. public void setMajorVersion(final String majorVersion)
  130. {
  131. this.majorVersion = majorVersion;
  132. }
  133. /**
  134. * Returns the minor version of the module. This property may be
  135. * null to indicate that the module version is not specified.
  136. * @see ModuleInfo#getMajorVersion()
  137. *
  138. * @return the minor version.
  139. */
  140. public String getMinorVersion()
  141. {
  142. return this.minorVersion;
  143. }
  144. /**
  145. * Defines the minor version of the module. This property may be
  146. * null to indicate that the module version is not specified.
  147. * @see ModuleInfo#getMajorVersion()
  148. *
  149. * @param minorVersion the minor version.
  150. */
  151. public void setMinorVersion(final String minorVersion)
  152. {
  153. this.minorVersion = minorVersion;
  154. }
  155. /**
  156. * Returns the patch level version of the module. This property may be
  157. * null to indicate that the module version is not specified.
  158. * @see ModuleInfo#getMajorVersion()
  159. *
  160. * @return the patch level version.
  161. */
  162. public String getPatchLevel()
  163. {
  164. return this.patchLevel;
  165. }
  166. /**
  167. * Defines 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. * @param patchLevel the patch level version.
  172. */
  173. public void setPatchLevel(final String patchLevel)
  174. {
  175. this.patchLevel = patchLevel;
  176. }
  177. /**
  178. * Two moduleinfos are equal,if they have the same module class.
  179. *
  180. * @param o the other object to compare.
  181. * @return true, if the module points to the same module, false otherwise.
  182. */
  183. public boolean equals(final Object o)
  184. {
  185. if (this == o)
  186. {
  187. return true;
  188. }
  189. if (!(o instanceof DefaultModuleInfo))
  190. {
  191. return false;
  192. }
  193. final ModuleInfo defaultModuleInfo = (ModuleInfo) o;
  194. if (!this.moduleClass.equals(defaultModuleInfo.getModuleClass()))
  195. {
  196. return false;
  197. }
  198. return true;
  199. }
  200. /**
  201. * Computes an hashcode for this module information.
  202. * @see java.lang.Object#hashCode()
  203. *
  204. * @return the hashcode.
  205. */
  206. public int hashCode()
  207. {
  208. final int result;
  209. result = this.moduleClass.hashCode();
  210. return result;
  211. }
  212. /**
  213. * Returns a string representation of this module information.
  214. *
  215. * @see java.lang.Object#toString()
  216. *
  217. * @return a string describing this class.
  218. */
  219. public String toString()
  220. {
  221. final StringBuffer buffer = new StringBuffer();
  222. buffer.append(getClass().getName());
  223. buffer.append("={ModuleClass=");
  224. buffer.append(getModuleClass());
  225. if (getMajorVersion() != null)
  226. {
  227. buffer.append("; Version=");
  228. buffer.append(getMajorVersion());
  229. if (getMinorVersion() != null)
  230. {
  231. buffer.append("-");
  232. buffer.append(getMinorVersion());
  233. if (getPatchLevel() != null)
  234. {
  235. buffer.append("_");
  236. buffer.append(getPatchLevel());
  237. }
  238. }
  239. }
  240. buffer.append("}");
  241. return buffer.toString();
  242. }
  243. }