KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > mbeanserver > JmxMBeanServer


1 /*
2  * @(#)JmxMBeanServer.java 1.67 04/01/21
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.jmx.mbeanserver;
9
10 // java import
11
import java.util.Iterator JavaDoc;
12 import java.util.ArrayList JavaDoc;
13 import java.util.Set JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.lang.reflect.InvocationTargetException JavaDoc;
16 import java.lang.reflect.Method JavaDoc;
17 import java.lang.reflect.Constructor JavaDoc;
18 import java.io.OptionalDataException JavaDoc;
19 import java.io.ObjectInputStream JavaDoc;
20 import java.io.ObjectOutputStream JavaDoc;
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.IOException JavaDoc ;
24 import java.security.AccessController JavaDoc;
25 import java.security.Permission JavaDoc;
26 import java.security.PrivilegedExceptionAction JavaDoc;
27
28 // RI import
29
import javax.management.MBeanPermission JavaDoc;
30 import javax.management.DynamicMBean JavaDoc;
31 import javax.management.AttributeNotFoundException JavaDoc;
32 import javax.management.MBeanException JavaDoc;
33 import javax.management.ReflectionException JavaDoc;
34 import javax.management.MBeanAttributeInfo JavaDoc;
35 import javax.management.MBeanInfo JavaDoc;
36 import javax.management.QueryExp JavaDoc;
37 import javax.management.NotificationListener JavaDoc;
38 import javax.management.NotificationFilter JavaDoc;
39 import javax.management.ListenerNotFoundException JavaDoc;
40 import javax.management.IntrospectionException JavaDoc;
41 import javax.management.OperationsException JavaDoc;
42 import javax.management.MBeanNotificationInfo JavaDoc;
43 import javax.management.JMRuntimeException JavaDoc;
44 import javax.management.InstanceNotFoundException JavaDoc;
45 import javax.management.NotCompliantMBeanException JavaDoc;
46 import javax.management.MBeanRegistrationException JavaDoc;
47 import javax.management.InstanceAlreadyExistsException JavaDoc;
48 import javax.management.InvalidAttributeValueException JavaDoc;
49 import javax.management.ObjectName JavaDoc;
50 import javax.management.ObjectInstance JavaDoc;
51 import javax.management.Attribute JavaDoc;
52 import javax.management.AttributeList JavaDoc;
53 import javax.management.RuntimeOperationsException JavaDoc;
54 import javax.management.MBeanServer JavaDoc;
55 import javax.management.MBeanServerDelegate JavaDoc;
56 import javax.management.loading.ClassLoaderRepository JavaDoc;
57
58 import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;
59 import com.sun.jmx.interceptor.MBeanServerInterceptor;
60 import com.sun.jmx.defaults.ServiceName;
61 import com.sun.jmx.trace.Trace;
62
63 /**
64  * This is the base class for MBean manipulation on the agent side. It
65  * contains the methods necessary for the creation, registration, and
66  * deletion of MBeans as well as the access methods for registered MBeans.
67  * This is the core component of the JMX infrastructure.
68  * <P>
69  * Every MBean which is added to the MBean server becomes manageable:
70  * its attributes and operations become remotely accessible through
71  * the connectors/adaptors connected to that MBean server.
72  * A Java object cannot be registered in the MBean server unless it is a
73  * JMX compliant MBean.
74  * <P>
75  * When an MBean is registered or unregistered in the MBean server an
76  * {@link javax.management.MBeanServerNotification MBeanServerNotification}
77  * Notification is emitted. To register an object as listener to
78  * MBeanServerNotifications you should call the MBean server method
79  * {@link #addNotificationListener addNotificationListener} with
80  * the <CODE>ObjectName</CODE> of the
81  * {@link javax.management.MBeanServerDelegate MBeanServerDelegate}.
82  * This <CODE>ObjectName</CODE> is:
83  * <BR>
84  * <CODE>JMImplementation:type=MBeanServerDelegate</CODE>.
85  *
86  * @since 1.5
87  */

88 public final class JmxMBeanServer
89     implements SunJmxMBeanServer {
90
91     /** The name of this class to be used for tracing */
92     private static final String JavaDoc dbgTag = "MBeanServer";
93     
94     private final MBeanInstantiator instantiator;
95     private final SecureClassLoaderRepository secureClr;
96
97     private final MetaData meta;
98
99     /** true if interceptors are enabled **/
100     private final boolean interceptorsEnabled;
101
102     /** Revisit: transient ??? **/
103     private final transient MBeanServer JavaDoc outerShell;
104
105     /** Revisit: transient ??? **/
106     private transient MBeanServerInterceptor mbsInterceptor = null;
107
108     /** Revisit: transient ??? **/
109     /** The MBeanServerDelegate object representing the MBean Server */
110     private final transient MBeanServerDelegate JavaDoc mBeanServerDelegateObject;
111
112     /** Revisit: transient ??? **/
113     /** The MBeanServerDelegate object name */
114     private transient ObjectName JavaDoc mBeanServerDelegateObjectName = null;
115     
116     /**
117      * <b>Package:</b> Creates an MBeanServer with the
118      * specified default domain name, outer interface, and delegate.
119      * <p>The default domain name is used as the domain part in the ObjectName
120      * of MBeans if no domain is specified by the user.
121      * <ul><b>Note:</b>Using this constructor directly is strongly
122      * discouraged. You should use
123      * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)}
124      * or
125      * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)}
126      * instead.
127      * <p>
128      * By default, {@link MBeanServerInterceptor} are disabled. Use
129      * {@link #JmxMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)} to enable them.
130      * </ul>
131      * @param domain The default domain name used by this MBeanServer.
132      * @param outer A pointer to the MBeanServer object that must be
133      * passed to the MBeans when invoking their
134      * {@link javax.management.MBeanRegistration} interface.
135      * @param delegate A pointer to the MBeanServerDelegate associated
136      * with the new MBeanServer. The new MBeanServer must register
137      * this MBean in its MBean repository.
138      * @exception IllegalArgumentException if the instantiator is null.
139      */

140     JmxMBeanServer(String JavaDoc domain, MBeanServer JavaDoc outer,
141            MBeanServerDelegate JavaDoc delegate) {
142     this(domain,outer,delegate,null,null,false);
143     }
144
145     /**
146      * <b>Package:</b> Creates an MBeanServer with the
147      * specified default domain name, outer interface, and delegate.
148      * <p>The default domain name is used as the domain part in the ObjectName
149      * of MBeans if no domain is specified by the user.
150      * <ul><b>Note:</b>Using this constructor directly is strongly
151      * discouraged. You should use
152      * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)}
153      * or
154      * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)}
155      * instead.
156      * </ul>
157      * @param domain The default domain name used by this MBeanServer.
158      * @param outer A pointer to the MBeanServer object that must be
159      * passed to the MBeans when invoking their
160      * {@link javax.management.MBeanRegistration} interface.
161      * @param delegate A pointer to the MBeanServerDelegate associated
162      * with the new MBeanServer. The new MBeanServer must register
163      * this MBean in its MBean repository.
164      * @param interceptors If <code>true</code>,
165      * {@link MBeanServerInterceptor} will be enabled (default is
166      * <code>false</code>).
167      * @exception IllegalArgumentException if the instantiator is null.
168      */

169     JmxMBeanServer(String JavaDoc domain, MBeanServer JavaDoc outer,
170            MBeanServerDelegate JavaDoc delegate, boolean interceptors) {
171     this(domain,outer,delegate,null,null,false);
172     }
173
174     /**
175      * <b>Package:</b> Creates an MBeanServer.
176      * @param domain The default domain name used by this MBeanServer.
177      * @param outer A pointer to the MBeanServer object that must be
178      * passed to the MBeans when invoking their
179      * {@link javax.management.MBeanRegistration} interface.
180      * @param delegate A pointer to the MBeanServerDelegate associated
181      * with the new MBeanServer. The new MBeanServer must register
182      * this MBean in its MBean repository.
183      * @param instantiator The MBeanInstantiator that will be used to
184      * instantiate MBeans and take care of class loading issues.
185      * @param metadata The MetaData object that will be used by the
186      * MBean server in order to invoke the MBean interface of
187      * the registered MBeans.
188      * @param interceptors If <code>true</code>,
189      * {@link MBeanServerInterceptor} will be enabled (default is
190      * <code>false</code>).
191      */

192     JmxMBeanServer(String JavaDoc domain, MBeanServer JavaDoc outer,
193            MBeanServerDelegate JavaDoc delegate,
194            MBeanInstantiator instantiator,
195            MetaData metadata,
196            boolean interceptors) {
197
198     if (instantiator == null) {
199         final ModifiableClassLoaderRepository
200         clr = new ClassLoaderRepositorySupport();
201         instantiator = new MBeanInstantiatorImpl(clr);
202     }
203     this.secureClr = new
204       SecureClassLoaderRepository(instantiator.getClassLoaderRepository());
205     if (metadata == null)
206         metadata = new MetaDataImpl(instantiator);
207     if (delegate == null)
208         delegate = new MBeanServerDelegateImpl();
209     if (outer == null)
210         outer = this;
211     
212     this.instantiator = instantiator;
213     this.meta = metadata;
214     this.mBeanServerDelegateObject = delegate;
215     this.outerShell = outer;
216
217     final Repository repository = new RepositorySupport(domain);
218     this.mbsInterceptor =
219         new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
220                           metadata, repository);
221     this.interceptorsEnabled = interceptors;
222     initialize();
223     }
224
225     /**
226      * Tell whether {@link MBeanServerInterceptor}s are enabled on this
227      * object.
228      * @return <code>true</code> if {@link MBeanServerInterceptor}s are
229      * enabled.
230      * @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)
231      **/

