KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > common > ObjectNames


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.admin.common;
25 //JMX imports
26
import javax.management.ObjectName JavaDoc;
27 import javax.management.MalformedObjectNameException JavaDoc;
28 //Admin imports
29
import com.sun.enterprise.admin.util.Debug;
30 import com.sun.enterprise.admin.util.Logger;
31 import com.sun.enterprise.util.SystemPropertyConstants;
32
33 /**
34     A convenience class to create the object names of various MBeans
35     that are of interest. Note that all the Object Names will be created
36     in domain with name "ias", unless specified otherwise.
37     Clients of this class need not worry of details of creating valid
38     Object Names.
39     <p>
40     Note that if any of the methods of this class returns a <code> null </code>
41     Object Name, then it implies that the input parameters specified were not
42     valid.
43     @author Kedar Mhaswade
44     @version 1.0
45 */

46 public class ObjectNames
47 {
48     public static final String JavaDoc kDefaultIASDomainName = "ias";
49
50     public static final char kWildcardChar = '*';
51     public static final char kDomainNameSeparatorChar = ':';
52     public static final char kPropertySeparatorChar = ',';
53     public static final char kNameValueSeparatorChar = '=';
54     public static final char kSingleMatchChar = '?';
55
56     public static final String JavaDoc kDomainNameInvalidatorString =
57             "" + kWildcardChar + kDomainNameSeparatorChar + kPropertySeparatorChar +
58             kNameValueSeparatorChar + kSingleMatchChar;
59     //constant names of the property keys
60
public static final String JavaDoc kTypeKeyName = "type";
61     public static final String JavaDoc kNameKeyName = "name";
62     public static final String JavaDoc kGroupIdKeyName = "group";
63     public static final String JavaDoc kCategoryKeyName = "category";
64     public static final String JavaDoc kClassIdKeyName = "class";
65     public static final String JavaDoc kServerIdKeyName = "server";
66     public static final String JavaDoc kDeployment = "deployment-service";
67     public static final String JavaDoc kModuleTypeKeyName = "module-type";
68     public static final String JavaDoc kServerInstanceKeyName = "instance-name";
69     public static final String JavaDoc kApplicationNameKeyName = "app-name";
70     public static final String JavaDoc kModuleNameKeyName = "module-name";
71     //constant names of property values
72
public static final String JavaDoc kController = "controller";
73     public static final String JavaDoc kConfig = "config";
74     public static final String JavaDoc kServer = "server";
75     public static final String JavaDoc kGenericConfigurator = "configurator";
76     public static final String JavaDoc kSystemServices = "system-services";
77     public static final String JavaDoc kServerInstance = "server-instance";
78     public static final String JavaDoc kApplication = "application";
79     public static final String JavaDoc kModule = "module";
80     public static final String JavaDoc kJMSAdminHandler = "jms-service";
81     public static final String JavaDoc kLogService = "log-service";
82
83     public static final String JavaDoc kComponentKeyName = "component"; //
84
public static final String JavaDoc kOrbType = "orb";
85     public static final String JavaDoc kOrbListenerType = "orblistener";
86
87     public static final String JavaDoc kHTTPServiceType = "httpservice";
88     public static final String JavaDoc kHTTPListenerType = "httplistener";
89     public static final String JavaDoc kHTTPListenerIdKeyName = "http-listener-id";
90 // public static final String kHTTPConnectionGroupType = "httpconnectiongroup";
91
public static final String JavaDoc kSecurityServiceType = "securityservice";
92
93     public static final String JavaDoc kVirtualServerClassType = "virtual-server-class";
94     public static final String JavaDoc kVirtualServerClassDefaultName = "defaultclass"; //only one class for now
95
public static final String JavaDoc kVirtualServerClassIdKeyName = "virtual-server-class-id";
96     public static final String JavaDoc kVirtualServerType = "virtual-server";
97     public static final String JavaDoc kVirtualServerIdKeyName = "virtual-server-id";
98
99     public static final String JavaDoc kMimeType = "mime";
100     public static final String JavaDoc kMimeIdKeyName = "mime-id";
101     public static final String JavaDoc kAclType = "acl";
102     public static final String JavaDoc kAclIdKeyName = "acl-id";
103     public static final String JavaDoc kAuthDbType = "authdb";
104     public static final String JavaDoc kAuthDbIdKeyName = "authdbId";
105     public static final String JavaDoc kAuthRealmType = "authrealm";
106     public static final String JavaDoc kHTTPQosType = "http-qos";
107
108     public static final String JavaDoc kJdbcConnectionPoolType = "jdbcpool";
109     public static final String JavaDoc kJdbcResourceType = "jdbc-resource";
110     public static final String JavaDoc kMailResourceType = "mail-resource";
111     public static final String JavaDoc kJmsResourceType = "jms-resource";
112     public static final String JavaDoc kJndiResourceType = "jndi-resource";
113     public static final String JavaDoc kCustomResourceType = "custom-resource";
114     public static final String JavaDoc kPersistenceManagerFactoryResourceType =
115         "persistence-manager-factory-resource";
116
117     public static final String JavaDoc kWebContainer = "web-container";
118     public static final String JavaDoc kEjbContainer = "ejb-container";
119     public static final String JavaDoc kMdbContainer = "mdb-container";
120     
121     public static final String JavaDoc kJtsComponent = "transaction-service";
122     public static final String JavaDoc kJvmType = "java-config";
123
124     public static final String JavaDoc kEjbModule = "ejb-module";
125     public static final String JavaDoc kWebModule = "web-module";
126     public static final String JavaDoc kStandaloneEjbModule = "standalone-ejb-module"; //only MBean naming type
127
public static final String JavaDoc kStandaloneWebModule = "standalone-web-module"; //only MBean naming type
128

129     public static final String JavaDoc kConnectorModule = "connector-module";
130     public static final String JavaDoc kLifecycleModule = "lifecycle-module";
131
132     public static final String JavaDoc kEjbType = "ejb";
133     public static final String JavaDoc kServletType = "servlet";
134
135     public static final String JavaDoc kMonitoringType = "monitor";
136     public static final String JavaDoc kMonitoringClassName = "mclass";
137     public static final String JavaDoc kMonitoringRootClass = "root";
138
139     public static final String JavaDoc kProfiler = "profiler";
140
141     /**
142             Making the only default constructor private.
143     */

144     private ObjectNames()
145     {
146     }
147     
148     /**
149             Returns the ObjectName of MBean representing Server Controller.
150             This is the Object Name of the entity that makes all Server side
151             entities manageable.
152
153             @return controller's ObjectName or null if something went wrong.
154     */

155     public static ObjectName JavaDoc getControllerObjectName()
156     {
157         return ( getObjectName(kDefaultIASDomainName,
158                 new String JavaDoc[]{kTypeKeyName},
159                 new String JavaDoc[]{kController}) );
160     }
161     
162      /**
163         Returns the ObjectName of MBean representing a <server> element.
164
165         @return <server> element's ObjectName, or null
166     */

167     public static ObjectName JavaDoc getServerObjectName( String JavaDoc serverName )
168     {
169         return ( getObjectName(kDefaultIASDomainName,
170             new String JavaDoc[]{kTypeKeyName, kNameKeyName, kCategoryKeyName},
171             new String JavaDoc[]{kServer, serverName, kConfig}) );
172     }
173     
174     /**
175         Returns the ObjectName of Generic Configurator.
176     */

177
178     public static ObjectName JavaDoc getGenericConfiguratorObjectName()
179     {
180         return ( getObjectName(kDefaultIASDomainName,
181                 new String JavaDoc[]{kTypeKeyName},
182                 new String JavaDoc[]{kGenericConfigurator}) );
183     }
184     /** Gets the System Service MBean Object Name in the Admin Server aka DAS.
185      * This method has been deprecated. Use #getPerInstanceSystemServicesObjectName
186      * instead.
187      * @deprecated
188      * @return the ObjectName of MBean responsible for System Services in the DAS.
189      * The MBean returned has the ObjectName of the form <p>
190      * com.sun.appserv:type=system-services,server=server
191      * <p>
192      * This is because the server-id of admin server (DAS) is "server".
193      * @see SystemPropertyConstants
194      */

195     public static ObjectName JavaDoc getSystemServicesObjectName()
196     {
197         return ( getPerInstanceSystemServicesObjectName(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME) );
198     }
199
200     /** Returns the ObjectName of the system services MBean that would
201      * be available in a given server instance name.
202      * @param instanceId String representing the id of instance - may not be null
203      * @return the ObjectName of such an MBean
204      */

205     public static ObjectName JavaDoc getPerInstanceSystemServicesObjectName(final String JavaDoc instanceId)
206     {
207          final ObjectName JavaDoc on = getObjectName(kDefaultIASDomainName,
208                 new String JavaDoc[]{kTypeKeyName, kServerIdKeyName},
209                 new String JavaDoc[]{kSystemServices, instanceId}) ;
210          //System.out.println("[[DELETE]] Getting the System Services MBean ObjectName for instance: " + instanceId + ", and it is: " + on.toString());
211
return ( on );
212     }
213     
214     /**
215         <LLC>
216         ObjectNames for the MBeans supporting dotted names--
217         registry -- associates dotted names with ObjectNames
218         resolver -- resolves a dotted name to an ObjectName
219         get-set -- supports the get/set/list commands within CLI
220      */

221     public static final String JavaDoc kDottedNameDomainName = "com.sun.appserv"; //kDefaultIASDomainName;
222
public static final String JavaDoc kDottedNameType = "dotted-name-support";
223     public static final String JavaDoc kDottedNameRegistryNameKeyName = "dotted-name-registry";
224     public static final String JavaDoc kDottedNameMonitoringRegistryNameKeyName = "dotted-name-monitoring-registry";
225     public static final String JavaDoc kDottedNameGetSetNameKeyName = "dotted-name-get-set";
226     
227     private static ObjectName JavaDoc getDottedNameObjectName( final String JavaDoc name )
228     {
229         return( getObjectName( kDottedNameDomainName,
230                 new String JavaDoc [] { kNameKeyName, kTypeKeyName },
231                 new String JavaDoc [] { name, kDottedNameType } )
232                 );
233     }
234      
235     public static ObjectName JavaDoc getDottedNameRegistryObjectName()
236     {
237         return( getDottedNameObjectName( kDottedNameRegistryNameKeyName ) );
238     }
239      
240     public static ObjectName JavaDoc getDottedNameMonitoringRegistryObjectName()
241     {
242         return( getDottedNameObjectName( kDottedNameMonitoringRegistryNameKeyName ) );
243     }
244     
245     public static ObjectName JavaDoc getDottedNameGetSetObjectName()
246     {
247         return( getDottedNameObjectName( kDottedNameGetSetNameKeyName ) );
248     }
249     
250     /* </LLC> */
251      
252      
253     /**
254             Returns the ObjectName of MBean representing JMS Admin handler.
255             This is the Object Name of the entity that does all JMS
256             related admin tasks.
257
258             @return JMSAdminHandler's ObjectName or null if something went
259                     wrong.
260     */

261     public static ObjectName JavaDoc getJMSAdminHandlerObjectName(String JavaDoc instanceName)
262     {
263         return ( getObjectName(kDefaultIASDomainName,
264                 new String JavaDoc[]{kTypeKeyName, kServerInstanceKeyName},
265                 new String JavaDoc[]{kJMSAdminHandler, instanceName}) );
266     }
267
268     /**
269      */

270     public static ObjectName JavaDoc getJMSAdminHandlerObjectName()
271     {
272         Debug.println("This method is deprecated. Use the overloaded method" +
273                       " instead.", Debug.LOW);
274         return ( getObjectName(kDefaultIASDomainName,
275                 new String JavaDoc[]{kTypeKeyName},
276                 new String JavaDoc[]{kJMSAdminHandler}) );
277     }
278
279     /**
280             Returns ObjectName of MBean that represents a managed Server Instance,
281             with given name.
282             @param instanceName String representing name of the Server Instance.
283             @return ObjectName of Server Instance MBean or null if input is invalid.
284     */

285     public static ObjectName JavaDoc getServerInstanceObjectName(String JavaDoc instanceName)
286     {
287         return ( getObjectName (kDefaultIASDomainName,
288                 new String JavaDoc[]{kTypeKeyName, kNameKeyName},
289                 new String JavaDoc[]{kServerInstance, instanceName}) );
290     }
291
292     /**
293      */

294     public static ObjectName JavaDoc getServerInstanceObjectNamePattern()
295     {
296         ObjectName JavaDoc pattern = null;
297         ObjectName JavaDoc tmp = getObjectName(kDefaultIASDomainName,
298         new String JavaDoc[] {kTypeKeyName}, new String JavaDoc[] {kServerInstance});
299         if (tmp != null)
300         {
301             String JavaDoc strPattern = tmp.toString() + kPropertySeparatorChar;
302             strPattern += kWildcardChar;
303             try
304             {
305                 pattern = new ObjectName JavaDoc(strPattern);
306             }
307             catch (MalformedObjectNameException JavaDoc mfone)
308             {
309                 pattern = null;
310                 Debug.printStackTrace(mfone);
311             }
312         }
313         return pattern;
314     }
315
316     /**
317      * System property name used to toggle between DeploymentMBean
318      * and ManagedServerInstance. Just Temporary till DeplMBean is tested.
319      * will be removed and DeploymentMBean will remain
320      */

321     private static final String JavaDoc USE_DEPLOYMENT_MBEAN ="com.sun.aas.deployment.UseDeploymentMBean";
322    
323     /**
324      * Returns objectName of the mbean representing deployment interface
325      * @param instanceName name of the instance to which this mbean belongs to
326      * @return objectName of deploymentMBean
327      */

328     public static ObjectName JavaDoc getDeploymentServiceObjectName(String JavaDoc instanceName)
329     {
330         if(System.getProperty(USE_DEPLOYMENT_MBEAN,"false").equals("true"))
331         {
332              return ( getObjectName (kDefaultIASDomainName,
333                 new String JavaDoc[]{kTypeKeyName, kServerInstanceKeyName},
334                 new String JavaDoc[]{kDeployment, instanceName}));
335         }
336         else {
337             return getServerInstanceObjectName(instanceName);
338         }
339     }
340
341
342     /**
343             Returns the ObjectName of MBean that represents a managed J2EE
344             application, with given name and deployed to given Server Instance.
345
346             @param instanceName String representing name of holding Server Instance.
347             @param appName String representing the name of application.
348             @return ObjectName of Application MBean or null if input is invalid.
349     */

350     public static ObjectName JavaDoc getApplicationObjectName(String JavaDoc instanceName,
351             String JavaDoc appName)
352     {
353         return ( getObjectName (kDefaultIASDomainName,
354                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
355                              kServerInstanceKeyName},
356                 new String JavaDoc[]{kApplication, appName, instanceName}) );
357     }
358
359     /**
360      * Returns a patterned ObjectName that can be used to query the
361      * MBeanServer for all the application mbeans that match this
362      * pattern. This method uses the default domain to construct the
363      * ObjectName.
364      * For example given an instance name "ias1" this method should return
365      * an ObjectName with pattern -
366      * "ias:type=application,instance-name=ias1,*"
367      * @param instanceName The name of the instance for which the
368      * application pattern name will be generated.
369      * @throws IllegalArgumentException if the inastanceName is null or
370      * of 0 length.
371      * @return Returns a valid ObjectName or null if unable to construct an
372      * ObjectName.
373      */

