KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > DescriptorFactory


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;
25
26 import java.util.Map JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.logging.Level JavaDoc;
29
30 import com.sun.enterprise.deployment.Descriptor;
31 import com.sun.enterprise.deployment.xml.TagNames;
32 import com.sun.enterprise.deployment.xml.EjbTagNames;
33 import com.sun.enterprise.deployment.xml.ConnectorTagNames;
34 import com.sun.enterprise.deployment.xml.WebTagNames;
35 import com.sun.enterprise.deployment.xml.ApplicationClientTagNames;
36 import com.sun.enterprise.deployment.xml.ApplicationTagNames;
37 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
38 import com.sun.enterprise.deployment.xml.PersistenceTagNames;
39
40
41
42 // all registered descriptors
43
import com.sun.enterprise.deployment.Application;
44 import com.sun.enterprise.deployment.EjbBundleDescriptor;
45 import com.sun.enterprise.deployment.MethodPermissionDescriptor;
46 import com.sun.enterprise.deployment.EjbSessionDescriptor;
47 import com.sun.enterprise.deployment.EjbEntityDescriptor;
48 import com.sun.enterprise.deployment.EntityManagerReferenceDescriptor;
49 import com.sun.enterprise.deployment.EntityManagerFactoryReferenceDescriptor;
50 import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
51 import com.sun.enterprise.deployment.SecurityRoleDescriptor;
52 import com.sun.enterprise.deployment.ResourceReferenceDescriptor;
53 import com.sun.enterprise.deployment.FieldDescriptor;
54 import com.sun.enterprise.deployment.EjbReferenceDescriptor;
55 import com.sun.enterprise.deployment.MethodDescriptor;
56 import com.sun.enterprise.deployment.RunAsIdentityDescriptor;
57 import com.sun.enterprise.deployment.EnvironmentProperty;
58 import com.sun.enterprise.deployment.RoleReference;
59 import com.sun.enterprise.deployment.QueryDescriptor;
60 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor;
61 import com.sun.enterprise.deployment.MessageDestinationDescriptor;
62 import com.sun.enterprise.deployment.JmsDestinationReferenceDescriptor;
63 import com.sun.enterprise.deployment.RelationshipDescriptor;
64 import com.sun.enterprise.deployment.RelationRoleDescriptor;
65 import com.sun.enterprise.deployment.SecurityPermission;
66 import com.sun.enterprise.deployment.LicenseDescriptor;
67 import com.sun.enterprise.deployment.WebBundleDescriptor;
68 import com.sun.enterprise.deployment.WebComponentDescriptor;
69 import com.sun.enterprise.deployment.MimeMappingDescriptor;
70 import com.sun.enterprise.deployment.ConnectorDescriptor;
71 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
72 import com.sun.enterprise.deployment.AuthMechanism;
73 import com.sun.enterprise.deployment.EnvironmentProperty;
74 import com.sun.enterprise.deployment.MessageListener;
75 import com.sun.enterprise.deployment.OutboundResourceAdapter;
76 import com.sun.enterprise.deployment.InboundResourceAdapter;
77 import com.sun.enterprise.deployment.AdminObject;
78 import com.sun.enterprise.deployment.ApplicationClientDescriptor;
79 import com.sun.enterprise.deployment.SecurityConstraintImpl;
80 import com.sun.enterprise.deployment.UserDataConstraintImpl;
81 import com.sun.enterprise.deployment.AuthorizationConstraintImpl;
82 import com.sun.enterprise.deployment.WebResourceCollectionImpl;
83 import com.sun.enterprise.deployment.ServletFilterDescriptor;
84 import com.sun.enterprise.deployment.AppListenerDescriptorImpl;
85 import com.sun.enterprise.deployment.ServletFilterMappingDescriptor;
86 import com.sun.enterprise.deployment.ErrorPageDescriptorImpl;
87 import com.sun.enterprise.deployment.TagLibConfigurationDescriptor;
88 import com.sun.enterprise.deployment.LoginConfigurationImpl;
89 import com.sun.enterprise.deployment.MessageDestinationReferenceDescriptor;
90 import com.sun.enterprise.deployment.ActivationConfigDescriptor;
91 import com.sun.enterprise.deployment.LocaleEncodingMappingListDescriptor;
92 import com.sun.enterprise.deployment.LocaleEncodingMappingDescriptor;
93 import com.sun.enterprise.deployment.JspConfigDescriptor;
94 import com.sun.enterprise.deployment.JspGroupDescriptor;
95 import com.sun.enterprise.deployment.util.ModuleDescriptor;
96 import com.sun.enterprise.deployment.EjbInterceptor;
97 import com.sun.enterprise.deployment.EjbRemovalInfo;
98 import com.sun.enterprise.deployment.EjbApplicationExceptionInfo;
99 import com.sun.enterprise.deployment.EjbInitInfo;
100 import com.sun.enterprise.deployment.InjectionTarget;
101 import com.sun.enterprise.deployment.InterceptorBindingDescriptor;
102
103 // Web services related classes
104
import com.sun.enterprise.deployment.WebService;
105 import com.sun.enterprise.deployment.WebServiceEndpoint;
106 import com.sun.enterprise.deployment.ServiceReferenceDescriptor;
107 import com.sun.enterprise.deployment.WebServiceHandler;
108 import com.sun.enterprise.deployment.xml.WebServicesTagNames;
109 import com.sun.enterprise.deployment.DeploymentExtensionDescriptor;
110
111 // JSR 220 Persistence related descriptor
112
import com.sun.enterprise.deployment.PersistenceUnitDescriptor;
113
114
115 import com.sun.enterprise.deployment.NameValuePairDescriptor;
116 import com.sun.enterprise.deployment.util.DOLUtils;
117
118 /**
119  * This class is responsible for instanciating Descriptor classes
120  *
121  * @author Jerome Dochez
122  * @version
123  */

