001: /*
002: * $Id: EngineState.java,v 1.13 2007/03/15 17:08:41 agoubard Exp $
003: *
004: * Copyright 2003-2007 Orange Nederland Breedband B.V.
005: * See the COPYRIGHT file for redistribution and use restrictions.
006: */
007: package org.xins.server;
008:
009: import org.xins.common.MandatoryArgumentChecker;
010:
011: /**
012: * State of an <code>Engine</code>.
013: *
014: * @version $Revision: 1.13 $ $Date: 2007/03/15 17:08:41 $
015: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
016: */
017: final class EngineState {
018: static final Type INTERMEDIATE_STATE = new Type();
019:
020: static final Type USABLE_STATE = new Type();
021:
022: static final Type ERROR_STATE = new Type();
023:
024: /**
025: * The <em>INITIAL</em> state.
026: */
027: static final EngineState INITIAL = new EngineState("INITIAL",
028: INTERMEDIATE_STATE);
029:
030: /**
031: * The <em>BOOTSTRAPPING_FRAMEWORK</em> state.
032: */
033: static final EngineState BOOTSTRAPPING_FRAMEWORK = new EngineState(
034: "BOOTSTRAPPING_FRAMEWORK", INTERMEDIATE_STATE);
035:
036: /**
037: * The <em>FRAMEWORK_BOOTSTRAP_FAILED</em> state.
038: */
039: static final EngineState FRAMEWORK_BOOTSTRAP_FAILED = new EngineState(
040: "FRAMEWORK_BOOTSTRAP_FAILED", ERROR_STATE);
041:
042: /**
043: * The <em>CONSTRUCTING_API</em> state.
044: */
045: static final EngineState CONSTRUCTING_API = new EngineState(
046: "CONSTRUCTING_API", INTERMEDIATE_STATE);
047:
048: /**
049: * The <em>API_CONSTRUCTION_FAILED</em> state.
050: */
051: static final EngineState API_CONSTRUCTION_FAILED = new EngineState(
052: "API_CONSTRUCTION_FAILED", ERROR_STATE);
053:
054: /**
055: * The <em>BOOTSTRAPPING_API</em> state.
056: */
057: static final EngineState BOOTSTRAPPING_API = new EngineState(
058: "BOOTSTRAPPING_API", INTERMEDIATE_STATE);
059:
060: /**
061: * The <em>API_BOOTSTRAP_FAILED</em> state.
062: */
063: static final EngineState API_BOOTSTRAP_FAILED = new EngineState(
064: "API_BOOTSTRAP_FAILED", ERROR_STATE);
065:
066: /**
067: * The <em>INITIALIZING_API</em> state.
068: */
069: static final EngineState INITIALIZING_API = new EngineState(
070: "INITIALIZING_API", INTERMEDIATE_STATE);
071:
072: /**
073: * The <em>API_INITIALIZATION_FAILED</em> state.
074: */
075: static final EngineState API_INITIALIZATION_FAILED = new EngineState(
076: "API_INITIALIZATION_FAILED", ERROR_STATE);
077:
078: /**
079: * The <em>READY</em> state.
080: */
081: static final EngineState READY = new EngineState("READY",
082: USABLE_STATE);
083:
084: /**
085: * The <em>DISPOSING</em> state.
086: */
087: static final EngineState DISPOSING = new EngineState("DISPOSING",
088: INTERMEDIATE_STATE);
089:
090: /**
091: * The <em>DISPOSED</em> state.
092: */
093: static final EngineState DISPOSED = new EngineState("DISPOSED",
094: INTERMEDIATE_STATE);
095:
096: /**
097: * The name of this state. Cannot be <code>null</code>.
098: */
099: private final String _name;
100:
101: /**
102: * The type of this state. Never <code>null</code>.
103: */
104: private final Type _type;
105:
106: /**
107: * Constructs a new <code>EngineState</code> object.
108: *
109: * @param name
110: * the name of this state, cannot be <code>null</code>.
111: *
112: * @param type
113: * the type of this state, cannot be <code>null</code>.
114: *
115: * @throws IllegalArgumentException
116: * if <code>name == null || type == null</code>.
117: */
118: EngineState(String name, Type type) throws IllegalArgumentException {
119:
120: // Check preconditions
121: MandatoryArgumentChecker.check("name", name, "type", type);
122:
123: // Initialize fields
124: _name = name;
125: _type = type;
126: }
127:
128: /**
129: * Returns the name of this state.
130: *
131: * @return
132: * the name of this state, cannot be <code>null</code>.
133: */
134: public String getName() {
135: return _name;
136: }
137:
138: /**
139: * Checks if this state is an error state.
140: *
141: * @return
142: * <code>true</code> if this is an error state, <code>false</code>
143: * otherwise.
144: */
145: public boolean isError() {
146: return _type == ERROR_STATE;
147: }
148:
149: /**
150: * Checks if this state allows function invocations.
151: *
152: * @return
153: * <code>true</code> if this state allows function invocations,
154: * <code>false</code> otherwise.
155: */
156: public boolean allowsInvocations() {
157: return _type == USABLE_STATE;
158: }
159:
160: /**
161: * Returns a textual representation of this object.
162: *
163: * @return
164: * the name of this state, never <code>null</code>.
165: */
166: public String toString() {
167: return _name;
168: }
169:
170: /**
171: * Categorization of an engine state.
172: *
173: * @version $Revision: 1.13 $ $Date: 2007/03/15 17:08:41 $
174: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
175: */
176: static class Type {
177:
178: /**
179: * Constructs a new instance.
180: */
181: private Type() {
182: // empty
183: }
184: }
185: }
|