374     public static ObjectName JavaDoc getApplicationObjectNamePattern(
375                                                 String JavaDoc instanceName)
376     {
377         ObjectName JavaDoc pattern = null;
378         ObjectName JavaDoc tmp = getObjectName(kDefaultIASDomainName,
379         new String JavaDoc[] {kTypeKeyName, kServerInstanceKeyName},
380         new String JavaDoc[] {kApplication, instanceName});
381         if (tmp != null)
382         {
383             String JavaDoc strPattern = tmp.toString() + kPropertySeparatorChar;
384             strPattern += kWildcardChar;
385             try
386             {
387                 pattern = new ObjectName JavaDoc(strPattern);
388             }
389             catch (MalformedObjectNameException JavaDoc mfone)
390             {
391                 Debug.printStackTrace(mfone);
392                 pattern = null;
393             }
394         }
395         return pattern;
396     }
397
398     /**
399             Returns the ObjectName of MBean that represents a managed J2EE
400             module, with given name and deployed to given Server Instance
401             as a part of given application (<strong>
402             not a standalone module)</strong>.
403
404             @param instanceName String representing name of holding Server Instance.
405             @param appName String representing the name of enveloping application.
406             @param moduleName name of the module.
407             @return ObjectName of Application MBean or null if input is invalid.
408     */

