KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > jmx > connector > weblogic > WebLogicMBeanServer


1 package org.apache.tools.ant.taskdefs.optional.jmx.connector.weblogic;
2
3 /*
4  * ============================================================================
5  * The Apache Software License, Version 1.1
6  * ============================================================================
7  *
8  * Copyright (C) 2000-2002 The Apache Software Foundation. All
9  * rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without modifica-
12  * tion, are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  *
17  * 2. Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any, must
22  * include the following acknowledgment: "This product includes software
23  * developed by the Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself, if
25  * and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Ant" and "Apache Software Foundation" must not be used to
28  * endorse or promote products derived from this software without prior
29  * written permission. For written permission, please contact
30  * apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache", nor may
33  * "Apache" appear in their name, without prior written permission of the
34  * Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
37  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
38  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
39  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
40  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
41  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
42  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
43  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
45  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46  *
47  * This software consists of voluntary contributions made by many individuals
48  * on behalf of the Apache Software Foundation. For more information on the
49  * Apache Software Foundation, please see <http://www.apache.org/>.
50  *
51  */

52
53 import java.io.ObjectInputStream JavaDoc;
54 import java.util.Set JavaDoc;
55
56 import javax.management.AttributeList JavaDoc;
57 import javax.management.AttributeNotFoundException JavaDoc;
58 import javax.management.InstanceAlreadyExistsException JavaDoc;
59 import javax.management.InstanceNotFoundException JavaDoc;
60 import javax.management.ListenerNotFoundException JavaDoc;
61 import javax.management.MBeanException JavaDoc;
62 import javax.management.MBeanRegistrationException JavaDoc;
63 import javax.management.NotCompliantMBeanException JavaDoc;
64 import javax.management.NotificationFilter JavaDoc;
65 import javax.management.NotificationListener JavaDoc;
66 import javax.management.ObjectInstance JavaDoc;
67 import javax.management.ObjectName JavaDoc;
68 import javax.management.OperationsException JavaDoc;
69 import javax.management.QueryExp JavaDoc;
70 import javax.management.ReflectionException JavaDoc;
71
72 import weblogic.management.RemoteMBeanServer;
73
74 /**
75  * Wraps weblogic.management.RemoteMBeanServer to provide special handling
76  * of invokeMBean in cases where a WebLogic TargetMBean is being exchanged.
77  * In these circumstances, WebLogic Mbeans are not invokeable via the normal
78  * JMX mbean interface.
79  *
80  * Therefore, this implementation performs additional processing on the
81  * MBeanServer.invoke() and MBeanServer.setAttribute() methods. All other
82  * methods are passed through to the underlying weblogic.management.RemoteMBeanServer
83  * without modification.
84  *
85  * @author <a HREF="mailto:bdueck@yahoo.com">Brian Dueck</a>
86  * @version $Id: WebLogicMBeanServer.java,v 1.1 2003/05/26 22:08:01 bdueck Exp $
87  */

88 public class WebLogicMBeanServer implements javax.management.MBeanServer JavaDoc {
89     
90     weblogic.management.RemoteMBeanServer remoteServer;
91     
92     /** Creates a new instance of JBossMBeanServer */
93     public WebLogicMBeanServer(RemoteMBeanServer remoteServer) {
94         this.remoteServer = remoteServer;
95     }
96
97
98     public Object JavaDoc invoke(ObjectName JavaDoc objectName, String JavaDoc methodName, Object JavaDoc[] values, String JavaDoc[] types)
99         throws InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
100         
101         // if any of the parameter values is a descendent of
102
// weblogic.management.WebLogicMBean, then
103
// perform "special" processing to invoke this method.
104
//
105
// otherwise, this is a normal invocation
106
//
107
boolean hasSpecialParam = false;
108         for (int counter = 0; counter < types.length; counter++) {
109             try {
110                 if (isSpecialType(types[counter])) {
111                     hasSpecialParam = true;
112                     break;
113                 }
114             } catch (ClassNotFoundException JavaDoc x) {
115                 throw new MBeanException JavaDoc(x);
116             }
117         }
118
119         if (!hasSpecialParam) {
120             return remoteServer.invoke(objectName,methodName,values,types);
121         } else{
122             // invoke using the invoke() method directly on the
123
// weblogic.management.WebLogicMBean interface
124
//
125
// has to be done this way instead with "special" param values
126
// instead of invoking as per JMX standard using the
127
// MBeanServer.invoke() method.
128
//
129
try {
130                 return remoteServer.getMBeanHome().getMBean(objectName).invoke(methodName, values, types);
131             } catch (Exception JavaDoc x) {
132                 throw new MBeanException JavaDoc(x);
133             }
134         }
135     }
136     
137     public void setAttribute(ObjectName JavaDoc objectName, javax.management.Attribute JavaDoc attribute)
138         throws InstanceNotFoundException JavaDoc, AttributeNotFoundException JavaDoc, javax.management.InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
139
140         try {
141             if (isSpecialType(attribute.getValue().getClass())) {
142                 remoteServer.getMBeanHome().getMBean(objectName).setAttribute(attribute);
143             } else {
144                 remoteServer.setAttribute(objectName, attribute);
145             }
146         } catch (Exception JavaDoc x) {
147             throw new MBeanException JavaDoc(x);
148         }
149     }
150     
151     /**
152      * Checks if the specified class is of a type that requires
153      * "special" processing by invoke().
154      *
155      * Current implementation does this check by seeing if the
156      * specified className is a descendent of
157      * weblogic.management.WebLogicMBean.
158      *
159      * @param className Checks if this
160      * @return true if the className is a special type.
161      * @throws ClassNotFoundException
162      */

