01: /*****************************************************************************
02: * Copyright (C) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: *****************************************************************************/package org.picocontainer.lifecycle;
08:
09: /**
10: * Current lifecycle state of the container.
11: * @author Michael Rimov
12: */
13: public enum LifecycleState {
14:
15: /**
16: * Default state of a container once it has been built.
17: */
18: CONSTRUCTED,
19:
20: /**
21: * 'Start' Lifecycle has been called.
22: */
23: STARTED,
24:
25: /**
26: * 'Stop' lifecycle has been called.
27: */
28: STOPPED,
29:
30: /**
31: * 'Dispose' lifecycle has been called.
32: */
33: DISPOSED;
34:
35: /**
36: * Start is normally allowed if the object is constructed or
37: * already stopped. It is not allowed if the system is already
38: * started or disposed.
39: * @return true if start lifecycle methods should be allowed.
40: */
41: public boolean isStartAllowed() {
42: if (this .equals(CONSTRUCTED) || this .equals(STOPPED)) {
43: return true;
44: }
45:
46: return false;
47: }
48:
49: /**
50: * Returns true if stop is normally allowed in the container
51: * lifecycle. Stop is normally only allowed while the current
52: * container state is STARTED.
53: * @return true if stop is allowed.
54: */
55: public boolean isStopAllowed() {
56: if (this .equals(STARTED)) {
57: return true;
58: }
59:
60: return false;
61: }
62:
63: public boolean isStarted() {
64: return this .equals(STARTED);
65: }
66:
67: /**
68: * Returns true if the dispose lifecycle method is normally called.
69: * Dispose is normally only allowed if the object has not been already
70: * disposed, and it is not started.
71: * @return
72: */
73: public boolean isDisposedAllowed() {
74: if (this .equals(STOPPED) || this .equals(CONSTRUCTED)) {
75: return true;
76: }
77:
78: return false;
79: }
80: }
|