KickJava   Java API By Example, From Geeks To Geeks.

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


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.server.core.mbean.config;
25
26 //JMX imports
27
import javax.management.DynamicMBean JavaDoc;
28 import javax.management.AttributeList JavaDoc;
29 import javax.management.MBeanInfo JavaDoc;
30 import javax.management.Attribute JavaDoc;
31 import javax.management.AttributeNotFoundException JavaDoc;
32 import javax.management.MBeanException JavaDoc;
33 import javax.management.ReflectionException JavaDoc;
34 import javax.management.InvalidAttributeValueException JavaDoc;
35
36 //i18n import
37
import com.sun.enterprise.util.i18n.StringManager;
38 /* New for 8.0 */
39 import com.sun.enterprise.admin.server.core.jmx.Introspector;
40 import java.lang.reflect.Method JavaDoc;
41 /* New for 8.0 */
42
43 /**
44     The base class for all the MBeans. Note that there will be no MBean that
45     is registered in the MBeanServer for this class. It serves as the base class
46     of all concrete implementations of MBeans.
47  
48 */

49
50 public abstract class AdminBase implements DynamicMBean JavaDoc
51 {
52     // i18n StringManager
53
private static StringManager localStrings =
54         StringManager.getManager( AdminBase.class );
55
56     protected AdminBase() {
57     }
58
59     public Object JavaDoc getAttribute(String JavaDoc attributeName) throws
60         AttributeNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
61     String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_not_implemented" );
62         throw new UnsupportedOperationException JavaDoc( msg );
63     }
64
65     public AttributeList JavaDoc getAttributes(String JavaDoc[] attributeNames) {
66     String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.getattribute_not_implemented" );
67         throw new UnsupportedOperationException JavaDoc( msg );
68     }
69
70     public MBeanInfo JavaDoc getMBeanInfo() {
71         String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.getmbeaninfo_not_implemented" );
72         throw new UnsupportedOperationException JavaDoc( msg );
73     }
74
75     /** Abstract method that subclasses have to implement. This is the way for
76      * invoke method to work, through reflection.
77     */

78     protected abstract Class JavaDoc getImplementingClass();
79
80     /** Reflection requires the implementing object. */
81     protected abstract Object JavaDoc getImplementingMBean();
82
83     /**
84      * Every resource MBean should override this method to execute specific
85      * operations on the MBean. This method is enhanced in 8.0. It was a no-op
86      * in 7.0. In 8.0, it is modified to invoke the actual method through
87      * reflection. It relieves all the subclasses to implement the invoke method
88      * for various operations. If the subclasses choose to implement it, they may
89      * do so.
90      * @since 8.0
91      * @see javax.management.MBeanServer#invoke
92      * @see #getImplementingClass
93     */

94     public Object JavaDoc invoke(String JavaDoc methodName, Object JavaDoc[] methodParams,
95         String JavaDoc[] methodSignature) throws MBeanException JavaDoc, ReflectionException JavaDoc {
96     /* New for 8.0 */
97         final Class JavaDoc implClass = getImplementingClass();
98         final Object JavaDoc mbeanReference = getImplementingMBean();
99         final Introspector reflector = new Introspector(implClass);
100         Object JavaDoc value = null;
101         try {
102
103             final Method JavaDoc method = reflector.getMethod(methodName, methodSignature);
104             value = reflector.invokeMethodOn(method, mbeanReference, methodParams);
105             return ( value );
106         }
107         catch (java.lang.ClassNotFoundException JavaDoc cnfe) {
108             throw new javax.management.ReflectionException JavaDoc(cnfe);
109         }
110         catch (java.lang.NoSuchMethodException JavaDoc nsme) {
111             throw new javax.management.ReflectionException JavaDoc(nsme);
112         }
113         catch (java.lang.SecurityException JavaDoc se) {
114             throw new javax.management.ReflectionException JavaDoc(se);
115         }
116         catch (java.lang.reflect.InvocationTargetException JavaDoc ite) {
117             Throwable JavaDoc t = ite.getTargetException();
118             if (t instanceof MBeanException JavaDoc) {
119                 throw (MBeanException JavaDoc)t;
120             }
121             else
122                 if (t instanceof Exception JavaDoc) {
123                     throw new MBeanException JavaDoc((Exception JavaDoc) t);
124                 }
125                 else { //if an error
126
String JavaDoc msg = localStrings.getString( "admin.server.core.jmx.error_from_mbean", t.getMessage() );
127                     RuntimeException JavaDoc re = new RuntimeException JavaDoc( msg );
128                     throw new MBeanException JavaDoc(re);
129                     //Do what?
130
}
131         }
132         catch (java.lang.IllegalAccessException JavaDoc iae) {
133             throw new javax.management.ReflectionException JavaDoc(iae);
134         }
135         catch (Exception JavaDoc e) {
136             throw new MBeanException JavaDoc(e);
137         }
138     /* New for 8.0 */
139     }
140
141     public void setAttribute(Attribute JavaDoc attribute) throws
142         AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc,
143         MBeanException JavaDoc, ReflectionException JavaDoc {
144
145         String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.setattribute_not_implemented" );
146         throw new UnsupportedOperationException JavaDoc( msg );
147     }
148
149     public AttributeList JavaDoc setAttributes(AttributeList JavaDoc parm1) {
150     String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.setattributes_not_implemented" );
151         throw new UnsupportedOperationException JavaDoc( msg );
152     }
153 }
154
Popular Tags