KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
28 import java.util.logging.Level JavaDoc;
29
30 import com.sun.enterprise.deployment.Descriptor;
31 import com.sun.enterprise.deployment.node.DescriptorFactory;
32 import com.sun.enterprise.deployment.node.XMLElement;
33 import com.sun.enterprise.deployment.runtime.IASPersistenceManagerDescriptor;
34 import com.sun.enterprise.deployment.runtime.PersistenceManagerInUse;
35 import com.sun.enterprise.deployment.runtime.web.Servlet;
36 import com.sun.enterprise.deployment.util.DOLUtils;
37 import com.sun.enterprise.deployment.xml.RuntimeTagNames;
38
39 // all registered descriptors
40
import com.sun.enterprise.deployment.runtime.common.DefaultResourcePrincipal;
41 import com.sun.enterprise.deployment.runtime.common.EjbRef;
42 import com.sun.enterprise.deployment.runtime.common.PrincipalNameDescriptor;
43 import com.sun.enterprise.deployment.runtime.common.ResourceEnvRef;
44 import com.sun.enterprise.deployment.runtime.common.ResourceRef;
45 import com.sun.enterprise.deployment.runtime.common.SecurityRoleMapping;
46 import com.sun.enterprise.deployment.runtime.connector.MapElement;
47 import com.sun.enterprise.deployment.runtime.connector.Principal;
48 import com.sun.enterprise.deployment.runtime.connector.ResourceAdapter;
49 import com.sun.enterprise.deployment.runtime.connector.RoleMap;
50 import com.sun.enterprise.deployment.runtime.web.Cache;
51 import com.sun.enterprise.deployment.runtime.web.CacheHelper;
52 import com.sun.enterprise.deployment.runtime.web.CacheMapping;
53 import com.sun.enterprise.deployment.runtime.web.ClassLoader;
54 import com.sun.enterprise.deployment.runtime.web.ConstraintField;
55 import com.sun.enterprise.deployment.runtime.web.CookieProperties;
56 import com.sun.enterprise.deployment.runtime.web.DefaultHelper;
57 import com.sun.enterprise.deployment.runtime.web.JspConfig;
58 import com.sun.enterprise.deployment.runtime.web.LocaleCharsetInfo;
59 import com.sun.enterprise.deployment.runtime.web.LocaleCharsetMap;
60 import com.sun.enterprise.deployment.runtime.web.ManagerProperties;
61 import com.sun.enterprise.deployment.runtime.web.SessionConfig;
62 import com.sun.enterprise.deployment.runtime.web.SessionManager;
63 import com.sun.enterprise.deployment.runtime.web.SessionProperties;
64 import com.sun.enterprise.deployment.runtime.web.StoreProperties;
65 import com.sun.enterprise.deployment.runtime.web.WebProperty;
66 import com.sun.enterprise.deployment.runtime.web.WebProperty;
67
68 /**
69  * This class is responsible for instanciating runtime Descriptor classes
70  *
71  * @author Jerome Dochez
72  * @version
73  */