163     private boolean isSpecialType(String JavaDoc className)
164         throws ClassNotFoundException JavaDoc {
165         Class JavaDoc theClass = Thread.currentThread().getContextClassLoader().loadClass(className);
166         return isSpecialType(theClass);
167     }
168         
169     private boolean isSpecialType(Class JavaDoc theClass)
170         throws ClassNotFoundException JavaDoc {
171         return ( (weblogic.management.WebLogicMBean.class.isAssignableFrom(theClass))
172         || ( (theClass.isArray()) && (isSpecialType(theClass.getComponentType().getName()) )) );
173     }
174     
175     public void addNotificationListener(ObjectName JavaDoc objectName, NotificationListener JavaDoc notificationListener, NotificationFilter JavaDoc notificationFilter, Object JavaDoc obj) throws InstanceNotFoundException JavaDoc {
176         remoteServer.addNotificationListener(objectName, notificationListener, notificationFilter, obj);
177     }
178     
179     public void addNotificationListener(ObjectName JavaDoc objectName, ObjectName JavaDoc objectName1, NotificationFilter JavaDoc notificationFilter, Object JavaDoc obj) throws InstanceNotFoundException JavaDoc {
180         remoteServer.addNotificationListener(objectName, objectName1, notificationFilter, obj);
181     }
182     
183     public ObjectInstance JavaDoc createMBean(String JavaDoc str, ObjectName JavaDoc objectName) throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc {
184         return remoteServer.createMBean(str,objectName);
185     }
186     
187     public ObjectInstance JavaDoc createMBean(String JavaDoc str, ObjectName JavaDoc objectName, ObjectName JavaDoc objectName2) throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc, InstanceNotFoundException JavaDoc {
188         return remoteServer.createMBean(str,objectName,objectName2);
189     }
190     
191     public ObjectInstance JavaDoc createMBean(String JavaDoc str, ObjectName JavaDoc objectName, Object JavaDoc[] obj, String JavaDoc[] str3) throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc {
192         return remoteServer.createMBean(str,objectName,obj,str3);
193     }
194     
195     public ObjectInstance JavaDoc createMBean(String JavaDoc str, ObjectName JavaDoc objectName, ObjectName JavaDoc objectName2, Object JavaDoc[] obj, String JavaDoc[] str4) throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc, MBeanException JavaDoc, NotCompliantMBeanException JavaDoc, InstanceNotFoundException JavaDoc {
196         return remoteServer.createMBean(str, objectName, objectName2, obj, str4);
197     }
198     
199     public ObjectInputStream JavaDoc deserialize(String JavaDoc str, byte[] values) throws OperationsException JavaDoc, ReflectionException JavaDoc {
200         return remoteServer.deserialize(str, values);
201     }
202     
203     public ObjectInputStream JavaDoc deserialize(ObjectName JavaDoc objectName, byte[] values) throws InstanceNotFoundException JavaDoc, OperationsException JavaDoc {
204         return remoteServer.deserialize(objectName, values);
205     }
206     
207     public ObjectInputStream JavaDoc deserialize(String JavaDoc str, ObjectName JavaDoc objectName, byte[] values) throws InstanceNotFoundException JavaDoc, OperationsException JavaDoc, ReflectionException JavaDoc {
208         return remoteServer.deserialize(str, objectName, values);
209     }
210     
211     public Object JavaDoc getAttribute(ObjectName JavaDoc objectName, String JavaDoc str) throws MBeanException JavaDoc, AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc, ReflectionException JavaDoc {
212         return remoteServer.getAttribute(objectName,str);
213     }
214     
215     public AttributeList JavaDoc getAttributes(ObjectName JavaDoc objectName, String JavaDoc[] str) throws InstanceNotFoundException JavaDoc, ReflectionException JavaDoc {
216         return remoteServer.getAttributes(objectName,str);
217     }
218     
219     public String JavaDoc getDefaultDomain() {
220         return remoteServer.getDefaultDomain();
221     }
222     
223     public Integer JavaDoc getMBeanCount() {
224         return remoteServer.getMBeanCount();
225     }
226     
227     public javax.management.MBeanInfo JavaDoc getMBeanInfo(ObjectName JavaDoc objectName) throws InstanceNotFoundException JavaDoc, javax.management.IntrospectionException JavaDoc, ReflectionException JavaDoc {
228         return remoteServer.getMBeanInfo(objectName);
229     }
230     
231     public ObjectInstance JavaDoc getObjectInstance(ObjectName JavaDoc objectName) throws InstanceNotFoundException JavaDoc {
232         return remoteServer.getObjectInstance(objectName);
233     }
234     
235     public Object JavaDoc instantiate(String JavaDoc str) throws ReflectionException JavaDoc, MBeanException JavaDoc {
236         return remoteServer.instantiate(str);
237     }
238     
239     public Object JavaDoc instantiate(String JavaDoc str, ObjectName JavaDoc objectName) throws ReflectionException JavaDoc, MBeanException JavaDoc, InstanceNotFoundException JavaDoc {
240         return remoteServer.instantiate(str,objectName);
241     }
242     
243     public Object JavaDoc instantiate(String JavaDoc str, Object JavaDoc[] obj, String JavaDoc[] str2) throws ReflectionException JavaDoc, MBeanException JavaDoc {
244         return remoteServer.instantiate(str,obj,str2);
245     }
246     
247     public Object JavaDoc instantiate(String JavaDoc str, ObjectName JavaDoc objectName, Object JavaDoc[] obj, String JavaDoc[] str3) throws ReflectionException JavaDoc, MBeanException JavaDoc, InstanceNotFoundException JavaDoc {
248         return remoteServer.instantiate(str,objectName,obj,str3);
249     }
250     
251     public boolean isInstanceOf(ObjectName JavaDoc objectName, String JavaDoc str) throws InstanceNotFoundException JavaDoc {
252         return remoteServer.isInstanceOf(objectName,str);
253     }
254     
255     public boolean isRegistered(ObjectName JavaDoc objectName) {
256         return remoteServer.isRegistered(objectName);
257     }
258     
259     public Set JavaDoc queryMBeans(ObjectName JavaDoc objectName, QueryExp JavaDoc queryExp) {
260         return remoteServer.queryMBeans(objectName,queryExp);
261     }
262     
263     public Set JavaDoc queryNames(ObjectName JavaDoc objectName, QueryExp JavaDoc queryExp) {
264         return remoteServer.queryNames(objectName,queryExp);
265     }
266     
267     public ObjectInstance JavaDoc registerMBean(Object JavaDoc obj, ObjectName JavaDoc objectName) throws InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc, NotCompliantMBeanException JavaDoc {
268         return remoteServer.registerMBean(obj,objectName);
269     }
270     
271     public void removeNotificationListener(ObjectName JavaDoc objectName, ObjectName JavaDoc objectName1) throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc {
272         remoteServer.removeNotificationListener(objectName,objectName1);
273     }
274     
275     public void removeNotificationListener(ObjectName JavaDoc objectName, NotificationListener JavaDoc notificationListener) throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc {
276         remoteServer.removeNotificationListener(objectName,notificationListener);
277     }
278     
279     public AttributeList JavaDoc setAttributes(ObjectName JavaDoc objectName, AttributeList JavaDoc attributeList) throws InstanceNotFoundException JavaDoc, ReflectionException JavaDoc {
280         return remoteServer.setAttributes(objectName,attributeList);
281     }
282     
283     public void unregisterMBean(ObjectName JavaDoc objectName) throws InstanceNotFoundException JavaDoc, MBeanRegistrationException JavaDoc {
284         remoteServer.unregisterMBean(objectName);
285     }
286     
287 }
288 /*
289  * $Log: WebLogicMBeanServer.java,v $
290  * Revision 1.1 2003/05/26 22:08:01 bdueck
291  * Added special logic required to support WebLogic TargetMBean
292  * and other descendents of WebLogicMBean.
293  *
294  *
295  */

296
Popular Tags