232     public boolean interceptorsEnabled() {
233     return interceptorsEnabled;
234     }
235
236     /**
237      * Return the MBeanInstantiator associated to this MBeanServer.
238      * @exception UnsupportedOperationException if
239      * {@link MBeanServerInterceptor}s
240      * are not enabled on this object.
241      * @see #interceptorsEnabled
242      **/

243     public MBeanInstantiator getMBeanInstantiator() {
244     if (interceptorsEnabled) return instantiator;
245     else throw new UnsupportedOperationException JavaDoc(
246                    "MBeanServerInterceptors are disabled.");
247     }
248
249     /**
250      * Return the MetaData associated to this MBeanServer.
251      */

252     public MetaData getMetaData() {
253
254     return meta;
255     }
256
257     /**
258      * Instantiates and registers an MBean in the MBean server.
259      * The MBean server will use its
260      * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}
261      * to load the class of the MBean.
262      * An object name is associated to the MBean.
263      * If the object name given is null, the MBean can automatically
264      * provide its own name by implementing the
265      * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
266      * The call returns an <CODE>ObjectInstance</CODE> object representing
267      * the newly created MBean.
268      *
269      * @param className The class name of the MBean to be instantiated.
270      * @param name The object name of the MBean. May be null.
271      *
272      * @return An <CODE>ObjectInstance</CODE>, containing the
273      * <CODE>ObjectName</CODE> and the Java class name of the newly
274      * instantiated MBean.
275      *
276      * @exception ReflectionException Wraps an
277      * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
278      * <CODE>{@link java.lang.Exception}</CODE> that occurred
279      * when trying to invoke the MBean's constructor.
280      * @exception InstanceAlreadyExistsException The MBean is already
281      * under the control of the MBean server.
282      * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
283      * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
284      * has thrown an exception. The MBean will not be registered.
285      * @exception MBeanException The constructor of the MBean has thrown
286      * an exception.
287      * @exception NotCompliantMBeanException This class is not a JMX
288      * compliant MBean.
289      * @exception RuntimeOperationsException Wraps an
290      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
291      * The className passed in parameter is null, the
292      * <CODE>ObjectName</CODE> passed in parameter contains a pattern
293      * or no <CODE>ObjectName</CODE> is specified for the MBean.
294      *
295      */

296     public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name)
297         throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc,
298            MBeanRegistrationException JavaDoc, MBeanException JavaDoc,
299            NotCompliantMBeanException JavaDoc {
300
301     return mbsInterceptor.createMBean(className,
302                       cloneObjectName(name),
303                       (Object JavaDoc[]) null,
304                       (String JavaDoc[]) null);
305     }
306
307     /**
308      * Instantiates and registers an MBean in the MBean server.
309      * The class loader to be used is identified by its object name.
310      * An object name is associated to the MBean.
311      * If the object name of the loader is null, the ClassLoader that
312      * loaded the MBean server will be used.
313      * If the MBean's object name given is null, the MBean can
314      * automatically provide its own name by implementing the
315      * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
316      * The call returns an <CODE>ObjectInstance</CODE> object representing
317      * the newly created MBean.
318      *
319      * @param className The class name of the MBean to be instantiated.
320      * @param name The object name of the MBean. May be null.
321      * @param loaderName The object name of the class loader to be used.
322      *
323      * @return An <CODE>ObjectInstance</CODE>, containing the
324      * <CODE>ObjectName</CODE> and the Java class name
325      * of the newly instantiated MBean.
326      *
327      * @exception ReflectionException Wraps an
328      * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
329      * <CODE>{@link java.lang.Exception}</CODE> that occurred when trying
330      * to invoke the MBean's constructor.
331      * @exception InstanceAlreadyExistsException The MBean is already
332      * under the control of the MBean server.
333      * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
334      * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
335      * has thrown an exception. The MBean will not be registered.
336      * @exception MBeanException The constructor of the MBean has thrown
337      * an exception
338      * @exception NotCompliantMBeanException This class is not a JMX
339      * compliant MBean.
340      * @exception InstanceNotFoundException The specified class loader
341      * is not registered in the MBean server.
342      * @exception RuntimeOperationsException Wraps an
343      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
344      * className passed in parameter is null, the <CODE>ObjectName</CODE>
345      * passed in parameter contains a pattern or no
346      * <CODE>ObjectName</CODE> is specified for the MBean.
347      */

