KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > ejb > 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.ejb;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28 import org.w3c.dom.Node JavaDoc;
29 import java.util.logging.Level JavaDoc;
30
31 import com.sun.enterprise.deployment.types.EjbReference;
32
33 import com.sun.enterprise.deployment.node.XMLElement;
34 import com.sun.enterprise.deployment.node.DisplayableComponentNode;
35 import com.sun.enterprise.deployment.node.EnvEntryNode;
36 import com.sun.enterprise.deployment.node.EjbReferenceNode;
37 import com.sun.enterprise.deployment.node.EntityManagerReferenceNode;
38 import com.sun.enterprise.deployment.node.EntityManagerFactoryReferenceNode;
39 import com.sun.enterprise.deployment.node.ServiceReferenceNode;
40 import com.sun.enterprise.deployment.node.EjbLocalReferenceNode;
41 import com.sun.enterprise.deployment.node.ResourceRefNode;
42 import com.sun.enterprise.deployment.node.ResourceEnvRefNode;
43 import com.sun.enterprise.deployment.node.MessageDestinationRefNode;
44 import com.sun.enterprise.deployment.node.LifecycleCallbackNode;
45
46 import com.sun.enterprise.deployment.EnvironmentProperty;
47 import com.sun.enterprise.deployment.Descriptor;
48 import com.sun.enterprise.deployment.EjbDescriptor;
49 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
50 import com.sun.enterprise.deployment.JmsDestinationReferenceDescriptor;
51 import com.sun.enterprise.deployment.MessageDestinationReferenceDescriptor;
52 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
53 import com.sun.enterprise.deployment.EjbBundleDescriptor;
54 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
55 import com.sun.enterprise.deployment.RunAsIdentityDescriptor;
56 import com.sun.enterprise.deployment.xml.TagNames;
57 import com.sun.enterprise.deployment.xml.EjbTagNames;
58 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
59
60 import com.sun.enterprise.deployment.util.DOLUtils;
61
62 /**
63  * This class is responsible for handling all common information
64  * shared by all types of entreprise beans (MDB, session, entity)
65  *
66  * @author Jerome Dochez
67  * @version
68  */

69 public abstract class EjbNode extends DisplayableComponentNode {
70
71     /** Creates new EjbNode */
72     public EjbNode() {
73         super();
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(EjbTagNames.SECURITY_IDENTITY),
82                                                             SecurityIdentityNode.class);
83         registerElementHandler(new XMLElement(TagNames.RESOURCE_ENV_REFERENCE),
84                                                             ResourceEnvRefNode.class, "addJmsDestinationReferenceDescriptor");
85         registerElementHandler(new XMLElement(TagNames.MESSAGE_DESTINATION_REFERENCE), MessageDestinationRefNode.class);
86         registerElementHandler(new XMLElement(TagNames.PERSISTENCE_CONTEXT_REF), EntityManagerReferenceNode.class, "addEntityManagerReferenceDescriptor");
87         registerElementHandler(new XMLElement(TagNames.PERSISTENCE_UNIT_REF), EntityManagerFactoryReferenceNode.class, "addEntityManagerFactoryReferenceDescriptor");
88
89     }
90
91     /**
92      * Adds a new DOL descriptor instance to the descriptor instance associated with
93      * this XMLNode
94      *
95      * @param descriptor the new descriptor
96      */

97     public void addDescriptor(Object JavaDoc newDescriptor) {
98         if (newDescriptor instanceof EjbReference) {
99             if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
100                 DOLUtils.getDefaultLogger().fine("Adding ejb ref " + newDescriptor);
101             }
102             getEjbDescriptor().addEjbReferenceDescriptor(
103                         (EjbReference) newDescriptor);
104         } else if (newDescriptor instanceof RunAsIdentityDescriptor) {
105             if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
106                 DOLUtils.getDefaultLogger().fine("Adding security-identity" + newDescriptor);
107             }
108             getEjbDescriptor().setUsesCallerIdentity(false);
109         getEjbDescriptor().setRunAsIdentity((RunAsIdentityDescriptor) newDescriptor);
110         } else if( newDescriptor instanceof
111                    MessageDestinationReferenceDescriptor ) {
112             MessageDestinationReferenceDescriptor msgDestRef =
113                 (MessageDestinationReferenceDescriptor) newDescriptor;
114             EjbBundleDescriptor ejbBundle = (EjbBundleDescriptor)
115                 getParentNode().getDescriptor();
116             // EjbBundle might not be set yet on EjbDescriptor, so set it
117
// explicitly here.
118
msgDestRef.setReferringBundleDescriptor(ejbBundle);
119             getEjbDescriptor().addMessageDestinationReferenceDescriptor
120                 (msgDestRef);
121         } else {
122             super.addDescriptor(newDescriptor);
123         }
124     }
125     
126     public Object JavaDoc getDescriptor() {
127         return getEjbDescriptor();
128     }
129     
130     public abstract EjbDescriptor getEjbDescriptor();
131     
132     /**
133      * all sub-implementation of this class can use a dispatch table to map xml element to
134      * method name on the descriptor class for setting the element value.
135      *
136      * @return the map with the element name as a key, the setter method as a value
137      */

138     protected Map JavaDoc getDispatchTable() {
139         // no need to be synchronized for now
140
Map JavaDoc table = super.getDispatchTable();
141         table.put(EjbTagNames.EJB_NAME, "setName");
142         table.put(EjbTagNames.EJB_CLASS, "setEjbClassName");
143         table.put(TagNames.MAPPED_NAME, "setMappedName");
144         return table;
145     }
146         
147     /**
148      * write the common descriptor info to a DOM tree and return it
149      *
150      * @param parent node for the DOM tree
151      * @param the descriptor to write
152      */

153     protected void writeCommonHeaderEjbDescriptor(Node JavaDoc ejbNode, Descriptor descriptor) {
154         EjbDescriptor ejbDescriptor = (EjbDescriptor)descriptor;
155         appendTextChild(ejbNode, EjbTagNames.EJB_NAME, descriptor.getName());
156         appendTextChild(ejbNode, TagNames.MAPPED_NAME, ejbDescriptor.getMappedName());
157     }
158     
159     /**
160      * write the security identity information about an EJB
161      *
162      * @param parent node for the DOM tree
163      * @param the EJB descriptor the security information to be retrieved
164      */

165     protected void writeSecurityIdentityDescriptor(Node JavaDoc parent, EjbDescriptor descriptor) {
166         
167         if (!descriptor.getUsesCallerIdentity() && descriptor.getRunAsIdentity()==null)
168             return;
169         
170         SecurityIdentityNode node = new SecurityIdentityNode();
171         node.writeDescriptor(parent, EjbTagNames.SECURITY_IDENTITY, descriptor);
172     }
173 }
174
Popular Tags