KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > event > EventBuilder


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 package com.sun.enterprise.admin.event;
24
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28 import com.sun.enterprise.server.ApplicationServer;
29 import com.sun.enterprise.server.Constants;
30 import com.sun.enterprise.config.serverbeans.Resources;
31 import com.sun.enterprise.config.serverbeans.Domain;
32 import com.sun.enterprise.config.serverbeans.ServerTags;
33 import com.sun.enterprise.config.ConfigException;
34 import com.sun.enterprise.config.ConfigContext;
35 import com.sun.enterprise.config.ConfigBean;
36
37 /**
38  * Factory class for dynamic reconfig events.
39  *
40  * @author Nazrul Islam
41  * @since JDK1.4
42  */

43 public class EventBuilder {
44     
45     /**
46      * Returns a resource deploy event. This assumes that the event
47      * stack is populated before this is called.
48      *
49      * @param action event action code
50      * @param resName name of the resource
51      *
52      * @throws ConfigException if an error while getting resource type
53      */

54     public ResourceDeployEvent createResourceDeployEvent(String JavaDoc action,
55             String JavaDoc resName) throws ConfigException {
56
57         EventStack stack = EventContext.getEventStackFromThreadLocal();
58
59         return createResourceDeployEvent(action, resName,
60                     stack.getConfigContext(),
61                     (ArrayList JavaDoc)stack.getConfigChangeList(),
62                     stack.getTarget());
63     }
64
65     /**
66      * Returns a resource deploy event.
67      *
68      * @param action event action code
69      * @param resName name of the resource
70      * @param ctx config context
71      * @param configChanges list of config changes
72      * @param target target name
73      *
74      * @throws ConfigException if an error while getting resource type
75      */

76     public ResourceDeployEvent createResourceDeployEvent(String JavaDoc action,
77             String JavaDoc resName, ConfigContext ctx, ArrayList JavaDoc configChanges,
78             String JavaDoc target) throws ConfigException {
79
80         // name of the current server instance runtime
81
String JavaDoc instName =
82             ApplicationServer.getServerContext().getInstanceName();
83          
84         // resource type from target string
85
String JavaDoc resType = getResourceTypeByName(ctx, resName, target);
86
87         // resource deploy event
88
ResourceDeployEvent rde = new ResourceDeployEvent(instName,
89                                             resName, resType, action);
90         rde.setTargetDestination(target);
91
92         // adds all the config changes
93
DependencyResolver dr = new DependencyResolver(ctx, target);
94         rde.addDependentConfigChange(
95             dr.resolveResources(resName, action, resType) );
96
97         rde.addConfigChange( configChanges );
98
99         // setEventKey
100

101         return rde;
102     }
103
104     /**
105      * Helper method to obtain ResourceDeployEvent's resource type
106      * correspondent to its name
107      *
108      * @returns ResourceDeployEvent's resource type
109      *
110      * @throws ConfigException if a config parsing exception
111      */

112     protected static String JavaDoc getResourceTypeByName(ConfigContext ctx,
113             String JavaDoc resName, String JavaDoc target) throws ConfigException {
114
115         String JavaDoc type = getTypeFromTarget(target);
116         if (type == null) {
117             type = getResourceType(ctx, resName, true);
118         }
119
120         return convertResourceType(type);
121     }
122
123     /**
124      * Returns the resource type of a given resource.
125      *
126      * @param ctx config context
127      * @param id resource name
128      * @param includePool if true, includes pool in the search
129      *
130      * @throws ConfigException if a config parsing exception
131      */

132     static String JavaDoc getResourceType(ConfigContext ctx, String JavaDoc id,
133             boolean includePool) throws ConfigException {
134
135         Resources root = ((Domain)ctx.getRootConfigBean()).getResources();
136
137         ConfigBean res = root.getJdbcResourceByJndiName(id);
138         if ( res != null ) {
139             return Resources.JDBC_RESOURCE;
140         }
141
142         res = root.getMailResourceByJndiName(id);
143         if ( res != null ) {
144             return Resources.MAIL_RESOURCE;
145         }
146
147         res = root.getCustomResourceByJndiName(id);
148         if ( res != null ) {
149             return Resources.CUSTOM_RESOURCE;
150         }
151
152         res = root.getExternalJndiResourceByJndiName(id);
153         if ( res != null ) {
154             return Resources.EXTERNAL_JNDI_RESOURCE;
155         }
156
157         res = root.getPersistenceManagerFactoryResourceByJndiName(id);
158         if ( res != null) {
159             return Resources.PERSISTENCE_MANAGER_FACTORY_RESOURCE;
160         }
161
162         res = root.getAdminObjectResourceByJndiName(id);
163         if ( res != null ) {
164             return Resources.ADMIN_OBJECT_RESOURCE;
165         }
166
167         res = root.getConnectorResourceByJndiName(id);
168         if ( res != null ) {
169             return Resources.CONNECTOR_RESOURCE;
170         }
171
172         res = root.getResourceAdapterConfigByResourceAdapterName(id);
173         if ( res != null ) {
174             return Resources.RESOURCE_ADAPTER_CONFIG;
175         }
176
177         if (includePool) {
178             res = root.getJdbcConnectionPoolByName(id);
179             if ( res != null ) {
180                 return Resources.JDBC_CONNECTION_POOL;
181             }
182
183             res = root.getConnectorConnectionPoolByName(id);
184             if ( res != null ) {
185                 return Resources.CONNECTOR_CONNECTION_POOL;
186             }
187         }
188
189         return null;
190     }
191
192     /**
193      * Adds a resource deploy event to the event stack.
194      *
195      * @param action event action code
196      * @param target event target
197      * @param resName name of the resource
198      * @throws ConfigException if an error while parsing configuration
199      */

200     public void addResourceDeployEvent(String JavaDoc action, String JavaDoc target,
201             String JavaDoc resName) throws ConfigException {
202
203         EventStack stack = EventContext.getEventStackFromThreadLocal();
204         ConfigContext ctx = stack.getConfigContext();
205         stack.setTarget(target);
206         stack.setConfigChangeList( ctx.getConfigChangeList());
207
208         ResourceDeployEvent event = createResourceDeployEvent(action, resName);
209         EventContext.addEvent(event);
210     }
211
212     /**
213      * Creates log level change event.
214      *
215      * @param ctx config context
216      * @param target event target
217      * @param newLogLevel new log level
218      * @param moduleName module name where log level was changed
219      *
220      * @throws ConfigException if a configuration parsing error
221      */

222     public LogLevelChangeEvent createLogLevelChangeEvent(ConfigContext ctx,
223          String JavaDoc target, String JavaDoc newLogLevel, String JavaDoc moduleName)
224          throws ConfigException {
225
226         // name of the current server instance runtime
227
String JavaDoc instName =
228             ApplicationServer.getServerContext().getInstanceName();
229          
230         // log level change event
231
LogLevelChangeEvent lde = new LogLevelChangeEvent(instName);
232         lde.setTargetDestination(target);
233
234         // FIXME: get the change list from each thread local
235
//rde.addConfigChange( ctx.getConfigChangeList() );
236

237         // setEventKey
238

239         // do i need to set old log level ????
240
lde.setModuleName(moduleName);
241         lde.setNewLogLevel(newLogLevel);
242         return lde;
243     }
244
245     /**
246      * Returns an application deploy event. This assumes that the event stack
247      * is populated before this method is called.
248      *
249      * <p> Example Usage:
250      * <xmp>
251      * ConfigContext ctx = stack.getConfigContext();
252      * EventStack stack = EventContext.getEventStackFromThreadLocal();
253      * stack.setTarget(targetName);
254      * stack.setConfigChangeList(ctx.getConfigChangeList());
255      *
256      * EventBuilder builder = new EventBuilder();
257      * ApplicationDeployEvent event = builder.createApplicationDeployEvent(
258      * BaseDeployEvent.REMOVE_REFERENCE, referenceName);
259      *
260      * AdminEventResult result = AdminEventMulticaster.multicast(event);
261      *
262      * Instead of using multicaster, you may also schedule the event
263      * to be sent out by the interceptor. This will release the lock
264      * for concurrent config users. Call the following API if you want
265      * to schedule the event:
266      *
267      * EventContext.addEvent(event);
268      * </xmp>
269      *
270      * @param action event action code
271      * @param appName name of the application
272      *
273      * @return application deploy event
274      *
275      * @throws ConfigException if an error while getting dependent
276      * config elements
277      */

278     public ApplicationDeployEvent createApplicationDeployEvent(String JavaDoc action,
279             String JavaDoc appName) throws ConfigException {
280
281         return createApplicationDeployEvent(action, appName, false);
282     }
283
284     /**
285      * Returns an application deploy event. This assumes that the event stack
286      * is populated before this method is called.
287      *
288      * @param action event action code
289      * @param appName name of the application
290      * @param cascade used by connector implementation to decide whether to
291      * remove resource adapter related resources
292      *
293      * @return application deploy event
294      *
295      * @throws ConfigException if an error while getting dependent
296      * config elements
297      */

298     public ApplicationDeployEvent createApplicationDeployEvent(String JavaDoc action,
299             String JavaDoc appName, boolean cascade) throws ConfigException {
300
301         return createApplicationDeployEvent(action, appName, cascade, false);
302     }
303
304     /**
305      * Returns an application deploy event. This assumes that the event stack
306      * is populated before this method is called.
307      *
308      * @param action event action code
309      * @param appName name of the application
310      * @param cascade used by connector implementation to decide whether to
311      * remove resource adapter related resources
312      * @param forceDeploy whether a deployment is enforced
313      *
314      * @return application deploy event
315      *
316      * @throws ConfigException if an error while getting dependent
317      * config elements
318      */

319     public ApplicationDeployEvent createApplicationDeployEvent(String JavaDoc action,
320             String JavaDoc appName, boolean cascade, boolean forceDeploy)
321                 throws ConfigException {
322         return createApplicationDeployEvent(action, appName, cascade,
323             forceDeploy, Constants.LOAD_UNSET);
324     }
325
326     /**
327      * Returns an application deploy event. This assumes that the event stack
328      * is populated before this method is called.
329      *
330      * @param action event action code
331      * @param appName name of the application
332      * @param cascade used by connector implementation to decide whether to
333      * remove resource adapter related resources
334      * @param forceDeploy whether a deployment is enforced
335      * @param loadUnloadAction what the load/unload action is
336      *
337      * @return application deploy event
338      *
339      * @throws ConfigException if an error while getting dependent
340      * config elements
341      */

342     public ApplicationDeployEvent createApplicationDeployEvent(String JavaDoc action,
343             String JavaDoc appName, boolean cascade, boolean forceDeploy,
344             int loadUnloadAction) throws ConfigException {
345         EventStack stack = EventContext.getEventStackFromThreadLocal();
346         String JavaDoc target = stack.getTarget();
347         assert(target != null);
348
349         // name of the current server instance
350
String JavaDoc instName =
351             ApplicationServer.getServerContext().getInstanceName();
352
353         ApplicationDeployEvent ade = new ApplicationDeployEvent(instName,
354             appName, action, cascade, forceDeploy, loadUnloadAction);
355
356         ade.setTargetDestination(target);
357
358         // adds all the config changes
359
DependencyResolver dr =
360             new DependencyResolver(stack.getConfigContext(), target);
361         ade.addDependentConfigChange(dr.resolveApplications(appName, action));
362
363         ade.addConfigChange( (ArrayList JavaDoc) stack.getConfigChangeList() );
364
365         return ade;
366     }
367
368     /**
369      * Returns a module deploy event.
370      *
371      * @param action event action code
372      * @param moduleName name of the module
373      * @param moduleType type of the module
374      * (ex. ModuleDeployEvent.TYPE_WEBMODULE)
375      *
376      * @return module deploy event
377      *
378      * @throws ConfigException if an error while getting dependent
379      * config elements
380      */

381     public ModuleDeployEvent createModuleDeployEvent(String JavaDoc action,
382             String JavaDoc moduleName, String JavaDoc moduleType)
383             throws ConfigException {
384
385         return createModuleDeployEvent(action, moduleName, moduleType, false);
386     }
387
388     /**
389      * Returns a module deploy event.
390      *
391      * @param action event action code
392      * @param moduleName name of the module
393      * @param moduleType type of the module
394      * (ex. ModuleDeployEvent.TYPE_WEBMODULE)
395      * @param cascade used by connector implementation to decide whether to
396      * remove resource adapter related resources
397      *
398      * @return module deploy event
399      *
400      * @throws ConfigException if an error while getting dependent
401      * config elements
402      */

403     public ModuleDeployEvent createModuleDeployEvent(String JavaDoc action,
404             String JavaDoc moduleName, String JavaDoc moduleType, boolean cascade)
405             throws ConfigException {
406
407         return createModuleDeployEvent(action, moduleName, moduleType,
408                     cascade, false);
409     }
410
411     /**
412      * Returns a module deploy event.
413      *
414      * @param action event action code
415      * @param moduleName name of the module
416      * @param moduleType type of the module
417      * (ex. ModuleDeployEvent.TYPE_WEBMODULE)
418      * @param cascade used by connector implementation to decide whether to
419      * remove resource adapter related resources
420      * @param forceDeploy whether a deployment is enforced
421      *
422      * @return module deploy event
423      *
424      * @throws ConfigException if an error while getting dependent
425      * config elements
426      */

427     public ModuleDeployEvent createModuleDeployEvent(String JavaDoc action,
428             String JavaDoc moduleName, String JavaDoc moduleType, boolean cascade,
429             boolean forceDeploy) throws ConfigException {
430         EventStack stack = EventContext.getEventStackFromThreadLocal();
431         String JavaDoc target = stack.getTarget();
432         assert(target != null);
433
434         String JavaDoc instName =
435              ApplicationServer.getServerContext().getInstanceName();
436
437         ModuleDeployEvent mde =
438             new ModuleDeployEvent(instName, moduleName, moduleType,
439                                     action, cascade);
440         mde.setTargetDestination(target);
441
442
443         // sets the force deploy flag in the event
444
mde.setForceDeploy(forceDeploy);
445
446         // adds all the config changes
447
DependencyResolver dr =
448             new DependencyResolver(stack.getConfigContext(), target);
449         mde.addDependentConfigChange(dr.resolveApplications(moduleName,action));
450         mde.addConfigChange( (ArrayList JavaDoc) stack.getConfigChangeList() );
451
452         return mde;
453     }
454
455     /**
456      * Creates config change event.
457      *
458      * @param target target for the event
459      * @param configChangeList config change list
460      *
461      * @throws ConfigException if a configuration parsing error
462      */

463     public ConfigChangeEvent createConfigChangeEvent(String JavaDoc target,
464             ArrayList JavaDoc configChangeList) throws ConfigException {
465
466         String JavaDoc instName =
467              ApplicationServer.getServerContext().getInstanceName();
468
469         ConfigChangeEvent cce =
470             new ConfigChangeEvent(instName, configChangeList);
471         cce.setTargetDestination(target);
472         return cce;
473     }
474
475     /**
476      * Creates a monitoring event.
477      *
478      * @param ctx config context
479      * @param target target for the event
480      * @param component name of monitoring module
481      * @param action new action
482      * @param command jmx command
483      *
484      * @throws ConfigException if a configuration parsing error
485      */

486     public MonitoringEvent createMonitoringEvent(ConfigContext ctx,
487             String JavaDoc target, String JavaDoc component, String JavaDoc action, Object JavaDoc command)
488             throws ConfigException {
489         
490         String JavaDoc instName =
491              ApplicationServer.getServerContext().getInstanceName();
492         MonitoringEvent me =
493             new MonitoringEvent(instName, component, action, command);
494         me.setTargetDestination(target);
495
496         return me;
497     }
498             
499     /**
500      * Creates monitoring level change event.
501      *
502      * @param ctx config context
503      * @param target target for the event
504      * @param component name of monitoring module
505      * @param monitoringLevel new monitoring level
506      *
507      * @throws ConfigException if a configuration parsing error
508      */

509     public MonitoringLevelChangeEvent createMonitoringLevelChangeEvent(
510             ConfigContext ctx, String JavaDoc target, String JavaDoc component,
511             String JavaDoc monitoringLevel) throws ConfigException {
512
513         String JavaDoc instName =
514             ApplicationServer.getServerContext().getInstanceName();
515
516         MonitoringLevelChangeEvent mle =
517             new MonitoringLevelChangeEvent(instName);
518         mle.setTargetDestination(target);
519
520         return mle;
521     }
522
523     /**
524      * Converts config bean type to resource deploy event type.
525      *
526      * @param type config bean type
527      * @return resource deploy event type
528      */

529     protected static String JavaDoc convertResourceType(String JavaDoc type) {
530         // XXX see if we can avoid this type conversion
531
// may be do hash instead of string comparision
532

533         if (type==null) {
534             return null;
535         } else {
536             type = type.trim();
537         }
538
539         if ( type.equals(ServerTags.CUSTOM_RESOURCE)
540                 || type.equals(Resources.CUSTOM_RESOURCE) ) {
541             return ResourceDeployEvent.RES_TYPE_CUSTOM;
542         }
543         if ( type.equals(ServerTags.EXTERNAL_JNDI_RESOURCE)
544                 || type.equals(Resources.EXTERNAL_JNDI_RESOURCE) ) {
545             return ResourceDeployEvent.RES_TYPE_EXTERNAL_JNDI;
546         }
547         if ( type.equals(ServerTags.JDBC_RESOURCE)
548                 || type.equals(Resources.JDBC_RESOURCE) ) {
549             return ResourceDeployEvent.RES_TYPE_JDBC;
550         }
551         if ( type.equals(ServerTags.MAIL_RESOURCE)
552                 || type.equals(Resources.MAIL_RESOURCE) ) {
553             return ResourceDeployEvent.RES_TYPE_MAIL;
554         }
555         if ( type.equals(ServerTags.PERSISTENCE_MANAGER_FACTORY_RESOURCE)
556             || type.equals(Resources.PERSISTENCE_MANAGER_FACTORY_RESOURCE)) {
557
558             return ResourceDeployEvent.RES_TYPE_PMF;
559         }
560         if ( type.equals(ServerTags.ADMIN_OBJECT_RESOURCE)
561                 || type.equals(Resources.ADMIN_OBJECT_RESOURCE) ) {
562             return ResourceDeployEvent.RES_TYPE_AOR;
563         }
564         if ( type.equals(ServerTags.CONNECTOR_RESOURCE)
565                 || type.equals(Resources.CONNECTOR_RESOURCE) ) {
566             return ResourceDeployEvent.RES_TYPE_CR;
567         }
568         if ( type.equals(ServerTags.RESOURCE_ADAPTER_CONFIG)
569                 || type.equals(Resources.RESOURCE_ADAPTER_CONFIG) ) {
570             return ResourceDeployEvent.RES_TYPE_RAC;
571         }
572         if ( type.equals(ServerTags.JDBC_CONNECTION_POOL)
573                 || type.equals(Resources.JDBC_CONNECTION_POOL) ) {
574             return ResourceDeployEvent.RES_TYPE_JCP;
575         }
576         if ( type.equals(ServerTags.CONNECTOR_CONNECTION_POOL)
577                 || type.equals(Resources.CONNECTOR_CONNECTION_POOL) ) {
578             return ResourceDeployEvent.RES_TYPE_CCP;
579         }
580
581         return type; // unsupported type
582
}
583
584     /**
585      * Returns a module aor app deploy event.
586      *
587      * @param action event action code
588      * @param name name of the module or application
589      * @param ctx config context
590      * @param configChanges list of config changes
591      * @param target target name
592      *
593      * @throws ConfigException if an error while getting resource type
594      */

595     public BaseDeployEvent createModAppDeployEvent(String JavaDoc action,
596             String JavaDoc name, ConfigContext ctx, ArrayList JavaDoc configChanges,
597             String JavaDoc target) throws ConfigException {
598
599         // name of the current server instance runtime
600
String JavaDoc instName =
601             ApplicationServer.getServerContext().getInstanceName();
602          
603         BaseDeployEvent event=getAppOrModuleEvent(instName, ctx, name, action);
604         event.setTargetDestination(target);
605         
606         // adds all the config changes
607
DependencyResolver dr = new DependencyResolver(ctx, target);
608         event.addDependentConfigChange(dr.resolveApplications(name,action));
609         event.addConfigChange( configChanges );
610
611         return event;
612     }
613
614     /**
615      * Provides deferred type resolution (usually on remote instance side).
616      *
617      * @param eventToResolve original event without resolved module type in it
618      * @param ctx effective config context used for type resolution
619      *
620      * @returns DeployEvent of the proper type
621      *
622      * @throws ConfigException if an error while getting resource type
623      */

624     public static BaseDeployEvent resolveModAppDeployEventType(
625             BaseDeployEvent eventToResolve, ConfigContext ctx)
626             throws ConfigException {
627
628         // name of the current server instance runtime
629
String JavaDoc instName = eventToResolve.getInstanceName();
630         String JavaDoc name = eventToResolve.getJ2EEComponentName();
631         String JavaDoc action = eventToResolve.getAction();
632
633         BaseDeployEvent event=getAppOrModuleEvent(instName, ctx, name, action);
634         event.setCascade(eventToResolve.getCascade());
635         event.setEventId(eventToResolve.getEventId());
636
637         if (eventToResolve.getDependentChangeList()!=null) {
638             event.addDependentConfigChange(
639                 eventToResolve.getDependentChangeList());
640         }
641
642         if (eventToResolve.getConfigChangeList()!=null) {
643             event.addConfigChange(eventToResolve.getConfigChangeList());
644         }
645
646         if (eventToResolve.getTargetDestination()!=null) {
647             event.setTargetDestination(eventToResolve.getTargetDestination());
648         }
649
650         return event;
651     }
652
653     /**
654      * Creates application deploy event.
655      *
656      * @param instName name of server instance where the event is created
657      * @param ctx config context
658      * @param name name of application
659      * @param action event action - deploy/undeploy/redeploy
660      *
661      * @return application deploy event
662      *
663      * @throws ConfigException if a configuration parsing error
664      */

665     private static BaseDeployEvent getAppOrModuleEvent(String JavaDoc instName,
666             ConfigContext ctx, String JavaDoc name, String JavaDoc action)
667             throws ConfigException {
668
669         String JavaDoc type = getAppOrModuleType(ctx, name);
670
671         if (type!=null) {
672
673             if (type.equals(BaseDeployEvent.APPLICATION)) {
674                 // application deploy event
675
return (BaseDeployEvent)new ApplicationDeployEvent(instName,
676                                                             name, action);
677             } else {
678                 // module deploy event
679
return (BaseDeployEvent)new ModuleDeployEvent(instName, name,
680                                                             type, action);
681             }
682         } else { //for deffered type set
683
return new BaseDeployEvent(instName, null, name, action);
684         }
685     }
686
687     /**
688      * Returns application type.
689      *
690      * @param ctx config context
691      * @param name name of application
692      *
693      * @return application type
694      * @throws ConfigException if a configuration parsing error
695      */

696     private static String JavaDoc getAppOrModuleType(ConfigContext ctx, String JavaDoc name)
697                 throws ConfigException {
698
699         //first try to find
700

701         ConfigBean[] beans = ((Domain)ctx.getRootConfigBean()).
702                                     getApplications().getAllChildBeans();
703         ConfigBean bean = null;
704         if (beans!=null) {
705             for(int i=0; i<beans.length; i++) {
706                 if(name.equals(beans[i].getAttributeValue("name"))) {
707                    bean = beans[i];
708                    break;
709                 }
710             }
711         }
712
713         if (bean==null) {
714             return null;
715         }
716
717         String JavaDoc type = null;
718
719         if (bean instanceof
720                 com.sun.enterprise.config.serverbeans.J2eeApplication) {
721             type = BaseDeployEvent.APPLICATION;
722         }
723
724         if (bean instanceof
725                 com.sun.enterprise.config.serverbeans.ConnectorModule) {
726             type = ModuleDeployEvent.TYPE_CONNECTOR;
727         } else if (bean instanceof
728                 com.sun.enterprise.config.serverbeans.EjbModule) {
729             type = ModuleDeployEvent.TYPE_EJBMODULE;
730         } else if (bean instanceof
731                 com.sun.enterprise.config.serverbeans.WebModule) {
732             type = ModuleDeployEvent.TYPE_WEBMODULE;
733         } else if (bean instanceof
734                 com.sun.enterprise.config.serverbeans.AppclientModule) {
735             type = ModuleDeployEvent.TYPE_APPCLIENT;
736         }
737
738         return type;
739     }
740
741     /**
742      * Returns the type (as defined in domain.xml) from a target.
743      * Target has the following three parts:
744      * <type>|<name-of-resORapp>|<type-of-resORapp>
745      *
746      * @param target target string
747      */

748     static String JavaDoc getTypeFromTarget(String JavaDoc target) {
749
750         String JavaDoc type = null;
751         String JavaDoc msg = "\n NAZRUL Could not determine resource type for target "
752         + target;
753
754         try {
755             if (target != null) {
756                 StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(target, "|");
757                 int tokens = st.countTokens();
758                 if (tokens == 3) {
759                     String JavaDoc prefix = st.nextToken();
760                     String JavaDoc name = st.nextToken();
761                     type = st.nextToken();
762                 }
763             }
764         } catch (Exception JavaDoc e) { }
765
766         return type;
767     }
768 }
769
Popular Tags