348     public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name,
349                       ObjectName JavaDoc loaderName)
350         throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc,
351            MBeanRegistrationException JavaDoc, MBeanException JavaDoc,
352            NotCompliantMBeanException JavaDoc, InstanceNotFoundException JavaDoc {
353     
354     return mbsInterceptor.createMBean(className,
355                       cloneObjectName(name),
356                       loaderName,
357                       (Object JavaDoc[]) null,
358                       (String JavaDoc[]) null);
359     }
360
361     /**
362      * Instantiates and registers an MBean in the MBean server.
363      * The MBean server will use its
364      * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}
365      * to load the class of the MBean.
366      * An object name is associated to the MBean.
367      * If the object name given is null, the MBean can automatically
368      * provide its own name by implementing the
369      * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
370      * The call returns an <CODE>ObjectInstance</CODE> object representing
371      * the newly created MBean.
372      *
373      * @param className The class name of the MBean to be instantiated.
374      * @param name The object name of the MBean. May be null.
375      * @param params An array containing the parameters of the constructor
376      * to be invoked.
377      * @param signature An array containing the signature of the
378      * constructor to be invoked.
379      *
380      * @return An <CODE>ObjectInstance</CODE>, containing the
381      * <CODE>ObjectName</CODE> and the Java class name
382      * of the newly instantiated MBean.
383      *
384      * @exception ReflectionException Wraps a
385      * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
386      * <CODE>{@link java.lang.Exception}</CODE> that occurred
387      * when trying to invoke the MBean's constructor.
388      * @exception InstanceAlreadyExistsException The MBean is already
389      * under the control of the MBean server.
390      * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
391      * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
392      * has thrown an exception. The MBean will not be registered.
393      * @exception MBeanException The constructor of the MBean has
394      * thrown an exception.
395      * @exception RuntimeOperationsException Wraps an
396      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
397      * className passed in parameter is null, the <CODE>ObjectName</CODE>
398      * passed in parameter contains a pattern or no
399      * <CODE>ObjectName</CODE> is specified for the MBean.
400      *
401      */

402     public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name,
403                       Object JavaDoc params[], String JavaDoc signature[])
404         throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc,
405            MBeanRegistrationException JavaDoc, MBeanException JavaDoc,
406            NotCompliantMBeanException JavaDoc {
407     
408     return mbsInterceptor.createMBean(className, cloneObjectName(name),
409                       params, signature);
410     }
411
412    /**
413      * Instantiates and registers an MBean in the MBean server.
414      * The class loader to be used is identified by its object name.
415      * An object name is associated to the MBean. If the object name
416      * of the loader is not specified, the ClassLoader that loaded the
417      * MBean server will be used.
418      * If the MBean object name given is null, the MBean can automatically
419      * provide its own name by implementing the
420      * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
421      * The call returns an <CODE>ObjectInstance</CODE> object representing
422      * the newly created MBean.
423      *
424      * @param className The class name of the MBean to be instantiated.
425      * @param name The object name of the MBean. May be null.
426      * @param params An array containing the parameters of the constructor
427      * to be invoked.
428      * @param signature An array containing the signature of the
429      * constructor to be invoked.
430      * @param loaderName The object name of the class loader to be used.
431      *
432      * @return An <CODE>ObjectInstance</CODE>, containing the
433      * <CODE>ObjectName</CODE> and the Java class name of the newly
434      * instantiated MBean.
435      *
436      * @exception ReflectionException Wraps a
437      * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
438      * <CODE>{@link java.lang.Exception}</CODE>
439      * that occurred when trying to invoke the MBean's constructor.
440      * @exception InstanceAlreadyExistsException The MBean is already
441      * under the control of the MBean server.
442      * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
443      * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
444      * has thrown an exception. The MBean will not be registered.
445      * @exception MBeanException The constructor of the MBean has
446      * thrown an exception
447      * @exception InstanceNotFoundException The specified class loader is
448      * not registered in the MBean server.
449      * @exception RuntimeOperationsException Wraps an
450      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
451      * className passed in parameter is null, the <CODE>ObjectName</CODE>
452      * passed in parameter contains a pattern or no
453      * <CODE>ObjectName</CODE> is specified for the MBean.
454      *
455      */

456     public ObjectInstance JavaDoc createMBean(String JavaDoc className, ObjectName JavaDoc name,
457                       ObjectName JavaDoc loaderName, Object JavaDoc params[],
458                       String JavaDoc signature[])
459         throws ReflectionException JavaDoc, InstanceAlreadyExistsException JavaDoc,
460            MBeanRegistrationException JavaDoc, MBeanException JavaDoc,
461            NotCompliantMBeanException JavaDoc, InstanceNotFoundException JavaDoc {
462      
463         return mbsInterceptor.createMBean(className, cloneObjectName(name),
464                       loaderName, params, signature);
465     }
466
467     /**
468      * Registers a pre-existing object as an MBean with the MBean server.
469      * If the object name given is null, the MBean may automatically
470      * provide its own name by implementing the
471      * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
472      * The call returns an <CODE>ObjectInstance</CODE> object representing
473      * the registered MBean.
474      *
475      * @param object The MBean to be registered as an MBean.
476      * @param name The object name of the MBean. May be null.
477      *
478      * @return The <CODE>ObjectInstance</CODE> for the MBean that has been
479      * registered.
480      *
481      * @exception InstanceAlreadyExistsException The MBean is already
482      * under the control of the MBean server.
483      * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
484      * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
485      * has thrown an exception. The MBean will not be registered.
486      * @exception NotCompliantMBeanException This object is not a JMX
487      * compliant MBean
488      * @exception RuntimeOperationsException Wraps an
489      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
490      * object passed in parameter is null or no object name is specified.
491      *
492      */

493     public ObjectInstance JavaDoc registerMBean(Object JavaDoc object, ObjectName JavaDoc name)
494     throws InstanceAlreadyExistsException JavaDoc, MBeanRegistrationException JavaDoc,
495            NotCompliantMBeanException JavaDoc {
496     
497     return mbsInterceptor.registerMBean(object, cloneObjectName(name));
498     }
499
500     /**
501      * De-registers an MBean from the MBean server. The MBean is identified by
502      * its object name. Once the method has been invoked, the MBean may
503      * no longer be accessed by its object name.
504      *
505      * @param name The object name of the MBean to be de-registered.
506      *
507      * @exception InstanceNotFoundException The MBean specified is not
508      * registered in the MBean server.
509      * @exception MBeanRegistrationException The <code>preDeregister()</code>
510      * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
511      * has thrown an exception.
512      * @exception RuntimeOperationsException Wraps an
513      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
514      * object name in parameter is null or the MBean you are when
515      * trying to de-register is the
516      * {@link javax.management.MBeanServerDelegate MBeanServerDelegate}
517      * MBean.
518      **/

519     public void unregisterMBean(ObjectName JavaDoc name)
520     throws InstanceNotFoundException JavaDoc, MBeanRegistrationException JavaDoc {
521     // Now handled by the delegate itself..
522
// if (name.equals(MBeanServerDelegateObjectName)) {
523
// throw new RuntimeOperationsException(
524
// new IllegalArgumentException(
525
// "The MBeanDelegate MBean cannot be unregistered"));
526
// }
527
mbsInterceptor.unregisterMBean(cloneObjectName(name));
528     }
529
530     /**
531      * Gets the <CODE>ObjectInstance</CODE> for a given MBean registered
532      * with the MBean server.
533      *
534      * @param name The object name of the MBean.
535      *
536      * @return The <CODE>ObjectInstance</CODE> associated to the MBean
537      * specified by <VAR>name</VAR>.
538      *
539      * @exception InstanceNotFoundException The MBean specified is not
540      * registered in the MBean server.
541      */

