KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > common > Status


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.common;
25
26 import com.sun.enterprise.util.LocalStringsImpl;
27 //JDK imports
28
import java.io.Serializable JavaDoc;
29
30 /**
31     Base class for status of a Server side entity. Entities with specific
32     semantics for status are expected to extend this class.
33 */

34 public class Status implements Serializable JavaDoc
35 {
36     /* javac 1.3 generated serialVersionUID */
37     public static final long serialVersionUID = -211313166471337363L;
38     public static final int kInstanceRunningCode = 0;
39     public static final int kInstanceStartingCode = 1;
40     public static final int kInstanceStoppingCode = 2;
41     public static final int kInstanceNotRunningCode = 3;
42     public static final int kEntityEnabledCode = 4;
43     public static final int kEntityDisabledCode = 5;
44     public static final int kClusterPartiallyRunningCode = 6;
45     public static final int kInstanceSynchronizingCode = 7;
46     public static final int kInstanceFailedCode = 8;
47
48     public static final String JavaDoc kInstanceRunningMsg;
49     public static final String JavaDoc kInstanceStartingMsg;
50     public static final String JavaDoc kInstanceStoppingMsg;
51     public static final String JavaDoc kInstanceNotRunningMsg;
52     public static final String JavaDoc kUnknownStateMsg;
53     public static final String JavaDoc kPartiallyRunningMsg;
54     public static final String JavaDoc kInstanceSynchronizingMsg;
55     public static final String JavaDoc kInstanceFailedMsg;
56
57     protected int mStatusCode;
58     protected String JavaDoc mStatusString;
59    
60     static
61     {
62         // use localized strings...
63
String JavaDoc pre = "admin.common.status.";
64         LocalStringsImpl ls = new LocalStringsImpl();
65         
66         kInstanceRunningMsg = ls.get(pre + "0");
67         kInstanceStartingMsg = ls.get(pre + "1");
68         kInstanceStoppingMsg = ls.get(pre + "2");
69         kInstanceNotRunningMsg = ls.get(pre + "3");
70         kUnknownStateMsg = ls.get(pre + "4");
71         kPartiallyRunningMsg = ls.get(pre + "6");
72         kInstanceSynchronizingMsg = ls.get(pre + "7");
73         kInstanceFailedMsg = ls.get(pre + "8");
74     }
75     
76     /**
77      * Create new status. The sub-classes must set protected instance
78      * variables mStatusCode and mStatusString appropriately.
79      */

80     protected Status()
81     {
82     }
83
84     /**
85             Creates new Status.
86     */

87     public Status (int code, String JavaDoc str)
88     {
89         mStatusCode = code;
90         mStatusString = str;
91     }
92     
93     public Status (int code)
94     {
95         mStatusCode = code;
96         mStatusString = getStatusString(code);
97     }
98     
99     /**
100             Returns the status code for this Status.
101
102             @return status code
103     */

104     public int getStatusCode()
105     {
106             return mStatusCode;
107     }
108
109     /**
110             Returns the status string for this Status.
111
112             @return string representing status
113     */

114     public String JavaDoc getStatusString()
115     {
116             return mStatusString;
117     }
118
119     /**
120      * Returns statusCode : statusString
121      */

122     public String JavaDoc toString()
123     {
124         return (mStatusCode + " : " + mStatusString);
125     }
126
127     public static String JavaDoc getStatusString(int code)
128     {
129         String JavaDoc status = kUnknownStateMsg;
130         switch (code)
131         {
132             case kInstanceNotRunningCode :
133                 status = kInstanceNotRunningMsg;
134                 break;
135             case kInstanceRunningCode :
136                 status = kInstanceRunningMsg;
137                 break;
138             case kInstanceStartingCode :
139                 status = kInstanceStartingMsg;
140                 break;
141             case kInstanceFailedCode :
142                 status = kInstanceFailedMsg;
143                 break;
144             case kInstanceStoppingCode :
145                 status = kInstanceStoppingMsg;
146                 break;
147             case kClusterPartiallyRunningCode :
148                 status = kPartiallyRunningMsg;
149                 break;
150             case kInstanceSynchronizingCode :
151                 status = kInstanceSynchronizingMsg;
152                 break;
153             default :
154                 break;
155         }
156         return status;
157     }
158 }
159
Popular Tags