1 23 package com.sun.enterprise.deployment.node.ejb; 24 25 import java.util.Map ; 26 import java.util.logging.Level ; 27 import org.w3c.dom.Node ; 28 import org.xml.sax.Attributes ; 29 30 import com.sun.enterprise.deployment.node.XMLElement; 31 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode; 32 import com.sun.enterprise.deployment.node.EnvEntryNode; 33 import com.sun.enterprise.deployment.node.EjbLocalReferenceNode; 34 import com.sun.enterprise.deployment.node.EjbReferenceNode; 35 import com.sun.enterprise.deployment.node.EntityManagerReferenceNode; 36 import com.sun.enterprise.deployment.node.EntityManagerFactoryReferenceNode; 37 import com.sun.enterprise.deployment.node.MessageDestinationRefNode; 38 import com.sun.enterprise.deployment.node.ResourceRefNode; 39 import com.sun.enterprise.deployment.node.ResourceEnvRefNode; 40 import com.sun.enterprise.deployment.node.LifecycleCallbackNode; 41 import com.sun.enterprise.deployment.node.LocalizedInfoNode; 42 import com.sun.enterprise.deployment.node.ServiceReferenceNode; 43 import com.sun.enterprise.deployment.node.DescriptorFactory; 44 45 import com.sun.enterprise.deployment.Descriptor; 46 import com.sun.enterprise.deployment.EjbBundleDescriptor; 47 import com.sun.enterprise.deployment.EjbInterceptor; 48 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor; 49 import com.sun.enterprise.deployment.MessageDestinationReferenceDescriptor; 50 import com.sun.enterprise.deployment.types.EjbReference; 51 import static com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType; 52 53 import com.sun.enterprise.deployment.util.DOLUtils; 54 55 import com.sun.enterprise.deployment.xml.EjbTagNames; 56 import com.sun.enterprise.deployment.xml.TagNames; 57 import com.sun.enterprise.deployment.xml.WebServicesTagNames; 58 59 public class EjbInterceptorNode extends DeploymentDescriptorNode { 60 private EjbInterceptor descriptor; 61 private CallbackType tempType; 62 63 public EjbInterceptorNode() { 64 super(); 65 66 registerElementHandler(new XMLElement(EjbTagNames.AROUND_INVOKE_METHOD), AroundInvokeNode.class, "addAroundInvokeDescriptor"); 67 registerElementHandler(new XMLElement(EjbTagNames.POST_ACTIVATE_METHOD), LifecycleCallbackNode.class, "addPostActivateDescriptor"); 68 registerElementHandler(new XMLElement(EjbTagNames.PRE_PASSIVATE_METHOD), LifecycleCallbackNode.class, "addPrePassivateDescriptor"); 69 70 registerElementHandler(new XMLElement(TagNames.POST_CONSTRUCT), LifecycleCallbackNode.class, "addPostConstructDescriptor"); 72 registerElementHandler(new XMLElement(TagNames.PRE_DESTROY), LifecycleCallbackNode.class, "addPreDestroyDescriptor"); 73 74 registerElementHandler(new XMLElement(TagNames.ENVIRONMENT_PROPERTY), 75 EnvEntryNode.class, "addEnvironmentProperty"); 76 registerElementHandler(new XMLElement(EjbTagNames.EJB_REFERENCE), EjbReferenceNode.class); 77 registerElementHandler(new XMLElement(EjbTagNames.EJB_LOCAL_REFERENCE), EjbLocalReferenceNode.class); 78 registerElementHandler(new XMLElement(WebServicesTagNames.SERVICE_REF), ServiceReferenceNode.class, "addServiceReferenceDescriptor"); 79 registerElementHandler(new XMLElement(EjbTagNames.RESOURCE_REFERENCE), 80 ResourceRefNode.class, "addResourceReferenceDescriptor"); 81 registerElementHandler(new XMLElement(TagNames.RESOURCE_ENV_REFERENCE), 82 ResourceEnvRefNode.class, "addJmsDestinationReferenceDescriptor"); 83 registerElementHandler(new XMLElement(TagNames.MESSAGE_DESTINATION_REFERENCE), MessageDestinationRefNode.class); 84 registerElementHandler(new XMLElement(TagNames.PERSISTENCE_CONTEXT_REF), EntityManagerReferenceNode.class, "addEntityManagerReferenceDescriptor"); 85 registerElementHandler(new XMLElement(TagNames.PERSISTENCE_UNIT_REF), EntityManagerFactoryReferenceNode.class, "addEntityManagerFactoryReferenceDescriptor"); 86 } 87 88 94 protected Map getDispatchTable() { 95 Map table = super.getDispatchTable(); 97 table.put(EjbTagNames.INTERCEPTOR_CLASS, "setInterceptorClassName"); 98 return table; 99 } 100 101 104 public Object getDescriptor() { 105 106 if (descriptor==null) { 107 descriptor = (EjbInterceptor)DescriptorFactory.getDescriptor(getXMLPath()); 108 descriptor.setEjbBundleDescriptor((EjbBundleDescriptor)getParentNode().getDescriptor()); 109 } 110 return descriptor; 111 } 112 113 private EjbInterceptor getInterceptor() { 114 return (EjbInterceptor)getDescriptor(); 115 } 116 117 123 public void addDescriptor(Object newDescriptor) { 124 if (newDescriptor instanceof EjbReference) { 125 if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) { 126 DOLUtils.getDefaultLogger().fine("Adding ejb ref " + newDescriptor); 127 } 128 getInterceptor().addEjbReferenceDescriptor( 129 (EjbReference) newDescriptor); 130 } else if( newDescriptor instanceof 131 MessageDestinationReferenceDescriptor ) { 132 MessageDestinationReferenceDescriptor msgDestRef = 133 (MessageDestinationReferenceDescriptor) newDescriptor; 134 EjbBundleDescriptor ejbBundle = (EjbBundleDescriptor) 135 getParentNode().getDescriptor(); 136 msgDestRef.setReferringBundleDescriptor(ejbBundle); 139 getInterceptor().addMessageDestinationReferenceDescriptor 140 (msgDestRef); 141 } else { 142 super.addDescriptor(newDescriptor); 143 } 144 } 145 146 154 public Node writeDescriptor(Node parent, String nodeName, EjbInterceptor descriptor) { 155 Node interceptorNode = appendChild(parent, nodeName); 156 157 writeLocalizedDescriptions(interceptorNode, descriptor); 158 159 appendTextChild(interceptorNode, EjbTagNames.INTERCEPTOR_CLASS, descriptor.getInterceptorClassName()); 160 161 if (descriptor.hasAroundInvokeDescriptor()) { 162 writeAroundInvokeDescriptors(interceptorNode, 163 descriptor.getAroundInvokeDescriptors().iterator()); 164 } 165 if (descriptor.hasCallbackDescriptor(CallbackType.POST_CONSTRUCT)) { 166 writePostConstructDescriptors(interceptorNode, 167 descriptor.getCallbackDescriptors(CallbackType.POST_CONSTRUCT).iterator()); 168 } 169 if (descriptor.hasCallbackDescriptor(CallbackType.PRE_DESTROY)) { 170 writePreDestroyDescriptors(interceptorNode, 171 descriptor.getCallbackDescriptors(CallbackType.PRE_DESTROY).iterator()); 172 } 173 if (descriptor.hasCallbackDescriptor(CallbackType.POST_ACTIVATE)) { 174 writePostActivateDescriptors(interceptorNode, 175 descriptor.getCallbackDescriptors(CallbackType.POST_ACTIVATE).iterator()); 176 } 177 if (descriptor.hasCallbackDescriptor(CallbackType.PRE_PASSIVATE)) { 178 writePrePassivateDescriptors(interceptorNode, 179 descriptor.getCallbackDescriptors(CallbackType.PRE_PASSIVATE).iterator()); 180 } 181 182 return interceptorNode; 183 } 184 } 185 | Popular Tags |