1 8 9 15 package jfun.yan.lifecycle; 16 17 27 public class DefaultLifecycleDescriptor { 28 private Phase initializer; 29 private Phase disposer; 30 private Phase verifier; 31 private Phase opener; 32 private Phase closer; 33 private Phase starter; 34 private Phase stopper; 35 38 public static final String DEFAULT_OPENER_NAME = "opener"; 39 42 public static final String DEFAULT_CLOSER_NAME = "closer"; 43 46 public static final String DEFAULT_INITIALIZER_NAME = "initializer"; 47 50 public static final String DEFAULT_VERIFIER_NAME = "verifier"; 51 54 public static final String DEFAULT_DISPOSER_NAME = "disposer"; 55 58 public static final String DEFAULT_STARTER_NAME = "starter"; 59 62 public static final String DEFAULT_STOPPER_NAME = "stopper"; 63 private static final ExceptionHandler thrower = ExceptionHandlers.thrower(); 64 private static final ExceptionHandler printer = ExceptionHandlers.printer(); 65 static final Phase DEFAULT_OPENER = 66 new Phase(DEFAULT_OPENER_NAME, thrower); 67 static final Phase DEFAULT_CLOSER = 68 new Phase(DEFAULT_CLOSER_NAME, printer); 69 static final Phase DEFAULT_INITIALIZER = 70 new Phase(DEFAULT_INITIALIZER_NAME, thrower); 71 static final Phase DEFAULT_VERIFIER = 72 new Phase(DEFAULT_VERIFIER_NAME, thrower); 73 static final Phase DEFAULT_DISPOSER = 74 new Phase(DEFAULT_DISPOSER_NAME, printer); 75 static final Phase DEFAULT_STARTER = 76 new Phase(DEFAULT_STARTER_NAME, thrower); 77 static final Phase DEFAULT_STOPPER = 78 new Phase(DEFAULT_STOPPER_NAME, printer); 79 91 public DefaultLifecycleDescriptor(){ 92 this.initializer = DEFAULT_INITIALIZER; 93 this.disposer = DEFAULT_DISPOSER; 94 this.verifier = DEFAULT_VERIFIER; 95 this.opener = DEFAULT_OPENER; 96 this.closer = DEFAULT_CLOSER; 97 this.starter = DEFAULT_STARTER; 98 this.stopper = DEFAULT_STOPPER; 99 } 100 105 public void open(LifecycleManager lm) 106 throws Throwable { 107 fifo(lm, opener, null); 108 } 109 114 public void close(LifecycleManager lm) 115 throws Throwable { 116 filo(lm, closer, null); 117 } 118 123 public void init(LifecycleManager lm) 124 throws Throwable { 125 fifo(lm, initializer, null); 126 } 127 132 public void dispose(LifecycleManager lm) 133 throws Throwable { 134 filo(lm, disposer, null); 135 } 136 141 public void verify(LifecycleManager lm) 142 throws Throwable { 143 fifo(lm, verifier, null); 144 } 145 150 public void start(LifecycleManager lm) 151 throws Throwable { 152 fifo(lm, starter, null); 153 } 154 159 public void stop(LifecycleManager lm) 160 throws Throwable { 161 filo(lm, stopper, null); 162 } 163 164 171 public DefaultLifecycleDescriptor opener(Lifecycle lc, Procedure proc, boolean reentrant){ 172 return addLifeProc(lc, opener, proc, reentrant); 173 } 174 181 public DefaultLifecycleDescriptor closer(Lifecycle lc, Procedure proc, boolean reentrant){ 182 return addLifeProc(lc, closer, proc, reentrant); 183 } 184 191 public DefaultLifecycleDescriptor initializer(Lifecycle lc, Procedure proc, boolean reentrant){ 192 return addLifeProc(lc, initializer, proc, reentrant); 193 } 194 201 public DefaultLifecycleDescriptor disposer(Lifecycle lc, Procedure proc, boolean reentrant){ 202 return addLifeProc(lc, disposer, proc, reentrant); 203 } 204 211 public DefaultLifecycleDescriptor verifier(Lifecycle lc, Procedure proc, boolean reentrant){ 212 return addLifeProc(lc, verifier, proc, reentrant); 213 } 214 221 public DefaultLifecycleDescriptor starter(Lifecycle lc, Procedure proc, boolean reentrant){ 222 return addLifeProc(lc, starter, proc, reentrant); 223 } 224 231 public DefaultLifecycleDescriptor stopper(Lifecycle lc, Procedure proc, boolean reentrant){ 232 return addLifeProc(lc, stopper, proc, reentrant); 233 } 234 241 public DefaultLifecycleDescriptor opener(Lifecycle lc, Procedure proc){ 242 return opener(lc, proc, true); 243 } 244 251 public DefaultLifecycleDescriptor closer(Lifecycle lc, Procedure proc){ 252 return closer(lc, proc, true); 253 } 254 261 public DefaultLifecycleDescriptor initializer(Lifecycle lc, Procedure proc){ 262 return initializer(lc, proc, false); 263 } 264 271 public DefaultLifecycleDescriptor disposer(Lifecycle lc, Procedure proc){ 272 return disposer(lc, proc, false); 273 } 274 281 public DefaultLifecycleDescriptor verifier(Lifecycle lc, Procedure proc){ 282 return verifier(lc, proc, true); 283 } 284 291 public DefaultLifecycleDescriptor starter(Lifecycle lc, Procedure proc){ 292 return starter(lc, proc, true); 293 } 294 301 public DefaultLifecycleDescriptor stopper(Lifecycle lc, Procedure proc){ 302 return stopper(lc, proc, true); 303 } 304 305 private DefaultLifecycleDescriptor addLifeProc(Lifecycle lc, Phase act, Procedure proc, boolean reentrant){ 306 lc.put(act.getPhaseKey(), proc, reentrant); 307 return this; 308 } 309 310 311 private static void fifo(LifecycleManager lm, Phase action, Object [] args) 312 throws Throwable { 313 lm.fifo(action.getPhaseKey(), args, action.getExceptionHandler()); 314 } 315 private static void filo(LifecycleManager lm, Phase action, Object [] args) 316 throws Throwable { 317 lm.filo(action.getPhaseKey(), args, action.getExceptionHandler()); 318 } 319 322 public Phase getCloser() { 323 return closer; 324 } 325 329 public void setCloser(Phase closer) { 330 this.closer = closer; 331 } 332 335 public Phase getDisposer() { 336 return disposer; 337 } 338 342 public void setDisposer(Phase disposer) { 343 this.disposer = disposer; 344 } 345 348 public Phase getInitializer() { 349 return initializer; 350 } 351 355 public void setInitializer(Phase initializer) { 356 this.initializer = initializer; 357 } 358 361 public Phase getOpener() { 362 return opener; 363 } 364 368 public void setOpener(Phase opener) { 369 this.opener = opener; 370 } 371 374 public Phase getStarter() { 375 return starter; 376 } 377 381 public void setStarter(Phase starter) { 382 this.starter = starter; 383 } 384 387 public Phase getStopper() { 388 return stopper; 389 } 390 394 public void setStopper(Phase stopper) { 395 this.stopper = stopper; 396 } 397 400 public Phase getVerifier() { 401 return verifier; 402 } 403 407 public void setVerifier(Phase verifier) { 408 this.verifier = verifier; 409 } 410 411 } 412 | Popular Tags |