001: /**
002: * This file or a portion of this file is licensed under the terms of
003: * the Globus Toolkit Public License, found at $PEGASUS_HOME/GTPL or
004: * http://www.globus.org/toolkit/download/license.html.
005: * This notice must appear in redistributions of this file
006: * with or without modification.
007: *
008: * Redistributions of this Software, with or without modification, must reproduce
009: * the GTPL in:
010: * (1) the Software, or
011: * (2) the Documentation or
012: * some other similar material which is provided with the Software (if any).
013: *
014: * Copyright 1999-2004
015: * University of Chicago and The University of Southern California.
016: * All rights reserved.
017: */package org.griphyn.cPlanner.classes;
018:
019: import java.util.StringTokenizer;
020:
021: /**
022: * This is a data class that stores the globus version installed and to be used
023: * on a particular pool for the gridftp server or the jobmanagers.
024: *
025: * @author Gaurang Mehta gmehta@isi.edu
026: * @author Karan Vahi vahi@isi.edu
027: *
028: * @version $Revision: 50 $
029: */
030: public class GlobusVersion {
031:
032: /**
033: * The constant for the major version type.
034: */
035: public static final String MAJOR = "major";
036:
037: /**
038: * The constant for the minor version type.
039: */
040: public static final String MINOR = "minor";
041:
042: /**
043: * The constant for patche version type.
044: */
045: public static final String PATCH = "patch";
046:
047: /**
048: * This variable defines the major version number.
049: */
050: private int mMajorVersion;
051:
052: /**
053: * This variable defines the minor version number.
054: */
055: private int mMinorVersion;
056:
057: /**
058: * This variable defines the patch version number.
059: */
060: private int mPatchVersion;
061:
062: /**
063: * The default constructor.
064: */
065: public GlobusVersion() {
066: mMajorVersion = 0;
067: mMinorVersion = 0;
068: mPatchVersion = 0;
069: }
070:
071: /**
072: * Overloaded constructor for the class;
073: *
074: * @param version a . separated String denoting the version . e.g. 2.2.4
075: */
076: public GlobusVersion(String version) {
077:
078: StringTokenizer st = new StringTokenizer(version, ".");
079: int count = st.countTokens();
080:
081: mMajorVersion = (count > 0) ? new Integer(st.nextToken())
082: .intValue() : 0;
083: mMinorVersion = (count > 1) ? new Integer(st.nextToken())
084: .intValue() : 0;
085: mPatchVersion = (count > 2) ? new Integer(st.nextToken())
086: .intValue() : 0;
087:
088: }
089:
090: /**
091: * Constructor to set the version information
092: *
093: * @param major Specifies the Major version number.
094: * @param minor Specifies the minor version number.
095: * @param patch Specifies the patch version number.
096: */
097: public GlobusVersion(int major, int minor, int patch) {
098: mMajorVersion = major;
099: mMinorVersion = minor;
100: mPatchVersion = patch;
101: }
102:
103: /**
104: * Returns the version corresponding to a particular version type.
105: * If an invalid version type is specified then 0 is returned.
106: *
107: * @param version the <code>String</code> type corresponding to the version that
108: * you want.
109: *
110: * @return int value corresponding to the version,
111: * 0 in case of incorrect version type.
112: *
113: * @see #MAJOR
114: * @see #MINOR
115: * @see #PATCH
116: */
117: public int getGlobusVersion(String version) {
118: int value = 0;
119: if (version.equalsIgnoreCase(MAJOR)) {
120: value = mMajorVersion;
121: } else if (version.equalsIgnoreCase(MINOR)) {
122: value = mMinorVersion;
123: } else if (version.equalsIgnoreCase(PATCH)) {
124: value = mPatchVersion;
125: }
126: return value;
127: }
128:
129: /**
130: * Returns the Globus version as a dot separated String.
131: * It is of type major.minor.patch where major, minor and patch are the
132: * various version numbers stored in the class.
133: *
134: * @return the version a dot separated String.
135: */
136: public String getGlobusVersion() {
137: StringBuffer version = new StringBuffer(5);
138: version.append(mMajorVersion).append(".").append(mMinorVersion)
139: .append(".").append(mPatchVersion);
140:
141: return version.toString();
142: }
143:
144: /**
145: * Returns the textual description of the contents of <code>GlobusVersion</code>
146: * object in the multiline format.
147: *
148: * @return the textual description in multiline format.
149: */
150: public String toMultiLine() {
151: return getGlobusVersion();
152: }
153:
154: /**
155: * Returns the textual description of the contents of <code>GlobusVersion
156: * </code> object.
157: *
158: * @return the textual description.
159: */
160: public String toString() {
161: return getGlobusVersion();
162: }
163:
164: }
|