KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > appclient > AppClientNode


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

24
25 package com.sun.enterprise.deployment.node.appclient;
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30 import org.w3c.dom.Node JavaDoc;
31
32 import com.sun.enterprise.deployment.types.EjbReference;
33
34 import com.sun.enterprise.deployment.EnvironmentProperty;
35 import com.sun.enterprise.deployment.Descriptor;
36 import com.sun.enterprise.deployment.ApplicationClientDescriptor;
37 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
38 import com.sun.enterprise.deployment.EntityManagerReferenceDescriptor;
39 import com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor;
40 import com.sun.enterprise.deployment.JmsDestinationReferenceDescriptor;
41 import com.sun.enterprise.deployment.RunAsIdentityDescriptor;
42 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
43 import com.sun.enterprise.deployment.xml.TagNames;
44 import com.sun.enterprise.deployment.xml.EjbTagNames;
45 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
46 import com.sun.enterprise.deployment.xml.ApplicationClientTagNames;
47
48 import com.sun.enterprise.deployment.node.DescriptorFactory;
49 import com.sun.enterprise.deployment.node.BundleNode;
50 import com.sun.enterprise.deployment.node.XMLElement;
51 import com.sun.enterprise.deployment.node.RootXMLNode;
52 import com.sun.enterprise.deployment.node.XMLNode;
53 import com.sun.enterprise.deployment.node.EjbReferenceNode;
54 import com.sun.enterprise.deployment.node.EjbLocalReferenceNode;
55 import com.sun.enterprise.deployment.node.ResourceRefNode;
56 import com.sun.enterprise.deployment.node.EnvEntryNode;
57 import com.sun.enterprise.deployment.node.ResourceEnvRefNode;
58 import com.sun.enterprise.deployment.node.MessageDestinationRefNode;
59 import com.sun.enterprise.deployment.node.EntityManagerReferenceNode;
60 import com.sun.enterprise.deployment.node.EntityManagerFactoryReferenceNode;
61 import com.sun.enterprise.deployment.node.ServiceReferenceNode;
62 import com.sun.enterprise.deployment.node.MessageDestinationNode;
63 import com.sun.enterprise.deployment.node.LifecycleCallbackNode;
64
65 import com.sun.enterprise.deployment.util.DOLUtils;
66
67 /**
68  * This class is responsible for handling app clients
69  *
70  * @author Sheetal Vartak
71  * @version
72  */

