KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > runtime > EjbNode


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.runtime;
25
26 import java.util.Map JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.logging.Level JavaDoc;
30 import org.w3c.dom.Node JavaDoc;
31 import org.w3c.dom.Element JavaDoc;
32
33 import com.sun.enterprise.deployment.node.XMLElement;
34 import com.sun.enterprise.deployment.node.DeploymentDescriptorNode;
35 import com.sun.enterprise.deployment.node.ServiceReferenceNode;
36 import com.sun.enterprise.deployment.node.WebServiceEndpointNode;
37 import com.sun.enterprise.deployment.Descriptor;
38 import com.sun.enterprise.deployment.EjbDescriptor;
39 import com.sun.enterprise.deployment.EjbCMPEntityDescriptor;
40 import com.sun.enterprise.deployment.IASEjbCMPEntityDescriptor;
41 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
42 import com.sun.enterprise.deployment.EjbSessionDescriptor;
43 import com.sun.enterprise.deployment.EjbIORConfigurationDescriptor;
44 import com.sun.enterprise.deployment.EjbBundleDescriptor;
45 import com.sun.enterprise.deployment.runtime.MdbConnectionFactoryDescriptor;
46 import com.sun.enterprise.deployment.runtime.BeanPoolDescriptor;
47 import com.sun.enterprise.deployment.runtime.BeanCacheDescriptor;
48 import com.sun.enterprise.deployment.runtime.FlushAtEndOfMethodDescriptor;
49 import com.sun.enterprise.deployment.runtime.CheckpointAtEndOfMethodDescriptor;
50 import com.sun.enterprise.deployment.QueryDescriptor;
51 import com.sun.enterprise.deployment.Application;
52 import com.sun.enterprise.deployment.RunAsIdentityDescriptor;
53 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
54 import com.sun.enterprise.deployment.JmsDestinationReferenceDescriptor;
55 import com.sun.enterprise.deployment.types.EjbReference;
56 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
57 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
58 import com.sun.enterprise.deployment.util.DOLUtils;
59
60 /**
61  * This node handles all runtime information for ejbs
62  *
63  * @author Jerome Dochez
64  * @version
65  */

