001: /**
002: * $Revision: 7655 $
003: * $Date: 2007-03-22 13:50:33 -0700 (Thu, 22 Mar 2007) $
004: *
005: * Copyright (C) 2004-2006 Jive Software. All rights reserved.
006: *
007: * This software is published under the terms of the GNU Public License (GPL),
008: * a copy of which is included in this distribution.
009: */package org.jivesoftware.util;
010:
011: /**
012: * Holds version information for Openfire.
013: *
014: * @author Iain Shigeoka
015: */
016: public class Version {
017:
018: /**
019: * The major number (ie 1.x.x).
020: */
021: private int major;
022:
023: /**
024: * The minor version number (ie x.1.x).
025: */
026: private int minor;
027:
028: /**
029: * The micro version number (ie x.x.1).
030: */
031: private int micro;
032:
033: /**
034: * A status release number or -1 to indicate none.
035: */
036: private int statusVersion;
037:
038: /**
039: * The release state of the product (Release, Release Candidate).
040: */
041: private ReleaseStatus status;
042:
043: /**
044: * Cached version string information
045: */
046: private String versionString;
047:
048: /**
049: * Create a new version information object.
050: *
051: * @param major the major release number.
052: * @param minor the minor release number.
053: * @param micro the micro release number.
054: * @param status the status of the release.
055: */
056: public Version(int major, int minor, int micro,
057: ReleaseStatus status, int statusVersion) {
058: this .major = major;
059: this .minor = minor;
060: this .micro = micro;
061: this .status = status;
062: this .statusVersion = statusVersion;
063: if (status != null) {
064: if (status == ReleaseStatus.Release) {
065: versionString = major + "." + minor + "." + micro;
066: } else {
067: if (statusVersion >= 0) {
068: versionString = major + "." + minor + "." + micro
069: + " " + status.toString() + " "
070: + statusVersion;
071: } else {
072: versionString = major + "." + minor + "." + micro
073: + " " + status.toString();
074: }
075: }
076: } else {
077: versionString = major + "." + minor + "." + micro;
078: }
079: }
080:
081: /**
082: * Returns the version number of this instance of Openfire as a
083: * String (ie major.minor.revision).
084: *
085: * @return The version as a string
086: */
087: public String getVersionString() {
088: return versionString;
089: }
090:
091: /**
092: * Returns the release status of this product.
093: *
094: * @return the release status of this product.
095: */
096: public ReleaseStatus getStatus() {
097: return status;
098: }
099:
100: /**
101: * Obtain the major release number for this product.
102: *
103: * @return The major release number 1.x.x
104: */
105: public int getMajor() {
106: return major;
107: }
108:
109: /**
110: * Obtain the minor release number for this product.
111: *
112: * @return The minor release number x.1.x
113: */
114: public int getMinor() {
115: return minor;
116: }
117:
118: /**
119: * Obtain the micro release number for this product.
120: *
121: * @return The micro release number x.x.1
122: */
123: public int getMicro() {
124: return micro;
125: }
126:
127: /**
128: * Obtain the status relase number for this product. For example, if
129: * the release status is <strong>alpha</strong> the release may be <strong>5</strong>
130: * resulting in a release status of <strong>Alpha 5</strong>.
131: *
132: * @return The status version or -1 if none is set.
133: */
134: public int getStatusVersion() {
135: return statusVersion;
136: }
137:
138: /**
139: * A class to represent the release status of the server. Product releases
140: * are indicated by type safe enum constants.
141: */
142: public enum ReleaseStatus {
143: Release(""), Release_Candidate("RC"), Beta("Beta"), Alpha(
144: "Alpha");
145:
146: private String status;
147:
148: private ReleaseStatus(String status) {
149: this .status = status;
150: }
151:
152: public String toString() {
153: return status;
154: }
155: }
156: }
|