KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > util > NodeTypes


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.sun.util;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.logging.Logger JavaDoc;
23 import java.util.logging.Level JavaDoc;
24
25 import com.sun.appserv.management.config.AdminObjectResourceConfig;
26 import com.sun.appserv.management.config.AppClientModuleConfig;
27 import com.sun.appserv.management.config.ConnectorConnectionPoolConfig;
28 import com.sun.appserv.management.config.ConnectorResourceConfig;
29 import com.sun.appserv.management.config.CustomResourceConfig;
30 import com.sun.appserv.management.config.EJBModuleConfig;
31 import com.sun.appserv.management.config.J2EEApplicationConfig;
32 import com.sun.appserv.management.config.JDBCConnectionPoolConfig;
33 import com.sun.appserv.management.config.JDBCResourceConfig;
34 import com.sun.appserv.management.config.JNDIResourceConfig;
35 import com.sun.appserv.management.config.JavaConfig;
36 import com.sun.appserv.management.config.MailResourceConfig;
37 import com.sun.appserv.management.config.PersistenceManagerFactoryResourceConfig;
38 import com.sun.appserv.management.config.RARModuleConfig;
39 import com.sun.appserv.management.config.ResourceAdapterConfig;
40 import com.sun.appserv.management.config.WebModuleConfig;
41
42 import com.sun.appserv.management.j2ee.AppClientModule;
43 import com.sun.appserv.management.j2ee.EJBModule;
44 import com.sun.appserv.management.j2ee.EntityBean;
45 import com.sun.appserv.management.j2ee.J2EEApplication;
46 import com.sun.appserv.management.j2ee.MessageDrivenBean;
47 import com.sun.appserv.management.j2ee.ResourceAdapter;
48 import com.sun.appserv.management.j2ee.ResourceAdapterModule;
49 import com.sun.appserv.management.j2ee.Servlet;
50 import com.sun.appserv.management.j2ee.StatefulSessionBean;
51 import com.sun.appserv.management.j2ee.StatelessSessionBean;
52 import com.sun.appserv.management.j2ee.WebModule;
53
54
55
56
57
58 /**
59  *
60  *
61  */

