1. /*
  2. * @(#)MBeanInstantiator.java 1.25 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.jmx.mbeanserver;
  8. import javax.management.*;
  9. import java.io.ObjectInputStream;
  10. /**
  11. * Contains methods for instantiating objects, finding the class given
  12. * its name and using different class loaders, deserializing objects
  13. * in the context of a given class loader.
  14. *
  15. * @since 1.5
  16. * @since.unbundled JMX RI 1.2
  17. */
  18. public interface MBeanInstantiator {
  19. /**
  20. * This methods tests if the MBean class makes it possible to
  21. * instantiate an MBean of this class in the MBeanServer.
  22. * e.g. it must have a public constructor, be a concrete class...
  23. */
  24. public void testCreation(Class c) throws NotCompliantMBeanException;
  25. /**
  26. * Loads the class with the specified name using this object's
  27. * Default Loader Repository.
  28. **/
  29. public Class findClassWithDefaultLoaderRepository(String className)
  30. throws ReflectionException;
  31. /**
  32. * Return the Default Loader Repository used by this instantiator object.
  33. **/
  34. public ModifiableClassLoaderRepository getClassLoaderRepository();
  35. /**
  36. * Gets the class for the specified class name using the MBean
  37. * Interceptor's classloader
  38. */
  39. public Class findClass(String className, ClassLoader loader)
  40. throws ReflectionException;
  41. /**
  42. * Gets the class for the specified class name using the specified
  43. * class loader
  44. */
  45. public Class findClass(String className, ObjectName loaderName)
  46. throws ReflectionException, InstanceNotFoundException ;
  47. /**
  48. * Return an array of Class corresponding to the given signature, using
  49. * the specified class loader.
  50. */
  51. public Class[] findSignatureClasses(String signature[],
  52. ClassLoader loader)
  53. throws ReflectionException;
  54. /**
  55. * De-serializes a byte array in the context of a classloader.
  56. *
  57. * @param loader the classloader to use for de-serialization
  58. * @param data The byte array to be de-sererialized.
  59. *
  60. * @return The de-serialized object stream.
  61. *
  62. * @exception OperationsException Any of the usual Input/Output related
  63. * exceptions.
  64. */
  65. public ObjectInputStream deserialize(ClassLoader loader, byte[] data)
  66. throws OperationsException;
  67. /**
  68. * De-serializes a byte array in the context of a given MBean class loader.
  69. * <P>The class loader is the one that loaded the class with name
  70. * "className".
  71. * <P>The name of the class loader to be used for loading the specified
  72. * class is specified. If null, a default one has to be provided (for a
  73. * MBean Server, its own class loader will be used).
  74. *
  75. * @param className The name of the class whose class loader should
  76. * be used for the de-serialization.
  77. * @param data The byte array to be de-sererialized.
  78. * @param loaderName The name of the class loader to be used for loading
  79. * the specified class. If null, a default one has to be provided (for a
  80. * MBean Server, its own class loader will be used).
  81. *
  82. * @return The de-serialized object stream.
  83. *
  84. * @exception InstanceNotFoundException The specified class loader MBean is
  85. * not found.
  86. * @exception OperationsException Any of the usual Input/Output related
  87. * exceptions.
  88. * @exception ReflectionException The specified class could not be loaded
  89. * by the specified class loader.
  90. */
  91. public ObjectInputStream deserialize(String className,
  92. ObjectName loaderName,
  93. byte[] data,
  94. ClassLoader loader)
  95. throws InstanceNotFoundException,
  96. OperationsException,
  97. ReflectionException;
  98. /**
  99. * Instantiates an object using the list of all class loaders registered
  100. * in the MBean Interceptor
  101. * (using its {@link javax.management.loading.ClassLoaderRepository}).
  102. * <P>The object's class should have a public constructor.
  103. * <P>It returns a reference to the newly created object.
  104. * <P>The newly created object is not registered in the MBean Interceptor.
  105. *
  106. * @param className The class name of the object to be instantiated.
  107. *
  108. * @return The newly instantiated object.
  109. *
  110. * @exception ReflectionException Wraps a
  111. * <CODE>java.lang.ClassNotFoundException</CODE> or the
  112. * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the
  113. * object's constructor.
  114. * @exception MBeanException The constructor of the object has thrown an
  115. * exception
  116. * @exception RuntimeOperationsException Wraps a
  117. * <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
  118. * parameter is null.
  119. */
  120. public Object instantiate(String className)
  121. throws ReflectionException,
  122. MBeanException;
  123. /**
  124. * Instantiates an object using the class Loader specified by its
  125. * <CODE>ObjectName</CODE>.
  126. * <P>If the loader name is null, a default one has to be provided (for a
  127. * MBean Server, the ClassLoader that loaded it will be used).
  128. * <P>The object's class should have a public constructor.
  129. * <P>It returns a reference to the newly created object.
  130. * <P>The newly created object is not registered in the MBean Interceptor.
  131. *
  132. * @param className The class name of the MBean to be instantiated.
  133. * @param loaderName The object name of the class loader to be used.
  134. *
  135. * @return The newly instantiated object.
  136. *
  137. * @exception ReflectionException Wraps a
  138. * <CODE>java.lang.ClassNotFoundException</CODE> or the
  139. * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the
  140. * object's constructor.
  141. * @exception MBeanException The constructor of the object has thrown an
  142. * exception.
  143. * @exception InstanceNotFoundException The specified class loader is not
  144. * registered in the MBeanServerInterceptor.
  145. * @exception RuntimeOperationsException Wraps a
  146. * <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
  147. * parameter is null.
  148. */
  149. public Object instantiate(String className, ObjectName loaderName, ClassLoader loader)
  150. throws ReflectionException,
  151. MBeanException,
  152. InstanceNotFoundException;
  153. /**
  154. * Instantiates an object using the list of all class loaders registered
  155. * in the MBean server
  156. * (using its {@link javax.management.loading.ClassLoaderRepository}).
  157. * <P>The object's class should have a public constructor.
  158. * <P>The call returns a reference to the newly created object.
  159. * <P>The newly created object is not registered in the MBean Interceptor.
  160. *
  161. * @param className The class name of the object to be instantiated.
  162. * @param params An array containing the parameters of the constructor to
  163. * be invoked.
  164. * @param signature An array containing the signature of the constructor to
  165. * be invoked.
  166. *
  167. * @return The newly instantiated object.
  168. *
  169. * @exception ReflectionException Wraps a
  170. * <CODE>java.lang.ClassNotFoundException</CODE> or the
  171. * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the
  172. * object's constructor.
  173. * @exception MBeanException The constructor of the object has thrown an
  174. * exception
  175. * @exception RuntimeOperationsException Wraps a
  176. * <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
  177. * parameter is null.
  178. */
  179. public Object instantiate(String className,
  180. Object params[],
  181. String signature[],
  182. ClassLoader loader)
  183. throws ReflectionException,
  184. MBeanException ;
  185. /**
  186. * Instantiates an object. The class loader to be used is identified by its
  187. * object name.
  188. * <P>If the object name of the loader is null, a default has to be
  189. * provided (for example, for a MBean Server, the ClassLoader that loaded
  190. * it will be used).
  191. * <P>The object's class should have a public constructor.
  192. * <P>The call returns a reference to the newly created object.
  193. * <P>The newly created object is not registered in the MBean server.
  194. *
  195. * @param className The class name of the object to be instantiated.
  196. * @param params An array containing the parameters of the constructor to
  197. * be invoked.
  198. * @param signature An array containing the signature of the constructor to
  199. * be invoked.
  200. * @param loaderName The object name of the class loader to be used.
  201. *
  202. * @return The newly instantiated object.
  203. *
  204. * @exception ReflectionException Wraps a
  205. * <CODE>java.lang.ClassNotFoundException</CODE> or the
  206. * <CODE>java.lang.Exception</CODE> that occurred when trying to invoke the
  207. * object's constructor.
  208. * @exception MBeanException The constructor of the object has thrown an
  209. * exception
  210. * @exception InstanceNotFoundException The specified class loader is not
  211. * registered in the MBean Interceptor.
  212. * @exception RuntimeOperationsException Wraps a
  213. * <CODE>java.lang.IllegalArgumentException</CODE>: the className passed in
  214. * parameter is null.
  215. */
  216. public Object instantiate(String className,
  217. ObjectName loaderName,
  218. Object params[],
  219. String signature[],
  220. ClassLoader loader)
  221. throws ReflectionException,
  222. MBeanException,
  223. InstanceNotFoundException;
  224. /**
  225. * Instantiates an object given its class, using its empty constructor.
  226. * The call returns a reference to the newly created object.
  227. */
  228. public Object instantiate(Class theClass) throws ReflectionException, MBeanException;
  229. /**
  230. * Instantiates an object given its class, the parameters and signature of its constructor
  231. * The call returns a reference to the newly created object.
  232. */
  233. public Object instantiate(Class theClass, Object params[], String signature[], ClassLoader loader) throws ReflectionException, MBeanException;
  234. }