1 23 24 package com.sun.enterprise.deployment; 25 26 import java.util.logging.*; 27 import com.sun.logging.*; 28 29 import java.util.Map ; 30 import java.util.HashMap ; 31 import java.util.HashSet ; 32 import java.util.Set ; 33 import java.util.List ; 34 import java.util.LinkedList ; 35 36 import com.sun.enterprise.util.LocalStringManagerImpl; 37 import com.sun.enterprise.deployment.util.LogDomains; 38 import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType; 39 40 43 44 public class EjbInterceptor extends JndiEnvironmentRefsGroupDescriptor 45 { 46 private static LocalStringManagerImpl localStrings = 47 new LocalStringManagerImpl(EjbInterceptor.class); 48 49 private static final Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER); 50 51 private Set <LifecycleCallbackDescriptor> aroundInvokeDescriptors; 52 private String interceptorClassName; 53 54 private boolean fromBeanClass = false; 59 60 public String getInterceptorClassName() { 61 return interceptorClassName; 62 } 63 64 public void setInterceptorClassName(String className) { 65 interceptorClassName = className; 66 } 67 68 public Set <LifecycleCallbackDescriptor> getAroundInvokeDescriptors() { 69 if (aroundInvokeDescriptors == null) { 70 aroundInvokeDescriptors = 71 new HashSet <LifecycleCallbackDescriptor>(); 72 } 73 return aroundInvokeDescriptors; 74 } 75 76 80 public List <LifecycleCallbackDescriptor> getOrderedAroundInvokeDescriptors 81 (ClassLoader loader) throws Exception { 82 83 return orderDescriptors(getAroundInvokeDescriptors(), loader); 84 85 } 86 87 public void setFromBeanClass(boolean flag) { 88 fromBeanClass = flag; 89 } 90 91 public boolean getFromBeanClass() { 92 return fromBeanClass; 93 } 94 95 public void addAroundInvokeDescriptor(LifecycleCallbackDescriptor aroundInvokeDesc) { 96 Set <LifecycleCallbackDescriptor> aroundInvokeDescs = 97 getAroundInvokeDescriptors(); 98 boolean found = false; 99 for (LifecycleCallbackDescriptor ai : aroundInvokeDescs) { 100 if ((aroundInvokeDesc.getLifecycleCallbackClass() != null) && 101 aroundInvokeDesc.getLifecycleCallbackClass().equals( 102 ai.getLifecycleCallbackClass())) { 103 found = true; 104 } 105 } 106 107 if (!found) { 108 aroundInvokeDescs.add(aroundInvokeDesc); 109 } 110 } 111 112 public void addAroundInvokeDescriptors( 113 Set <LifecycleCallbackDescriptor> aroundInvokes) { 114 for (LifecycleCallbackDescriptor ai : aroundInvokes) { 115 addAroundInvokeDescriptor(ai); 116 } 117 } 118 119 public boolean hasAroundInvokeDescriptor() { 120 return (getAroundInvokeDescriptors().size() > 0); 121 } 122 123 127 public List <LifecycleCallbackDescriptor> getOrderedCallbackDescriptors 128 (CallbackType type, ClassLoader loader) throws Exception { 129 130 return orderDescriptors(getCallbackDescriptors(type), loader); 131 } 132 133 public void addPostActivateDescriptor(LifecycleCallbackDescriptor lcDesc) { 134 addCallbackDescriptor(CallbackType.POST_ACTIVATE, lcDesc); 135 } 136 137 public void addPrePassivateDescriptor(LifecycleCallbackDescriptor lcDesc) { 138 addCallbackDescriptor(CallbackType.PRE_PASSIVATE, lcDesc); 139 } 140 141 146 private List <LifecycleCallbackDescriptor> orderDescriptors 147 (Set <LifecycleCallbackDescriptor> lcds, ClassLoader loader) 148 throws Exception 149 { 150 151 LinkedList <LifecycleCallbackDescriptor> orderedDescs = 152 new LinkedList <LifecycleCallbackDescriptor>(); 153 154 Map <String , LifecycleCallbackDescriptor> map = 155 new HashMap <String , LifecycleCallbackDescriptor>(); 156 157 for(LifecycleCallbackDescriptor next : lcds) { 158 map.put(next.getLifecycleCallbackClass(), next); 159 } 160 161 Class nextClass = loader.loadClass(getInterceptorClassName()); 162 163 while((nextClass != Object .class) && (nextClass != null)) { 164 String nextClassName = nextClass.getName(); 165 if( map.containsKey(nextClassName) ) { 166 LifecycleCallbackDescriptor lcd = map.get(nextClassName); 167 orderedDescs.addFirst(lcd); 168 } 169 170 nextClass = nextClass.getSuperclass(); 171 } 172 173 174 return orderedDescs; 175 176 } 177 178 public String toString() { 179 return "EjbInterceptor class = " + getInterceptorClassName(); 180 } 181 } 182 | Popular Tags |