409     public static ObjectName JavaDoc getModuleObjectName(String JavaDoc instanceName,
410             String JavaDoc appName, String JavaDoc moduleName)
411     {
412         return ( getObjectName (kDefaultIASDomainName,
413                 new String JavaDoc[]{kTypeKeyName, kNameKeyName, kApplicationNameKeyName,
414                              kServerInstanceKeyName},
415                 new String JavaDoc[]{kModule, moduleName, appName, instanceName}) );
416     }
417
418     public static ObjectName JavaDoc getEjbModuleObjectName(String JavaDoc instanceName,
419                                                     String JavaDoc moduleName)
420     {
421         return ( getObjectName (kDefaultIASDomainName,
422                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
423                              kServerInstanceKeyName, kModuleTypeKeyName},
424                 new String JavaDoc[]{kModule, moduleName, instanceName, kEjbModule}) );
425     }
426
427     public static ObjectName JavaDoc getEjbModuleObjectName(String JavaDoc instanceName,
428                                                     String JavaDoc moduleName,
429                                                     String JavaDoc applicationName)
430     {
431         return ( getObjectName (kDefaultIASDomainName,
432                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
433                              kServerInstanceKeyName, kModuleTypeKeyName,
434                              kApplicationNameKeyName},
435                 new String JavaDoc[]{kModule, moduleName, instanceName, kEjbModule,
436                              applicationName}) );
437     }
438
439     public static ObjectName JavaDoc getWebModuleObjectName(String JavaDoc instanceName,
440                                                     String JavaDoc moduleName)
441     {
442         return ( getObjectName (kDefaultIASDomainName,
443                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
444                              kServerInstanceKeyName, kModuleTypeKeyName},
445                 new String JavaDoc[]{kModule, moduleName, instanceName, kWebModule}) );
446     }
447
448     public static ObjectName JavaDoc getWebModuleObjectName(String JavaDoc instanceName,
449                                                     String JavaDoc moduleName,
450                                                     String JavaDoc applicationName)
451     {
452         return ( getObjectName (kDefaultIASDomainName,
453                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
454                              kServerInstanceKeyName, kModuleTypeKeyName,
455                              kApplicationNameKeyName},
456                 new String JavaDoc[]{kModule, moduleName, instanceName, kWebModule,
457                              applicationName}) );
458     }
459
460     public static ObjectName JavaDoc getConnectorModuleObjectName(String JavaDoc instanceName,
461                                                           String JavaDoc moduleName)
462     {
463         return ( getObjectName (kDefaultIASDomainName,
464                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
465                              kServerInstanceKeyName, kModuleTypeKeyName},
466                 new String JavaDoc[]{kModule, moduleName, instanceName,
467                              kConnectorModule}) );
468     }
469
470     public static ObjectName JavaDoc getConnectorModuleObjectName(
471                                                       String JavaDoc instanceName,
472                                                       String JavaDoc moduleName,
473                                                       String JavaDoc applicationName)
474     {
475         return ( getObjectName (kDefaultIASDomainName,
476                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
477                              kServerInstanceKeyName, kModuleTypeKeyName,
478                              kApplicationNameKeyName},
479                 new String JavaDoc[]{kModule, moduleName, instanceName,
480                              kConnectorModule, applicationName}) );
481     }
482
483     /**
484      */

