/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Implements the MBeanInstantiator interface. Provides methods for
* instantiating objects, finding the class given its name and using
* different class loaders, deserializing objects in the context of a
* given class loader.
*
* @since 1.5
*/
public class MBeanInstantiator {
// private MetaData meta = null;
}
/**
* This methods tests if the MBean class makes it possible to
* instantiate an MBean of this class in the MBeanServer.
* e.g. it must have a public constructor, be a concrete class...
*/
}
/**
* Loads the class with the specified name using this object's
* Default Loader Repository.
**/
throws ReflectionException {
throw new RuntimeOperationsException(new
IllegalArgumentException("The class name cannot be null"),
"Exception occurred during object instantiation");
}
try {
}
catch (ClassNotFoundException ee) {
throw new ReflectionException(ee,
"The MBean class could not be loaded by the default loader repository");
}
return theClass;
}
/**
* Gets the class for the specified class name using the MBean
* Interceptor's classloader
*/
throws ReflectionException {
}
/**
* Gets the class for the specified class name using the specified
* class loader
*/
throws ReflectionException, InstanceNotFoundException {
throw new RuntimeOperationsException(new
IllegalArgumentException(), "Null loader passed in parameter");
// Retrieve the class loader from the repository
synchronized (this) {
}
throw new InstanceNotFoundException("The loader named " +
aLoader + " is not registered in the MBeanServer");
}
}
/**
* Return an array of Class corresponding to the given signature, using
* the specified class loader.
*/
throws ReflectionException {
try {
for (int i= 0; i < length; i++) {
// Start handling primitive types (int. boolean and so
// forth)
//
continue;
}
// Ok we do not have a primitive type ! We need to build
// the signature of the method
//
// We need to load the class through the class
// loader of the target object.
//
} else {
// Load through the default class loader
//
this.getClass().getClassLoader());
}
}
} catch (ClassNotFoundException e) {
MBeanInstantiator.class.getName(),
"findSignatureClasses",
"The parameter class could not be found", e);
}
throw new ReflectionException(e,
"The parameter class could not be found");
} catch (RuntimeException e) {
MBeanInstantiator.class.getName(),
"findSignatureClasses",
"Unexpected exception", e);
}
throw e;
}
return tab;
}
/**
* Instantiates an object given its class, using its empty constructor.
* The call returns a reference to the newly created object.
*/
throws ReflectionException, MBeanException {
// ------------------------------
// ------------------------------
throw new ReflectionException(new
NoSuchMethodException("No such constructor"));
}
// Instantiate the new object
try {
} catch (InvocationTargetException e) {
// Wrap the exception.
Throwable t = e.getTargetException();
if (t instanceof RuntimeException) {
throw new RuntimeMBeanException((RuntimeException)t,
"RuntimeException thrown in the MBean's empty constructor");
} else if (t instanceof Error) {
throw new RuntimeErrorException((Error) t,
"Error thrown in the MBean's empty constructor");
} else {
throw new MBeanException((Exception) t,
"Exception thrown in the MBean's empty constructor");
}
} catch (NoSuchMethodError error) {
throw new ReflectionException(new
NoSuchMethodException("No constructor"),
"No such constructor");
} catch (InstantiationException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's empty constructor");
} catch (IllegalAccessException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's empty constructor");
} catch (IllegalArgumentException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's empty constructor");
}
return moi;
}
/**
* Instantiates an object given its class, the parameters and
* signature of its constructor The call returns a reference to
* the newly created object.
*/
throws ReflectionException, MBeanException {
// Instantiate the new object
// ------------------------------
// ------------------------------
try {
// Build the signature of the method
//
// Build the signature of the method
//
tab =
}
// Exception IllegalArgumentException raised in Jdk1.1.8
catch (IllegalArgumentException e) {
throw new ReflectionException(e,
"The constructor parameter classes could not be loaded");
}
// Query the metadata service to get the right constructor
throw new ReflectionException(new
NoSuchMethodException("No such constructor"));
}
try {
}
catch (NoSuchMethodError error) {
throw new ReflectionException(new
NoSuchMethodException("No such constructor found"),
"No such constructor" );
}
catch (InstantiationException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's constructor");
}
catch (IllegalAccessException e) {
throw new ReflectionException(e,
"Exception thrown trying to invoke the MBean's constructor");
}
catch (InvocationTargetException e) {
// Wrap the exception.
if (th instanceof RuntimeException) {
"RuntimeException thrown in the MBean's constructor");
"Error thrown in the MBean's constructor");
} else {
"Exception thrown in the MBean's constructor");
}
}
return moi;
}
/**
* De-serializes a byte array in the context of a classloader.
*
* @param loader the classloader to use for de-serialization
* @param data The byte array to be de-sererialized.
*
* @return The de-serialized object stream.
*
* exceptions.
*/
throws OperationsException {
// Check parameter validity
throw new RuntimeOperationsException(new
IllegalArgumentException(), "Null data passed in parameter");
}
throw new RuntimeOperationsException(new
IllegalArgumentException(), "Empty data passed in parameter");
}
// Object deserialization
try {
} catch (IOException e) {
throw new OperationsException(
"An IOException occurred trying to de-serialize the data");
}
return objIn;
}
/**
* De-serializes a byte array in the context of a given MBean class loader.
* <P>The class loader is the one that loaded the class with name
* "className".
* <P>The name of the class loader to be used for loading the specified
* class is specified. If null, a default one has to be provided (for a
* MBean Server, its own 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, a default one has to be provided (for a
* MBean Server, its own class loader will be used).
*
* @return The de-serialized object stream.
*
* @exception InstanceNotFoundException The specified class loader MBean is
* not found.
* exceptions.
* @exception ReflectionException The specified class could not be loaded
* by the specified class loader.
*/
byte[] data,
throws InstanceNotFoundException,
// Check parameter validity
throw new RuntimeOperationsException(new
IllegalArgumentException(), "Null data passed in parameter");
}
throw new RuntimeOperationsException(new
IllegalArgumentException(), "Empty data passed in parameter");
}
throw new RuntimeOperationsException(new
IllegalArgumentException(), "Null className passed in parameter");
}
if (loaderName == null) {
// Load the class using the agent class loader
} else {
// Get the class loader MBean
try {
throw new ClassNotFoundException(className);
}
catch (ClassNotFoundException e) {
throw new ReflectionException(e,
"The MBean class could not be loaded by the " +
}
}
// Object deserialization
try {
} catch (IOException e) {
throw new OperationsException(
"An IOException occurred trying to de-serialize the data");
}
return objIn;
}
/**
* Instantiates an object using the list of all class loaders registered
* in the MBean Interceptor
* (using its {@link javax.management.loading.ClassLoaderRepository}).
* <P>The object's class should have a public constructor.
* <P>It returns a reference to the newly created object.
* <P>The newly created object is not registered in the MBean Interceptor.
*
* @param className The class name of the object to be instantiated.
*
* @return The newly instantiated object.
*
* @exception ReflectionException Wraps a
* <CODE>java.lang.ClassNotFoundException</CODE> or the
* <CODE>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 a
* <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
* parameter is null.
*/
throws ReflectionException,
}
/**
* Instantiates an object using the class Loader specified by its
* <CODE>ObjectName</CODE>.
* <P>If the loader name is null, a default one has to be provided (for a
* MBean Server, the ClassLoader that loaded it will be used).
* <P>The object's class should have a public constructor.
* <P>It returns a reference to the newly created object.
* <P>The newly created object is not registered in the MBean Interceptor.
*
* @param className The class name of the MBean to be instantiated.
* @param loaderName The object name of the class loader to be used.
*
* @return The newly instantiated object.
*
* @exception ReflectionException Wraps a
* <CODE>java.lang.ClassNotFoundException</CODE> or the
* <CODE>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 MBeanServerInterceptor.
* @exception RuntimeOperationsException Wraps a
* <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
* parameter is null.
*/
throws ReflectionException, MBeanException,
}
/**
* Instantiates an object using the list of all class loaders registered
* in the MBean server
* (using its {@link javax.management.loading.ClassLoaderRepository}).
* <P>The object's class should have a public constructor.
* <P>The call returns a reference to the newly created object.
* <P>The newly created object is not registered in the MBean Interceptor.
*
* @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.
*
* @return The newly instantiated object.
*
* @exception ReflectionException Wraps a
* <CODE>java.lang.ClassNotFoundException</CODE> or the
* <CODE>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 a
* <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
* parameter is null.
*/
throws ReflectionException,
}
/**
* Instantiates an object. The class loader to be used is identified by its
* object name.
* <P>If the object name of the loader is null, a default has to be
* provided (for example, for a MBean Server, the ClassLoader that loaded
* it will be used).
* <P>The object's class should have a public constructor.
* <P>The call returns a reference to the newly created object.
* <P>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 a
* <CODE>java.lang.ClassNotFoundException</CODE> or the
* <CODE>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 Interceptor.
* @exception RuntimeOperationsException Wraps a
* <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
* parameter is null.
*/
throws ReflectionException,
// ------------------------------
// ------------------------------
if (loaderName == null) {
} else {
}
}
/**
* Return the Default Loader Repository used by this instantiator object.
**/
return clr;
}
/**
* Load a class with the specified loader, or with this object
* class loader if the specified loader is null.
**/
throws ReflectionException {
throw new RuntimeOperationsException(new
IllegalArgumentException("The class name cannot be null"),
"Exception occurred during object instantiation");
}
try {
} else {
}
} catch (ClassNotFoundException e) {
throw new ReflectionException(e,
"The MBean class could not be loaded");
}
return theClass;
}
/**
* Load the classes specified in the signature with the given loader,
* or with this object class loader.
**/
throws ReflectionException {
final ClassLoader aLoader =
try {
for (int i= 0; i < length; i++) {
// Start handling primitive types (int. boolean and so
// forth)
//
continue;
}
// Ok we do not have a primitive type ! We need to build
// the signature of the method
//
// We need to load the class through the class
// loader of the target object.
//
}
} catch (ClassNotFoundException e) {
MBeanInstantiator.class.getName(),
"findSignatureClasses",
"The parameter class could not be found", e);
}
throw new ReflectionException(e,
"The parameter class could not be found");
} catch (RuntimeException e) {
MBeanInstantiator.class.getName(),
"findSignatureClasses",
"Unexpected exception", e);
}
throw e;
}
return tab;
}
try {
} catch (Exception e) {
return null;
}
}
static {
long.class, float.class, double.class,
char.class, boolean.class})
}
}
}
throws SecurityException {
actions);
}
}
throws IllegalAccessException
{
throw new IllegalAccessException("Class is not public and can't be instantiated");
}
}
return null;
}
// Restrict to getClassLoader permission only
public ClassLoader run() {
}
}, ctx);
return loader;
}
}