KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > BaseAdminMBean


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: BaseAdminMBean.java,v 1.3 2005/12/25 03:47:28 tcfujii Exp $
26  * @author: alexkrav
27  *
28  * $Log: BaseAdminMBean.java,v $
29  * Revision 1.3 2005/12/25 03:47:28 tcfujii
30  * Updated copyright text and year.
31  *
32  * Revision 1.2 2005/06/27 21:19:39 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 2004/11/14 07:04:15 tcfujii
39  * Updated copyright text and/or year.
40  *
41  * Revision 1.8 2004/02/20 03:56:05 qouyang
42  *
43  *
44  * First pass at code merge.
45  *
46  * Details for the merge will be published at:
47  * http://javaweb.sfbay.sun.com/~qouyang/workspace/PE8FCSMerge/02202004/
48  *
49  * Revision 1.7 2003/11/11 01:33:13 ai109478
50  * Initial notification related changes. It supports the notion of fat pipe model.
51  *
52  * Revision 1.6.4.1 2004/02/02 07:25:12 tcfujii
53  * Copyright updates notices; reviewer: Tony Ng
54  *
55  * Revision 1.6 2003/08/29 02:16:40 kravtch
56  * Bug #4910964 (and similar others)
57  * Reviewer: Sridatta
58  *
59  * Exception handling and logging enchancements:
60  * - extraction target exception for MBeanException and TargetInvocationException:
61  * - switch to localStrings usage;
62  * - throwing exception for config MBeans if error in creation of ConfigBean;
63  * - exceptions for null-results in configbean operations,like getXXbyYYY() [changes commented because of crashing of quick test]
64  *
65  * Revision 1.5 2003/08/14 20:40:46 kravtch
66  * _sLogger and _LocalStrings are defined and set in the base class for all infra mbeans.
67  *
68  * Revision 1.4 2003/06/25 20:03:35 kravtch
69  * 1. java file headers modified
70  * 2. properties handling api is added
71  * 3. fixed bug for xpathes containing special symbols;
72  * 4. new testcases added for jdbc-resource
73  * 5. introspector modified by not including base classes operations;
74  *
75  *
76 */

77
78 package com.sun.enterprise.admin;
79
80 //JMX imports
81
import javax.management.DynamicMBean JavaDoc;
82 import javax.management.AttributeList JavaDoc;
83 import javax.management.MBeanInfo JavaDoc;
84 import javax.management.Attribute JavaDoc;
85 import javax.management.AttributeNotFoundException JavaDoc;
86 import javax.management.MBeanException JavaDoc;
87 import javax.management.ReflectionException JavaDoc;
88 import javax.management.InvalidAttributeValueException JavaDoc;
89 import javax.management.InstanceNotFoundException JavaDoc;
90 import javax.management.RuntimeOperationsException JavaDoc;
91 import javax.management.Descriptor JavaDoc;
92
93 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
94
95 /* New for 8.0 */
96 //import com.sun.enterprise.admin.server.core.jmx.Introspector;
97
import java.lang.reflect.Method JavaDoc;
98
99 import com.sun.enterprise.admin.meta.MBeanMetaConstants;
100
101 // Logging
102
import java.util.logging.Logger JavaDoc;
103 import java.util.logging.Level JavaDoc;
104 import com.sun.logging.LogDomains;
105
106 import javax.management.NotificationBroadcasterSupport JavaDoc;
107 import com.sun.enterprise.util.i18n.StringManager;
108
109 /**
110     The base class for all the MBeans. Note that there will be no MBean that
111     is registered in the MBeanServer for this class. It serves as the base class
112     of all concrete implementations of MBeans.
113  
114 */

115
116 public class BaseAdminMBean extends NotificationBroadcasterSupport JavaDoc implements DynamicMBean JavaDoc
117 {
118     protected ModelMBeanInfo JavaDoc info = null;
119     protected String JavaDoc mbeanType = "unknown";
120
121     // Logging
122
static protected Logger JavaDoc _sLogger = LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
123     protected StringManager _localStrings = null;
124     public BaseAdminMBean() {
125         _localStrings = StringManager.getManager( BaseAdminMBean.class );
126     }
127     
128     public void setModelMBeanInfo(ModelMBeanInfo JavaDoc mbeanInfo) {
129         info = mbeanInfo;
130         //now we can set the type of bean
131
try {
132             Descriptor JavaDoc descr = info.getMBeanDescriptor();
133             mbeanType = (String JavaDoc)descr.getFieldValue(MBeanMetaConstants.NMTYPE_FIELD_NAME);
134         } catch (Exception JavaDoc e)
135         {
136         }
137     }
138
139     public void setManagedResource(Object JavaDoc resource, String JavaDoc type)
140                                 throws InstanceNotFoundException JavaDoc, /*InvalidTargetObjectTypeException,*/
141                                         MBeanException JavaDoc, RuntimeOperationsException JavaDoc {
142
143         String JavaDoc msg = _localStrings.getString("mbean.baseadmin.setmanagedresource_not_implemented");
144         throw new UnsupportedOperationException JavaDoc( msg );
145     }
146
147     public Object JavaDoc getAttribute(String JavaDoc attributeName) throws
148         AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
149     String JavaDoc msg = _localStrings.getString("mbean.baseadmin.getattribute_not_implemented");
150         throw new UnsupportedOperationException JavaDoc( msg );
151     }
152
153     public AttributeList JavaDoc getAttributes(String JavaDoc[] attributeNames) {
154     String JavaDoc msg = _localStrings.getString("mbean.baseadmin.getattributes_not_implemented");
155         throw new UnsupportedOperationException JavaDoc( msg );
156     }
157
158     public MBeanInfo JavaDoc getMBeanInfo() {
159         return (MBeanInfo JavaDoc)info;
160     }
161
162     /** Abstract method that subclasses have to implement. This is the way for
163      * invoke method to work, through reflection.
164     */