485     public static ObjectName JavaDoc getModuleObjectNamePattern(String JavaDoc instanceName,
486             String JavaDoc appName)
487     {
488         ObjectName JavaDoc pattern = null;
489
490         ObjectName JavaDoc tmp = getObjectName(kDefaultIASDomainName,
491             new String JavaDoc[] {kTypeKeyName, kServerInstanceKeyName,
492                 kApplicationNameKeyName},
493             new String JavaDoc[] {kModule, instanceName, appName});
494
495         if (tmp != null)
496         {
497             String JavaDoc strPattern = tmp.toString() + kPropertySeparatorChar;
498             strPattern += kWildcardChar;
499             try
500             {
501                 pattern = new ObjectName JavaDoc(strPattern);
502             }
503             catch (MalformedObjectNameException JavaDoc mfone)
504             {
505                 pattern = null;
506             }
507         }
508         return pattern;
509     }
510
511     /**
512             Returns the ObjectName of MBean that represents a managed J2EE
513             module, with given name and deployed to given Server Instance
514             as a <strong> standalone module </strong>. Note that this is an
515             overloaded method.
516
517             @param instanceName String representing name of holding Server Instance.
518             @param moduleName name of the module.
519             @return ObjectName of Application MBean or null if input is invalid.
520     */

521     public static ObjectName JavaDoc getModuleObjectName(String JavaDoc instanceName,
522             String JavaDoc moduleName)
523     {
524         return ( getObjectName (kDefaultIASDomainName,
525                 new String JavaDoc[]{kTypeKeyName, kNameKeyName, kServerInstanceKeyName},
526                 new String JavaDoc[]{kModule, moduleName, instanceName}) );
527     }
528
529     /**
530      */

