KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > mbean > config > naming > ConfigMBeanNamingInfo


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     PROPRIETARY/CONFIDENTIAL. Use of this product is subject
26     to license terms. Copyright (c) 2002 Sun Microsystems, Inc.
27         All rights reserved.
28  
29     $Id: ConfigMBeanNamingInfo.java,v 1.4 2005/12/25 04:14:34 tcfujii Exp $
30  */

31
32 package com.sun.enterprise.admin.server.core.mbean.config.naming;
33
34 import com.sun.enterprise.admin.AdminContext;
35 import com.sun.enterprise.admin.common.MalformedNameException;
36
37 import com.sun.enterprise.admin.server.core.mbean.config.ConfigMBeanBase;
38 import com.sun.enterprise.admin.common.exception.MBeanConfigException;
39
40 //JMX imports
41
import javax.management.ObjectName JavaDoc;
42 import javax.management.MalformedObjectNameException JavaDoc;
43
44 //i18n import
45
import com.sun.enterprise.util.i18n.StringManager;
46
47
48 /**
49  * Provides naming support for ConfigMbeans
50  */

51 public class ConfigMBeanNamingInfo
52 {
53     private AdminContext m_AdminContext;
54     String JavaDoc[] m_ids = null;
55     MBeanNamingDescriptor m_descr = null;
56
57     // i18n StringManager
58
private static StringManager localStrings =
59         StringManager.getManager( ConfigMBeanNamingInfo.class );
60
61     public ConfigMBeanNamingInfo(String JavaDoc type, String JavaDoc[] params) throws MBeanConfigException
62     {
63        this(type, params, true);
64     }
65     public ConfigMBeanNamingInfo(String JavaDoc type, String JavaDoc[] params, boolean bTestParamSize) throws MBeanConfigException
66     {
67         m_descr = ConfigMBeansNaming.findNamingDescriptorByType(type);
68         if(m_descr==null) {
69             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_type", type );
70             throw new MBeanConfigException( msg );
71         }
72
73         if(bTestParamSize)
74         {
75             int parmSize = (params==null)?0:params.length;
76             if(m_descr.getParmListSize()!=parmSize) {
77                 String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.naming.wrong_parameters_array_size", type );
78                 throw new MBeanConfigException( msg );
79             }
80         }
81         m_ids = params;
82     }
83     
84     public ConfigMBeanNamingInfo(String JavaDoc dottedName) throws MBeanConfigException, MalformedNameException
85     {
86         m_descr = ConfigMBeansNaming.findNamingDescriptor(dottedName);
87         if(m_descr==null) {
88             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_dotted_name", dottedName );
89             throw new MBeanConfigException( msg );
90         }
91         m_ids = m_descr.extractParmList(dottedName);
92     }
93     
94     public ConfigMBeanNamingInfo(ObjectName JavaDoc objectName) throws MBeanConfigException
95     {
96         m_descr = ConfigMBeansNaming.findNamingDescriptor(objectName);
97         if(m_descr==null) {
98             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_not_found_for_object_name", objectName );
99             throw new MBeanConfigException( msg );
100         }
101         m_ids = m_descr.extractParmList(objectName);
102     }
103
104     public void setAdminContext(AdminContext adminContext) {
105         m_AdminContext = adminContext;
106     }
107     
108     //******************************M A P P I N G S***************************
109
public ObjectName JavaDoc getObjectName() throws MalformedObjectNameException JavaDoc
110     {
111         return m_descr.createObjectName(m_ids);
112     }
113
114     public String JavaDoc[] getLocationParams()
115     {
116         return m_ids;
117     }
118
119     public String JavaDoc getXPath()
120     {
121         return m_descr.createXPath(m_ids);
122     }
123
124     public int getMode()
125     {
126         return m_descr.getMode();
127     }
128
129     public boolean isModeConfig()
130     {
131         int mode = m_descr.getMode();
132         return ((mode&MBeansDescriptions.MODE_CONFIG)!=0);
133     }
134
135     public boolean isModeMonitorable()
136     {
137         int mode = m_descr.getMode();
138         return ((mode&MBeansDescriptions.MODE_MONITOR)!=0);
139     }
140
141     public ConfigMBeanBase constructConfigMBean() throws MBeanConfigException
142     {
143         String JavaDoc className = MBeansDescriptions.CONFIG_MBEANS_BASE_CLASS_PREFIX + m_descr.getMBeanClassName();
144         Class JavaDoc cl;
145         ConfigMBeanBase configMBean;
146         try
147         {
148             cl = Class.forName(className);
149             //create configMBean by defaul constructor;
150
configMBean = (ConfigMBeanBase)cl.newInstance();
151         }
152         catch (Exception JavaDoc e)
153         {
154             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.naming.mbeannamingdescriptor_couldnot_create_mbean_class", className );
155             throw new MBeanConfigException( msg );
156         }
157         configMBean.setAdminContext(m_AdminContext);
158         configMBean.initialize(this);
159         return configMBean;
160     }
161
162     public String JavaDoc getServerInstanceName() throws MBeanConfigException
163     {
164         if(m_ids==null || m_ids.length==0)
165         {
166             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.naming.wrong_parameters_array_size", m_descr.getType() );
167             throw new MBeanConfigException( msg );
168         }
169         return m_ids[0];
170     }
171
172 }
173
Popular Tags