KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > meta > naming > MBeanNamingInfo


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 /*
25  * $Id: MBeanNamingInfo.java,v 1.3 2005/12/25 03:47:39 tcfujii Exp $
26  * @author: alexkrav
27  *
28  * $Log: MBeanNamingInfo.java,v $
29  * Revision 1.3 2005/12/25 03:47:39 tcfujii
30  * Updated copyright text and year.
31  *
32  * Revision 1.2 2005/06/27 21:19:45 tcfujii
33  * Issue number: CDDL header updates.
34  *
35  * Revision 1.1.1.1 2005/05/27 22:52:02 dpatil
36  * GlassFish first drop
37  *
38  * Revision 1.10 2004/11/14 07:04:22 tcfujii
39  * Updated copyright text and/or year.
40  *
41  * Revision 1.9 2004/10/25 01:49:09 sg112326
42  * fix for bug # 6157490, 6189188
43  *
44  * Ran EE QL
45  *
46  * Revision 1.8 2004/10/22 22:07:33 kravtch
47  * Dots in element's names are escaped during dotted names registration.
48  * Reviewer: Sridatta
49  * Bug #6182305
50  * Tests: QLT PE/EE; devtest
51  *
52  * Revision 1.7 2004/02/20 03:56:16 qouyang
53  *
54  *
55  * First pass at code merge.
56  *
57  * Details for the merge will be published at:
58  * http://javaweb.sfbay.sun.com/~qouyang/workspace/PE8FCSMerge/02202004/
59  *
60  * Revision 1.6.4.1 2004/02/02 07:25:21 tcfujii
61  * Copyright updates notices; reviewer: Tony Ng
62  *
63  * Revision 1.6 2003/08/15 23:08:29 kravtch
64  * DottedName Support (generation and call to manager)
65  * notifyRegisterMBean/UnregisterMBean are implemented;
66  * dotted name related opeartions are added to NaminDescriptor and NamingInfo
67  * removeChild support is added;
68  *
69  * Revision 1.5 2003/07/29 18:59:36 kravtch
70  * MBeanRegistryEntry:
71  * - support for toFormatString();
72  * - instantiateMBean() method modified to instantiate runtime MBeans as well;
73  * MBeanRegistryFactory:
74  * - fixed bug in getRuntimeRegistry();
75  * MBeanNamingInfo:
76  * - less strict requirements for parm_list_array size in constructor (can be more then needed);
77  * BaseRuntimeMBean:
78  * - exception ClassCastException("Managed resource is not a Jsr77ModelBean") handling;
79  * ManagedJsr77MdlBean:
80  * - call managed bean bug fixed ( getDeclaredMethod()->getMethod())
81  * admin/dtds/runtime-mbeans-descriptors.xml - modified to represent new runtime mbeans;
82  *
83  * Revision 1.4 2003/06/25 20:03:41 kravtch
84  * 1. java file headers modified
85  * 2. properties handling api is added
86  * 3. fixed bug for xpathes containing special symbols;
87  * 4. new testcases added for jdbc-resource
88  * 5. introspector modified by not including base classes operations;
89  *
90  *
91 */

92
93 package com.sun.enterprise.admin.meta.naming;
94
95 //JMX imports
96
import javax.management.ObjectName JavaDoc;
97 import javax.management.MalformedObjectNameException JavaDoc;
98
99 //i18n import
100
//import com.iplanet.ias.util.i18n.StringManager;
101

102
103 /**
104  * Provides naming support for Mbeans
105  */