74 public class RuntimeDescriptorFactory {
75
76     
77     static Map JavaDoc descriptorClasses;
78     
79     /** This is a factory object no need for DescriptorFactory instance */
80     protected RuntimeDescriptorFactory() {
81     }
82
83     private static void initMapping() {
84         descriptorClasses = new HashMap JavaDoc();
85     
86     // WEB
87
register(new XMLElement(RuntimeTagNames.PROPERTY), WebProperty.class);
88     register(new XMLElement(RuntimeTagNames.COOKIE_PROPERTIES), CookieProperties.class);
89     register(new XMLElement(RuntimeTagNames.LOCALE_CHARSET_MAP), LocaleCharsetMap.class);
90     register(new XMLElement(RuntimeTagNames.LOCALE_CHARSET_INFO), LocaleCharsetInfo.class);
91     register(new XMLElement(RuntimeTagNames.MANAGER_PROPERTIES), ManagerProperties.class);
92     register(new XMLElement(RuntimeTagNames.SERVLET), Servlet.class);
93     register(new XMLElement(RuntimeTagNames.SESSION_CONFIG), SessionConfig.class);
94     register(new XMLElement(RuntimeTagNames.SESSION_MANAGER), SessionManager.class);
95     register(new XMLElement(RuntimeTagNames.JSP_CONFIG), JspConfig.class);
96     register(new XMLElement(RuntimeTagNames.CACHE_MAPPING), CacheMapping.class);
97     register(new XMLElement(RuntimeTagNames.CACHE_HELPER), CacheHelper.class);
98     register(new XMLElement(RuntimeTagNames.CACHE), Cache.class);
99     register(new XMLElement(RuntimeTagNames.CLASS_LOADER), ClassLoader JavaDoc.class);
100     register(new XMLElement(RuntimeTagNames.STORE_PROPERTIES), StoreProperties.class);
101     register(new XMLElement(RuntimeTagNames.SESSION_PROPERTIES), SessionProperties.class);
102     register(new XMLElement(RuntimeTagNames.DEFAULT_HELPER), DefaultHelper.class);
103     register(new XMLElement(RuntimeTagNames.EJB_REF), EjbRef.class);
104         register(new XMLElement(RuntimeTagNames.RESOURCE_REF), ResourceRef.class);
105         register(new XMLElement(RuntimeTagNames.RESOURCE_ENV_REF), ResourceEnvRef.class);
106         register(new XMLElement(RuntimeTagNames.DEFAULT_RESOURCE_PRINCIPAL), DefaultResourcePrincipal.class);
107         register(new XMLElement(RuntimeTagNames.CONSTRAINT_FIELD), ConstraintField.class);
108         
109         // EJB
110
register(new XMLElement(RuntimeTagNames.PM_DESCRIPTOR), IASPersistenceManagerDescriptor.class);
111         register(new XMLElement(RuntimeTagNames.PM_INUSE), PersistenceManagerInUse.class);
112         
113     // connector related
114
register(new XMLElement(RuntimeTagNames.PRINCIPAL), Principal.class);
115     register(new XMLElement(RuntimeTagNames.BACKEND_PRINCIPAL), Principal.class);
116     register(new XMLElement(RuntimeTagNames.MAP_ELEMENT), MapElement.class);
117     register(new XMLElement(RuntimeTagNames.ROLE_MAP), RoleMap.class);
118     register(new XMLElement(RuntimeTagNames.RESOURCE_ADAPTER), ResourceAdapter.class);
119
120         //common
121
register(new XMLElement(RuntimeTagNames.PRINCIPAL_NAME), PrincipalNameDescriptor.class);
122         register(new XMLElement(RuntimeTagNames.SECURITY_ROLE_MAPPING), SecurityRoleMapping.class);
123      }
124     /**
125      * register a new descriptor class handling a particular XPATH in the DTD.
126      *
127      * @param xmlPath absolute or relative XPath
128      * @param clazz the descriptor class to use
129      */

130     public static void register(XMLElement xmlPath, Class JavaDoc clazz) {
131         if (DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
132             DOLUtils.getDefaultLogger().fine("Register " + clazz + " to handle " + xmlPath.getQName());
133         }
134     descriptorClasses.put(xmlPath.getQName(), clazz);
135     }
136     
137     /**
138      * @return the descriptor tag for a particular XPath
139      */

140     public static Class JavaDoc getDescriptorClass(String JavaDoc xmlPath) {
141         String JavaDoc s = xmlPath;
142         do {
143             if (DOLUtils.getDefaultLogger().isLoggable(Level.FINER)) {
144                 DOLUtils.getDefaultLogger().finer("looking for " + xmlPath + " in " + descriptorClasses);
145             }
146             if (descriptorClasses.containsKey(xmlPath)) {
147                 return (Class JavaDoc) descriptorClasses.get(xmlPath);
148             }
149             if (xmlPath.indexOf('/')!=-1) {
150                 xmlPath = xmlPath.substring(xmlPath.indexOf('/')+1);
151             } else {
152                 xmlPath=null;
153             }
154         } while (xmlPath!=null);
155
156     if(DOLUtils.getDefaultLogger().isLoggable(Level.FINE)) {
157             DOLUtils.getDefaultLogger().fine("No descriptor registered for " + s);
158     }
159         return null;
160     }
161     
162     /**
163      * @return a new instance of a registered descriptor class for the
164      * supplied XPath
165      */

166     public static Object JavaDoc getDescriptor(String JavaDoc xmlPath) {
167         
168         try {
169             Class JavaDoc c = getDescriptorClass(xmlPath);
170         if (c!=null) {
171                 return c.newInstance();
172             }
173         } catch (Throwable JavaDoc t) {
174             t.printStackTrace();
175         }
176         return null;
177     }
178             
179     static {
180         initMapping();
181     }
182 }
183
Popular Tags