KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
25  * MessageDrivenBeanNode.java
26  *
27  * Created on February 1, 2002, 11:25 AM
28  */

29
30 package com.sun.enterprise.deployment.node.ejb;
31
32 import java.util.Map JavaDoc;
33 import java.util.Map.Entry;
34 import java.util.Set JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import org.w3c.dom.Node JavaDoc;
37
38 import com.sun.enterprise.deployment.xml.TagNames;
39 import com.sun.enterprise.deployment.node.XMLElement;
40 import com.sun.enterprise.deployment.node.LifecycleCallbackNode;
41 import com.sun.enterprise.deployment.node.MethodNode;
42 import com.sun.enterprise.deployment.node.DescriptorFactory;
43
44 import com.sun.enterprise.deployment.Descriptor;
45 import com.sun.enterprise.deployment.EjbDescriptor;
46 import com.sun.enterprise.deployment.EjbBundleDescriptor;
47 import com.sun.enterprise.deployment.EntityManagerReferenceDescriptor;
48 import com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor;
49 import com.sun.enterprise.deployment.EjbInterceptor;
50 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
51 import com.sun.enterprise.deployment.xml.EjbTagNames;
52
53 /**
54  * This class handles message-driven related xml information
55  *
56  * @author Jerome Dochez
57  * @version
58  */

