}
public ObjectName registerMBean(final Mbean mbean) throws CustomMBeanException {
/* This is the only place where the "registration of the MBean happens.
*/
if (mbean == null)
throw new CustomMBeanException(CMBStrings.get("InternalError", "registerMBean() received a null argument"));
ObjectName ron = null;
try {
logger.fine(CMBStrings.get("cmb.loadingMBean1", mbean.getName()));
final ObjectName mon = getCascadingAwareObjectName(mbean);
logger.fine(CMBStrings.get("cmb.loadingMBean2", mon.toString()));
final Class mc = loadIt(mbean);
final Object mo = newIt(mc);
ron = registerIt(mo, mon);
// if the MBean implements MBeanRegistration -- it can set the ON to
// anything at all...
if(!ObjectNameSelectionAlgorithm.implementsMBeanRegistrationInterface(mbean.getImplClassName()))
{
if(!mon.equals(ron))
throw new CustomMBeanException(CMBStrings.get("objNameMismatch", mon, ron));
}
initIt(mbean, ron);
// WBN 12-15-2005
// this is just defensive programming -- the Listener should not be
// calling us on a disabled mbean. In the case we are being called
// as part of pre-reg in order to get an objectname, this will make
// one extra unneeded call to unregisterIt()
// I say, safety first, performance second!
if(!mbean.isEnabled())
unregisterIt(mbean, ron);
return ( ron );
}catch (final CustomMBeanException cmbe) {
if(ron != null) {
try {
// paranoia...
unregisterIt(mbean, ron);
}catch(Throwable t) {
}
}
throw cmbe;
}catch (final Throwable e) {
if(ron != null) {
try {
// paranoia...
unregisterIt(mbean, ron);
}catch(Throwable t) {
}
}
throw new CustomMBeanException(e);
}
}