001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ----------------------
028: * DefaultModuleInfo.java
029: * ----------------------
030: * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
031: *
032: * Original Author: Thomas Morgner;
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * $Id: DefaultModuleInfo.java,v 1.2 2005/10/18 13:14:50 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 05-Jul-2003 : Initial version
040: * 07-Jun-2004 : Added JCommon header (DG);
041: *
042: */
043:
044: package org.jfree.base.modules;
045:
046: /**
047: * Provides a default implementation of the module info interface.
048: *
049: * @author Thomas Morgner
050: */
051: public class DefaultModuleInfo implements ModuleInfo {
052: /** The name of the module class. */
053: private String moduleClass;
054: /** The major version of the described module. */
055: private String majorVersion;
056: /** The minor version of the described module. */
057: private String minorVersion;
058: /** The patchlevel version of the described module. */
059: private String patchLevel;
060:
061: /**
062: * DefaultConstructor.
063: */
064: public DefaultModuleInfo() {
065: // nothing required
066: }
067:
068: /**
069: * Creates a new module info an initalizes it with the given values.
070: *
071: * @param moduleClass the class name of the module implementation holding the module
072: * description.
073: * @param majorVersion the modules major version.
074: * @param minorVersion the modules minor version.
075: * @param patchLevel the modules patchlevel.
076: * @throws NullPointerException if the moduleClass is null.
077: */
078: public DefaultModuleInfo(final String moduleClass,
079: final String majorVersion, final String minorVersion,
080: final String patchLevel) {
081: if (moduleClass == null) {
082: throw new NullPointerException(
083: "Module class must not be null.");
084: }
085: this .moduleClass = moduleClass;
086: this .majorVersion = majorVersion;
087: this .minorVersion = minorVersion;
088: this .patchLevel = patchLevel;
089: }
090:
091: /**
092: * Returns the class name of the module described implementation.
093: *
094: * @see ModuleInfo#getModuleClass()
095: *
096: * @return the module class name.
097: */
098: public String getModuleClass() {
099: return this .moduleClass;
100: }
101:
102: /**
103: * Defines the module class name.
104: *
105: * @param moduleClass the class name of the module implementation.
106: */
107: public void setModuleClass(final String moduleClass) {
108: if (moduleClass == null) {
109: throw new NullPointerException();
110: }
111: this .moduleClass = moduleClass;
112: }
113:
114: /**
115: * Returns the major version of the module. This property may be
116: * null to indicate that the module version is not specified.
117: * @see ModuleInfo#getMajorVersion()
118: *
119: * @return the major version.
120: */
121: public String getMajorVersion() {
122: return this .majorVersion;
123: }
124:
125: /**
126: * Defines the major version of the module. This property may be
127: * null to indicate that the module version is not specified.
128: * @see ModuleInfo#getMajorVersion()
129: *
130: * @param majorVersion the major version.
131: */
132: public void setMajorVersion(final String majorVersion) {
133: this .majorVersion = majorVersion;
134: }
135:
136: /**
137: * Returns the minor version of the module. This property may be
138: * null to indicate that the module version is not specified.
139: * @see ModuleInfo#getMajorVersion()
140: *
141: * @return the minor version.
142: */
143: public String getMinorVersion() {
144: return this .minorVersion;
145: }
146:
147: /**
148: * Defines the minor version of the module. This property may be
149: * null to indicate that the module version is not specified.
150: * @see ModuleInfo#getMajorVersion()
151: *
152: * @param minorVersion the minor version.
153: */
154: public void setMinorVersion(final String minorVersion) {
155: this .minorVersion = minorVersion;
156: }
157:
158: /**
159: * Returns the patch level version of the module. This property may be
160: * null to indicate that the module version is not specified.
161: * @see ModuleInfo#getMajorVersion()
162: *
163: * @return the patch level version.
164: */
165: public String getPatchLevel() {
166: return this .patchLevel;
167: }
168:
169: /**
170: * Defines the patch level version of the module. This property may be
171: * null to indicate that the module version is not specified.
172: * @see ModuleInfo#getMajorVersion()
173: *
174: * @param patchLevel the patch level version.
175: */
176: public void setPatchLevel(final String patchLevel) {
177: this .patchLevel = patchLevel;
178: }
179:
180: /**
181: * Two moduleinfos are equal,if they have the same module class.
182: *
183: * @param o the other object to compare.
184: * @return true, if the module points to the same module, false otherwise.
185: */
186: public boolean equals(final Object o) {
187: if (this == o) {
188: return true;
189: }
190: if (!(o instanceof DefaultModuleInfo)) {
191: return false;
192: }
193:
194: final ModuleInfo defaultModuleInfo = (ModuleInfo) o;
195:
196: if (!this .moduleClass
197: .equals(defaultModuleInfo.getModuleClass())) {
198: return false;
199: }
200: return true;
201: }
202:
203: /**
204: * Computes an hashcode for this module information.
205: * @see java.lang.Object#hashCode()
206: *
207: * @return the hashcode.
208: */
209: public int hashCode() {
210: final int result;
211: result = this .moduleClass.hashCode();
212: return result;
213: }
214:
215: /**
216: * Returns a string representation of this module information.
217: *
218: * @see java.lang.Object#toString()
219: *
220: * @return a string describing this class.
221: */
222: public String toString() {
223: final StringBuffer buffer = new StringBuffer();
224: buffer.append(getClass().getName());
225: buffer.append("={ModuleClass=");
226: buffer.append(getModuleClass());
227: if (getMajorVersion() != null) {
228: buffer.append("; Version=");
229: buffer.append(getMajorVersion());
230: if (getMinorVersion() != null) {
231: buffer.append("-");
232: buffer.append(getMinorVersion());
233: if (getPatchLevel() != null) {
234: buffer.append("_");
235: buffer.append(getPatchLevel());
236: }
237: }
238: }
239: buffer.append("}");
240: return buffer.toString();
241: }
242: }
|