62 public class NodeTypes {
63     
64     private static Logger JavaDoc logger;
65     private static HashMap JavaDoc nodeHierarchy;
66     private static HashMap JavaDoc nodeToInterfaceMap;
67     private static HashMap JavaDoc nodeToConfigPeerInterfaceMap;
68     private static HashMap JavaDoc deleteResOpNameMapper;
69     
70     public static final String JavaDoc ENABLED = "Enabled";
71     
72     //Container Nodes
73
public static final String JavaDoc DOMAIN = "ROOT";
74     public static final String JavaDoc APPLICATIONS = "APPLICATIONS";
75     public static final String JavaDoc RESOURCES = "RESOURCES";
76     public static final String JavaDoc RESOURCES90 = "RESOURCES90";
77     public static final String JavaDoc ENTERPRISE_APPLICATIONS = "ENTERPRISE_APPS";
78     public static final String JavaDoc ENTERPRISE_APPLICATION = "ENTERPRISE_APP";
79     public static final String JavaDoc WEB_APPLICATIONS = "WEB_APPS";
80     public static final String JavaDoc WEB_MODULE = "WEB_APP";
81     public static final String JavaDoc EJB_MODULES = "EJB_MODULES";
82     public static final String JavaDoc EJB_MODULE = "EJB_MODULE";
83     public static final String JavaDoc CONNECTOR_MODULES = "CONNECTOR_MODULES";
84     public static final String JavaDoc CONNECTOR_MODULE = "CONNECTOR_MODULE";
85     public static final String JavaDoc APP_CLIENT_MODULES = "APPCLIENTS";
86     
87     public static final String JavaDoc JDBC = "JDBC";
88     public static final String JavaDoc JDBC_RESOURCES = "JDBC_RESOURCES";
89     public static final String JavaDoc CONNECTION_POOLS = "CONNECTION_POOLS";
90     public static final String JavaDoc PERSISTENCE_MANAGER_RESOURCES = "PM_RESOURCES";
91     public static final String JavaDoc JMS_RESOURCES = "JMS_RESOURCES";
92     public static final String JavaDoc CONNECTION_FACTORIES = "CONNECTION_FACTORIES";
93     public static final String JavaDoc DESTINATION_RESOURCES = "DESTINATION_RESOURCES";
94     public static final String JavaDoc MAIL_RESOURCES = "MAIL_RESOURCES";
95     public static final String JavaDoc JNDI = "JNDI";
96     public static final String JavaDoc CUSTOM_RESOURCES = "CUSTOM_RESOURCES";
97     public static final String JavaDoc EXTERNAL_RESOURCES = "EXTERNAL_RESOURCES";
98     public static final String JavaDoc CONNECTORS = "CONNECTORS";
99     public static final String JavaDoc CONNECTOR_RESOURCES = "CONNECTOR_RESOURCES";
100     public static final String JavaDoc CONNECTOR_CONNECTION_POOLS = "CONNECTOR_CONNECTION_POOLS";
101     public static final String JavaDoc ADMIN_OBJECT_RESOURCES = "ADMIN_OBJECT_RESOURCES";
102   
103
104     
105     //Leaf Nodes
106
public static final String JavaDoc CLUSTER = "CLUSTER";
107     public static final String JavaDoc STANDALONE_INSTANCE = "STANDALONE_INSTANCE";
108     public static final String JavaDoc JDBC_RESOURCE = "JDBC_RESOURCE";
109     public static final String JavaDoc CONNECTION_FACTORY = "CONNECTION_FACTORY";
110     public static final String JavaDoc CONNECTION_POOL = "CONNECTION_POOL";
111     public static final String JavaDoc DESTINATION_RESOURCE = "DESTINATION_RESOURCE";
112     public static final String JavaDoc CUSTOM_RESOURCE = "CUSTOM_RESOURCE";
113     public static final String JavaDoc EXTERNAL_RESOURCE = "EXTERNAL_RESOURCE";
114     public static final String JavaDoc CONNECTOR_RESOURCE = "CONNECTOR_RESOURCE";
115     public static final String JavaDoc CONNECTOR_CONNECTION_POOL = "CONNECTOR_CONNECTION_POOL";
116     public static final String JavaDoc MAIL_RESOURCE = "MAIL_RESOURCE";
117     public static final String JavaDoc PM_RESOURCE = "PM_RESOURCE";
118     public static final String JavaDoc ADMIN_OBJECT_RESOURCE = "ADMIN_OBJECT_RESOURCE";
119     public static final String JavaDoc JVM = "JVM";
120     public static final String JavaDoc SERVLET = "SERVLET";
121     public static final String JavaDoc EJB = "EJB";
122     public static final String JavaDoc STATELESS_SESSION_BEAN = "STATELESS_BEAN";
123     public static final String JavaDoc STATEFUL_SESSION_BEAN = "STATEFUL_BEAN";
124     public static final String JavaDoc MESSAGE_DRIVEN_BEAN = "MESSAGE_DRIVEN_BEAN";
125     public static final String JavaDoc ENTITY_BEAN = "ENTITY_BEAN";
126     public static final String JavaDoc APP_CLIENT_MODULE = "APPCLIENT";
127     public static final String JavaDoc RESOURCE_ADAPTER = "RESOURCE_ADAPTER";
128     
129     
130     //configs
131
public static final String JavaDoc EJB_MODULE_CONFIG = "EJB_MODULE_CONFIG";
132     public static final String JavaDoc CONNECTOR_MODULE_CONFIG = "CONNECTOR_MODULE_CONFIG";
133     public static final String JavaDoc RESOURCE_ADAPTER_CONFIG = "RESOURCE_ADAPTER_CONFIG";
134     public static final String JavaDoc APP_CLIENT_MODULE_CONFIG = "APP_CLIENT_MODULE_CONFIG";
135     public static final String JavaDoc WEB_MODULE_CONFIG = "WEB_MODULE_CONFIG";
136     public static final String JavaDoc SERVLET_CONFIG = "SERVLET_CONFIG";
137
138     //Property Editor values
139
public static final String JavaDoc[] ENTERPRISE_APPLICATION_NODE = {
140        "ObjectType", "server", "modules", "Properties","PropertyNames" };
141     public static final String JavaDoc[] WEB_MODULE_NODE = {
142        "AvailabilityEnabled", "ContextRoot", "deploymentDescriptor", "Description", "DirectoryDeployed", "Enabled", "HasWebServices", "Location", "Name", "WelcomeFiles" };
143     public static final String JavaDoc[] EJB_MODULE_NODE = {
144        "ObjectType", "server", "ejbs", "Properties","PropertyNames" };
145     public static final String JavaDoc[] CONNECTOR_MODULE_NODE = {
146        "ObjectType", "server", "resourceAdapters", "Properties","PropertyNames" };
147     public static final String JavaDoc[] APP_CLIENT_MODULES_NODE = {
148        "server" };
149     public static final String JavaDoc[] JVM_NODE = {
150        "Name", "Properties", "PropertyNames" };
151     public static final String JavaDoc[] SERVER_RESOURCE_NODES = {
152        "ObjectType", "PropertyNames" };
153        
154     //Child definitions
155
// private static final String[] DOMAIN_CHILD_TYPES = {
156
// APPLICATIONS, RESOURCES, JVM };
157
private static final String JavaDoc[] APPLICATIONS_CHILD_TYPES = {
158         ENTERPRISE_APPLICATIONS, WEB_APPLICATIONS, EJB_MODULES,
159         CONNECTOR_MODULES, APP_CLIENT_MODULES };
160     private static final String JavaDoc[] RESOURCES_CHILD_TYPES = {
161         JDBC, PERSISTENCE_MANAGER_RESOURCES, JMS_RESOURCES,
162         MAIL_RESOURCES ,JNDI, CONNECTORS
163     };
164     private static final String JavaDoc[] RESOURCES90_CHILD_TYPES = {
165         JDBC, JMS_RESOURCES, MAIL_RESOURCES ,JNDI, CONNECTORS
166     };
167     private static final String JavaDoc[] JDBC_CHILD_TYPES = {
168         JDBC_RESOURCES, CONNECTION_POOLS };
169     private static final String JavaDoc[] JMS_RESOURCES_CHILD_TYPES = {
170         CONNECTION_FACTORIES, DESTINATION_RESOURCES };
171     private static final String JavaDoc[] JNDI_CHILD_TYPES = {
172         CUSTOM_RESOURCES, EXTERNAL_RESOURCES };
173     private static final String JavaDoc[] CONNECTORS_CHILD_TYPES = {
174         CONNECTOR_RESOURCES, CONNECTOR_CONNECTION_POOLS,
175         ADMIN_OBJECT_RESOURCES };
176
177
178
179         
180     static {
181         
182         //initialize logging
183
logger = Logger.getLogger("org.netbeans.modules.j2ee.sun");
184         
185         nodeHierarchy = new HashMap JavaDoc();
186 // nodeHierarchy.put(DOMAIN, DOMAIN_CHILD_TYPES);
187
nodeHierarchy.put(APPLICATIONS, APPLICATIONS_CHILD_TYPES);
188         nodeHierarchy.put(RESOURCES, RESOURCES_CHILD_TYPES);
189         nodeHierarchy.put(RESOURCES90, RESOURCES90_CHILD_TYPES);
190         nodeHierarchy.put(JDBC, JDBC_CHILD_TYPES);
191         nodeHierarchy.put(JMS_RESOURCES, JMS_RESOURCES_CHILD_TYPES);
192         nodeHierarchy.put(JNDI, JNDI_CHILD_TYPES);
193         nodeHierarchy.put(CONNECTORS, CONNECTORS_CHILD_TYPES);
194         
195         nodeToInterfaceMap = new HashMap JavaDoc();
196         nodeToInterfaceMap.put(JDBC_RESOURCE, JDBCResourceConfig.class);
197         nodeToInterfaceMap.put(PM_RESOURCE, PersistenceManagerFactoryResourceConfig.class);
198         nodeToInterfaceMap.put(MAIL_RESOURCE, MailResourceConfig.class);
199         nodeToInterfaceMap.put(CONNECTOR_RESOURCE, ConnectorResourceConfig.class);
200         nodeToInterfaceMap.put(ADMIN_OBJECT_RESOURCE, AdminObjectResourceConfig.class);
201 // nodeToInterfaceMap.put(CONNECTION_FACTORY, JMSResourceConfig.class);
202
nodeToInterfaceMap.put(CONNECTION_POOL, JDBCConnectionPoolConfig.class);
203         nodeToInterfaceMap.put(CUSTOM_RESOURCE, CustomResourceConfig.class);
204         nodeToInterfaceMap.put(CONNECTOR_RESOURCE, ConnectorResourceConfig.class);
205         nodeToInterfaceMap.put(EXTERNAL_RESOURCE, JNDIResourceConfig.class);
206         nodeToInterfaceMap.put(CONNECTOR_CONNECTION_POOL, ConnectorConnectionPoolConfig.class);
207         nodeToInterfaceMap.put(JVM, JavaConfig.class);
208         nodeToInterfaceMap.put(SERVLET, Servlet.class);
209         nodeToInterfaceMap.put(EJB_MODULE, EJBModule.class);
210         nodeToInterfaceMap.put(CONNECTOR_MODULE, ResourceAdapterModule.class);
211         nodeToInterfaceMap.put(WEB_MODULE, WebModule.class);
212         nodeToInterfaceMap.put(ENTERPRISE_APPLICATION, J2EEApplication.class);
213         nodeToInterfaceMap.put(CONNECTION_FACTORY, ConnectorResourceConfig.class);
214         nodeToInterfaceMap.put(DESTINATION_RESOURCE, AdminObjectResourceConfig.class);
215         nodeToInterfaceMap.put(STATELESS_SESSION_BEAN, StatelessSessionBean.class);
216         nodeToInterfaceMap.put(STATEFUL_SESSION_BEAN, StatefulSessionBean.class);
217         nodeToInterfaceMap.put(MESSAGE_DRIVEN_BEAN, MessageDrivenBean.class);
218         nodeToInterfaceMap.put(ENTITY_BEAN, EntityBean.class);
219         nodeToInterfaceMap.put(APP_CLIENT_MODULE, AppClientModule.class);
220         nodeToInterfaceMap.put(RESOURCE_ADAPTER, ResourceAdapter.class);
221 // nodeToInterfaceMap.put(JBI, ResourceAdapter.class);
222
// nodeToInterfaceMap.put(SERVICE_ENGINES, ResourceAdapter.class);
223
// nodeToInterfaceMap.put(BINDING_COMPONENTS, ResourceAdapter.class);
224
// nodeToInterfaceMap.put(SHARED_LIBRARIES, ResourceAdapter.class);
225
// nodeToInterfaceMap.put(SERVICE_ASSEMBLIES, ResourceAdapter.class);
226

227         
228         //constructed nodeType to config peer interface map
229
nodeToConfigPeerInterfaceMap = new HashMap JavaDoc();
230         nodeToConfigPeerInterfaceMap.put(APP_CLIENT_MODULE, AppClientModuleConfig.class);
231         nodeToConfigPeerInterfaceMap.put(EJB_MODULE, EJBModuleConfig.class);
232         nodeToConfigPeerInterfaceMap.put(CONNECTOR_MODULE, RARModuleConfig.class);
233         nodeToConfigPeerInterfaceMap.put(WEB_MODULE, WebModuleConfig.class);
234         nodeToConfigPeerInterfaceMap.put(RESOURCE_ADAPTER, ResourceAdapterConfig.class);
235         nodeToConfigPeerInterfaceMap.put(APP_CLIENT_MODULE, AppClientModuleConfig.class);
236         nodeToConfigPeerInterfaceMap.put(ENTERPRISE_APPLICATION, J2EEApplicationConfig.class);
237         
238         //mapping of resource to delete method on resources mbean = WORKAROUND
239
deleteResOpNameMapper = new HashMap JavaDoc();
240         deleteResOpNameMapper.put(JDBC_RESOURCE,
241                 "deleteJdbcResource");
242         deleteResOpNameMapper.put(PM_RESOURCE,
243                 "deletePersistenceManagerFactoryResource");
244         deleteResOpNameMapper.put(MAIL_RESOURCE,
245                 "deleteMailResource");
246         deleteResOpNameMapper.put(CONNECTOR_RESOURCE,
247                 "deleteConnectorResource");
248         deleteResOpNameMapper.put(ADMIN_OBJECT_RESOURCE,
249                 "deleteAdminObjectResource");
250         deleteResOpNameMapper.put(EXTERNAL_RESOURCE,
251                 "deleteExternalJndiResource");
252         deleteResOpNameMapper.put(CONNECTOR_CONNECTION_POOL,
253                 "deleteConnectorConnectionPool");
254         deleteResOpNameMapper.put(CONNECTION_POOL,
255                 "deleteJdbcConnectionPool");
256         deleteResOpNameMapper.put(CUSTOM_RESOURCE,
257                 "deleteCustomResource");
258         deleteResOpNameMapper.put(CONNECTOR_RESOURCE,
259                 "deleteConnectorResource");
260         deleteResOpNameMapper.put(CONNECTION_FACTORY,
261                 "deleteJmsResource");
262         deleteResOpNameMapper.put(DESTINATION_RESOURCE,
263                 "deleteJmsDestinationResource");
264     }
265         
266     /**
267      *
268      */

269     private NodeTypes() { }
270     
271     /**
272      * Returns an array of NodeType children as strings given a particular
273      * NodeType name.
274      *
275      * @param nodeType The node from which children types are derived.
276      *
277      * @return All the node types for the node name passed.
278      */

279     static String JavaDoc[] getChildTypes(String JavaDoc nodeType){
280         return (String JavaDoc[]) nodeHierarchy.get(nodeType);
281     }
282     
283     /**
284      * Returns the corresponding AMX interface for a particular nodeType.
285      *
286      * @param nodeType The node from which the equivalent AMX interface is
287      * derived.
288      *
289      * @return The corresponding AMX interface.
290      */

291     public static Class JavaDoc getAMXInterface(String JavaDoc nodeType){
292         return (Class JavaDoc) nodeToInterfaceMap.get(nodeType);
293     }
294     
295     
296     /**
297      * Returns the corresponding AMX config peer interface for a
298      * particular nodeType.
299      *
300      * @param nodeType The node from which the equivalent AMX config peer
301      * interface is derived.
302      *
303      * @return The corresponding AMX config peer interface.
304      */

305     public static Class JavaDoc getAMXConfigPeerInterface(String JavaDoc nodeType){
306         return (Class JavaDoc) nodeToConfigPeerInterfaceMap.get(nodeType);
307     }
308     
309     
310     /**
311      * Returns the corresponding AMX config peer interface for a
312      * particular nodeType.
313      *
314      * @param nodeType The node from which the equivalent AMX config peer
315      * interface is derived.
316      *
317      * @return The corresponding AMX config peer interface.
318      */

319     public static String JavaDoc getDeleteResourceMethodName(String JavaDoc nodeType){
320         return (String JavaDoc) deleteResOpNameMapper.get(nodeType);
321     }
322     
323     
324     /**
325      * Returns the corresponding AMX J2EE_TYPE for a particular nodeType.
326      *
327      * @param nodeType The node from which the equivalent AMX interface is
328      * derived.
329      *
330      * @return The corresponding AMX J2EE_TYPE given a nodeType.
331      */

332     public static String JavaDoc getAMXJ2EETypeByNodeType(String JavaDoc nodeType){
333         return getJ2EETypeValueFromInterface(
334             NodeTypes.getAMXInterface(nodeType));
335     }
336     
337     
338     /**
339      * Returns the corresponding AMX J2EE_TYPE for a particular nodeType.
340      *
341      * @param nodeType The node from which the equivalent AMX interface is
342      * derived.
343      *
344      * @return The corresponding AMX J2EE_TYPE given a nodeType.
345      */

346     public static String JavaDoc getAMXConfigPeerJ2EETypeByNodeType(String JavaDoc nodeType){
347         return getJ2EETypeValueFromInterface(
348             NodeTypes.getAMXConfigPeerInterface(nodeType));
349     }
350
351     
352     /**
353      *
354      */

355     private static String JavaDoc getJ2EETypeValueFromInterface(Class JavaDoc clazz) {
356         String JavaDoc type = null;
357         try {
358             java.lang.reflect.Field JavaDoc j2eeType = clazz.getField("J2EE_TYPE");
359             if(j2eeType == null) {
360                 return "";
361             }
362             type = (String JavaDoc)j2eeType.get(String JavaDoc.class);
363         } catch (Exception JavaDoc e) {
364             logger.log(Level.FINE, e.getMessage(), e);
365         }
366         return (type != null) ? type : "";
367     }
368 }
369
Popular Tags