542     public ObjectInstance JavaDoc getObjectInstance(ObjectName JavaDoc name)
543     throws InstanceNotFoundException JavaDoc {
544
545     return mbsInterceptor.getObjectInstance(cloneObjectName(name));
546     }
547
548     /**
549      * Gets MBeans controlled by the MBean server. This method allows any
550      * of the following to be obtained: All MBeans, a set of MBeans specified
551      * by pattern matching on the <CODE>ObjectName</CODE> and/or a Query
552      * expression, a specific MBean. When the object name is null or no
553      * domain and key properties are specified, all objects are to be
554      * selected (and filtered if a query is specified). It returns the
555      * set of <CODE>ObjectInstance</CODE> objects (containing the
556      * <CODE>ObjectName</CODE> and the Java Class name) for
557      * the selected MBeans.
558      *
559      * @param name The object name pattern identifying the MBeans to
560      * be retrieved. If null or or no domain and key properties
561      * are specified, all the MBeans registered will be retrieved.
562      * @param query The query expression to be applied for selecting
563      * MBeans. If null no query expression will be applied for
564      * selecting MBeans.
565      *
566      * @return A set containing the <CODE>ObjectInstance</CODE> objects
567      * for the selected MBeans.
568      * If no MBean satisfies the query an empty list is returned.
569      *
570      */

571     public Set JavaDoc queryMBeans(ObjectName JavaDoc name, QueryExp JavaDoc query) {
572     
573     return mbsInterceptor.queryMBeans(cloneObjectName(name), query);
574     }
575
576     /**
577      * Gets the names of MBeans controlled by the MBean server. This method
578      * enables any of the following to be obtained: The names of all MBeans,
579      * the names of a set of MBeans specified by pattern matching on the
580      * <CODE>ObjectName</CODE> and/or a Query expression, a specific
581      * MBean name (equivalent to testing whether an MBean is registered).
582      * When the object name is null or or no domain and key properties are
583      * specified, all objects are selected (and filtered if a query is
584      * specified). It returns the set of ObjectNames for the MBeans
585      * selected.
586      *
587      * @param name The object name pattern identifying the MBeans to be
588      * retrieved. If null or no domain and key properties are
589      * specified, all the MBeans registered will be retrieved.
590      * @param query The query expression to be applied for selecting
591      * MBeans. If null no query expression will be applied for
592      * selecting MBeans.
593      *
594      * @return A set containing the ObjectNames for the MBeans selected.
595      * If no MBean satisfies the query, an empty list is returned.
596      *
597      */

598     public Set JavaDoc queryNames(ObjectName JavaDoc name, QueryExp JavaDoc query) {
599
600         return mbsInterceptor.queryNames(cloneObjectName(name), query);
601     }
602
603     /**
604      * Checks whether an MBean, identified by its object name, is already
605      * registered with the MBean server.
606      *
607      * @param name The object name of the MBean to be checked.
608      *
609      * @return True if the MBean is already registered in the MBean server,
610      * false otherwise.
611      *
612      * @exception RuntimeOperationsException Wraps an
613      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The object
614      * name in parameter is null.
615      *
616      */

617     public boolean isRegistered(ObjectName JavaDoc name) {
618
619         return mbsInterceptor.isRegistered(name);
620     }
621
622     /**
623      * Returns the number of MBeans registered in the MBean server.
624      */

625     public Integer JavaDoc getMBeanCount() {
626
627         return mbsInterceptor.getMBeanCount();
628     }
629
630     /**
631      * Gets the value of a specific attribute of a named MBean. The MBean
632      * is identified by its object name.
633      *
634      * @param name The object name of the MBean from which the attribute
635      * is to be retrieved.
636      * @param attribute A String specifying the name of the attribute to be
637      * retrieved.
638      *
639      * @return The value of the retrieved attribute.
640      *
641      * @exception AttributeNotFoundException The attribute specified
642      * is not accessible in the MBean.
643      * @exception MBeanException Wraps an exception thrown by the
644      * MBean's getter.
645      * @exception InstanceNotFoundException The MBean specified is not
646      * registered in the MBean server.
647      * @exception ReflectionException Wraps an
648      * <CODE>{@link java.lang.Exception}</CODE> thrown when trying to
649      * invoke the setter.
650      * @exception RuntimeOperationsException Wraps an
651      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
652      * The object name in parameter is null or the attribute in
653      * parameter is null.
654      */

655     public Object JavaDoc getAttribute(ObjectName JavaDoc name, String JavaDoc attribute)
656     throws MBeanException JavaDoc, AttributeNotFoundException JavaDoc,
657            InstanceNotFoundException JavaDoc, ReflectionException JavaDoc {
658
659     return mbsInterceptor.getAttribute(cloneObjectName(name), attribute);
660     }
661
662
663     /**
664      * Enables the values of several attributes of a named MBean. The MBean
665      * is identified by its object name.
666      *
667      * @param name The object name of the MBean from which the attributes are
668      * retrieved.
669      * @param attributes A list of the attributes to be retrieved.
670      *
671      * @return The list of the retrieved attributes.
672      *
673      * @exception InstanceNotFoundException The MBean specified is not
674      * registered in the MBean server.
675      * @exception ReflectionException An exception occurred when trying
676      * to invoke the getAttributes method of a Dynamic MBean.
677      * @exception RuntimeOperationsException Wrap an
678      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
679      * object name in parameter is null or attributes in parameter
680      * is null.
681      *
682      */

683     public AttributeList JavaDoc getAttributes(ObjectName JavaDoc name, String JavaDoc[] attributes)
684         throws InstanceNotFoundException JavaDoc, ReflectionException JavaDoc {
685   
686     return mbsInterceptor.getAttributes(cloneObjectName(name), attributes);
687    
688     }
689
690     /**
691      * Sets the value of a specific attribute of a named MBean. The MBean
692      * is identified by its object name.
693      *
694      * @param name The name of the MBean within which the attribute is
695      * to be set.
696      * @param attribute The identification of the attribute to be set
697      * and the value it is to be set to.
698      *
699      * @return The value of the attribute that has been set.
700      *
701      * @exception InstanceNotFoundException The MBean specified is
702      * not registered in the MBean server.
703      * @exception AttributeNotFoundException The attribute specified is
704      * not accessible in the MBean.
705      * @exception InvalidAttributeValueException The value specified for
706      * the attribute is not valid.
707      * @exception MBeanException Wraps an exception thrown by the
708      * MBean's setter.
709      * @exception ReflectionException Wraps an
710      * <CODE>{@link java.lang.Exception}</CODE> thrown when trying
711      * to invoke the setter.
712      * @exception RuntimeOperationsException Wraps an
713      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
714      * object name in parameter is null or the attribute in parameter
715      * is null.
716      */

717     public void setAttribute(ObjectName JavaDoc name, Attribute JavaDoc attribute)
718     throws InstanceNotFoundException JavaDoc, AttributeNotFoundException JavaDoc,
719            InvalidAttributeValueException JavaDoc, MBeanException JavaDoc,
720            ReflectionException JavaDoc {
721     
722     mbsInterceptor.setAttribute(cloneObjectName(name),
723                     cloneAttribute(attribute));
724     }
725
726     /**
727      * Sets the values of several attributes of a named MBean. The MBean is
728      * identified by its object name.
729      *
730      * @param name The object name of the MBean within which the
731      * attributes are to be set.
732      * @param attributes A list of attributes: The identification of the
733      * attributes to be set and the values they are to be set to.
734      *
735      * @return The list of attributes that were set, with their new values.
736      *
737      * @exception InstanceNotFoundException The MBean specified is not
738      * registered in the MBean server.
739      * @exception ReflectionException An exception occurred when trying
740      * to invoke the getAttributes method of a Dynamic MBean.
741      * @exception RuntimeOperationsException Wraps an
742      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
743      * The object name in parameter is null or attributes in
744      * parameter is null.
745      *
746      */