124 public class DescriptorFactory {
125
126     static Map JavaDoc descriptorClasses;
127     
128     /** This is a factory object no need for DescriptorFactory instance */
129     protected DescriptorFactory() {
130     }
131
132     private static void initMapping() {
133         descriptorClasses = new HashMap JavaDoc();
134     
135         // common
136
register(new XMLElement(TagNames.DEPLOYMENT_EXTENSION), DeploymentExtensionDescriptor.class);
137         register(new XMLElement(TagNames.MESSAGE_DESTINATION), MessageDestinationDescriptor.class);
138         register(new XMLElement(TagNames.INJECTION_TARGET), InjectionTarget.class);
139         
140         // Application
141
register(new XMLElement(ApplicationTagNames.APPLICATION), Application.class);
142         register(new XMLElement(ApplicationTagNames.MODULE), ModuleDescriptor.class);
143         
144     //EJB
145
register(new XMLElement(EjbTagNames.EJB_BUNDLE_TAG), EjbBundleDescriptor.class);
146         register(new XMLElement(WebTagNames.WEB_BUNDLE), WebBundleDescriptor.class);
147         register(new XMLElement(EjbTagNames.SESSION), EjbSessionDescriptor.class);
148         register(new XMLElement(EjbTagNames.ENTITY), EjbEntityDescriptor.class);
149         register(new XMLElement(EjbTagNames.MESSAGE_DRIVEN), EjbMessageBeanDescriptor.class);
150         register(new XMLElement(EjbTagNames.ACTIVATION_CONFIG),
151                  ActivationConfigDescriptor.class);
152         register(new XMLElement(TagNames.EJB_REFERENCE), EjbReferenceDescriptor.class);
153         register(new XMLElement(TagNames.EJB_LOCAL_REFERENCE), EjbReferenceDescriptor.class);
154         register(new XMLElement(TagNames.ROLE), SecurityRoleDescriptor.class);
155         register(new XMLElement(EjbTagNames.EXCLUDE_LIST), MethodPermissionDescriptor.class);
156         register(new XMLElement(EjbTagNames.RESOURCE_REFERENCE), ResourceReferenceDescriptor.class);
157         register(new XMLElement(EjbTagNames.CMP_FIELD), FieldDescriptor.class);
158         register(new XMLElement(EjbTagNames.METHOD), MethodDescriptor.class);
159         register(new XMLElement(EjbTagNames.METHOD_PERMISSION), MethodPermissionDescriptor.class);
160         register(new XMLElement(EjbTagNames.RUNAS_SPECIFIED_IDENTITY), RunAsIdentityDescriptor.class);
161         register(new XMLElement(TagNames.ENVIRONMENT_PROPERTY), EnvironmentProperty.class);
162         register(new XMLElement(EjbTagNames.ROLE_REFERENCE), RoleReference.class);
163         register(new XMLElement(EjbTagNames.QUERY), QueryDescriptor.class);
164         register(new XMLElement(EjbTagNames.QUERY_METHOD), MethodDescriptor.class);
165         register(new XMLElement(RuntimeTagNames.JAVA_METHOD), MethodDescriptor.class);
166         register(new XMLElement(TagNames.RESOURCE_ENV_REFERENCE), JmsDestinationReferenceDescriptor.class);
167         register(new XMLElement(TagNames.MESSAGE_DESTINATION_REFERENCE), MessageDestinationReferenceDescriptor.class);
168         register(new XMLElement(EjbTagNames.EJB_RELATION), RelationshipDescriptor.class);
169         register(new XMLElement(EjbTagNames.EJB_RELATIONSHIP_ROLE), RelationRoleDescriptor.class);
170         register(new XMLElement(EjbTagNames.AROUND_INVOKE_METHOD), LifecycleCallbackDescriptor.class);
171        register(new XMLElement(TagNames.POST_CONSTRUCT), LifecycleCallbackDescriptor.class);
172        register(new XMLElement(TagNames.PRE_DESTROY), LifecycleCallbackDescriptor.class);
173        register(new XMLElement(EjbTagNames.POST_ACTIVATE_METHOD), LifecycleCallbackDescriptor.class);
174        register(new XMLElement(EjbTagNames.PRE_PASSIVATE_METHOD), LifecycleCallbackDescriptor.class);
175        register(new XMLElement(EjbTagNames.TIMEOUT_METHOD), MethodDescriptor.class);
176        register(new XMLElement(EjbTagNames.INIT_BEAN_METHOD), MethodDescriptor.class);
177        register(new XMLElement(EjbTagNames.INIT_CREATE_METHOD), MethodDescriptor.class);
178        register(new XMLElement(EjbTagNames.INIT_METHOD), EjbInitInfo.class);
179        register(new XMLElement(EjbTagNames.REMOVE_METHOD), EjbRemovalInfo.class);
180        register(new XMLElement(EjbTagNames.INTERCEPTOR), EjbInterceptor.class);
181        register(new XMLElement(EjbTagNames.INTERCEPTOR_BINDING),
182                 InterceptorBindingDescriptor.class);
183        register(new XMLElement(EjbTagNames.APPLICATION_EXCEPTION),
184                 EjbApplicationExceptionInfo.class);
185
186     //connector
187
register(new XMLElement(ConnectorTagNames.CONNECTOR), ConnectorDescriptor.class);
188     register(new XMLElement(ConnectorTagNames.OUTBOUND_RESOURCE_ADAPTER), OutboundResourceAdapter.class);
189     register(new XMLElement(ConnectorTagNames.INBOUND_RESOURCE_ADAPTER), InboundResourceAdapter.class);
190     register(new XMLElement(ConnectorTagNames.RESOURCE_ADAPTER), OutboundResourceAdapter.class);
191     register(new XMLElement(ConnectorTagNames.AUTH_MECHANISM), AuthMechanism.class);
192     register(new XMLElement(ConnectorTagNames.SECURITY_PERMISSION), SecurityPermission.class);
193     register(new XMLElement(ConnectorTagNames.LICENSE), LicenseDescriptor.class);
194     register(new XMLElement(ConnectorTagNames.CONFIG_PROPERTY), EnvironmentProperty.class);
195     register(new XMLElement(ConnectorTagNames.REQUIRED_CONFIG_PROP), EnvironmentProperty.class);
196     register(new XMLElement(ConnectorTagNames.MSG_LISTENER), MessageListener.class);
197     register(new XMLElement(ConnectorTagNames.ACTIVATION_SPEC),MessageListener.class);
198     register(new XMLElement(ConnectorTagNames.ADMIN_OBJECT), AdminObject.class);
199     register(new XMLElement(ConnectorTagNames.CONNECTION_DEFINITION), ConnectionDefDescriptor.class);
200
201     //appclient
202
register(new XMLElement(ApplicationClientTagNames.APPLICATION_CLIENT_TAG), ApplicationClientDescriptor.class);
203
204     //web stuff
205
register(new XMLElement(WebTagNames.WEB_BUNDLE), WebBundleDescriptor.class);
206         register(new XMLElement(WebTagNames.SERVLET), WebComponentDescriptor.class);
207         register(new XMLElement(WebTagNames.INIT_PARAM), EnvironmentProperty.class);
208         register(new XMLElement(WebTagNames.MIME_MAPPING), MimeMappingDescriptor.class);
209         register(new XMLElement(WebTagNames.CONTEXT_PARAM), EnvironmentProperty.class);
210         register(new XMLElement(WebTagNames.SECURITY_CONSTRAINT), SecurityConstraintImpl.class);
211         register(new XMLElement(WebTagNames.USERDATA_CONSTRAINT), UserDataConstraintImpl.class);
212         register(new XMLElement(WebTagNames.AUTH_CONSTRAINT), AuthorizationConstraintImpl.class);
213         register(new XMLElement(WebTagNames.WEB_RESOURCE_COLLECTION), WebResourceCollectionImpl.class);
214         register(new XMLElement(WebTagNames.LISTENER), AppListenerDescriptorImpl.class);
215         register(new XMLElement(WebTagNames.FILTER), ServletFilterDescriptor.class);
216         register(new XMLElement(WebTagNames.FILTER_MAPPING), ServletFilterMappingDescriptor.class);
217         register(new XMLElement(WebTagNames.ERROR_PAGE), ErrorPageDescriptorImpl.class);
218         register(new XMLElement(WebTagNames.LOGIN_CONFIG), LoginConfigurationImpl.class);
219         register(new XMLElement(WebTagNames.TAGLIB), TagLibConfigurationDescriptor.class);
220         register(new XMLElement(WebTagNames.JSPCONFIG), JspConfigDescriptor.class);
221         register(new XMLElement(WebTagNames.JSP_GROUP), JspGroupDescriptor.class);
222         register(new XMLElement(WebTagNames.LOCALE_ENCODING_MAPPING_LIST), LocaleEncodingMappingListDescriptor.class);
223         register(new XMLElement(WebTagNames.LOCALE_ENCODING_MAPPING), LocaleEncodingMappingDescriptor.class);
224
225         // JSR 109 integration
226
register(new XMLElement(WebServicesTagNames.SERVICE_REF), ServiceReferenceDescriptor.class);
227         register(new XMLElement(WebServicesTagNames.WEB_SERVICE), WebService.class);
228         register(new XMLElement(WebServicesTagNames.PORT_COMPONENT), com.sun.enterprise.deployment.WebServiceEndpoint.class);
229         register(new XMLElement(WebServicesTagNames.HANDLER),
230                  com.sun.enterprise.deployment.WebServiceHandler.class);
231         register(new XMLElement(WebServicesTagNames.HANDLER_CHAIN),
232                  com.sun.enterprise.deployment.WebServiceHandlerChain.class);
233         register(new XMLElement(WebServicesTagNames.PORT_INFO),
234                com.sun.enterprise.deployment.ServiceRefPortInfo.class);
235         register(new XMLElement(WebServicesTagNames.STUB_PROPERTY),
236                  NameValuePairDescriptor.class);
237         register(new XMLElement(WebServicesTagNames.CALL_PROPERTY),
238                  NameValuePairDescriptor.class);
239          
240         // persistence.xsd related entries (JSR 220)
241
// Note we do not register PersistenceUnitsDescriptor, because that
242
// is created by PersistenceDeploymentDescriptorFile.getRootXMLNode().
243
register(new XMLElement(PersistenceTagNames.PERSISTENCE_UNIT),
244                  PersistenceUnitDescriptor.class);
245         register(new XMLElement(TagNames.PERSISTENCE_CONTEXT_REF),
246                  EntityManagerReferenceDescriptor.class);
247         register(new XMLElement(TagNames.PERSISTENCE_UNIT_REF),
248                  EntityManagerFactoryReferenceDescriptor.class);
249     }
250     
251     /**
252      * register a new descriptor class handling a particular XPATH in the DTD.
253      *
254      * @param xmlPath absolute or relative XPath
255      * @param clazz the descriptor class to use
256      */

257     public static void register(XMLElement xmlPath, Class JavaDoc clazz) {
258         if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
259             DOLUtils.getDefaultLogger().fine("Register " + clazz + " to handle " + xmlPath.getQName());
260         }
261     descriptorClasses.put(xmlPath.getQName(), clazz);
262     }
263     
264     /**
265      * @return the descriptor tag for a particular XPath
266      */

