001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ComponentState.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi;
030:
031: /**
032: * ComponentState Enumeration
033: *
034: * @author Sun Microsystems, Inc.
035: */
036: public enum ComponentState {
037: /**
038: * Loaded status. Note: This never appears in the permanent registry,
039: * only in the runtime registry. It is a transient state used only during
040: * installation of a component.
041: */
042: LOADED("Loaded"), SHUTDOWN("Shutdown"), STOPPED("Stopped"), STARTED(
043: "Started"), UNKNOWN("Unknown");
044:
045: /** The String value */
046: private String mString;
047:
048: ComponentState(String strValue) {
049: mString = strValue;
050: }
051:
052: /**
053: * Compute the effective state of the Component from a list of Component States
054: *
055: * If one or more state is a STARTED state the state is STARTED
056: * If one or more state is STOPPED state and there is no STARTED state
057: * the state is STOPPED
058: * If there are no STOPPED or STARTED states the state is SHUTDOWN
059: *
060: * @param states - a List of states.
061: * @return the effective component state
062: */
063: public static ComponentState computeEffectiveState(
064: java.util.List<ComponentState> states) {
065: if (states.contains(ComponentState.STARTED)) {
066: return ComponentState.STARTED;
067: } else if (states.contains(ComponentState.STOPPED)) {
068: return ComponentState.STOPPED;
069: } else {
070: return ComponentState.SHUTDOWN;
071: }
072: }
073:
074: /**
075: * Given the LifeCycleMBean state string convert it to a ComponentState.
076: *
077: * This method will be deleted after
078: * (a) state strings are fixed "Shutdown" and not "SHUTDOWN"
079: * (b) LifeCycleMBean.RUNNING is changed to LifeCycleMBean.STARTED
080: */
081: public static ComponentState valueOfLifeCycleState(String state) {
082: if (javax.jbi.management.LifeCycleMBean.STARTED.equals(state)) {
083: return ComponentState.STARTED;
084: }
085:
086: if (javax.jbi.management.LifeCycleMBean.STOPPED.equals(state)) {
087: return ComponentState.STOPPED;
088: }
089:
090: if (javax.jbi.management.LifeCycleMBean.SHUTDOWN.equals(state)) {
091: return ComponentState.SHUTDOWN;
092: }
093:
094: return ComponentState.UNKNOWN;
095: }
096:
097: /**
098: * Given the ComponentState convert it to a LifeCycleMBean state string.
099: *
100: * This method will be deleted after
101: * (a) state strings are fixed "Shutdown" and not "SHUTDOWN"
102: * (b) LifeCycleMBean.RUNNING is changed to LifeCycleMBean.STARTED
103: */
104: public static String getLifeCycleState(ComponentState state) {
105: if (ComponentState.STARTED == state) {
106: return javax.jbi.management.LifeCycleMBean.STARTED;
107: }
108:
109: if (ComponentState.STOPPED == state) {
110: return javax.jbi.management.LifeCycleMBean.STOPPED;
111: }
112:
113: if (ComponentState.SHUTDOWN == state) {
114: return javax.jbi.management.LifeCycleMBean.SHUTDOWN;
115: }
116:
117: return javax.jbi.management.LifeCycleMBean.UNKNOWN;
118: }
119:
120: /**
121: * @return the String value for the ComponentType
122: */
123: public String toString() {
124: return mString;
125: }
126:
127: /**
128: * @return a ComponentState based on the String value.
129: * @param valStr - the string whose equivalent ComponentState
130: * instance is required. This operation ignores
131: * the case, i.e. Stopped or STOPPED or sToPped
132: * would return ComponentState.STOPPED
133: */
134: public static ComponentState valueOfString(String valStr) {
135: return ComponentState.valueOf(valStr.toUpperCase());
136: }
137:
138: public static void main(String[] args) {
139: System.out.println(ComponentState.STOPPED.toString());
140: System.out.println(ComponentState.valueOfString("Stopped")
141: .toString());
142: System.out.println(ComponentState.valueOfString("StoPPed")
143: .toString());
144: System.out.println(ComponentState.valueOfString("sTaRted")
145: .toString());
146: }
147: };
|