66 public class EjbNode extends DeploymentDescriptorNode {
67
68     private EjbDescriptor descriptor;
69     private String JavaDoc availEnabled;
70     
71     /** Creates new EjbNode */
72     public EjbNode() {
73         super();
74         registerElementHandler(new XMLElement(RuntimeTagNames.RESOURCE_REFERENCE),
75                                ResourceRefNode.class);
76         registerElementHandler(new XMLElement(RuntimeTagNames.EJB_REFERENCE),
77                                EjbRefNode.class);
78         registerElementHandler(new XMLElement(RuntimeTagNames.RESOURCE_ENV_REFERENCE),
79                                ResourceEnvRefNode.class);
80         registerElementHandler(new XMLElement(RuntimeTagNames.MESSAGE_DESTINATION_REFERENCE),
81                                MessageDestinationRefNode.class);
82         registerElementHandler(new XMLElement(WebServicesTagNames.SERVICE_REF),
83                                ServiceRefNode.class);
84         registerElementHandler(new XMLElement(RuntimeTagNames.CMP),
85                                CmpNode.class);
86     registerElementHandler(new XMLElement(RuntimeTagNames.MDB_CONNECTION_FACTORY),
87                 MDBConnectionFactoryNode.class);
88         registerElementHandler(new XMLElement(RuntimeTagNames.IOR_CONFIG),
89                                IORConfigurationNode.class,"addIORConfigurationDescriptor");
90         registerElementHandler(new XMLElement(RuntimeTagNames.BEAN_POOL),
91                                BeanPoolNode.class);
92         registerElementHandler(new XMLElement(RuntimeTagNames.BEAN_CACHE),
93                                BeanCacheNode.class);
94         registerElementHandler(new XMLElement(RuntimeTagNames.MDB_RESOURCE_ADAPTER),
95                         MDBResourceAdapterNode.class);
96         registerElementHandler(new XMLElement(WebServicesTagNames.WEB_SERVICE_ENDPOINT),
97                                WebServiceEndpointRuntimeNode.class);
98         registerElementHandler(new XMLElement(RuntimeTagNames.FLUSH_AT_END_OF_METHOD), FlushAtEndOfMethodNode.class);
99         registerElementHandler(new XMLElement(RuntimeTagNames.CHECKPOINT_AT_END_OF_METHOD), CheckpointAtEndOfMethodNode.class);
100     }
101     
102    /**
103     * @return the descriptor instance to associate with this XMLNode
104     */

105     public Object JavaDoc getDescriptor() {
106         return descriptor;
107     }
108     
109     /**
110      * receives notification of the value for a particular tag
111      *
112      * @param element the xml element
113      * @param value it's associated value
114      */

115     public void setElementValue(XMLElement element, String JavaDoc value) {
116         if (RuntimeTagNames.EJB_NAME.equals(element.getQName())) {
117             Object JavaDoc parentDesc = getParentNode().getDescriptor();
118             if (parentDesc==null) {
119         // In J2EE 1.2.x, all ejbs in app were clubbed under
120
// one <enterprise-beans> element.
121
// So we get the ejbDescriptor from the application
122
Object JavaDoc application = getParentNode().getParentNode().getDescriptor();
123                 if (application!=null && application instanceof Application) {
124                     descriptor = ((Application) application).getEjbByName(value);
125                 }
126             } else {
127                 if (parentDesc instanceof EjbBundleDescriptor) {
128                     descriptor = ((EjbBundleDescriptor) parentDesc).getEjbByName(value);
129                 }
130             }
131             if (descriptor==null) {
132                 DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.addDescriptorFailure",
133                             new Object JavaDoc[]{element , value});
134             } else {
135                 if (availEnabled != null) {
136                     descriptor.getIASEjbExtraDescriptors().setAttributeValue(descriptor.getIASEjbExtraDescriptors().AVAILABILITY_ENABLED, availEnabled);
137                 }
138             }
139             return;
140         } else if (descriptor==null && ! RuntimeTagNames.AVAILABILITY_ENABLED.equals(element.getQName())) {
141             DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.addDescriptorFailure",
142                             new Object JavaDoc[] {element.getQName() , value });
143         }
144         // if this is the availability-enabled attribute, save the value
145
// and set it later
146
if (RuntimeTagNames.AVAILABILITY_ENABLED.equals(element.getQName())) {
147             availEnabled = value;
148         } else if (RuntimeTagNames.NAME.equals(element.getQName())) {
149         // principal
150
if (Boolean.FALSE.equals(descriptor.getUsesCallerIdentity())
151                 && descriptor.getRunAsIdentity() != null) {
152                     descriptor.getRunAsIdentity().setPrincipal(value);
153             }
154         } else if (RuntimeTagNames.PASS_BY_REFERENCE.equals(element.getQName())) {
155         descriptor.getIASEjbExtraDescriptors().setPassByReference(Boolean.valueOf(value));
156     } else if (RuntimeTagNames.JMS_MAX_MESSAGES_LOAD.equals(element.getQName())) {
157         descriptor.getIASEjbExtraDescriptors().setJmsMaxMessagesLoad((Integer.valueOf(value)).intValue());
158     } else if (RuntimeTagNames.IS_READ_ONLY_BEAN.equals(element.getQName())) {
159         descriptor.getIASEjbExtraDescriptors().setIsReadOnlyBean((Boolean.valueOf(value)).booleanValue());
160     } else if (RuntimeTagNames.REFRESH_PERIOD_IN_SECONDS.equals(element.getQName())) {
161         descriptor.getIASEjbExtraDescriptors().setRefreshPeriodInSeconds((Integer.valueOf(value)).intValue());
162     } else if (RuntimeTagNames.COMMIT_OPTION.equals(element.getQName())) {
163         descriptor.getIASEjbExtraDescriptors().setCommitOption(value);
164     } else if (RuntimeTagNames.CMT_TIMEOUT_IN_SECONDS.equals(element.getQName())) {
165         descriptor.getIASEjbExtraDescriptors().setCmtTimeoutInSeconds((Integer.valueOf(value)).intValue());
166     } else if (RuntimeTagNames.USE_THREAD_POOL_ID.equals(element.getQName())) {
167         descriptor.getIASEjbExtraDescriptors().setUseThreadPoolId(value);
168     } else if (RuntimeTagNames.CHECKPOINTED_METHODS.equals(
169             element.getQName())) {
170             descriptor.getIASEjbExtraDescriptors().setCheckpointedMethods(
171                 value);
172         }
173         else super.setElementValue(element, value);
174     }
175     
176     /**
177      * all sub-implementation of this class can use a dispatch table to map xml element to
178      * method name on the descriptor class for setting the element value.
179      *
180      * @return the map with the element name as a key, the setter method as a value
181      */

