1 23 24 package com.sun.enterprise.deployment.node.ejb; 25 26 import java.util.Map ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.LinkedList ; 30 import java.util.Iterator ; 31 import org.w3c.dom.Node ; 32 import org.xml.sax.Attributes ; 33 34 import com.sun.enterprise.deployment.node.XMLElement; 35 import com.sun.enterprise.deployment.node.MethodNode; 36 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode; 37 38 import com.sun.enterprise.deployment.Descriptor; 39 import com.sun.enterprise.deployment.EjbBundleDescriptor; 40 import com.sun.enterprise.deployment.InterceptorBindingDescriptor; 41 import com.sun.enterprise.deployment.MethodDescriptor; 42 import com.sun.enterprise.deployment.EjbDescriptor; 43 import com.sun.enterprise.deployment.EjbInterceptor; 44 import com.sun.enterprise.deployment.xml.EjbTagNames; 45 46 public class InterceptorBindingNode extends DeploymentDescriptorNode { 47 48 private MethodDescriptor businessMethod = null; 49 private boolean needsOverloadResolution = false; 50 51 public InterceptorBindingNode() { 52 super(); 53 } 54 55 public void startElement(XMLElement element, Attributes attributes) { 56 57 if( EjbTagNames.METHOD.equals(element.getQName()) ) { 58 59 businessMethod = new MethodDescriptor(); 60 needsOverloadResolution = true; 63 64 } else if( EjbTagNames.METHOD_PARAMS.equals(element.getQName()) ) { 65 66 needsOverloadResolution = false; 70 71 } 72 73 super.startElement(element, attributes); 74 } 75 76 public void setElementValue(XMLElement element, String value) { 77 78 if( EjbTagNames.METHOD_NAME.equals(element.getQName()) ) { 79 businessMethod.setName(value); 80 } else if( EjbTagNames.METHOD_PARAM.equals(element.getQName()) ) { 81 if( (value != null) && (value.trim().length() > 0) ) { 82 businessMethod.addParameterClass(value.trim()); 83 } 84 } else { 85 super.setElementValue(element, value); 86 } 87 88 } 89 90 96 public boolean endElement(XMLElement element) { 97 98 if (EjbTagNames.INTERCEPTOR_ORDER.equals(element.getQName())) { 99 100 InterceptorBindingDescriptor desc = (InterceptorBindingDescriptor) 101 getDescriptor(); 102 desc.setIsTotalOrdering(true); 103 104 } else if( EjbTagNames.METHOD.equals(element.getQName()) ) { 105 106 InterceptorBindingDescriptor bindingDesc = 107 (InterceptorBindingDescriptor) getDescriptor(); 108 businessMethod.setEjbClassSymbol(MethodDescriptor.EJB_BEAN); 109 bindingDesc.setBusinessMethod(businessMethod); 110 111 if( needsOverloadResolution ) { 112 bindingDesc.setNeedsOverloadResolution(true); 113 } 114 115 businessMethod = null; 116 needsOverloadResolution = false; 117 118 } 119 120 return super.endElement(element); 121 } 122 123 129 protected Map getDispatchTable() { 130 Map table = super.getDispatchTable(); 131 132 table.put(EjbTagNames.EJB_NAME, "setEjbName"); 133 table.put(EjbTagNames.INTERCEPTOR_CLASS, "appendInterceptorClass"); 134 table.put(EjbTagNames.EXCLUDE_DEFAULT_INTERCEPTORS, 135 "setExcludeDefaultInterceptors"); 136 table.put(EjbTagNames.EXCLUDE_CLASS_INTERCEPTORS, 137 "setExcludeClassInterceptors"); 138 139 return table; 140 } 141 142 148 public void writeBindings(Node parent, EjbDescriptor ejbDesc) { 149 150 List <EjbInterceptor> classInterceptors = ejbDesc.getInterceptorChain(); 151 if( classInterceptors.size() > 0 ) { 152 writeTotalOrdering(parent, classInterceptors, ejbDesc, null); 153 } 154 155 Map <MethodDescriptor, List <EjbInterceptor>> methodInterceptorsMap = 156 ejbDesc.getMethodInterceptorsMap(); 157 158 for(MethodDescriptor nextMethod : methodInterceptorsMap.keySet()) { 159 160 List <EjbInterceptor> interceptors = 161 methodInterceptorsMap.get(nextMethod); 162 163 if(interceptors.isEmpty()) { 164 writeExclusionBinding(parent, ejbDesc, nextMethod); 165 } else { 166 writeTotalOrdering(parent, interceptors, ejbDesc, nextMethod); 167 } 168 169 } 170 171 return; 172 } 173 174 private void writeTotalOrdering(Node parent, 175 List <EjbInterceptor> interceptors, 176 EjbDescriptor ejbDesc, 177 MethodDescriptor method) { 178 179 Node bindingNode = appendChild(parent, 180 EjbTagNames.INTERCEPTOR_BINDING); 181 182 appendTextChild(bindingNode, EjbTagNames.EJB_NAME, 183 ejbDesc.getName()); 184 185 Node totalOrderingNode = appendChild(bindingNode, 186 EjbTagNames.INTERCEPTOR_ORDER); 187 for(EjbInterceptor next : interceptors) { 188 189 appendTextChild(totalOrderingNode, EjbTagNames.INTERCEPTOR_CLASS, 190 next.getInterceptorClassName()); 191 } 192 193 if( method != null ) { 194 195 MethodNode methodNode = new MethodNode(); 196 197 methodNode.writeJavaMethodDescriptor 201 (bindingNode, EjbTagNames.INTERCEPTOR_BUSINESS_METHOD, method, 202 true); 203 204 } 205 206 } 207 208 private void writeExclusionBinding(Node parent, EjbDescriptor ejbDesc, 209 MethodDescriptor method) { 210 211 Node bindingNode = appendChild(parent, 212 EjbTagNames.INTERCEPTOR_BINDING); 213 214 appendTextChild(bindingNode, EjbTagNames.EJB_NAME, 215 ejbDesc.getName()); 216 217 appendTextChild(bindingNode, EjbTagNames.EXCLUDE_CLASS_INTERCEPTORS, 218 "true"); 219 220 MethodNode methodNode = new MethodNode(); 221 222 methodNode.writeJavaMethodDescriptor 226 (bindingNode, EjbTagNames.INTERCEPTOR_BUSINESS_METHOD, method, 227 true); 228 229 } 230 } 231 | Popular Tags |