59 public class MessageDrivenBeanNode extends EjbNode {
60
61     private EjbMessageBeanDescriptor descriptor;
62         
63     public MessageDrivenBeanNode() {
64         super();
65         registerElementHandler(new XMLElement(EjbTagNames.ACTIVATION_CONFIG),
66                                ActivationConfigNode.class,
67                                "setActivationConfigDescriptor");
68
69         registerElementHandler(new XMLElement(EjbTagNames.AROUND_INVOKE_METHOD), AroundInvokeNode.class, "addAroundInvokeDescriptor");
70
71         registerElementHandler(new XMLElement(TagNames.POST_CONSTRUCT), LifecycleCallbackNode.class, "addPostConstructDescriptor");
72
73         registerElementHandler(new XMLElement(TagNames.PRE_DESTROY), LifecycleCallbackNode.class, "addPreDestroyDescriptor");
74
75         registerElementHandler(new XMLElement(EjbTagNames.TIMEOUT_METHOD), MethodNode.class, "setEjbTimeoutMethod");
76
77     }
78
79     /**
80      * @return the descriptor instance to associate with this XMLNode
81      */

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

97     protected Map JavaDoc getDispatchTable() {
98         // no need to be synchronized for now
99
Map JavaDoc table = super.getDispatchTable();
100
101         table.put(EjbTagNames.MESSAGING_TYPE, "setMessageListenerType");
102         table.put(EjbTagNames.TRANSACTION_TYPE, "setTransactionType");
103         table.put(EjbTagNames.MESSAGE_DESTINATION_TYPE, "setDestinationType");
104         table.put(TagNames.MESSAGE_DESTINATION_LINK,
105                   "setMessageDestinationLinkName");
106
107         // These are the EJB 2.0 elements that no longer exist in the EJB 2.1
108
// schema. We still set them on the descriptor but they will be
109
// written out as activation config properties.
110
table.put(EjbTagNames.MSG_SELECTOR, "setJmsMessageSelector");
111         table.put(EjbTagNames.JMS_ACKNOWLEDGE_MODE, "setJmsAcknowledgeMode");
112         table.put(EjbTagNames.JMS_DEST_TYPE, "setDestinationType");
113         table.put(EjbTagNames.JMS_SUBSCRIPTION_DURABILITY,
114                   "setSubscriptionDurability");
115         return table;
116     }
117     
118     /**
119      * write the descriptor class to a DOM tree and return it
120      *
121      * @param parent node for the DOM tree
122      * @param node name for the root element of this xml fragment
123      * @param the descriptor to write
124      * @return the DOM tree top node
125      */

126     public Node JavaDoc writeDescriptor(Node JavaDoc parent, String JavaDoc nodeName, Descriptor descriptor) {
127         if (! (descriptor instanceof EjbMessageBeanDescriptor)) {
128             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handles descriptors of type " + descriptor.getClass());
129         }
130         EjbMessageBeanDescriptor ejbDesc = (EjbMessageBeanDescriptor) descriptor;
131         
132         Node JavaDoc ejbNode = super.writeDescriptor(parent, nodeName, descriptor);
133         writeDisplayableComponentInfo(ejbNode, descriptor);
134         writeCommonHeaderEjbDescriptor(ejbNode, ejbDesc);
135         appendTextChild(ejbNode, EjbTagNames.EJB_CLASS, ejbDesc.getEjbClassName());
136         appendTextChild(ejbNode, EjbTagNames.MESSAGING_TYPE, ejbDesc.getMessageListenerType());
137
138
139         MethodNode methodNode = new MethodNode();
140         
141         if( ejbDesc.isTimedObject() ) {
142             methodNode.writeJavaMethodDescriptor
143                 (ejbNode, EjbTagNames.TIMEOUT_METHOD,
144                  ejbDesc.getEjbTimeoutMethod());
145         }
146
147         appendTextChild(ejbNode, EjbTagNames.TRANSACTION_TYPE, ejbDesc.getTransactionType());
148
149         // message-destination-type
150
appendTextChild(ejbNode, TagNames.MESSAGE_DESTINATION_TYPE,
151                         ejbDesc.getDestinationType());
152
153         // message-destination-link
154
String JavaDoc link = ejbDesc.getMessageDestinationLinkName();
155         appendTextChild(ejbNode, TagNames.MESSAGE_DESTINATION_LINK, link);
156         
157         ActivationConfigNode activationConfigNode = new ActivationConfigNode();
158         activationConfigNode.writeDescriptor
159             (ejbNode, EjbTagNames.ACTIVATION_CONFIG,
160              ejbDesc.getActivationConfigDescriptor());
161
162         // around-invoke-method
163
writeAroundInvokeDescriptors(ejbNode, ejbDesc.getAroundInvokeDescriptors().iterator());
164
165         // env-entry*
166
writeEnvEntryDescriptors(ejbNode, ejbDesc.getEnvironmentProperties().iterator());
167         
168         // ejb-ref * and ejb-local-ref*
169
writeEjbReferenceDescriptors(ejbNode, ejbDesc.getEjbReferenceDescriptors().iterator());
170
171         // service-ref*
172
writeServiceReferenceDescriptors(ejbNode, ejbDesc.getServiceReferenceDescriptors().iterator());
173         
174         // resource-ref*
175
writeResourceRefDescriptors(ejbNode, ejbDesc.getResourceReferenceDescriptors().iterator());
176         
177         // resource-env-ref*
178
writeResourceEnvRefDescriptors(ejbNode, ejbDesc.getJmsDestinationReferenceDescriptors().iterator());
179         
180         // message-destination-ref*
181
writeMessageDestinationRefDescriptors(ejbNode, ejbDesc.getMessageDestinationReferenceDescriptors().iterator());
182
183         // persistence-context-ref*
184
writeEntityManagerReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerReferenceDescriptors().iterator());
185         
186         // persistence-unit-ref*
187
writeEntityManagerFactoryReferenceDescriptors(ejbNode, ejbDesc.getEntityManagerFactoryReferenceDescriptors().iterator());
188
189         // post-construct
190
writePostConstructDescriptors(ejbNode, ejbDesc.getPostConstructDescriptors().iterator());
191
192         // pre-destroy
193
writePreDestroyDescriptors(ejbNode, ejbDesc.getPreDestroyDescriptors().iterator());
194
195         // security-identity
196
writeSecurityIdentityDescriptor(ejbNode, ejbDesc);
197         
198         return ejbNode;
199     }
200 }
201
Popular Tags