182     protected Map JavaDoc getDispatchTable() {
183         Map JavaDoc table = super.getDispatchTable();
184         
185         table.put(RuntimeTagNames.JNDI_NAME, "setJndiName");
186         
187         // gen-classes
188
table.put(RuntimeTagNames.REMOTE_IMPL, "setEJBObjectImplClassName");
189         table.put(RuntimeTagNames.LOCAL_IMPL, "setEJBLocalObjectImplClassName");
190         table.put(RuntimeTagNames.REMOTE_HOME_IMPL, "setRemoteHomeImplClassName");
191         table.put(RuntimeTagNames.LOCAL_HOME_IMPL, "setLocalHomeImplClassName");
192         
193         // for mdbs...
194
table.put(RuntimeTagNames.DURABLE_SUBSCRIPTION, "setDurableSubscriptionName");
195         table.put(RuntimeTagNames.MDB_CONNECTION_FACTORY, "setConnectionFactoryName");
196         table.put(RuntimeTagNames.RESOURCE_ADAPTER_MID, "setResourceAdapterMid");
197         return table;
198     }
199     
200     /**
201      * Adds a new DOL descriptor instance to the descriptor instance associated with
202      * this XMLNode
203      *
204      * @param descriptor the new descriptor
205      */

206     public void addDescriptor(Object JavaDoc newDescriptor) {
207     if (newDescriptor instanceof MdbConnectionFactoryDescriptor) {
208         descriptor.getIASEjbExtraDescriptors().setMdbConnectionFactory(
209             (MdbConnectionFactoryDescriptor) newDescriptor);
210     } else
211     if (newDescriptor instanceof BeanPoolDescriptor) {
212         descriptor.getIASEjbExtraDescriptors().setBeanPool(
213         (BeanPoolDescriptor) newDescriptor);
214     } else
215     if (newDescriptor instanceof BeanCacheDescriptor) {
216         descriptor.getIASEjbExtraDescriptors().setBeanCache(
217         (BeanCacheDescriptor) newDescriptor);
218     } else
219     if (newDescriptor instanceof FlushAtEndOfMethodDescriptor) {
220         descriptor.getIASEjbExtraDescriptors().setFlushAtEndOfMethodDescriptor((FlushAtEndOfMethodDescriptor)newDescriptor);
221     } else
222     if (newDescriptor instanceof CheckpointAtEndOfMethodDescriptor) {
223         descriptor.getIASEjbExtraDescriptors().setCheckpointAtEndOfMethodDescriptor((CheckpointAtEndOfMethodDescriptor)newDescriptor);
224     }
225     }
226     
227     /**
228      * write the descriptor class to a DOM tree and return it
229      *
230      * @param parent node for the DOM tree
231      * @param node name for the descriptor
232      * @param the descriptor to write
233      * @return the DOM tree top node
234      */

