1 23 package com.sun.enterprise.deployment; 24 25 import java.lang.reflect.Method ; 26 27 32 public class LifecycleCallbackDescriptor extends Descriptor { 33 34 private String lifecycleCallbackClass; 35 private String lifecycleCallbackMethod; 36 private String defaultLifecycleCallbackClass; 37 38 public enum CallbackType { 39 40 POST_CONSTRUCT, 41 PRE_DESTROY, 42 PRE_PASSIVATE, 43 POST_ACTIVATE 44 45 } 46 47 public void setLifecycleCallbackClass(String clazz) { 48 lifecycleCallbackClass = clazz; 49 } 50 51 public String getLifecycleCallbackClass() { 52 if (lifecycleCallbackClass == null || 53 lifecycleCallbackClass.trim().equals("")) { 54 return defaultLifecycleCallbackClass; 55 } else { 56 return lifecycleCallbackClass; 57 } 58 } 59 60 public void setDefaultLifecycleCallbackClass(String clazz) { 61 defaultLifecycleCallbackClass = clazz; 62 } 63 64 public String getDefaultLifecycleCallbackClass() { 65 return defaultLifecycleCallbackClass; 66 } 67 68 public void setLifecycleCallbackMethod(String method) { 69 lifecycleCallbackMethod = method; 70 } 71 72 public String getLifecycleCallbackMethod() { 73 return lifecycleCallbackMethod; 74 } 75 76 82 public Method getLifecycleCallbackMethodObject(ClassLoader loader) 83 throws Exception { 84 85 Method m = null; 86 87 if( getLifecycleCallbackClass() == null ) { 88 throw new IllegalArgumentException ("no lifecycle class defined"); 89 } 90 91 Class clazz = loader.loadClass(getLifecycleCallbackClass()); 92 93 for(Method next : clazz.getDeclaredMethods()) { 96 97 if( next.getName().equals(lifecycleCallbackMethod) ) { 100 m = next; 101 break; 102 } 103 } 104 105 if( m == null ) { 106 throw new NoSuchMethodException ("no method matching " + 107 lifecycleCallbackMethod); 108 } 109 110 return m; 111 } 112 } 113 | Popular Tags |