73 public class AppClientNode extends BundleNode implements RootXMLNode {
74
75      // Descriptor class we are using
76
private ApplicationClientDescriptor descriptor;
77
78     //app client 1.2
79
public final static String JavaDoc PUBLIC_DTD_ID_12 = "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.2//EN";
80     public final static String JavaDoc SYSTEM_ID_12 = "http://java.sun.com/dtd/application-client_1_2.dtd";
81     
82     //app client 1.3
83
public final static String JavaDoc PUBLIC_DTD_ID = "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN";
84     public final static String JavaDoc SYSTEM_ID = "http://java.sun.com/dtd/application-client_1_3.dtd";
85     
86     public final static String JavaDoc SCHEMA_ID_14 = "application-client_1_4.xsd";
87     
88     public final static String JavaDoc SCHEMA_ID = "application-client_5.xsd";
89     public final static String JavaDoc SPEC_VERSION = "5";
90     private static List JavaDoc<String JavaDoc> systemIDs = null;
91  
92     public final static XMLElement tag = new XMLElement(ApplicationClientTagNames.APPLICATION_CLIENT_TAG);
93
94     /** Creates new AppClientNode */
95     public AppClientNode() {
96     registerElementHandler(new XMLElement(TagNames.ENVIRONMENT_PROPERTY),
97                                                              EnvEntryNode.class, "addEnvironmentProperty");
98         registerElementHandler(new XMLElement(EjbTagNames.EJB_REFERENCE), EjbReferenceNode.class);
99         registerElementHandler(new XMLElement(EjbTagNames.EJB_LOCAL_REFERENCE), EjbLocalReferenceNode.class);
100         registerElementHandler(new XMLElement(WebServicesTagNames.SERVICE_REF), ServiceReferenceNode.class, "addServiceReferenceDescriptor");
101         registerElementHandler(new XMLElement(EjbTagNames.RESOURCE_REFERENCE),
102                                                              ResourceRefNode.class, "addResourceReferenceDescriptor");
103     registerElementHandler(new XMLElement(TagNames.RESOURCE_ENV_REFERENCE),
104                                                             ResourceEnvRefNode.class, "addJmsDestinationReferenceDescriptor");
105         registerElementHandler(new XMLElement(TagNames.MESSAGE_DESTINATION_REFERENCE), MessageDestinationRefNode.class, "addMessageDestinationReferenceDescriptor");
106         registerElementHandler(new XMLElement(TagNames.PERSISTENCE_UNIT_REF), EntityManagerFactoryReferenceNode.class, "addEntityManagerFactoryReferenceDescriptor");
107         registerElementHandler(new XMLElement(TagNames.MESSAGE_DESTINATION),
108                                MessageDestinationNode.class,
109                                "addMessageDestination");
110         registerElementHandler(new XMLElement(TagNames.POST_CONSTRUCT), LifecycleCallbackNode.class, "addPostConstructDescriptor");
111         registerElementHandler(new XMLElement(TagNames.PRE_DESTROY), LifecycleCallbackNode.class, "addPreDestroyDescriptor");
112     }
113
114     /**
115      * register this node as a root node capable of loading entire DD files
116      *
117      * @param publicIDToDTD is a mapping between xml Public-ID to DTD
118      * @return the doctype tag name
119      */

120     public static String JavaDoc registerBundle(Map JavaDoc publicIDToDTD) {
121         publicIDToDTD.put(PUBLIC_DTD_ID, SYSTEM_ID);
122         publicIDToDTD.put(PUBLIC_DTD_ID_12, SYSTEM_ID_12);
123         return tag.getQName();
124    }
125
126     /**
127      * Adds a new DOL descriptor instance to the descriptor instance associated with
128      * this XMLNode
129      *
130      * @param descriptor the new descriptor
131      */

132     public void addDescriptor(Object JavaDoc newDescriptor) {
133         if (newDescriptor instanceof EjbReference) {
134             DOLUtils.getDefaultLogger().fine("Adding ejb ref " + newDescriptor);
135             ((ApplicationClientDescriptor)getDescriptor()).addEjbReferenceDescriptor(
136                         (EjbReference) newDescriptor);
137         } else {
138             super.addDescriptor(newDescriptor);
139         }
140     }
141     
142     public Object JavaDoc getDescriptor() {
143         if (descriptor == null) {
144             descriptor = (ApplicationClientDescriptor) DescriptorFactory.getDescriptor(getXMLPath());
145         }
146         return descriptor;
147     }
148     
149     /**
150      * all sub-implementation of this class can use a dispatch table to map xml element to
151      * method name on the descriptor class for setting the element value.
152      *
153      * @return the map with the element name as a key, the setter method as a value
154      */

155     protected Map JavaDoc getDispatchTable() {
156         // no need to be synchronized for now
157
Map JavaDoc table = super.getDispatchTable();
158     table.put(ApplicationClientTagNames.CALLBACK_HANDLER, "setCallbackHandler");
159         return table;
160     }
161         
162     /**
163      * @return the XML tag associated with this XMLNode
164      */

165     protected XMLElement getXMLRootTag() {
166         return tag;
167     }
168
169      /**
170      * @return the DOCTYPE of the XML file
171      */

172     public String JavaDoc getDocType() {
173         return null;
174     }
175     
176     /**
177      * @return the SystemID of the XML file
178      */

179     public String JavaDoc getSystemID() {
180         return SCHEMA_ID;
181     }
182
183     /**
184      * @return the list of SystemID of the XML schema supported
185      */

186     public List JavaDoc<String JavaDoc> getSystemIDs() {
187         if (systemIDs != null) {
188             return systemIDs;
189         }
190
191         systemIDs = new ArrayList JavaDoc<String JavaDoc>();
192         systemIDs.add(SCHEMA_ID);
193         systemIDs.add(SCHEMA_ID_14);
194         return systemIDs;
195     }
196
197
198     /**
199      * write the descriptor class to a DOM tree and return it
200      *
201      * @param parent node for the DOM tree
202      * @param the descriptor to write
203      * @return the DOM tree top node
204      */

205     public Node JavaDoc writeDescriptor(Node JavaDoc parent, Descriptor descriptor) {
206
207         if (! (descriptor instanceof ApplicationClientDescriptor)) {
208             throw new IllegalArgumentException JavaDoc(getClass() + " cannot handle descriptors of type " + descriptor.getClass());
209         }
210         ApplicationClientDescriptor appclientDesc = (ApplicationClientDescriptor) descriptor;
211         Node JavaDoc appclientNode = super.writeDescriptor(parent, appclientDesc);
212
213     // env-entry*
214
writeEnvEntryDescriptors(appclientNode, appclientDesc.getEnvironmentProperties().iterator());
215         
216         // ejb-ref * and ejb-local-ref*
217
writeEjbReferenceDescriptors(appclientNode, appclientDesc.getEjbReferenceDescriptors().iterator());
218
219         // service-ref*
220
writeServiceReferenceDescriptors(appclientNode, appclientDesc.getServiceReferenceDescriptors().iterator());
221
222         // resource-ref*
223
writeResourceRefDescriptors(appclientNode, appclientDesc.getResourceReferenceDescriptors().iterator());
224         
225         // resource-env-ref*
226
writeResourceEnvRefDescriptors(appclientNode, appclientDesc.getJmsDestinationReferenceDescriptors().iterator());
227
228         // message-destination-ref*
229
writeMessageDestinationRefDescriptors(appclientNode, appclientDesc.getMessageDestinationReferenceDescriptors().iterator());
230
231         // persistence-unit-ref*
232
writeEntityManagerFactoryReferenceDescriptors(appclientNode, appclientDesc.getEntityManagerFactoryReferenceDescriptors().iterator());
233
234         // post-construct
235
writePostConstructDescriptors(appclientNode, appclientDesc.getPostConstructDescriptors().iterator());
236         
237         // pre-destroy
238
writePreDestroyDescriptors(appclientNode, appclientDesc.getPreDestroyDescriptors().iterator());
239         
240         appendTextChild(appclientNode, ApplicationClientTagNames.CALLBACK_HANDLER, appclientDesc.getCallbackHandler());
241
242          // message-destination*
243
writeMessageDestinations
244            (appclientNode, appclientDesc.getMessageDestinations().iterator());
245         
246     return appclientNode;
247               
248     }
249     
250     /**
251      * @return the default spec version level this node complies to
252      */

253     public String JavaDoc getSpecVersion() {
254         return SPEC_VERSION;
255     }
256     
257 }
258
Popular Tags