private void initialize(MBeanInstantiator instantiator, MetaData meta, String domain) {

    this.instantiator = instantiator;
    if (instantiator == null) throw new IllegalArgumentException("instantiator must not be null.");
    this.meta = (meta == null ? new MetaDataImpl(instantiator) : meta);
    this.secureClr = new SecureClassLoaderRepository(instantiator.getClassLoaderRepository());

    if (domain != null) {
      interceptor = new DefaultMBeanInterceptor(this, domain);
    } else {
      interceptor = new DefaultMBeanInterceptor(this);
    }

    // Create the MBeanServer identification MBean
    try {
      MBeanServerDelegateObject = new MBeanServerDelegateImpl(new MBeanServerDelegate());
      MBeanServerDelegateObjectName = new ObjectName(ServiceName.DELEGATE);

      interceptor.registerMBean(MBeanServerDelegateObject, MBeanServerDelegateObjectName);
    } catch (JMException e) {
      // This should never happen!
      final RuntimeException r = new RuntimeException("Unexpected JMException: " + e);
      Utils.initCause(r, e);
      throw r;
    }
    ClassLoader myLoader = this.getClass().getClassLoader();
    final ModifiableClassLoaderRepository loaders = instantiator.getClassLoaderRepository();
    if (loaders != null && myLoader != null) {
      loaders.addClassLoader(myLoader);
    }
  }
  /**
   * Instantiates an object. The class loader to be used is identified by its object name. If the
   * object name of the loader is null, the ClassLoader that loaded the MBean server will be used.
   * The object's class should have a public constructor. The call returns a reference to the newly
   * created object. The newly created object is not registered in the MBean server.
   *
   * @param className The class name of the object to be instantiated.
   * @param params An array containing the parameters of the constructor to be invoked.
   * @param signature An array containing the signature of the constructor to be invoked.
   * @param loaderName The object name of the class loader to be used.
   * @return The newly instantiated object.
   * @exception ReflectionException Wraps the <CODE>{@link java.lang.ClassNotFoundException}</CODE>
   *     or the <CODE>{@link java.lang.Exception}</CODE> that occurred when trying to invoke the
   *     object's constructor.
   * @exception MBeanException The constructor of the object has thrown an exception.
   * @exception InstanceNotFoundException The specified class loader is not registered in the MBean
   *     server.
   * @exception RuntimeOperationsException Wraps an <CODE>{@link java.lang.IllegalArgumentException}
   *     </CODE>: The className passed in parameter is null.
   */
  public Object instantiate(
      String className, ObjectName loaderName, Object params[], String signature[])
      throws ReflectionException, MBeanException, InstanceNotFoundException {

    return instantiator.instantiate(
        className, loaderName, params, signature, this.getClass().getClassLoader());
  }
  /**
   * Implements {@link MBeanServer#getClassLoader(ObjectName)}. Contrarily to JMX 1.2
   * specifications, this methods only works for ClassLoaders that are registered in the
   * ClassLoaderRepository. If you need a fully JMX 1.2 compatible MBeanServer use {@link
   * JdmkMBeanServerBuilder} to create one.
   *
   * @since Java DMK 5.1 (JMX 1.2)
   */
  public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException {

    if (interceptor instanceof MBeanServerInterceptor) {
      return ((MBeanServerInterceptor) interceptor).getClassLoader(loaderName);
    }
    final ModifiableClassLoaderRepository loaders = instantiator.getClassLoaderRepository();
    final ClassLoader loader;
    synchronized (instantiator) {
      loader = loaders.getClassLoader(loaderName);
    }
    if (loader == null) {
      throw new InstanceNotFoundException(
          "The loader named " + loaderName + " is not registered in the MBeanServer");
    }
    return loader;
  }
  /**
   * De-serializes a byte array in the context of a given MBean class loader. The class loader is
   * the one that loaded the class with name "className". The name of the class loader to be used
   * for loading the specified class is specified. If null, the MBean Server's class loader will be
   * used.
   *
   * @param className The name of the class whose class loader should be used for the
   *     de-serialization.
   * @param data The byte array to be de-sererialized.
   * @param loaderName The name of the class loader to be used for loading the specified class. If
   *     null, the MBean Server's class loader will be used.
   * @return The de-serialized object stream.
   * @exception InstanceNotFoundException The specified class loader MBean is not found.
   * @exception OperationsException Any of the usual Input/Output related exceptions.
   * @exception ReflectionException The specified class could not be loaded by the specified class
   *     loader.
   */
  public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data)
      throws InstanceNotFoundException, OperationsException, ReflectionException {

    return instantiator.deserialize(className, loaderName, data, this.getClass().getClassLoader());
  }
  /**
   * De-serializes a byte array in the context of a given MBean class loader. The class loader is
   * the one that loaded the class with name "className".
   *
   * @param className The name of the class whose class loader should be used for the
   *     de-serialization.
   * @param data The byte array to be de-sererialized.
   * @return The de-serialized object stream.
   * @exception OperationsException Any of the usual Input/Output related exceptions.
   * @exception ReflectionException The specified class could not be loaded by the default loader
   *     repository
   */
  public ObjectInputStream deserialize(String className, byte[] data)
      throws OperationsException, ReflectionException {

    return instantiator.deserialize(className, data);
  }
  /**
   * De-serializes a byte array in the context of the class loader of an MBean.
   *
   * @param name The name of the MBean whose class loader should be used for the de-serialization.
   * @param data The byte array to be de-sererialized.
   * @return The de-serialized object stream.
   * @exception InstanceNotFoundException The MBean specified is not found.
   * @exception OperationsException Any of the usual Input/Output related exceptions.
   */
  public ObjectInputStream deserialize(ObjectName name, byte[] data)
      throws InstanceNotFoundException, OperationsException {

    return instantiator.deserialize(name, data);
  }
 /**
  * Instantiates an object using the list of all class loaders registered in the MBean server
  * (using its {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).
  * The object's class should have a public constructor. It returns a reference to the newly
  * created object. The newly created object is not registered in the MBean server.
  *
  * @param className The class name of the object to be instantiated.
  * @return The newly instantiated object.
  * @exception ReflectionException Wraps the <CODE>{@link java.lang.ClassNotFoundException}</CODE>
  *     or the <CODE>{@link java.lang.Exception}</CODE> that occurred when trying to invoke the
  *     object's constructor.
  * @exception MBeanException The constructor of the object has thrown an exception.
  * @exception RuntimeOperationsException Wraps an <CODE>{@link java.lang.IllegalArgumentException}
  *     </CODE>: The className passed in parameter is null.
  */
 public Object instantiate(String className) throws ReflectionException, MBeanException {
   return instantiator.instantiate(className);
 }