KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > custom > ObjectNameSelectionAlgorithm


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.mbeans.custom;
25
26 import com.sun.enterprise.admin.mbeans.custom.loading.MBeanClassLoader;
27 import java.util.Map JavaDoc;
28 import javax.management.MalformedObjectNameException JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30
31 /** Implements an algorithm to select the ObjectName given the various parameters. See Design Document for details.
32  */

33 public class ObjectNameSelectionAlgorithm {
34     
35     private ObjectNameSelectionAlgorithm() {
36     }
37     public static ObjectName JavaDoc select(final Map JavaDoc<String JavaDoc, String JavaDoc> params) throws RuntimeException JavaDoc {
38         ObjectName JavaDoc on = null;
39         try {
40             if (params.containsKey(CustomMBeanConstants.OBJECT_NAME_KEY))
41                 on = new ObjectName JavaDoc(params.get(CustomMBeanConstants.OBJECT_NAME_KEY));
42             else {
43                 /* WBN
44                  * note that we always form an ON. For a CMB that implements
45                  * MBeanRegistration -- it may use that name or it may create its
46                  * own name. If it creates its own name, we'll see it soon and then use
47                  * that name in preference to this one...
48                  */

49                 on = MBeanValidator.formDefaultObjectName(params);
50             }
51             return ( on );
52         } catch(final MalformedObjectNameException JavaDoc me) {
53             throw new RuntimeException JavaDoc(me);
54         }
55     }
56     
57     public static boolean implementsMBeanRegistrationInterface(String JavaDoc className) throws RuntimeException JavaDoc {
58         boolean imri = false;
59         try {
60             //Note that the bits of the class need to be loaded dynamically and hence we need MBeanClassLoader
61
ClassLoader JavaDoc mbcl = new MBeanClassLoader();
62             Class JavaDoc mbc = Class.forName(className, false, mbcl);
63             final Class JavaDoc[] iifs = mbc.getInterfaces();
64             for (Class JavaDoc c : iifs) {
65                 if (javax.management.MBeanRegistration JavaDoc.class.equals(c)) {
66                     imri = true;
67                     mbc = null; mbcl = null; // make them garbage-collectible asap :), purpose served
68
break;
69                 }
70             }
71         } catch (final Exception JavaDoc e) {
72             throw new RuntimeException JavaDoc (e);
73         }
74         return ( imri );
75     }
76     
77     private static boolean implementsMBeanRegistrationInterface(final Map JavaDoc<String JavaDoc, String JavaDoc> params) throws RuntimeException JavaDoc {
78         return implementsMBeanRegistrationInterface(params.get(CustomMBeanConstants.IMPL_CLASS_NAME_KEY));
79     }
80 }
81
Popular Tags