531     public static ObjectName JavaDoc getModuleObjectNamePattern(String JavaDoc instanceName)
532     {
533         ObjectName JavaDoc pattern = null;
534         ObjectName JavaDoc tmp = getObjectName(kDefaultIASDomainName,
535         new String JavaDoc[] {kTypeKeyName, kServerInstanceKeyName},
536         new String JavaDoc[] {kModule, instanceName});
537         if (tmp != null)
538         {
539             try
540             {
541                 String JavaDoc strPattern = tmp.toString() + kPropertySeparatorChar;
542                 strPattern += kWildcardChar;
543                 pattern = new ObjectName JavaDoc(strPattern);
544             }
545             catch (MalformedObjectNameException JavaDoc mfone)
546             {
547                 pattern = null;
548                 Debug.printStackTrace(mfone);
549             }
550         }
551         return pattern;
552     }
553
554     public static ObjectName JavaDoc getORBObjectName(String JavaDoc instanceName)
555     {
556         return ( getObjectName (kDefaultIASDomainName,
557                 new String JavaDoc[]{kTypeKeyName, kServerInstanceKeyName},
558                 new String JavaDoc[]{kOrbType, instanceName}));
559     }
560
561     public static ObjectName JavaDoc getIiopListenerObjectName(String JavaDoc instanceName,
562                                                        String JavaDoc listenerId)
563     {
564         return ( getObjectName (kDefaultIASDomainName,
565                 new String JavaDoc[]{kTypeKeyName,
566                              kServerInstanceKeyName,
567                              kNameKeyName},
568                 new String JavaDoc[]{kOrbListenerType, instanceName, listenerId}));
569     }
570
571         public static ObjectName JavaDoc
572     getJDBCConnectionPoolObjectName(String JavaDoc instanceName, String JavaDoc poolName)
573     {
574         return ( getObjectName (kDefaultIASDomainName,
575                 new String JavaDoc[]{kTypeKeyName,
576                              kServerInstanceKeyName,
577                              kNameKeyName},
578                 new String JavaDoc[]{kJdbcConnectionPoolType, instanceName, poolName}));
579     }
580
581         public static ObjectName JavaDoc
582     getJDBCResourceObjectName(String JavaDoc instanceName, String JavaDoc jndiName)
583     {
584         return ( getObjectName (kDefaultIASDomainName,
585                 new String JavaDoc[]{kTypeKeyName,
586                              kServerInstanceKeyName,
587                              kNameKeyName},
588                 new String JavaDoc[]{kJdbcResourceType, instanceName, jndiName}));
589     }
590
591         public static ObjectName JavaDoc
592     getJNDIResourceObjectName(String JavaDoc instanceName, String JavaDoc jndiName)
593     {
594         return ( getObjectName (kDefaultIASDomainName,
595                 new String JavaDoc[]{kTypeKeyName,
596                              kServerInstanceKeyName,
597                              kNameKeyName},
598                 new String JavaDoc[]{kJndiResourceType, instanceName, jndiName}));
599     }
600
601         public static ObjectName JavaDoc
602     getJMSResourceObjectName(String JavaDoc instanceName, String JavaDoc jndiName)
603     {
604         return ( getObjectName (kDefaultIASDomainName,
605                 new String JavaDoc[]{kTypeKeyName,
606                              kServerInstanceKeyName,
607                              kNameKeyName},
608                 new String JavaDoc[]{kJmsResourceType, instanceName, jndiName}));
609     }
610
611         public static ObjectName JavaDoc
612     getPersistenceManagerFactoryResourceObjectName(String JavaDoc instanceName,
613                                                    String JavaDoc jndiName)
614     {
615         return ( getObjectName (kDefaultIASDomainName,
616                 new String JavaDoc[]{kTypeKeyName,
617                              kServerInstanceKeyName,
618                              kNameKeyName},
619                 new String JavaDoc[]{kPersistenceManagerFactoryResourceType,
620                              instanceName, jndiName}));
621     }
622
623         public static ObjectName JavaDoc
624     getMailResourceObjectName(String JavaDoc instanceName, String JavaDoc jndiName)
625     {
626         return ( getObjectName (kDefaultIASDomainName,
627                 new String JavaDoc[]{kTypeKeyName,
628                              kServerInstanceKeyName,
629                              kNameKeyName},
630                 new String JavaDoc[]{kMailResourceType, instanceName, jndiName}));
631     }
632
633         public static ObjectName JavaDoc
634     getCustomResourceObjectName(String JavaDoc instanceName, String JavaDoc jndiName)
635     {
636         return ( getObjectName (kDefaultIASDomainName,
637                 new String JavaDoc[]{kTypeKeyName,
638                              kServerInstanceKeyName,
639                              kNameKeyName},
640                 new String JavaDoc[]{kCustomResourceType, instanceName, jndiName}));
641     }
642
643     public static ObjectName JavaDoc getWebContainerObjectName(String JavaDoc instanceName)
644     {
645         return ( getObjectName (kDefaultIASDomainName,
646                 new String JavaDoc[]{kTypeKeyName,
647                              kServerInstanceKeyName},
648                 new String JavaDoc[]{kWebContainer, instanceName}));
649     }
650
651     public static ObjectName JavaDoc getEjbContainerObjectName(String JavaDoc instanceName)
652     {
653         return ( getObjectName (kDefaultIASDomainName,
654                 new String JavaDoc[]{kTypeKeyName,
655                              kServerInstanceKeyName},
656                 new String JavaDoc[]{kEjbContainer, instanceName}));
657     }
658
659     public static ObjectName JavaDoc getMdbContainerObjectName(String JavaDoc instanceName)
660     {
661         return ( getObjectName (kDefaultIASDomainName,
662                 new String JavaDoc[]{kTypeKeyName,
663                              kServerInstanceKeyName},
664                 new String JavaDoc[]{kMdbContainer, instanceName}));
665     }
666
667     public static ObjectName JavaDoc getJVMComponentObjectName(String JavaDoc instanceName)
668     {
669         return ( getObjectName (kDefaultIASDomainName,
670                 new String JavaDoc[] {kTypeKeyName,
671                               kServerInstanceKeyName},
672                 new String JavaDoc[] {kJvmType, instanceName}));
673     }
674
675     public static ObjectName JavaDoc getJTSComponentObjectName(String JavaDoc instanceName)
676     {
677         return ( getObjectName (kDefaultIASDomainName,
678                 new String JavaDoc[]{kTypeKeyName,
679                              kServerInstanceKeyName},
680                 new String JavaDoc[]{kJtsComponent, instanceName}));
681     }
682
683     public static ObjectName JavaDoc getLogServiceObjectName(String JavaDoc instanceName)
684     {
685         return ( getObjectName (kDefaultIASDomainName,
686                 new String JavaDoc[]{kTypeKeyName,
687                              kServerInstanceKeyName},
688                 new String JavaDoc[]{kLogService, instanceName}));
689     }
690
691     public static ObjectName JavaDoc getSecurityServiceObjectName(String JavaDoc instanceName)
692     {
693         return ( getObjectName (kDefaultIASDomainName,
694                 new String JavaDoc[]{kTypeKeyName,
695                              kServerInstanceKeyName},
696                 new String JavaDoc[]{kSecurityServiceType, instanceName}));
697     }
698
699     public static ObjectName JavaDoc getHttpListenerObjectName(String JavaDoc instanceName,
700                                                        String JavaDoc id)
701     {
702         return ( getObjectName (kDefaultIASDomainName,
703                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
704                              kServerInstanceKeyName},
705                 new String JavaDoc[]{kHTTPListenerType, id, instanceName}));
706     }
707
708 /* public static ObjectName
709     getHttpConnectionGroupObjectName(String instanceName,
710                                      String listenerId,
711                                      String connectionGroupId)
712     {
713         return ( getObjectName (kDefaultIASDomainName,
714                 new String[]{kTypeKeyName, kNameKeyName,
715                              kHTTPListenerIdKeyName, kServerInstanceKeyName},
716                 new String[]{kHTTPConnectionGroupType, connectionGroupId,
717                              listenerId, instanceName}));
718     }
719 */

