KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > runtime > ManagedJsr77MdlBean


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: ManagedJsr77MdlBean.java,v 1.3 2005/12/25 03:47:41 tcfujii Exp $
26  * @author: alexkrav
27  *
28  * $Log: ManagedJsr77MdlBean.java,v $
29  * Revision 1.3 2005/12/25 03:47:41 tcfujii
30  * Updated copyright text and year.
31  *
32  * Revision 1.2 2005/06/27 21:19:46 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.9 2005/05/07 04:35:28 ruyakr
39  * Engineer: Rob Ruyak
40  *
41  * Fixed warning messages displayed from jdk1.5 because of introduction of varargs in certain apis such as ja
42  * va.lang.Class.
43  *
44  *
45  * This is my last checkin here at Sun! Thanks for all the good times!
46  *
47  * Revision 1.8 2004/11/14 07:04:24 tcfujii
48  * Updated copyright text and/or year.
49  *
50  * Revision 1.7 2004/02/20 03:56:18 qouyang
51  *
52  *
53  * First pass at code merge.
54  *
55  * Details for the merge will be published at:
56  * http://javaweb.sfbay.sun.com/~qouyang/workspace/PE8FCSMerge/02202004/
57  *
58  * Revision 1.6.4.2 2004/02/02 07:25:23 tcfujii
59  * Copyright updates notices; reviewer: Tony Ng
60  *
61  * Revision 1.6.4.1 2004/01/20 20:39:32 ramakant
62  * Bug# 4958195
63  * Reviewers: Abhijit, Alex, Prashanth
64  * Fix:
65  * reintroduced the deprecated command - jms-ping to cli.
66  * added a new operation pingJMS to J2EEServerMdl.
67  * modified exception handling in ManagedJsr77MdlBean.
68  *
69  * Revision 1.6 2003/08/24 02:58:50 kravtch
70  * dependancy from J2EEManagedObjectMdl
71  * is removed: J2EEManagedObjectMdl->Object
72  * CVS: ----------------------------------------------------------------------
73  *
74  * Revision 1.5 2003/08/20 15:41:34 kravtch
75  * added support for primitive parameters handling (for JSR77 objects):
76  * getClassForName();
77  *
78  * Revision 1.4 2003/08/16 21:26:19 kravtch
79  * repare for setAttribute in runtime mbean:
80  * descriptor.GETTER__FIELD_NAME->SETTER_FIELD_NAME
81  *
82  * Revision 1.3 2003/08/14 23:16:17 kravtch
83  * invokeOperation() signature changed;
84  * BaseConfigMBean now uses mcb.invokeOperation();
85  *
86  * Revision 1.2 2003/07/29 18:59:37 kravtch
87  * MBeanRegistryEntry:
88  * - support for toFormatString();
89  * - instantiateMBean() method modified to instantiate runtime MBeans as well;
90  * MBeanRegistryFactory:
91  * - fixed bug in getRuntimeRegistry();
92  * MBeanNamingInfo:
93  * - less strict requirements for parm_list_array size in constructor (can be more then needed);
94  * BaseRuntimeMBean:
95  * - exception ClassCastException("Managed resource is not a Jsr77ModelBean") handling;
96  * ManagedJsr77MdlBean:
97  * - call managed bean bug fixed ( getDeclaredMethod()->getMethod())
98  * admin/dtds/runtime-mbeans-descriptors.xml - modified to represent new runtime mbeans;
99  *
100  * Revision 1.1 2003/07/18 20:14:47 kravtch
101  * 1. ALL config mbeans are now covered by descriptors.xml
102  * 2. new infrastructure for runtime mbeans is added
103  * 3. generic constructors added to jsr77Mdl beans (String[])
104  * 4. new test cases are added to admintest
105  * 5. MBeanRegistryFactory has now different methods to obtain admin/runtime registries
106  * 6. runtime-descriptors xml-file is added to build
107  *
108 */

109
110 package com.sun.enterprise.admin.runtime;
111
112 import java.text.CharacterIterator JavaDoc;
113 import java.text.StringCharacterIterator JavaDoc;
114 import java.lang.reflect.Method JavaDoc;
115 import java.util.Iterator JavaDoc;
116 import java.util.ArrayList JavaDoc;
117 import java.util.logging.Level JavaDoc;
118 import java.util.logging.Logger JavaDoc;
119
120 //JMX imports
121
import javax.management.*;
122 import javax.management.Descriptor JavaDoc;
123 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
124 import javax.management.modelmbean.ModelMBeanOperationInfo JavaDoc;
125 import javax.management.modelmbean.ModelMBeanAttributeInfo JavaDoc;
126
127 //import com.sun.enterprise.management.model.J2EEManagedObjectMdl;
128

129 import com.sun.enterprise.admin.MBeanHelper;
130 import com.sun.enterprise.admin.meta.MBeanMetaConstants;
131
132 /****************************************************************************************************************
133  */