747     public AttributeList JavaDoc setAttributes(ObjectName JavaDoc name,
748                        AttributeList JavaDoc attributes)
749         throws InstanceNotFoundException JavaDoc, ReflectionException JavaDoc {
750     
751     return mbsInterceptor.setAttributes(cloneObjectName(name),
752                         cloneAttributeList(attributes));
753     }
754
755     /**
756      * Invokes an operation on an MBean.
757      *
758      * @param name The object name of the MBean on which the method is to be
759      * invoked.
760      * @param operationName The name of the operation to be invoked.
761      * @param params An array containing the parameters to be set when
762      * the operation is invoked
763      * @param signature An array containing the signature of the operation.
764      * The class objects will be loaded using the same class loader as
765      * the one used for loading the MBean on which the operation was
766      * invoked.
767      *
768      * @return The object returned by the operation, which represents the
769      * result ofinvoking the operation on the MBean specified.
770      *
771      * @exception InstanceNotFoundException The MBean specified is not
772      * registered in the MBean server.
773      * @exception MBeanException Wraps an exception thrown by the MBean's
774      * invoked method.
775      * @exception ReflectionException Wraps an
776      * <CODE>{@link java.lang.Exception}</CODE> thrown while trying
777      * to invoke the method.
778      *
779      */

780     public Object JavaDoc invoke(ObjectName JavaDoc name, String JavaDoc operationName,
781              Object JavaDoc params[], String JavaDoc signature[])
782     throws InstanceNotFoundException JavaDoc, MBeanException JavaDoc,
783            ReflectionException JavaDoc {
784         return mbsInterceptor.invoke(cloneObjectName(name), operationName,
785                      params, signature);
786     }
787  
788     /**
789      * Returns the default domain used for naming the MBean.
790      * The default domain name is used as the domain part in the ObjectName
791      * of MBeans if no domain is specified by the user.
792      */

793     public String JavaDoc getDefaultDomain() {
794         return mbsInterceptor.getDefaultDomain();
795     }
796     
797     // From MBeanServer
798
public String JavaDoc[] getDomains() {
799         return mbsInterceptor.getDomains();
800     }
801
802     /**
803      * Adds a listener to a registered MBean.
804      *
805      * @param name The name of the MBean on which the listener should be added.
806      * @param listener The listener object which will handle the
807      * notifications emitted by the registered MBean.
808      * @param filter The filter object. If filter is null, no filtering
809      * will be performed before handling notifications.
810      * @param handback The context to be sent to the listener when a
811      * notification is emitted.
812      *
813      * @exception InstanceNotFoundException The MBean name provided does
814      * not match any of the registered MBeans.
815      */

816     public void addNotificationListener(ObjectName JavaDoc name,
817                     NotificationListener JavaDoc listener,
818                     NotificationFilter JavaDoc filter,
819                     Object JavaDoc handback)
820         throws InstanceNotFoundException JavaDoc {
821
822     mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,
823                            filter, handback);
824     }
825
826     /**
827      * Adds a listener to a registered MBean.
828      *
829      * @param name The name of the MBean on which the listener should be added.
830      * @param listener The object name of the listener which will handle the
831      * notifications emitted by the registered MBean.
832      * @param filter The filter object. If filter is null, no filtering will
833      * be performed before handling notifications.
834      * @param handback The context to be sent to the listener when a
835      * notification is emitted.
836      *
837      * @exception InstanceNotFoundException The MBean name of the
838      * notification listener or of the notification broadcaster
839      * does not match any of the registered MBeans.
840      */

841     public void addNotificationListener(ObjectName JavaDoc name, ObjectName JavaDoc listener,
842                    NotificationFilter JavaDoc filter, Object JavaDoc handback)
843         throws InstanceNotFoundException JavaDoc {
844     
845         mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,
846                            filter, handback);
847     }
848
849     public void removeNotificationListener(ObjectName JavaDoc name,
850                        NotificationListener JavaDoc listener)
851         throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc {
852     
853     mbsInterceptor.removeNotificationListener(cloneObjectName(name),
854                           listener);
855     }
856
857     public void removeNotificationListener(ObjectName JavaDoc name,
858                        NotificationListener JavaDoc listener,
859                        NotificationFilter JavaDoc filter,
860                        Object JavaDoc handback)
861         throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc {
862     
863     mbsInterceptor.removeNotificationListener(cloneObjectName(name),
864                           listener, filter, handback);
865     }
866
867     public void removeNotificationListener(ObjectName JavaDoc name,
868                        ObjectName JavaDoc listener)
869         throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc {
870
871     mbsInterceptor.removeNotificationListener(cloneObjectName(name),
872                           listener);
873     }
874
875     public void removeNotificationListener(ObjectName JavaDoc name,
876                        ObjectName JavaDoc listener,
877                        NotificationFilter JavaDoc filter,
878                        Object JavaDoc handback)
879         throws InstanceNotFoundException JavaDoc, ListenerNotFoundException JavaDoc {
880
881     mbsInterceptor.removeNotificationListener(cloneObjectName(name),
882                           listener, filter, handback);
883     }
884
885     /**
886      * This method discovers the attributes and operations that an MBean exposes
887      * for management.
888      *
889      * @param name The name of the MBean to analyze
890      *
891      * @return An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of
892      * all attributes and operations of this MBean.
893      *
894      * @exception IntrospectionException An exception occurs during
895      * introspection.
896      * @exception InstanceNotFoundException The MBean specified is not found.
897      * @exception ReflectionException An exception occurred when trying to
898      * invoke the getMBeanInfo of a Dynamic MBean.
899      */

900     public MBeanInfo JavaDoc getMBeanInfo(ObjectName JavaDoc name) throws
901     InstanceNotFoundException JavaDoc, IntrospectionException JavaDoc, ReflectionException JavaDoc {
902     
903     return mbsInterceptor.getMBeanInfo(cloneObjectName(name));
904     }
905
906     /**
907      * Instantiates an object using the list of all class loaders registered
908      * in the MBean server (using its
909      * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).
910      * The object's class should have a public constructor.
911      * It returns a reference to the newly created object.
912      * The newly created object is not registered in the MBean server.
913      *
914      * @param className The class name of the object to be instantiated.
915      *
916      * @return The newly instantiated object.
917      *
918      * @exception ReflectionException Wraps the
919      * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
920      * <CODE>{@link java.lang.Exception}</CODE> that
921      * occurred when trying to invoke the object's constructor.
922      * @exception MBeanException The constructor of the object has thrown
923      * an exception.
924      * @exception RuntimeOperationsException Wraps an
925      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
926      * The className passed in parameter is null.
927      *
928      */

929     public Object JavaDoc instantiate(String JavaDoc className)
930     throws ReflectionException JavaDoc, MBeanException JavaDoc {
931
932     /* Permission check */
933     checkMBeanPermission(className, null, null, "instantiate");
934
935     return instantiator.instantiate(className);
936     }
937
938     /**
939      * Instantiates an object using the class Loader specified by its
940      * <CODE>ObjectName</CODE>.
941      * If the loader name is null, the ClassLoader that loaded the
942      * MBean Server will be used.
943      * The object's class should have a public constructor.
944      * It returns a reference to the newly created object.
945      * The newly created object is not registered in the MBean server.
946      *
947      * @param className The class name of the MBean to be instantiated.
948      * @param loaderName The object name of the class loader to be used.
949      *
950      * @return The newly instantiated object.
951      *
952      * @exception ReflectionException Wraps the
953      * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
954      * <CODE>{@link java.lang.Exception}</CODE> that
955      * occurred when trying to invoke the object's constructor.
956      * @exception MBeanException The constructor of the object has thrown
957      * an exception.
958      * @exception InstanceNotFoundException The specified class loader
959      * is not registered in the MBaenServer.
960      * @exception RuntimeOperationsException Wraps an
961      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
962      * className passed in parameter is null.
963      *
964      */