267     public static Class JavaDoc getDescriptorClass(String JavaDoc xmlPath) {
268         String JavaDoc s = xmlPath;
269         do {
270             if (DOLUtils.getDefaultLogger().isLoggable(Level.FINER)) {
271                 DOLUtils.getDefaultLogger().finer("looking for " + xmlPath);
272             }
273             if (descriptorClasses.containsKey(xmlPath)) {
274                 return (Class JavaDoc) descriptorClasses.get(xmlPath);
275             }
276             if (xmlPath.indexOf('/')!=-1) {
277                 xmlPath = xmlPath.substring(xmlPath.indexOf('/')+1);
278             } else {
279                 xmlPath=null;
280             }
281         } while (xmlPath!=null);
282     if(DOLUtils.getDefaultLogger().isLoggable(Level.SEVERE)) {
283             DOLUtils.getDefaultLogger().log(Level.SEVERE, "enterprise.deployment.backend.invalidDescriptorMappingFailure",
284                 new Object JavaDoc[] {"No descriptor registered for " + s});
285     }
286         return null;
287     }
288     
289     /**
290      * @return a new instance of a registered descriptor class for the
291      * supplied XPath
292      */

293     public static Object JavaDoc getDescriptor(String JavaDoc xmlPath) {
294         
295         try {
296             Class JavaDoc c = getDescriptorClass(xmlPath);
297         if (c!=null) {
298                 return c.newInstance();
299             }
300         } catch (Throwable JavaDoc t) {
301             t.printStackTrace();
302         }
303         return null;
304     }
305             
306     static {
307         initMapping();
308     }
309 }
310
Popular Tags