KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 import java.util.ArrayList JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 //JMX imports
31
import javax.management.ObjectName JavaDoc;
32 import javax.management.ObjectInstance JavaDoc;
33 import javax.management.MBeanServer JavaDoc;
34
35 //Admin imports
36
import com.sun.enterprise.admin.common.ObjectNames;
37
38 /**
39     A Class to derive cues for Bean in Config API from ObjectName.
40 */

41
42 public class ObjectNameHelper
43 {
44     /**
45         A static method that returns type of the MBean as indicated in
46         com.sun.enterprise.admin.common.ObjectNames class. The given ObjectName
47         may not be null. Returns null, if the ObjectName does not contain
48         a property with name "type" in its property name value set.
49     */

50     
51     public static String JavaDoc getType(ObjectName JavaDoc objectName)
52     {
53        String JavaDoc type = objectName.getKeyProperty(ObjectNames.kTypeKeyName);
54        //type has to one of the declared ones and hence this should be asserted.
55

56        return ( type );
57     }
58
59     /**
60         Returns the name of the MBean denoted by this ObjectName. Name is the
61         value of property with name "name" in key properties.
62     */

63     
64     public static String JavaDoc getName(ObjectName JavaDoc objectName)
65     {
66         String JavaDoc name = objectName.getKeyProperty(ObjectNames.kNameKeyName);
67         
68         return ( name );
69     }
70     
71     public static String JavaDoc getClassId(ObjectName JavaDoc objectName)
72     {
73         String JavaDoc classId = objectName.getKeyProperty(ObjectNames.kClassIdKeyName);
74         return ( classId );
75     }
76
77     public static String JavaDoc getServerId(ObjectName JavaDoc objectName)
78     {
79         String JavaDoc serverId = objectName.getKeyProperty(ObjectNames.kServerIdKeyName);
80         return ( serverId );
81     }
82
83     public static String JavaDoc getServerInstanceName(ObjectName JavaDoc objectName)
84     {
85         String JavaDoc instanceName = null;
86
87         if (getType(objectName) != null) {
88         if (getType(objectName).equals(ObjectNames.kServerInstance))
89         {
90             instanceName = getName(objectName);
91         }
92         else
93         {
94             instanceName = objectName.getKeyProperty(ObjectNames.kServerInstanceKeyName);
95         }
96     }
97
98         return ( instanceName );
99     }
100     
101     public static String JavaDoc getModuleType(ObjectName JavaDoc objectName)
102     {
103         String JavaDoc moduleType = null;
104         
105         moduleType = objectName.getKeyProperty(ObjectNames.kModuleTypeKeyName);
106         
107         return ( moduleType );
108     }
109
110     public static String JavaDoc getApplicationName(ObjectName JavaDoc objectName)
111     {
112         String JavaDoc app = null;
113         
114         app = objectName.getKeyProperty(ObjectNames.kApplicationNameKeyName);
115         
116         return ( app );
117     }
118
119     public static String JavaDoc getGroupId(ObjectName JavaDoc objectName)
120     {
121         String JavaDoc moduleType = null;
122         
123         moduleType = objectName.getKeyProperty(ObjectNames.kGroupIdKeyName);
124         
125         return ( moduleType );
126     }
127
128     public static String JavaDoc getVirtualServerClassId(ObjectName JavaDoc objectName)
129     {
130         String JavaDoc classId = objectName.getKeyProperty(
131                             ObjectNames.kVirtualServerClassIdKeyName);
132         return ( classId );
133     }
134
135     public static String JavaDoc getVirtualServerId(ObjectName JavaDoc objectName)
136     {
137         String JavaDoc virtualServerId = objectName.getKeyProperty(
138                                     ObjectNames.kVirtualServerIdKeyName);
139         return ( virtualServerId );
140     }
141
142     public static String JavaDoc getHttpListenerId(ObjectName JavaDoc objectName)
143     {
144         String JavaDoc listenerId = null;
145         listenerId = objectName.getKeyProperty(ObjectNames.kHTTPListenerIdKeyName);
146         return ( listenerId );
147     }
148     
149     /**
150         Returns true if this MBean is of type monitor.
151         Useful to decide whether the persistent storage check should
152         be performed.
153     */

154     public static boolean isMonitorMBean(ObjectName JavaDoc objectName)
155     {
156         boolean isMonitor = false;
157         String JavaDoc monitorKeyValue = null;
158
159         monitorKeyValue = objectName.getKeyProperty(
160                 ObjectNames.kTypeKeyName);
161         if (monitorKeyValue != null)
162         {
163             isMonitor = monitorKeyValue.
164                      equals(ObjectNames.kMonitoringType);
165         }
166         return ( isMonitor );
167     }
168     
169     /**
170         Returns array of config MBeans created for given server instance
171     */

172     public static ObjectName JavaDoc[] getInstanceRelatedMBeans(MBeanServer JavaDoc mbs, String JavaDoc instanceName) {
173         final ObjectName JavaDoc pattern = ObjectNames.getAllObjectNamesPattern(); //aka "ias:*"
174
final Set JavaDoc names = mbs.queryMBeans(pattern, null);
175         /* gets all the mbeans in the "ias" domain */
176         final Iterator JavaDoc iter = names.iterator();
177         final ArrayList JavaDoc arr = new ArrayList JavaDoc();
178         while(iter.hasNext()) {
179             final ObjectInstance JavaDoc objectInstance = (ObjectInstance JavaDoc) iter.next();
180             final ObjectName JavaDoc objectName = objectInstance.getObjectName();
181             final String JavaDoc name = ObjectNameHelper.getServerInstanceName(objectName);
182             if(instanceName.equals(name)) {
183                 arr.add(objectName);
184             }
185         }
186         return (ObjectName JavaDoc [])arr.toArray(new ObjectName JavaDoc[arr.size()]);
187     }
188 }
189
Popular Tags