965     public Object JavaDoc instantiate(String JavaDoc className, ObjectName JavaDoc loaderName)
966         throws ReflectionException JavaDoc, MBeanException JavaDoc,
967            InstanceNotFoundException JavaDoc {
968          
969     /* Permission check */
970     checkMBeanPermission(className, null, null, "instantiate");
971
972     ClassLoader JavaDoc myLoader = outerShell.getClass().getClassLoader();
973         return instantiator.instantiate(className, loaderName, myLoader);
974     }
975
976     /**
977      * Instantiates an object using the list of all class loaders registered
978      * in the MBean server (using its
979      * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).
980      * The object's class should have a public constructor.
981      * The call returns a reference to the newly created object.
982      * The newly created object is not registered in the MBean server.
983      *
984      * @param className The class name of the object to be instantiated.
985      * @param params An array containing the parameters of the constructor
986      * to be invoked.
987      * @param signature An array containing the signature of the
988      * constructor to be invoked.
989      *
990      * @return The newly instantiated object.
991      *
992      * @exception ReflectionException Wraps the
993      * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
994      * <CODE>{@link java.lang.Exception}</CODE> that
995      * occurred when trying to invoke the object's constructor.
996      * @exception MBeanException The constructor of the object has thrown
997      * an exception.
998      * @exception RuntimeOperationsException Wraps an
999      * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
1000     * The className passed in parameter is null.
1001     *
1002     */

1003    public Object JavaDoc instantiate(String JavaDoc className, Object JavaDoc params[],
1004                  String JavaDoc signature[])
1005        throws ReflectionException JavaDoc, MBeanException JavaDoc {
1006
1007    /* Permission check */
1008    checkMBeanPermission(className, null, null, "instantiate");
1009
1010    ClassLoader JavaDoc myLoader = outerShell.getClass().getClassLoader();
1011    return instantiator.instantiate(className, params, signature,
1012                    myLoader);
1013    }
1014
1015    /**
1016     * Instantiates an object. The class loader to be used is identified
1017     * by its object name. If the object name of the loader is null,
1018     * the ClassLoader that loaded the MBean server will be used.
1019     * The object's class should have a public constructor.
1020     * The call returns a reference to the newly created object.
1021     * The newly created object is not registered in the MBean server.
1022     *
1023     * @param className The class name of the object to be instantiated.
1024     * @param params An array containing the parameters of the constructor
1025     * to be invoked.
1026     * @param signature An array containing the signature of the constructor
1027     * to be invoked.
1028     * @param loaderName The object name of the class loader to be used.
1029     *
1030     * @return The newly instantiated object.
1031     *
1032     * @exception ReflectionException Wraps the
1033     * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
1034     * <CODE>{@link java.lang.Exception}</CODE> that
1035     * occurred when trying to invoke the object's constructor.
1036     * @exception MBeanException The constructor of the object has thrown
1037     * an exception.
1038     * @exception InstanceNotFoundException The specified class loader
1039     * is not registered in the MBean server.
1040     * @exception RuntimeOperationsException Wraps an
1041     * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
1042     * The className passed in parameter is null.
1043     *
1044     */

1045    public Object JavaDoc instantiate(String JavaDoc className, ObjectName JavaDoc loaderName,
1046                  Object JavaDoc params[], String JavaDoc signature[])
1047        throws ReflectionException JavaDoc, MBeanException JavaDoc,
1048           InstanceNotFoundException JavaDoc {
1049
1050    /* Permission check */
1051    checkMBeanPermission(className, null, null, "instantiate");
1052
1053    ClassLoader JavaDoc myLoader = outerShell.getClass().getClassLoader();
1054    return instantiator.instantiate(className,loaderName,params,signature,
1055                    myLoader);
1056    }
1057 
1058    /**
1059     * Returns true if the MBean specified is an instance of the specified
1060     * class, false otherwise.
1061     *
1062     * @param name The <CODE>ObjectName</CODE> of the MBean.
1063     * @param className The name of the class.
1064     *
1065     * @return true if the MBean specified is an instance of the specified
1066     * class, false otherwise.
1067     *
1068     * @exception InstanceNotFoundException The MBean specified is not
1069     * registered in the MBean server.
1070     */

1071    public boolean isInstanceOf(ObjectName JavaDoc name, String JavaDoc className)
1072    throws InstanceNotFoundException JavaDoc {
1073
1074    return mbsInterceptor.isInstanceOf(cloneObjectName(name), className);
1075    }
1076
1077    /**
1078     * De-serializes a byte array in the context of the class loader
1079     * of an MBean.
1080     *
1081     * @param name The name of the MBean whose class loader should
1082     * be used for the de-serialization.
1083     * @param data The byte array to be de-sererialized.
1084     *
1085     * @return The de-serialized object stream.
1086     *
1087     * @exception InstanceNotFoundException The MBean specified is not
1088     * found.
1089     * @exception OperationsException Any of the usual Input/Output
1090     * related exceptions.
1091     *
1092     */

1093    public ObjectInputStream JavaDoc deserialize(ObjectName JavaDoc name, byte[] data)
1094        throws InstanceNotFoundException JavaDoc, OperationsException JavaDoc {
1095
1096    /* Permission check */
1097    // This call requires MBeanPermission 'getClassLoaderFor'
1098
final ClassLoader JavaDoc loader = getClassLoaderFor(name);
1099
1100    return instantiator.deserialize(loader, data);
1101    }
1102
1103    /**
1104     * De-serializes a byte array in the context of a given MBean class loader.
1105     * The class loader is the one that loaded the class with name "className".
1106     *
1107     * @param className The name of the class whose class loader should be
1108     * used for the de-serialization.
1109     * @param data The byte array to be de-sererialized.
1110     *
1111     * @return The de-serialized object stream.
1112     *
1113     * @exception OperationsException Any of the usual Input/Output
1114     * related exceptions.
1115     * @exception ReflectionException The specified class could not be
1116     * loaded by the default loader repository
1117     *
1118     */

