455 * |
455 * |
456 * <p>Subclasses may redefine this method to provide an implementation. |
456 * <p>Subclasses may redefine this method to provide an implementation. |
457 * All the various flavors of {@code MBeanServer.createMBean} methods |
457 * All the various flavors of {@code MBeanServer.createMBean} methods |
458 * will eventually call this method. A subclass that wishes to |
458 * will eventually call this method. A subclass that wishes to |
459 * support MBean creation through {@code createMBean} thus only |
459 * support MBean creation through {@code createMBean} thus only |
460 * needs to provide an implementation for this one method. |
460 * needs to provide an implementation for this one method.</p> |
|
461 * |
|
462 * <p>A subclass implementation of this method should respect the contract |
|
463 * of the various {@code createMBean} methods in the {@link MBeanServer} |
|
464 * interface, in particular as regards exception wrapping.</p> |
461 * |
465 * |
462 * @param className The class name of the MBean to be instantiated. |
466 * @param className The class name of the MBean to be instantiated. |
463 * @param name The object name of the MBean. May be null. |
467 * @param name The object name of the MBean. May be null. |
464 * @param params An array containing the parameters of the |
468 * @param params An array containing the parameters of the |
465 * constructor to be invoked. |
469 * constructor to be invoked. |
486 * under the control of the MBean server. |
490 * under the control of the MBean server. |
487 * @exception MBeanRegistrationException The |
491 * @exception MBeanRegistrationException The |
488 * <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> |
492 * <CODE>preRegister</CODE> (<CODE>MBeanRegistration</CODE> |
489 * interface) method of the MBean has thrown an exception. The |
493 * interface) method of the MBean has thrown an exception. The |
490 * MBean will not be registered. |
494 * MBean will not be registered. |
|
495 * @exception RuntimeMBeanException If the MBean's constructor or its |
|
496 * {@code preRegister} or {@code postRegister} method threw |
|
497 * a {@code RuntimeException}. If the <CODE>postRegister</CODE> |
|
498 * (<CODE>MBeanRegistration</CODE> interface) method of the MBean throws a |
|
499 * <CODE>RuntimeException</CODE>, the <CODE>createMBean</CODE> method will |
|
500 * throw a <CODE>RuntimeMBeanException</CODE>, although the MBean creation |
|
501 * and registration succeeded. In such a case, the MBean will be actually |
|
502 * registered even though the <CODE>createMBean</CODE> method |
|
503 * threw an exception. Note that <CODE>RuntimeMBeanException</CODE> can |
|
504 * also be thrown by <CODE>preRegister</CODE>, in which case the MBean |
|
505 * will not be registered. |
491 * @exception MBeanException The constructor of the MBean has |
506 * @exception MBeanException The constructor of the MBean has |
492 * thrown an exception |
507 * thrown an exception |
493 * @exception NotCompliantMBeanException This class is not a JMX |
508 * @exception NotCompliantMBeanException This class is not a JMX |
494 * compliant MBean |
509 * compliant MBean |
495 * @exception InstanceNotFoundException The specified class loader |
510 * @exception InstanceNotFoundException The specified class loader |
1094 Object[] params, String[] signature) |
1109 Object[] params, String[] signature) |
1095 throws ReflectionException, InstanceAlreadyExistsException, |
1110 throws ReflectionException, InstanceAlreadyExistsException, |
1096 MBeanRegistrationException, MBeanException, |
1111 MBeanRegistrationException, MBeanException, |
1097 NotCompliantMBeanException { |
1112 NotCompliantMBeanException { |
1098 try { |
1113 try { |
1099 return safeCreateMBean(className, name, null, params, signature, true); |
1114 return createMBean(className, name, null, params, signature, true); |
1100 } catch (InstanceNotFoundException ex) { |
1115 } catch (InstanceNotFoundException ex) { |
1101 // should not happen! |
1116 // should not happen! |
1102 throw new MBeanException(ex, "Unexpected exception: " + ex); |
1117 throw new MBeanException(ex, "Unexpected exception: " + ex); |
1103 } |
1118 } |
1104 } |
1119 } |
1111 public final ObjectInstance createMBean(String className, ObjectName name, |
1126 public final ObjectInstance createMBean(String className, ObjectName name, |
1112 ObjectName loaderName, Object[] params, String[] signature) |
1127 ObjectName loaderName, Object[] params, String[] signature) |
1113 throws ReflectionException, InstanceAlreadyExistsException, |
1128 throws ReflectionException, InstanceAlreadyExistsException, |
1114 MBeanRegistrationException, MBeanException, |
1129 MBeanRegistrationException, MBeanException, |
1115 NotCompliantMBeanException, InstanceNotFoundException { |
1130 NotCompliantMBeanException, InstanceNotFoundException { |
1116 return safeCreateMBean(className, name, loaderName, params, signature, false); |
1131 return createMBean(className, name, loaderName, params, signature, false); |
1117 } |
1132 } |
1118 |
1133 |
1119 /** |
1134 /** |
1120 * Calls {@link #createMBean(String, ObjectName, |
1135 * Calls {@link #createMBean(String, ObjectName, |
1121 * ObjectName, Object[], String[], boolean) |
1136 * ObjectName, Object[], String[], boolean) |
1124 public final ObjectInstance createMBean(String className, ObjectName name) |
1139 public final ObjectInstance createMBean(String className, ObjectName name) |
1125 throws ReflectionException, InstanceAlreadyExistsException, |
1140 throws ReflectionException, InstanceAlreadyExistsException, |
1126 MBeanRegistrationException, MBeanException, |
1141 MBeanRegistrationException, MBeanException, |
1127 NotCompliantMBeanException { |
1142 NotCompliantMBeanException { |
1128 try { |
1143 try { |
1129 return safeCreateMBean(className, name, null, null, null, true); |
1144 return createMBean(className, name, null, null, null, true); |
1130 } catch (InstanceNotFoundException ex) { |
1145 } catch (InstanceNotFoundException ex) { |
1131 // should not happen! |
1146 // should not happen! |
1132 throw new MBeanException(ex, "Unexpected exception: " + ex); |
1147 throw new MBeanException(ex, "Unexpected exception: " + ex); |
1133 } |
1148 } |
1134 } |
1149 } |
1141 public final ObjectInstance createMBean(String className, ObjectName name, |
1156 public final ObjectInstance createMBean(String className, ObjectName name, |
1142 ObjectName loaderName) |
1157 ObjectName loaderName) |
1143 throws ReflectionException, InstanceAlreadyExistsException, |
1158 throws ReflectionException, InstanceAlreadyExistsException, |
1144 MBeanRegistrationException, MBeanException, |
1159 MBeanRegistrationException, MBeanException, |
1145 NotCompliantMBeanException, InstanceNotFoundException { |
1160 NotCompliantMBeanException, InstanceNotFoundException { |
1146 return safeCreateMBean(className, name, loaderName, null, null, false); |
1161 return createMBean(className, name, loaderName, null, null, false); |
1147 } |
|
1148 |
|
1149 // make sure all exceptions are correctly wrapped in a JMXException |
|
1150 private ObjectInstance safeCreateMBean(String className, |
|
1151 ObjectName name, ObjectName loaderName, Object[] params, |
|
1152 String[] signature, boolean useRepository) |
|
1153 throws ReflectionException, InstanceAlreadyExistsException, |
|
1154 MBeanRegistrationException, MBeanException, |
|
1155 NotCompliantMBeanException, InstanceNotFoundException { |
|
1156 try { |
|
1157 return createMBean(className, name, loaderName, params, |
|
1158 signature, useRepository); |
|
1159 } catch (ReflectionException x) { throw x; |
|
1160 } catch (InstanceAlreadyExistsException x) { throw x; |
|
1161 } catch (MBeanRegistrationException x) { throw x; |
|
1162 } catch (MBeanException x) { throw x; |
|
1163 } catch (NotCompliantMBeanException x) { throw x; |
|
1164 } catch (InstanceNotFoundException x) { throw x; |
|
1165 } catch (SecurityException x) { throw x; |
|
1166 } catch (JMRuntimeException x) { throw x; |
|
1167 } catch (RuntimeException x) { |
|
1168 throw new RuntimeOperationsException(x, x.toString()); |
|
1169 } catch (Exception x) { |
|
1170 throw new MBeanException(x, x.toString()); |
|
1171 } |
|
1172 } |
1162 } |
1173 |
1163 |
1174 |
1164 |
1175 /** |
1165 /** |
1176 * {@inheritDoc} |
1166 * {@inheritDoc} |