720     public static ObjectName JavaDoc getHttpServiceObjectName(String JavaDoc instanceName)
721     {
722         return ( getObjectName (kDefaultIASDomainName,
723                 new String JavaDoc[]{kTypeKeyName, kServerInstanceKeyName},
724                 new String JavaDoc[]{kHTTPServiceType, instanceName}));
725     }
726
727     public static ObjectName JavaDoc getVirtualServerClassObjectName(
728                                                         String JavaDoc instanceName,
729                                                         String JavaDoc classId)
730     {
731         return ( getObjectName (kDefaultIASDomainName,
732                 new String JavaDoc[]{kTypeKeyName,
733                              kNameKeyName,
734                              kServerInstanceKeyName},
735                 new String JavaDoc[]{kVirtualServerClassType, classId, instanceName}));
736     }
737
738     public static ObjectName JavaDoc getVirtualServerObjectName(
739                                             String JavaDoc instanceName,
740                                             String JavaDoc virtualServerClassId,
741                                             String JavaDoc virtualServerId)
742     {
743         return ( getObjectName (kDefaultIASDomainName,
744                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
745                              kVirtualServerClassIdKeyName,
746                              kServerInstanceKeyName},
747                 new String JavaDoc[]{kVirtualServerType,
748                              virtualServerId,
749                              virtualServerClassId,
750                              instanceName}));
751     }
752
753         public static ObjectName JavaDoc
754     getVirtualServerAuthDBObjectName(String JavaDoc instanceName,
755                                      String JavaDoc virtualServerClassId,
756                                      String JavaDoc virtualServerId,
757                                      String JavaDoc authDBId)
758     {
759         return ( getObjectName (kDefaultIASDomainName,
760                 new String JavaDoc[]{kTypeKeyName,
761                              kNameKeyName,
762                              kVirtualServerIdKeyName,
763                              kVirtualServerClassIdKeyName,
764                              kServerInstanceKeyName},
765                 new String JavaDoc[]{kAuthDbType,
766                              authDBId,
767                              virtualServerId,
768                              virtualServerClassId,
769                              instanceName}));
770     }
771
772         public static ObjectName JavaDoc
773     getMimeObjectName(String JavaDoc instanceName, String JavaDoc id)
774     {
775         return ( getObjectName (kDefaultIASDomainName,
776                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
777                              kServerInstanceKeyName},
778                 new String JavaDoc[]{kMimeType, id,
779                              instanceName}));
780     }
781
782         public static ObjectName JavaDoc
783     getAclObjectName(String JavaDoc instanceName, String JavaDoc id)
784     {
785         return ( getObjectName (kDefaultIASDomainName,
786                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
787                              kServerInstanceKeyName},
788                 new String JavaDoc[]{kAclType, id,
789                              instanceName}));
790     }
791
792         public static ObjectName JavaDoc
793     getLifeCycleModuleObjectName(String JavaDoc instanceName, String JavaDoc name)
794     {
795         return ( getObjectName (kDefaultIASDomainName,
796                 new String JavaDoc[]{kTypeKeyName, kNameKeyName,
797                              kServerInstanceKeyName},
798                 new String JavaDoc[]{kLifecycleModule, name,
799                              instanceName}));
800     }
801
802     public static ObjectName JavaDoc getEjbObjectName(String JavaDoc instanceName,
803                                               String JavaDoc moduleName,
804                                               String JavaDoc ejbName)
805     {
806         return ( getObjectName (kDefaultIASDomainName,
807                 new String JavaDoc[]{kTypeKeyName, kNameKeyName, kModuleNameKeyName,
808                              kServerInstanceKeyName},
809                 new String JavaDoc[]{kEjbType, ejbName, moduleName, instanceName}));
810     }
811
812     public static ObjectName JavaDoc getEjbObjectName(String JavaDoc instanceName,
813                                               String JavaDoc appName,
814                                               String JavaDoc moduleName,
815                                               String JavaDoc ejbName)
816     {
817         return ( getObjectName (kDefaultIASDomainName,
818                 new String JavaDoc[]{kTypeKeyName, kNameKeyName, kModuleNameKeyName,
819                              kApplicationNameKeyName, kServerInstanceKeyName},
820                 new String JavaDoc[]{kEjbType, ejbName, moduleName, appName,
821                              instanceName}));
822     }
823
824     public static ObjectName JavaDoc getServletObjectName(String JavaDoc instanceName,
825                                                   String JavaDoc moduleName,
826                                                   String JavaDoc servletName)
827     {
828         return ( getObjectName (kDefaultIASDomainName,
829                 new String JavaDoc[]{kTypeKeyName, kNameKeyName, kModuleNameKeyName,
830                              kServerInstanceKeyName},
831                 new String JavaDoc[]{kServletType, servletName, moduleName,
832                              instanceName}));
833     }
834
835     public static ObjectName JavaDoc getServletObjectName(String JavaDoc instanceName,
836                                                   String JavaDoc appName,
837                                                   String JavaDoc moduleName,
838                                                   String JavaDoc servletName)
839     {
840         return ( getObjectName (kDefaultIASDomainName,
841                 new String JavaDoc[]{kTypeKeyName, kNameKeyName, kModuleNameKeyName,
842                              kApplicationNameKeyName, kServerInstanceKeyName},
843                 new String JavaDoc[]{kServletType, servletName, moduleName, appName,
844                              instanceName}));
845     }
846
847     /**
848         Get ObjectName for root monitoring mBean.
849         @param instanceName name of the server instance
850         @return jmx ObjectName for root monitoring MBean
851     */

