KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > ejb > EjbInterceptorNode


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment.node.ejb;
24
25 import java.util.Map JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28 import org.xml.sax.Attributes JavaDoc;
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         //jndiEnvironmentRefsGroup
71
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     /**
89      * all sub-implementation of this class can use a dispatch table to map xml element to
90      * method name on the descriptor class for setting the element value.
91      *
92      * @return the map with the element name as a key, the setter method as a value
93      */

94     protected Map JavaDoc getDispatchTable() {
95         // no need to be synchronized for now
96
Map JavaDoc table = super.getDispatchTable();
97         table.put(EjbTagNames.INTERCEPTOR_CLASS, "setInterceptorClassName");
98         return table;
99     }
100
101    /**
102     * @return the descriptor instance to associate with this XMLNode
103     */

104     public Object JavaDoc 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     /**
118      * Adds a new DOL descriptor instance to the descriptor instance associated with
119      * this XMLNode
120      *
121      * @param descriptor the new descriptor
122      */

123     public void addDescriptor(Object JavaDoc 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             // EjbBundle might not be set yet on EjbInterceptor, so set it
137
// explicitly here.
138
msgDestRef.setReferringBundleDescriptor(ejbBundle);
139             getInterceptor().addMessageDestinationReferenceDescriptor
140                 (msgDestRef);
141         } else {
142             super.addDescriptor(newDescriptor);
143         }
144     }
145
146    /**
147      * write the relationships descriptor class to a DOM tree and return it
148      *
149      * @param parent node in the DOM tree
150      * @param node name for the root element of this xml fragment
151      * @param the descriptor to write
152      * @return the DOM tree top node
153      */

154     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, EjbInterceptor descriptor) {
155         Node JavaDoc 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