235     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, EjbDescriptor ejbDescriptor) {
236         Element JavaDoc ejbNode = (Element JavaDoc)super.writeDescriptor(parent, nodeName, ejbDescriptor);
237         appendTextChild(ejbNode, RuntimeTagNames.EJB_NAME, ejbDescriptor.getName());
238         appendTextChild(ejbNode, RuntimeTagNames.JNDI_NAME, ejbDescriptor.getJndiName());
239     
240         RuntimeDescriptorNode.writeCommonComponentInfo(ejbNode, (Descriptor) ejbDescriptor);
241
242     appendTextChild(ejbNode, RuntimeTagNames.PASS_BY_REFERENCE,
243         String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getPassByReference()));
244
245     if (ejbDescriptor instanceof IASEjbCMPEntityDescriptor) {
246         CmpNode cmpNode = new CmpNode();
247         cmpNode.writeDescriptor(ejbNode, RuntimeTagNames.CMP, (IASEjbCMPEntityDescriptor) ejbDescriptor);
248     }
249     
250         // principal
251
if ( Boolean.FALSE.equals(ejbDescriptor.getUsesCallerIdentity()) ) {
252             RunAsIdentityDescriptor raid = ejbDescriptor.getRunAsIdentity();
253             if ( raid != null && raid.getPrincipal() != null ) {
254                 Node JavaDoc principalNode = appendChild(ejbNode, RuntimeTagNames.PRINCIPAL);
255                 appendTextChild(principalNode, RuntimeTagNames.NAME,raid.getPrincipal());
256             }
257         }
258     
259     if (ejbDescriptor instanceof EjbMessageBeanDescriptor) {
260         EjbMessageBeanDescriptor msgBeanDesc = (EjbMessageBeanDescriptor) ejbDescriptor;
261             
262             // mdb-connection-factory?
263
if (ejbDescriptor.getIASEjbExtraDescriptors().getMdbConnectionFactory()!=null) {
264                 MDBConnectionFactoryNode mcfNode = new MDBConnectionFactoryNode();
265                 mcfNode.writeDescriptor(ejbNode, RuntimeTagNames.MDB_CONNECTION_FACTORY,
266                     ejbDescriptor.getIASEjbExtraDescriptors().getMdbConnectionFactory());
267             }
268             
269             // jms-durable-subscription-name
270
if (msgBeanDesc.hasDurableSubscription()) {
271         appendTextChild(ejbNode, RuntimeTagNames.DURABLE_SUBSCRIPTION,
272             msgBeanDesc.getDurableSubscriptionName());
273         }
274         appendTextChild(ejbNode, RuntimeTagNames.JMS_MAX_MESSAGES_LOAD,
275             String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getJmsMaxMessagesLoad()));
276     }
277     
278     // ior-configuration
279
IORConfigurationNode iorNode = new IORConfigurationNode();
280         for (Iterator JavaDoc iorIterator = ejbDescriptor.getIORConfigurationDescriptors().iterator();
281             iorIterator.hasNext();) {
282                 iorNode.writeDescriptor(ejbNode,RuntimeTagNames.IOR_CONFIG, (EjbIORConfigurationDescriptor) iorIterator.next());
283         }
284         
285     appendTextChild(ejbNode, RuntimeTagNames.IS_READ_ONLY_BEAN,
286         String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().isIsReadOnlyBean()));
287     appendTextChild(ejbNode, RuntimeTagNames.REFRESH_PERIOD_IN_SECONDS,
288         String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getRefreshPeriodInSeconds()));
289     appendTextChild(ejbNode, RuntimeTagNames.COMMIT_OPTION,
290         ejbDescriptor.getIASEjbExtraDescriptors().getCommitOption());
291     appendTextChild(ejbNode, RuntimeTagNames.CMT_TIMEOUT_IN_SECONDS,
292         String.valueOf(ejbDescriptor.getIASEjbExtraDescriptors().getCmtTimeoutInSeconds()));
293     appendTextChild(ejbNode, RuntimeTagNames.USE_THREAD_POOL_ID,
294         ejbDescriptor.getIASEjbExtraDescriptors().getUseThreadPoolId());
295     
296         // gen-classes
297
writeGenClasses(ejbNode, ejbDescriptor);
298         
299     // bean-pool
300
BeanPoolDescriptor beanPoolDesc = ejbDescriptor.getIASEjbExtraDescriptors().getBeanPool();
301     if (beanPoolDesc!=null) {
302         BeanPoolNode bpNode = new BeanPoolNode();
303         bpNode.writeDescriptor(ejbNode, RuntimeTagNames.BEAN_POOL, beanPoolDesc);
304     }
305     
306     // bean-cache
307
BeanCacheDescriptor beanCacheDesc = ejbDescriptor.getIASEjbExtraDescriptors().getBeanCache();
308     if (beanCacheDesc!=null) {
309         BeanCacheNode bcNode = new BeanCacheNode();
310         bcNode.writeDescriptor(ejbNode, RuntimeTagNames.BEAN_CACHE, beanCacheDesc);
311     }
312     
313     if (ejbDescriptor instanceof EjbMessageBeanDescriptor) {
314         EjbMessageBeanDescriptor msgBeanDesc = (EjbMessageBeanDescriptor) ejbDescriptor;
315             if (msgBeanDesc.hasResourceAdapterMid()) {
316                 MDBResourceAdapterNode mdb = new MDBResourceAdapterNode();
317                 mdb.writeDescriptor(ejbNode, RuntimeTagNames.MDB_RESOURCE_ADAPTER, msgBeanDesc);
318             }
319         } else if( ejbDescriptor instanceof EjbSessionDescriptor ) {
320             
321             // web-services
322
WebServiceEndpointRuntimeNode wsRuntime = new WebServiceEndpointRuntimeNode();
323             wsRuntime.writeWebServiceEndpointInfo(ejbNode, ejbDescriptor);
324         }
325
326     // flush-at-end-of-method
327
FlushAtEndOfMethodDescriptor flushMethodDesc = ejbDescriptor.getIASEjbExtraDescriptors().getFlushAtEndOfMethodDescriptor();
328     if (flushMethodDesc!=null) {
329         FlushAtEndOfMethodNode flushNode = new FlushAtEndOfMethodNode();
330         flushNode.writeDescriptor(ejbNode, RuntimeTagNames.FLUSH_AT_END_OF_METHOD, flushMethodDesc);
331     }
332
333         // checkpointed-methods
334
ejbDescriptor.getIASEjbExtraDescriptors().parseCheckpointedMethods(ejbDescriptor);
335
336         // checkpoint-at-end-of-method
337
CheckpointAtEndOfMethodDescriptor checkpointMethodDesc = ejbDescriptor.getIASEjbExtraDescriptors().getCheckpointAtEndOfMethodDescriptor();
338         if (checkpointMethodDesc!=null) {
339             CheckpointAtEndOfMethodNode checkpointNode =
340                 new CheckpointAtEndOfMethodNode();
341             checkpointNode.writeDescriptor(ejbNode, RuntimeTagNames.CHECKPOINT_AT_END_OF_METHOD, checkpointMethodDesc);
342         }
343     
344         // availability-enabled
345
setAttribute(ejbNode, RuntimeTagNames.AVAILABILITY_ENABLED, (String JavaDoc) ejbDescriptor.getIASEjbExtraDescriptors().getAttributeValue(ejbDescriptor.getIASEjbExtraDescriptors().AVAILABILITY_ENABLED));
346
347         return ejbNode;
348     }
349
350     /**
351    * write all the classes info generated at deployment
352    * @param parent node for the information
353    * @param descriptor the descriptor containing the generated info
354    */

355     private void writeGenClasses(Node JavaDoc parent, EjbDescriptor ejbDescriptor) {
356         // common to all ejbs but mdb...
357
Node JavaDoc genClasses = appendChild(parent, RuntimeTagNames.GEN_CLASSES);
358         
359         appendTextChild(genClasses, RuntimeTagNames.REMOTE_IMPL,
360             ejbDescriptor.getEJBObjectImplClassName());
361         
362         appendTextChild(genClasses, RuntimeTagNames.LOCAL_IMPL,
363             ejbDescriptor.getEJBLocalObjectImplClassName());
364
365         appendTextChild(genClasses, RuntimeTagNames.REMOTE_HOME_IMPL,
366             ejbDescriptor.getRemoteHomeImplClassName());
367         
368         appendTextChild(genClasses, RuntimeTagNames.LOCAL_HOME_IMPL,
369             ejbDescriptor.getLocalHomeImplClassName());
370
371
372
373     }
374 }
375
Popular Tags