106 public class MBeanNamingInfo
107 {
108     String JavaDoc[] m_ids = null;
109     MBeanNamingDescriptor m_descr = null;
110
111     // i18n StringManager
112
// private static StringManager localStrings =
113
// StringManager.getManager( MBeanNamingInfo.class );
114

115     public MBeanNamingInfo(/*int category, */ MBeanNamingDescriptor descr, String JavaDoc type, String JavaDoc[] params) throws MBeanNamingException
116     {
117        this(/*category,*/ descr, type, params, true);
118     }
119     
120     public MBeanNamingInfo(/*int category,*/ MBeanNamingDescriptor descr, String JavaDoc type, String JavaDoc[] params, boolean bTestParamSize) throws MBeanNamingException
121     {
122         m_descr = descr;
123         if(m_descr==null) {
124             String JavaDoc msg = /*localStrings.getString*/( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_type" + type );
125             throw new MBeanNamingException( msg );
126         }
127
128         if(bTestParamSize)
129         {
130             int parmSize = (params==null)?0:params.length;
131             if(m_descr.getParmListSize()>parmSize) {
132                 String JavaDoc msg = /*localStrings.getString*/( "admin.server.core.mbean.config.naming.wrong_parameters_array_size"+ type );
133                 throw new MBeanNamingException( msg );
134             }
135         }
136         
137         m_ids = new String JavaDoc[m_descr.getParmListSize()];
138         for(int i=0; i<m_ids.length; i++)
139             m_ids[i] = params[i];
140     }
141     
142     public MBeanNamingInfo(MBeanNamingDescriptor descr, String JavaDoc dottedName) throws MBeanNamingException, MalformedObjectNameException JavaDoc
143     {
144         m_descr = descr; //MBeansNaming.findNamingDescriptor(dottedName);
145
if(m_descr==null) {
146             String JavaDoc msg = /*localStrings.getString*/( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_dotted_name"+dottedName );
147             throw new MBeanNamingException( msg );
148         }
149         m_ids = m_descr.extractParmList(dottedName);
150     }
151     
152     public MBeanNamingInfo(MBeanNamingDescriptor descr, ObjectName JavaDoc objectName) throws MBeanNamingException
153     {
154         m_descr = descr; //MBeansNaming.findNamingDescriptor(objectName);
155
if(m_descr==null) {
156             String JavaDoc msg = /*localStrings.getString*/( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_object_name"+ objectName );
157             throw new MBeanNamingException( msg );
158         }
159         m_ids = m_descr.extractParmList(objectName);
160     }
161     
162     //******************************M A P P I N G S***************************
163
public ObjectName JavaDoc getObjectName() throws MalformedObjectNameException JavaDoc
164     {
165         return m_descr.createObjectName(m_ids);
166     }
167
168     private String JavaDoc escapeString(String JavaDoc str)
169     {
170         if(str == null)
171             return null;
172         return str.replace('.', '`').replaceAll("`","\\\\.");
173     }
174     
175     private String JavaDoc[] escapeStrings(String JavaDoc[] arr)
176     {
177         if(arr == null)
178             return null;
179         String JavaDoc[] ret = new String JavaDoc[arr.length];
180         for(int i=0; i<arr.length; i++)
181         {
182             ret[i] = escapeString(arr[i]);
183         }
184         return ret;
185     }
186     public String JavaDoc[] getDottedNames() throws MalformedObjectNameException JavaDoc
187     {
188         return m_descr.createDottedNames(escapeStrings(m_ids));
189     }
190     
191     public String JavaDoc[] getLocationParams()
192     {
193         return m_ids;
194     }
195
196     public String JavaDoc getXPath()
197     {
198         return m_descr.createXPath(m_ids);
199     }
200
201     public String JavaDoc getType()
202     {
203         return m_descr.getType();
204     }
205
206     public int getMode()
207     {
208         return m_descr.getMode();
209     }
210
211     public boolean isModeConfig()
212     {
213         int mode = m_descr.getMode();
214         return ((mode&MBeansNaming.MODE_CONFIG)!=0);
215     }
216
217     public boolean isModeMonitorable()
218     {
219         int mode = m_descr.getMode();
220         return ((mode&MBeansNaming.MODE_MONITOR)!=0);
221     }
222
223 /* public ConfigMBeanBase constructConfigMBean() throws MBeanNamingException
224     {
225         String className = MBeansNaming.CONFIG_MBEANS_BASE_CLASS_PREFIX + m_descr.getMBeanClassName();
226         Class cl;
227         ConfigMBeanBase configMBean;
228         try
229         {
230             cl = Class.forName(className);
231             //create configMBean by defaul constructor;
232             configMBean = (ConfigMBeanBase)cl.newInstance();
233         }
234         catch (Exception e)
235         {
236             String msg = ( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_couldnot_create_mbean_class"+ className );
237             throw new MBeanNamingException( msg );
238         }
239         configMBean.initialize(this);
240         return configMBean;
241     }
242 */

243     public String JavaDoc getServerInstanceName() throws MBeanNamingException
244     {
245         if(m_ids==null || m_ids.length==0)
246         {
247             String JavaDoc msg = /*localStrings.getString*/( "admin.server.core.mbean.config.naming.wrong_parameters_array_size"+ m_descr.getType() );
248             throw new MBeanNamingException( msg );
249         }
250         return m_ids[0];
251     }
252
253 }
254
Popular Tags