1119    public ObjectInputStream JavaDoc deserialize(String JavaDoc className, byte[] data)
1120        throws OperationsException JavaDoc, ReflectionException JavaDoc {
1121
1122        if (className == null) {
1123            throw new RuntimeOperationsException JavaDoc(
1124                    new IllegalArgumentException JavaDoc(),
1125                    "Null className passed in parameter");
1126        }
1127
1128    /* Permission check */
1129    // This call requires MBeanPermission 'getClassLoaderRepository'
1130
final ClassLoaderRepository JavaDoc clr = getClassLoaderRepository();
1131
1132    Class JavaDoc theClass;
1133    try {
1134        if (clr == null) throw new ClassNotFoundException JavaDoc(className);
1135        theClass = clr.loadClass(className);
1136    } catch (ClassNotFoundException JavaDoc e) {
1137        throw new ReflectionException JavaDoc(e,
1138                      "The given class could not be " +
1139                      "loaded by the default loader " +
1140                      "repository");
1141    }
1142
1143    return instantiator.deserialize(theClass.getClassLoader(), data);
1144    }
1145
1146    /**
1147     * De-serializes a byte array in the context of a given MBean class loader.
1148     * The class loader is the one that loaded the class with name "className".
1149     * The name of the class loader to be used for loading the specified
1150     * class is specified.
1151     * If null, the MBean Server's class loader will be used.
1152     *
1153     * @param className The name of the class whose class loader should be
1154     * used for the de-serialization.
1155     * @param data The byte array to be de-sererialized.
1156     * @param loaderName The name of the class loader to be used for
1157     * loading the specified class.
1158     * If null, the MBean Server's class loader will be used.
1159     *
1160     * @return The de-serialized object stream.
1161     *
1162     * @exception InstanceNotFoundException The specified class loader
1163     * MBean is not found.
1164     * @exception OperationsException Any of the usual Input/Output
1165     * related exceptions.
1166     * @exception ReflectionException The specified class could not
1167     * be loaded by the specified class loader.
1168     *
1169     */

1170    public ObjectInputStream JavaDoc deserialize(String JavaDoc className,
1171                     ObjectName JavaDoc loaderName,
1172                     byte[] data) throws
1173    InstanceNotFoundException JavaDoc, OperationsException JavaDoc, ReflectionException JavaDoc {
1174
1175    // Clone ObjectName
1176
//
1177
loaderName = cloneObjectName(loaderName);
1178
1179    /* Permission check */
1180    // Make this call just to force the 'getClassLoader'
1181
// permission check
1182
try {
1183        getClassLoader(loaderName);
1184    } catch (SecurityException JavaDoc e) {
1185        throw e;
1186    } catch (Exception JavaDoc e) {
1187    }
1188
1189    ClassLoader JavaDoc myLoader = outerShell.getClass().getClassLoader();
1190        return instantiator.deserialize(className, loaderName, data, myLoader);
1191    }
1192
1193    /**
1194     * Initializes this MBeanServer, registering the MBeanServerDelegate.
1195     * <p>This method must be called once, before using the MBeanServer.
1196     **/

1197    private void initialize() {
1198    if (instantiator == null) throw new
1199        IllegalStateException JavaDoc("instantiator must not be null.");
1200    
1201    // Registers the MBeanServer identification MBean
1202
try {
1203        mBeanServerDelegateObjectName =
1204        new ObjectName JavaDoc(ServiceName.DELEGATE) ;
1205
1206        AccessController.doPrivileged(new PrivilegedExceptionAction JavaDoc() {
1207        public Object JavaDoc run() throws Exception JavaDoc {
1208            mbsInterceptor.registerMBean(mBeanServerDelegateObject,
1209                         mBeanServerDelegateObjectName);
1210            return null;
1211        }
1212        });
1213    } catch (SecurityException JavaDoc e) {
1214        if (isDebugOn()) {
1215        debug("new", "Unexpected security exception occured: " +
1216              e);
1217        }
1218        mBeanServerDelegateObjectName = null;
1219        throw e;
1220    } catch (Exception JavaDoc e) {
1221        if (isDebugOn()) {
1222        debug("new", "Unexpected exception occured: " +
1223              e.getClass().getName());
1224        }
1225        mBeanServerDelegateObjectName = null;
1226        throw new
1227        IllegalStateException JavaDoc("Can't register delegate.");
1228    }
1229
1230
1231    /* Add my class loader to the repository
1232       This can be null if my class loader is the bootstrap
1233       class loader. The ClassLoaderRepository knows how
1234       to handle that case. */

1235    ClassLoader JavaDoc myLoader = outerShell.getClass().getClassLoader();
1236    final ModifiableClassLoaderRepository loaders =
1237        instantiator.getClassLoaderRepository();
1238    if (loaders != null) {
1239        loaders.addClassLoader(myLoader);
1240
1241        /* Add the system class loader, so that if the MBean server is
1242           loaded by the bootstrap class loader we can still load
1243           MBeans from the classpath using
1244           createMBean(className, objectName).
1245           
1246           If this class (JmxMBeanServer) was not loaded by the
1247           system class loader or a parent of it, then the caller
1248           must have RuntimePermission("getClassLoader") for the
1249           getSystemClassLoader() call to succeed. If the caller
1250           does not have that permission, any call to
1251           Class.getClassLoader() will fail. Since there are lots
1252           of those in JMX, we better throw the exception now.
1253
1254           This permission question is irrelevant when JMX is part
1255           of J2SE (as of 1.5). */

1256        ClassLoader JavaDoc systemLoader = ClassLoader.getSystemClassLoader();
1257        if (systemLoader != myLoader)
1258        loaders.addClassLoader(systemLoader);
1259    }
1260    }
1261
1262    /**
1263     * Return the MBeanServerInterceptor.
1264     * @exception UnsupportedOperationException if
1265     * {@link MBeanServerInterceptor}s
1266     * are not enabled on this object.
1267     * @see #interceptorsEnabled
1268     **/

1269    public synchronized MBeanServerInterceptor getMBeanServerInterceptor() {
1270    if (interceptorsEnabled) return mbsInterceptor;
1271    else throw new UnsupportedOperationException JavaDoc(
1272                   "MBeanServerInterceptors are disabled.");
1273    }
1274
1275    /**
1276     * Set the MBeanServerInterceptor.
1277     * @exception UnsupportedOperationException if
1278     * {@link MBeanServerInterceptor}s
1279     * are not enabled on this object.
1280     * @see #interceptorsEnabled
1281     **/

1282    public synchronized void
1283    setMBeanServerInterceptor(MBeanServerInterceptor interceptor) {
1284    if (!interceptorsEnabled) throw new UnsupportedOperationException JavaDoc(
1285                   "MBeanServerInterceptors are disabled.");
1286    if (interceptor == null) throw new
1287        IllegalArgumentException JavaDoc("MBeanServerInterceptor is null");
1288    mbsInterceptor = interceptor;
1289    }
1290
1291    /**
1292     * <p>Return the {@link java.lang.ClassLoader} that was used for
1293     * loading the class of the named MBean.
1294     * @param mbeanName The ObjectName of the MBean.
1295     * @return The ClassLoader used for that MBean.
1296     * @exception InstanceNotFoundException if the named MBean is not found.
1297     */

1298    public ClassLoader JavaDoc getClassLoaderFor(ObjectName JavaDoc mbeanName)
1299    throws InstanceNotFoundException JavaDoc {
1300    return mbsInterceptor.getClassLoaderFor(cloneObjectName(mbeanName));
1301    }
1302
1303    /**
1304     * <p>Return the named {@link java.lang.ClassLoader}.
1305     * @param loaderName The ObjectName of the ClassLoader.
1306     * @return The named ClassLoader.
1307     * @exception InstanceNotFoundException if the named ClassLoader
1308     * is not found.
1309     */

1310    public ClassLoader JavaDoc getClassLoader(ObjectName JavaDoc loaderName)
1311    throws InstanceNotFoundException JavaDoc {
1312    return mbsInterceptor.getClassLoader(cloneObjectName(loaderName));
1313    }
1314
1315    /**
1316     * <p>Return the ClassLoaderRepository for that MBeanServer.
1317     * @return The ClassLoaderRepository for that MBeanServer.
1318     **/

