KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > lifecycle > Status


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.rm.resources.lifecycle;
20
21 /**
22  * Typesafe enum class which holds valid status values.
23  *
24  * @author Michael Bell
25  * @version $Revision: 1.1 $
26  *
27  */

28 public final class Status {
29
30     
31     //int constants
32
private static final int NUM_STATUS_APPROVED = 0;
33     private static final int NUM_STATUS_UNAPPROVED = 1;
34     private static final int NUM_STATUS_UNKNOWN = -1;
35     
36     //String constants
37
private static final String JavaDoc STRING_STATUS_APPROVED = "APPROVED";
38     private static final String JavaDoc STRING_STATUS_UNAPPROVED = "UNAPPROVED";
39     private static final String JavaDoc STRING_STATUS_UNKNOWN = "UNKNOWN";
40     
41     //Status constants
42
static public final Status APPROVED = new Status(NUM_STATUS_APPROVED,STRING_STATUS_APPROVED);
43     static public final Status UNAPPROVED = new Status(NUM_STATUS_UNAPPROVED,STRING_STATUS_UNAPPROVED);
44     static public final Status UNKNOWN = new Status(NUM_STATUS_UNKNOWN,STRING_STATUS_UNKNOWN);
45     
46     //member variables
47
private int m_nStatus = -1;
48     private String JavaDoc m_sStatus = STRING_STATUS_UNKNOWN;
49     
50     protected Status(int nStatus,String JavaDoc sStatus) {
51         m_nStatus = nStatus;
52         m_sStatus = sStatus;
53     }
54     
55     /**
56      * Returns a <code>Status</code> object which corresponds to the <code>int</code> value given.
57      * If the <code>int</code> does not correspond with a valid status the STATUS_UNKNOWN will
58      * be returned.
59      *
60      * @param nStatus
61      * @return
62      */

63     static public Status getStatus(int nStatus) {
64         Status retStatus = null;
65         
66         if(nStatus == NUM_STATUS_APPROVED) {
67             retStatus = APPROVED;
68         } else if(nStatus == NUM_STATUS_UNAPPROVED) {
69             retStatus = UNAPPROVED;
70         } else {
71             retStatus = UNKNOWN;
72         }
73         
74         return retStatus;
75     }
76
77     /**
78      * Returns the <code>int</code> value of this status.
79      *
80      * @return the <code>int</code> value of this status
81      */

82     public int getIntValue() {
83         return m_nStatus;
84     }
85     
86     /**
87      * Returns the <code>String</code> value of this status.
88      *
89      * @return the <code>String</code> value of this status
90      */

91     public String JavaDoc getStringValue() {
92         return m_sStatus;
93     }
94     
95     
96     /* (non-Javadoc)
97      * @see java.lang.Object#toString()
98      */

99     public String JavaDoc toString() {
100         return m_sStatus;
101     }
102         
103 }
104
Popular Tags