852     public static ObjectName JavaDoc getRootMonitorMBeanName(String JavaDoc instanceName)
853     {
854         return ( getObjectName (kDefaultIASDomainName,
855                 new String JavaDoc[]{kTypeKeyName, kMonitoringClassName,
856                              kServerInstanceKeyName, kNameKeyName},
857                 new String JavaDoc[]{kMonitoringType, kMonitoringRootClass,
858                              instanceName, kMonitoringRootClass}));
859     }
860
861     /**
862      */

863     public static ObjectName JavaDoc getProfilerObjectName(String JavaDoc instanceName)
864     {
865         return ( getObjectName (kDefaultIASDomainName,
866                 new String JavaDoc[]{kTypeKeyName, kServerInstanceKeyName},
867                 new String JavaDoc[]{kProfiler, instanceName}));
868     }
869
870     /**
871      */

872     public static ObjectName JavaDoc getAuthRealmObjectName(String JavaDoc instanceName,
873                                                     String JavaDoc realmName)
874     {
875         return ( getObjectName (kDefaultIASDomainName,
876                 new String JavaDoc[]{kTypeKeyName, kServerInstanceKeyName,
877                              kNameKeyName},
878                 new String JavaDoc[]{kAuthRealmType, instanceName, realmName}));
879     }
880
881     /**
882             A generic method to create the Object Name of an MBean in given
883             domain with specified arrays of Property Names-Values.
884
885             @param domainName String representing the name of domain. May not
886                     be null. May not contain any DomainInvalidator characters.
887             @param keyNames Array of Strings representing the Property Key Names.
888             @param keyValues Array of Strings representing the Property Key Values.
889             None of the names, values (and arrays themseleves) may be null.
890             @return valid ObjectName with given params, null if there is any error.
891     */