1319    public ClassLoaderRepository JavaDoc getClassLoaderRepository() {
1320    /* Permission check */
1321    checkMBeanPermission(null, null, null, "getClassLoaderRepository");
1322    return secureClr;
1323    }
1324
1325    public MBeanServerDelegate JavaDoc getMBeanServerDelegate() {
1326    return mBeanServerDelegateObject;
1327    }
1328
1329    // These methods are called by the JMX MBeanServerBuilder.
1330

1331    /**
1332     * This method creates a new MBeanServerDelegate for a new MBeanServer.
1333     * When creating a new MBeanServer the
1334     * {@link javax.management.MBeanServerBuilder} first calls this method
1335     * in order to create a new MBeanServerDelegate.
1336     * <br>Then it calls
1337     * <code>newMBeanServer(defaultDomain,outer,delegate,interceptors)</code>
1338     * passing the <var>delegate</var> that should be used by the MBeanServer
1339     * implementation.
1340     * <p>Note that the passed <var>delegate</var> might not be directly the
1341     * MBeanServerDelegate that was returned by this method. It could
1342     * be, for instance, a new object wrapping the previously
1343     * returned object.
1344     *
1345     * @return A new {@link javax.management.MBeanServerDelegate}.
1346     **/

1347    public static MBeanServerDelegate JavaDoc newMBeanServerDelegate() {
1348    return new MBeanServerDelegateImpl();
1349    }
1350
1351    /**
1352     * This method creates a new MBeanServer implementation object.
1353     * When creating a new MBeanServer the
1354     * {@link javax.management.MBeanServerBuilder} first calls
1355     * <code>newMBeanServerDelegate()</code> in order to obtain a new
1356     * {@link javax.management.MBeanServerDelegate} for the new
1357     * MBeanServer. Then it calls
1358     * <code>newMBeanServer(defaultDomain,outer,delegate)</code>
1359     * passing the <var>delegate</var> that should be used by the
1360     * MBeanServer implementation.
1361     * <p>Note that the passed <var>delegate</var> might not be directly the
1362     * MBeanServerDelegate that was returned by this implementation. It could
1363     * be, for instance, a new object wrapping the previously
1364     * returned delegate.
1365     * <p>The <var>outer</var> parameter is a pointer to the MBeanServer that
1366     * should be passed to the {@link javax.management.MBeanRegistration}
1367     * interface when registering MBeans inside the MBeanServer.
1368     * If <var>outer</var> is <code>null</code>, then the MBeanServer
1369     * implementation is free to use its own <code>this</code> pointer when
1370     * invoking the {@link javax.management.MBeanRegistration} interface.
1371     * <p>This makes it possible for a MBeanServer implementation to wrap
1372     * another MBeanServer implementation, in order to implement, e.g,
1373     * security checks, or to prevent access to the actual MBeanServer
1374     * implementation by returning a pointer to a wrapping object.
1375     *
1376     * @param defaultDomain Default domain of the new MBeanServer.
1377     * @param outer A pointer to the MBeanServer object that must be
1378     * passed to the MBeans when invoking their
1379     * {@link javax.management.MBeanRegistration} interface.
1380     * @param delegate A pointer to the MBeanServerDelegate associated
1381     * with the new MBeanServer. The new MBeanServer must register
1382     * this MBean in its MBean repository.
1383     * @param interceptors If <code>true</code>,
1384     * {@link MBeanServerInterceptor}s will be enabled (default is
1385     * <code>false</code>).
1386     * @return A new private implementation of an MBeanServer.
1387     * @see #interceptorsEnabled
1388     * @see javax.management.MBeanServerBuilder
1389     * @see com.sun.jmx.mbeanserver.JmxMBeanServerBuilder
1390     **/

1391    public static MBeanServer JavaDoc newMBeanServer(String JavaDoc defaultDomain,
1392                         MBeanServer JavaDoc outer,
1393                         MBeanServerDelegate JavaDoc delegate,
1394                         boolean interceptors) {
1395    return new JmxMBeanServer(defaultDomain,outer,delegate,interceptors);
1396    }
1397
1398    // JMX OBJECT CLONING
1399
//-------------------
1400

1401    /**
1402     * Clone object name.
1403     */

1404    private ObjectName JavaDoc cloneObjectName(ObjectName JavaDoc name) {
1405    if (name != null) {
1406        return ObjectName.getInstance(name);
1407    }
1408    return name;
1409    }
1410
1411    /**
1412     * Clone attribute.
1413     */

1414    private Attribute JavaDoc cloneAttribute(Attribute JavaDoc attribute) {
1415    if (attribute != null) {
1416        if (!attribute.getClass().equals(Attribute JavaDoc.class)) {
1417        return new Attribute JavaDoc(attribute.getName(), attribute.getValue());
1418        }
1419    }
1420    return attribute;
1421    }
1422
1423    /**
1424     * Clone attribute list.
1425     */

1426    private AttributeList JavaDoc cloneAttributeList(AttributeList JavaDoc list) {
1427    if (list != null) {
1428        if (!list.getClass().equals(AttributeList JavaDoc.class)) {
1429        // Create new attribute list
1430
//
1431
AttributeList JavaDoc newList = new AttributeList JavaDoc(list.size());
1432
1433        // Iterate through list and replace non JMX attributes
1434
//
1435
for (Iterator JavaDoc i = list.iterator(); i.hasNext(); ) {
1436            Attribute JavaDoc attribute = (Attribute JavaDoc) i.next();
1437            newList.add(cloneAttribute(attribute));
1438        }
1439        return newList;
1440        } else {
1441        // Iterate through list and replace non JMX attributes
1442
//
1443
for (int i = 0; i < list.size(); i++) {
1444            Attribute JavaDoc attribute = (Attribute JavaDoc) list.get(i);
1445            if (!attribute.getClass().equals(Attribute JavaDoc.class)) {
1446            list.set(i, cloneAttribute(attribute));
1447            }
1448        }
1449        return list;
1450        }
1451    }
1452    return list;
1453    }
1454
1455    // SECURITY CHECKS
1456
//----------------
1457

1458    private static void checkMBeanPermission(String JavaDoc classname,
1459                         String JavaDoc member,
1460                         ObjectName JavaDoc objectName,
1461                         String JavaDoc actions)
1462    throws SecurityException JavaDoc {
1463    SecurityManager JavaDoc sm = System.getSecurityManager();
1464    if (sm != null) {
1465        Permission JavaDoc perm = new MBeanPermission JavaDoc(classname,
1466                          member,
1467                          objectName,
1468                          actions);
1469        sm.checkPermission(perm);
1470    }
1471    }
1472
1473    // TRACES & DEBUG
1474
//---------------
1475

1476    private boolean isTraceOn() {
1477        return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER);
1478    }
1479
1480    private void trace(String JavaDoc clz, String JavaDoc func, String JavaDoc info) {
1481        Trace.send(Trace.LEVEL_TRACE, Trace.INFO_MBEANSERVER, clz, func, info);
1482    }
1483
1484    private void trace(String JavaDoc func, String JavaDoc info) {
1485        trace(dbgTag, func, info);
1486    }
1487
1488    private boolean isDebugOn() {
1489        return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER);
1490    }
1491
1492    private void debug(String JavaDoc clz, String JavaDoc func, String JavaDoc info) {
1493        Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_MBEANSERVER, clz, func, info);
1494    }
1495
1496    private void debug(String JavaDoc func, String JavaDoc info) {
1497        debug(dbgTag, func, info);
1498    }
1499}
1500
Popular Tags