165 // protected abstract Class getImplementingClass();
166

167     /** Reflection requires the implementing object. */
168 // protected abstract Object getImplementingMBean();
169

170     /**
171      * Every resource MBean should override this method to execute specific
172      * operations on the MBean. This method is enhanced in 8.0. It was a no-op
173      * in 7.0. In 8.0, it is modified to invoke the actual method through
174      * reflection. It relieves all the subclasses to implement the invoke method
175      * for various operations. If the subclasses choose to implement it, they may
176      * do so.
177      * @since 8.0
178      * @see javax.management.MBeanServer#invoke
179      * @see #getImplementingClass
180     */

181     public Object JavaDoc invoke(String JavaDoc methodName, Object JavaDoc[] methodParams,
182         String JavaDoc[] methodSignature) throws MBeanException JavaDoc, ReflectionException JavaDoc {
183             /*
184     
185         final Class implClass = this.getClass(); //getImplementingClass();
186         final Object mbeanReference = this; //getImplementingMBean();
187         final Introspector reflector = new Introspector(implClass);
188         Object value = null;
189         try {
190
191             final Method method = reflector.getMethod(methodName, methodSignature);
192             value = reflector.invokeMethodOn(method, mbeanReference, methodParams);
193             return ( value );
194         }
195         catch (java.lang.ClassNotFoundException cnfe) {
196             throw new javax.management.ReflectionException(cnfe);
197         }
198         catch (java.lang.NoSuchMethodException nsme) {
199             throw new javax.management.ReflectionException(nsme);
200         }
201         catch (java.lang.SecurityException se) {
202             throw new javax.management.ReflectionException(se);
203         }
204         catch (java.lang.reflect.InvocationTargetException ite) {
205             Throwable t = ite.getTargetException();
206             if (t instanceof MBeanException) {
207                 throw (MBeanException)t;
208             }
209             else
210                 if (t instanceof Exception) {
211                     throw new MBeanException((Exception) t);
212                 }
213                 else { //if an error
214                     String msg = _localStrings.getString("mbean.baseadmin.admin.server.core.jmx.error_from_mbean", t.getMessage() );
215                     RuntimeException re = new RuntimeException( msg );
216                     throw new MBeanException(re);
217                     //Do what?
218                 }
219         }
220         catch (java.lang.IllegalAccessException iae) {
221             throw new javax.management.ReflectionException(iae);
222         }
223         catch (Exception e) {
224             throw new MBeanException(e);
225         }
226     */

227             
228             throw new java.lang.UnsupportedOperationException JavaDoc("Not Yet Implemented");
229     }
230
231     public void setAttribute(Attribute JavaDoc attribute) throws
232         AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc,
233         MBeanException JavaDoc, ReflectionException JavaDoc {
234
235         String JavaDoc msg = _localStrings.getString("mbean.baseadmin.setattribute_not_implemented" );
236         throw new UnsupportedOperationException JavaDoc( msg );
237     }
238
239     public AttributeList JavaDoc setAttributes(AttributeList JavaDoc parm1) {
240     String JavaDoc msg = _localStrings.getString("mbean.baseadmin.setattributes_not_implemented" );
241         throw new UnsupportedOperationException JavaDoc( msg );
242     }
243     /**
244      * call app server logging
245      */

246     protected boolean isDebugEnabled() {
247         return true;
248     }
249     
250     protected void debug(String JavaDoc s) {
251         //TODO: change this to app server logging
252
System.out.println(s);
253     }
254     protected void info(String JavaDoc s) {
255         //TODO: change this to app server logging
256
System.out.println(s);
257     }
258     protected void error(String JavaDoc s) {
259         //TODO: change this to app server logging
260
System.out.println(s);
261     }
262     
263 }
264
Popular Tags