KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ioc > common > State


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ioc.common;
8
9 /**
10  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
11  */

12
13 public final class State {
14
15     public final static State ORIGINAL = new State(0, "Original");
16
17     /**
18      * INITIALIZING, system is in initializing, doCreate()
19      */

20     public final static State INITIALIZING = new State(1, "Initializing");
21
22     /**
23      * INITIALIZED, system is initialized
24      */

25     public final static State INITIALIZED = new State(2, "Initialized");
26
27     /**
28      * STOPPING, system is in starting
29      */

30     public final static State STARTING = new State(3, "Starting");
31
32     /**
33      * STARTED, system has started
34      */

35     public final static State STARTED = new State(4, "Started");
36
37     /**
38      * STOPPING, system is in stopping
39      */

40     public final static State STOPPING = new State(5, "Stopping");
41
42     /**
43      * STOPPED, system stopped by user
44      */

45     public final static State STOPPED = new State(6, "Stopped");
46
47     /**
48      * DESTROYING, system is in destroying
49      */

50     public final static State DESTROYING = new State(7, "Destroying");
51
52     /**
53      * DESTROYED, system stopped and it's resource destoryed, example: it's connection closed
54      */

55     public final static State DESTROYED = new State(8, "Destroyed");
56
57     /**
58      * INTERRUPPTED, system interrupted because of some error or exception
59      */

60     public final static State INTERRUPTED = new State(9, "Interrupted");
61
62
63     public int id = 0;
64     public String JavaDoc name = "";
65
66     public State(int id, String JavaDoc name) {
67         this.id = id;
68         this.name = name;
69     }
70
71     public int getId() {
72         return id;
73     }
74
75     public String JavaDoc getName() {
76         return name;
77     }
78
79     public int hashCode() {
80         return (id + "").hashCode() + name.hashCode();
81     }
82
83     public String JavaDoc toString() {
84         return id + " [" + name + "]";
85     }
86
87     public boolean equals(Object JavaDoc obj) {
88         if(obj instanceof State) {
89             State state = (State) obj;
90             return state.id == id && state.name.equals(name);
91         }
92         return false;
93
94     }
95
96     public static boolean canInit(State state) {
97         if(state == State.ORIGINAL || state == State.DESTROYED) {
98             return true;
99         }
100         return false;
101     }
102
103     public static boolean canStart(State state) {
104         if(state == State.STOPPED || state == State.INITIALIZED) {
105             return true;
106         }
107         return false;
108     }
109
110     public static boolean canStop(State state) {
111         if(state == State.STARTED) {
112             return true;
113         }
114         return false;
115     }
116
117     public static boolean canDestroy(State state) {
118         if(state == State.INITIALIZED || state == State.STOPPED || state == State.INTERRUPTED) {
119             return true;
120         }
121         return false;
122     }
123
124 }
125
126
Popular Tags