KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 package com.sun.enterprise.deployment.node.ejb;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.w3c.dom.Node JavaDoc;
30
31 import com.sun.enterprise.deployment.node.XMLElement;
32 import com.sun.enterprise.deployment.node.DescriptorFactory;
33 import com.sun.enterprise.deployment.node.LifecycleCallbackNode;
34 import com.sun.enterprise.deployment.node.MethodNode;
35
36 import com.sun.enterprise.deployment.Descriptor;
37 import com.sun.enterprise.deployment.MethodDescriptor;
38 import com.sun.enterprise.deployment.EjbInitInfo;
39
40 import com.sun.enterprise.deployment.EjbDescriptor;
41 import com.sun.enterprise.deployment.EjbInterceptor;
42 import com.sun.enterprise.deployment.EjbRemovalInfo;
43 import com.sun.enterprise.deployment.EjbBundleDescriptor;
44 import com.sun.enterprise.deployment.EjbSessionDescriptor;
45 import com.sun.enterprise.deployment.EntityManagerReferenceDescriptor;
46 import com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor;
47 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
48 import com.sun.enterprise.deployment.xml.EjbTagNames;
49
50 /**
51  * This class handles all information pertinent to session beans
52  *
53  * @author Jerome Dochez
54  * @version
55  */

56 public class EjbSessionNode extends InterfaceBasedEjbNode {
57     
58     private EjbSessionDescriptor descriptor;
59
60     public EjbSessionNode() {
61        super();
62        // register sub XMLNodes
63

64        registerElementHandler(new XMLElement(EjbTagNames.AROUND_INVOKE_METHOD), AroundInvokeNode.class, "addAroundInvokeDescriptor");
65
66        registerElementHandler(new XMLElement(EjbTagNames.POST_CONSTRUCT), LifecycleCallbackNode.class, "addPostConstructDescriptor");
67
68        registerElementHandler(new XMLElement(EjbTagNames.PRE_DESTROY), LifecycleCallbackNode.class, "addPreDestroyDescriptor");
69
70        registerElementHandler(new XMLElement(EjbTagNames.POST_ACTIVATE_METHOD), LifecycleCallbackNode.class, "addPostActivateDescriptor");
71
72        registerElementHandler(new XMLElement(EjbTagNames.PRE_PASSIVATE_METHOD), LifecycleCallbackNode.class, "addPrePassivateDescriptor");
73
74        registerElementHandler(new XMLElement(EjbTagNames.TIMEOUT_METHOD), MethodNode.class, "setEjbTimeoutMethod");
75
76        registerElementHandler(new XMLElement(EjbTagNames.INIT_METHOD), EjbInitNode.class, "addInitMethod");
77
78        registerElementHandler(new XMLElement(EjbTagNames.REMOVE_METHOD), EjbRemoveNode.class, "addRemoveMethod");
79    }
80         
81    /**
82     * @return the descriptor instance to associate with this XMLNode
83     */

84     public EjbDescriptor getEjbDescriptor() {
85         
86         if (descriptor==null) {
87             descriptor = (EjbSessionDescriptor) DescriptorFactory.getDescriptor(getXMLPath());
88             descriptor.setEjbBundleDescriptor((EjbBundleDescriptor) getParentNode().getDescriptor());
89         }
90         return descriptor;
91     }
92     
93     /**
94      * all sub-implementation of this class can use a dispatch table to map xml element to
95      * method name on the descriptor class for setting the element value.
96      *
97      * @return the map with the element name as a key, the setter method as a value
98      */

99     protected Map JavaDoc getDispatchTable() {
100         // no need to be synchronized for now
101
Map JavaDoc table = super.getDispatchTable();
102         table.put(EjbTagNames.SESSION_TYPE, "setSessionType");
103         table.put(EjbTagNames.TRANSACTION_TYPE, "setTransactionType");
104         return table;
105     }
106     
107     /**
108      * write the descriptor class to a DOM tree and return it
109      *
110      * @param parent node for the DOM tree
111      * @param node name for the root element of this xml fragment
112      * @param the descriptor to write
113      * @return the DOM tree top node
114      */

115     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, Descriptor descriptor) {
116         if (! (descriptor instanceof EjbSessionDescriptor)) {
117             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handles descriptors of type " + descriptor.getClass());
118         }
119         EjbSessionDescriptor ejbDesc = (EjbSessionDescriptor) descriptor;
120         
121         Node JavaDoc ejbNode = super.writeDescriptor(parent, nodeName, descriptor);
122         writeDisplayableComponentInfo(ejbNode, descriptor);
123         writeCommonHeaderEjbDescriptor(ejbNode, ejbDesc);
124         appendTextChild(ejbNode, EjbTagNames.SESSION_TYPE, ejbDesc.getSessionType());
125
126         MethodNode methodNode = new MethodNode();
127         
128         if( ejbDesc.isTimedObject() ) {
129             methodNode.writeJavaMethodDescriptor
130                 (ejbNode, EjbTagNames.TIMEOUT_METHOD,
131                  ejbDesc.getEjbTimeoutMethod());
132         }
133
134         if( ejbDesc.hasInitMethods() ) {
135             EjbInitNode initNode = new EjbInitNode();
136             for(EjbInitInfo next : ejbDesc.getInitMethods()) {
137                 initNode.writeDescriptor(ejbNode,
138                                          EjbTagNames.INIT_METHOD, next);
139             }
140         }
141
142         if( ejbDesc.hasRemoveMethods() ) {
143             EjbRemoveNode removeNode = new EjbRemoveNode();
144             for(EjbRemovalInfo next : ejbDesc.getAllRemovalInfo()) {
145                 removeNode.writeDescriptor(ejbNode,
146                                            EjbTagNames.REMOVE_METHOD, next);
147             }
148         }
149
150
151         appendTextChild(ejbNode, EjbTagNames.TRANSACTION_TYPE, ejbDesc.getTransactionType());
152
153         //around-invoke-method
154
writeAroundInvokeDescriptors(ejbNode, ejbDesc.getAroundInvokeDescriptors().iterator());
155
156         // env-entry*
157
writeEnvEntryDescriptors(ejbNode, ejbDesc.getEnvironmentProperties().iterator());
158         
159         // ejb-ref * and ejb-local-ref*
160
writeEjbReferenceDescriptors(ejbNode, ejbDesc.getEjbReferenceDescriptors().iterator());
161
162         // service-ref*
163
writeServiceReferenceDescriptors(ejbNode, ejbDesc.getServiceReferenceDescriptors().iterator());
164         
165         // resource-ref*
166
writeResourceRefDescriptors(ejbNode, ejbDesc.getResourceReferenceDescriptors().iterator());
167         
168         // resource-env-ref*
169
writeResourceEnvRefDescriptors(ejbNode, ejbDesc.getJmsDestinationReferenceDescriptors().iterator());
170
171         // message-destination-ref*
172
writeMessageDestinationRefDescriptors(ejbNode, ejbDesc.getMessageDestinationReferenceDescriptors().iterator());
173
174         // persistence-context-ref*
175
writeEntityManagerReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerReferenceDescriptors().iterator());
176         
177         // persistence-unit-ref*
178
writeEntityManagerFactoryReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerFactoryReferenceDescriptors().iterator());
179         
180         // post-construct
181
writePostConstructDescriptors(ejbNode, ejbDesc.getPostConstructDescriptors().iterator());
182
183         // pre-destroy
184
writePreDestroyDescriptors(ejbNode, ejbDesc.getPreDestroyDescriptors().iterator());
185
186         // post-activate-method
187
writePostActivateDescriptors(ejbNode, ejbDesc.getPostActivateDescriptors().iterator());
188
189         // pre-passivate-method
190
writePrePassivateDescriptors(ejbNode, ejbDesc.getPrePassivateDescriptors().iterator());
191
192         // security-role-ref*
193
writeRoleReferenceDescriptors(ejbNode, ejbDesc.getRoleReferences().iterator());
194         
195         // security-identity
196
writeSecurityIdentityDescriptor(ejbNode, ejbDesc);
197         
198         return ejbNode;
199     }
200 }
201
Popular Tags