1 17 18 package org.apache.geronimo.kernel.management; 19 20 import java.io.Serializable ; 21 22 23 28 public final class State implements Serializable { 29 public static final int STARTING_INDEX = 0; 30 public static final int RUNNING_INDEX = 1; 31 public static final int STOPPING_INDEX = 2; 32 public static final int STOPPED_INDEX = 3; 33 public static final int FAILED_INDEX = 4; 34 35 public static final State STARTING = new State("starting", STARTING_INDEX, NotificationType.STATE_STARTING); 36 public static final State RUNNING = new State("running", RUNNING_INDEX, NotificationType.STATE_RUNNING); 37 public static final State STOPPING = new State("stopping", STOPPING_INDEX, NotificationType.STATE_STOPPING); 38 public static final State STOPPED = new State("stopped", STOPPED_INDEX, NotificationType.STATE_STOPPED); 39 public static final State FAILED = new State("failed", FAILED_INDEX, NotificationType.STATE_FAILED); 40 41 private static final State[] fromInt = {STARTING, RUNNING, STOPPING, STOPPED, FAILED}; 42 43 49 public static State fromInt(int index) { 50 if (index < 0 || index >= fromInt.length) { 51 return null; 52 } 53 return fromInt[index]; 54 } 55 56 62 public static State fromInteger(Integer index) { 63 return fromInt(index.intValue()); 64 } 65 66 public static String toString(int state) { 67 if (state < 0 || state >= fromInt.length) { 68 throw new IllegalArgumentException ("State must be between 0 and " + fromInt.length); 69 } 70 return fromInt[state].name; 71 } 72 73 76 private final String name; 77 78 81 private final int index; 82 83 86 private final String eventTypeValue; 87 88 private State(String name, int index, String anEventTypeValue) { 89 this.name = name; 90 this.index = index; 91 eventTypeValue = anEventTypeValue; 92 } 93 94 97 public int toInt() { 98 return index; 99 } 100 101 106 public String getEventTypeValue() { 107 return eventTypeValue; 108 } 109 110 public String getName() { 111 return name; 112 } 113 114 public boolean isRunning() { 115 return this == State.RUNNING; 116 } 117 118 public boolean isStopped() { 119 return this == State.STOPPED; 120 } 121 122 public boolean isFailed() { 123 return this == State.FAILED; 124 } 125 126 public String toString() { 127 return name; 128 } 129 130 private Object readResolve() { 131 return fromInt[index]; 132 } 133 } 134 | Popular Tags |