001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.rm.resources.lifecycle;
020:
021: /**
022: * Typesafe enum class which holds valid status values.
023: *
024: * @author Michael Bell
025: * @version $Revision: 1.1 $
026: *
027: */
028: public final class Status {
029:
030: //int constants
031: private static final int NUM_STATUS_APPROVED = 0;
032: private static final int NUM_STATUS_UNAPPROVED = 1;
033: private static final int NUM_STATUS_UNKNOWN = -1;
034:
035: //String constants
036: private static final String STRING_STATUS_APPROVED = "APPROVED";
037: private static final String STRING_STATUS_UNAPPROVED = "UNAPPROVED";
038: private static final String STRING_STATUS_UNKNOWN = "UNKNOWN";
039:
040: //Status constants
041: static public final Status APPROVED = new Status(
042: NUM_STATUS_APPROVED, STRING_STATUS_APPROVED);
043: static public final Status UNAPPROVED = new Status(
044: NUM_STATUS_UNAPPROVED, STRING_STATUS_UNAPPROVED);
045: static public final Status UNKNOWN = new Status(NUM_STATUS_UNKNOWN,
046: STRING_STATUS_UNKNOWN);
047:
048: //member variables
049: private int m_nStatus = -1;
050: private String m_sStatus = STRING_STATUS_UNKNOWN;
051:
052: protected Status(int nStatus, String sStatus) {
053: m_nStatus = nStatus;
054: m_sStatus = sStatus;
055: }
056:
057: /**
058: * Returns a <code>Status</code> object which corresponds to the <code>int</code> value given.
059: * If the <code>int</code> does not correspond with a valid status the STATUS_UNKNOWN will
060: * be returned.
061: *
062: * @param nStatus
063: * @return
064: */
065: static public Status getStatus(int nStatus) {
066: Status retStatus = null;
067:
068: if (nStatus == NUM_STATUS_APPROVED) {
069: retStatus = APPROVED;
070: } else if (nStatus == NUM_STATUS_UNAPPROVED) {
071: retStatus = UNAPPROVED;
072: } else {
073: retStatus = UNKNOWN;
074: }
075:
076: return retStatus;
077: }
078:
079: /**
080: * Returns the <code>int</code> value of this status.
081: *
082: * @return the <code>int</code> value of this status
083: */
084: public int getIntValue() {
085: return m_nStatus;
086: }
087:
088: /**
089: * Returns the <code>String</code> value of this status.
090: *
091: * @return the <code>String</code> value of this status
092: */
093: public String getStringValue() {
094: return m_sStatus;
095: }
096:
097: /* (non-Javadoc)
098: * @see java.lang.Object#toString()
099: */
100: public String toString() {
101: return m_sStatus;
102: }
103:
104: }
|