134 public class ManagedJsr77MdlBean {
135        
136     DynamicMBean m_mbean = null;
137     /*J2EEManagedObjectMdl*/ Object JavaDoc m_baseJsr77Bean = null;
138
139     public ManagedJsr77MdlBean(DynamicMBean mbean, /*J2EEManagedObjectMdl*/ Object JavaDoc cb)
140     {
141         m_baseJsr77Bean = cb;
142         m_mbean = mbean;
143     }
144     /****************************************************************************************************************
145      * Gets MBean's attribute value.
146      * @param externalName the MBean's attribute name.
147      * @return The value of the attribute retrieved.
148      * @throws MBeanException exception
149      * @throws AttributeNotFoundException exception
150      */

151     public Object JavaDoc getAttribute(ModelMBeanAttributeInfo JavaDoc attrInfo, String JavaDoc attrName) throws MBeanException,AttributeNotFoundException {
152         Descriptor JavaDoc descr = attrInfo.getDescriptor();
153         String JavaDoc getter = (String JavaDoc)descr.getFieldValue(MBeanMetaConstants.GETTER_FIELD_NAME);
154         if(getter==null)
155             throw new MBeanException(new MBeanRuntimeException("ManagedJsr77MdlBean:getAttribute:No getter found in descriptor"));
156         try
157         {
158             Method JavaDoc method = m_baseJsr77Bean.getClass().getMethod(getter);
159             return method.invoke(m_baseJsr77Bean);
160         }
161         catch (Exception JavaDoc e)
162         {
163             //throw new MBeanException(e, "Exception invoking getter method in runtime bean " + getter);
164
throw MBeanHelper.extractAndWrapTargetException(e,
165                 "Exception invoking getter method in runtime bean " + getter);
166         }
167     }
168     /****************************************************************************************************************
169      * Sets MBean's attribute value.
170      * @param attr The identification of the attribute to be set and the value it is to be set to.
171      * @throws MBeanException exception
172      * @throws AttributeNotFoundException exception
173      */

174     public void setAttribute(ModelMBeanAttributeInfo JavaDoc attrInfo, Attribute attr) throws MBeanException,AttributeNotFoundException {
175         Descriptor JavaDoc descr = attrInfo.getDescriptor();
176         String JavaDoc setter = (String JavaDoc)descr.getFieldValue(MBeanMetaConstants.SETTER_FIELD_NAME);
177         if(setter==null)
178             throw new MBeanException(new MBeanRuntimeException("ManagedJsr77MdlBean:getAttribute:No setter found in descriptor"));
179         try
180         {
181             Method JavaDoc method = m_baseJsr77Bean.getClass().getMethod(setter, new Class JavaDoc[]{getClassForName(attrInfo.getType())});
182             method.invoke(m_baseJsr77Bean, new Object JavaDoc[]{attr.getValue()});
183         }
184         catch (Exception JavaDoc e)
185         {
186 //e.printStackTrace();
187
//throw new MBeanException(e, "Exception invoking setter method in runtime bean " + setter);
188
throw MBeanHelper.extractAndWrapTargetException(e,
189                 "Exception invoking setter method in runtime bean " + setter);
190         }
191     }
192
193     public Object JavaDoc invokeOperation(ModelMBeanOperationInfo JavaDoc opInfo, Object JavaDoc params[], String JavaDoc signature[]) throws MBeanException, ReflectionException
194     {
195        String JavaDoc name = opInfo.getName();
196         try
197         {
198             Object JavaDoc ret = MBeanHelper.invokeOperationInBean(opInfo, this, params);
199             if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
200             {
201                 return ret;
202             }
203         }
204         catch (Exception JavaDoc e)
205         {
206             //throw new MBeanException(e, "Exception invoking method in runtime bean" + name);
207
throw MBeanHelper.extractAndWrapTargetException(e,
208                 "Exception invoking method in runtime bean " + name);
209         }
210
211        try
212         {
213             return MBeanHelper.invokeOperationInBean(opInfo, m_baseJsr77Bean, params);
214             // IT MAYBE:MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT !!!
215
}
216         catch (Exception JavaDoc e)
217         {
218             //throw new MBeanException(e, "Exception invoking method in runtime bean" + name);
219
throw MBeanHelper.extractAndWrapTargetException(e,
220                 "Exception invoking method in runtime bean " + name);
221         }
222     }
223 private Class JavaDoc getClassForName(String JavaDoc type) throws ClassNotFoundException JavaDoc
224     {
225         if(type.equals("int"))
226            return Integer.TYPE;
227         if(type.equals("long"))
228            return Long.TYPE;
229         if(type.equals("boolean"))
230            return Boolean.TYPE;
231         return Class.forName(type);
232     }
233 }
234  
235
Popular Tags