892     public static ObjectName JavaDoc getObjectName(String JavaDoc domainName,
893             String JavaDoc[] keyNames, String JavaDoc[] keyValues)
894     {
895         ObjectName JavaDoc validObjectName = null;
896
897         try
898         {
899             if (domainName == null ||
900                 !isDomainNameValid(domainName) ||
901                 keyNames == null ||
902                 keyValues == null ||
903                 keyNames.length < 1 ||
904                 keyNames.length != keyValues.length)
905             {
906                 throw new IllegalArgumentException JavaDoc();
907             }
908             StringBuffer JavaDoc nameBuffer = new StringBuffer JavaDoc();
909             nameBuffer.append(domainName);
910             nameBuffer.append(kDomainNameSeparatorChar);
911             for (int i = 0 ; i < keyNames.length ; i++)
912             {
913                 if (keyNames[i] == null || keyValues[i] == null)
914                 {
915                     throw new IllegalArgumentException JavaDoc();
916                 }
917                 nameBuffer.append(keyNames[i]);
918                 nameBuffer.append(kNameValueSeparatorChar);
919                 nameBuffer.append(keyValues[i]);
920                 if (i != (keyNames.length-1))
921                 {
922                     nameBuffer.append(kPropertySeparatorChar);
923                 }
924             }
925             validObjectName = new ObjectName JavaDoc(nameBuffer.toString());
926         }
927         catch(Exception JavaDoc e)
928         {
929             Debug.printStackTrace(e);
930         }
931         return ( validObjectName );
932     }
933
934     public static ObjectName JavaDoc getAllObjectNamesPattern()
935     {
936         String JavaDoc name = kDefaultIASDomainName + kDomainNameSeparatorChar + kWildcardChar;
937         try
938         {
939            return new ObjectName JavaDoc(name);
940         }
941         catch (Exception JavaDoc e)
942         {
943             return null;
944         }
945     }
946     
947     private static boolean isDomainNameValid(String JavaDoc name)
948     {
949         boolean isValid = false;
950
951         isValid = (name.indexOf(kWildcardChar) == -1) &&
952                     (name.indexOf(kDomainNameSeparatorChar) == -1) &&
953                     (name.indexOf(kPropertySeparatorChar) == -1) &&
954                     (name.indexOf(kNameValueSeparatorChar) == -1) &&
955                     (name.indexOf(kSingleMatchChar) == -1);
956
957         return ( isValid );
958     }
959
960     public static void main(String JavaDoc[] args) throws Exception JavaDoc
961     {
962         Logger.log(ObjectNames.getServerInstanceObjectName("ias1"));
963         Logger.log(ObjectNames.getApplicationObjectName("ias1", "app1"));
964         Logger.log(ObjectNames.getControllerObjectName());
965         Logger.log(ObjectNames.getModuleObjectName("ias1", "standalone"));
966         Logger.log(ObjectNames.getModuleObjectName("ias1", "app1", "inner"));
967         Logger.log(ObjectNames.getObjectName("ias111",
968                 new String JavaDoc[]{"key1", "key2", "key3"},
969                 new String JavaDoc[]{"v1", "v2", "v3"}));
970
971         //Testers for patterns
972
ObjectName JavaDoc pattern =
973             ObjectNames.getServerInstanceObjectNamePattern();
974         Logger.log("" + pattern.isPropertyPattern());
975         pattern = ObjectNames.getApplicationObjectNamePattern("ias1");
976         Logger.log("" + pattern.isPropertyPattern());
977         pattern = ObjectNames.getModuleObjectNamePattern("ias1");
978         Logger.log("" + pattern.isPropertyPattern());
979         pattern = ObjectNames.getModuleObjectNamePattern("ias1", "bank");
980         Logger.log("" + pattern.isPropertyPattern());
981         
982         ObjectName JavaDoc jmsObjectName =
983             ObjectNames.getJMSAdminHandlerObjectName("ias1");
984         Logger.log("JMS Objectname = " + jmsObjectName.toString());
985         jmsObjectName = ObjectNames.getJMSAdminHandlerObjectName();
986         Logger.log("JMS Objectname = " + jmsObjectName.toString());
987
988         ObjectName JavaDoc httpListener = ObjectNames.getHttpListenerObjectName(
989                                     "ias1", "listener1");
990         Logger.log("Http listener object name = " + httpListener);
991
992         
993         ObjectName JavaDoc mime = ObjectNames.getMimeObjectName("ias1", "text/html");
994         Logger.log("Mime object name = " + mime);
995
996         ObjectName JavaDoc acl = ObjectNames.getAclObjectName("ias1", "acl1");
997         Logger.log("ACL object name = " + acl);
998
999     }
1000}
1001
Popular Tags