docs: @SuppressWarnings({ "unchecked", "rawtypes" })
      public static Object getRegisterableMBean(ServiceReference<?> serviceReference, Object mBean)
                      throws NotCompliantMBeanException {
  
          // String methodName = "getRegisterableMBean";
          // System.out.println(methodName + ": ENTER: MBean [ " + mBean + " ]");
  
          // Follows the algorithm used by Apache Aries for registering MBeans.
  
          // REVISIT: The read-only restriction might be relaxed if and when security
          // support is added to JMX.
          if ( mBean instanceof DynamicMBean ) {
              // System.out.println(methodName + ": RETURN : MBean [ " + mBean + " ] (DynamicMBean)");
              return mBean;
          } else if ( mBean instanceof ConfigurationAdminMBean ) {
              Object readOnlyMBean = new ReadOnlyConfigurationAdmin((ConfigurationAdminMBean) mBean);
              // System.out.println(methodName + ": RETURN : MBean [ " + readOnlyMBean + " ] (ConfigurationAdminBean)");            
              return readOnlyMBean;
          }
  
          Class<?> fallbackInterface = null;
  
          Class<?> mBeanClass = mBean.getClass();
          String directInterfaceName = mBeanClass.getName() + "MBean";
  
          List<String> publishedInterfaceNames =
              Arrays.asList((String[]) serviceReference.getProperty(Constants.OBJECTCLASS));
  
          // for ( String publishedName : publishedInterfaceNames ) {
          //     System.out.println(methodName + ": Published [ " + publishedName + " ]");
          // }
          
          for ( Class<?> nextInterface : mBeanClass.getInterfaces() ) {
              String nextInterfaceName = nextInterface.getName();
  
              // Skip any interface which is not published.
              if ( !publishedInterfaceNames.contains(nextInterfaceName) ) {
                  // System.out.println(methodName + ": Candidate interface [ " + nextInterfaceName + " ]: Skip, not published");
                  continue;
              }
  
              // Immediate case: Match on the bean class name and ends with "MBean".            
              if ( nextInterfaceName.equals(directInterfaceName) ) {
                  // System.out.println(methodName + ": RETURN [ " + mBean + " ] Direct match on interface [ " + nextInterfaceName + " ]");                
                  return mBean;
              }
  
              // Immediate case: Match on interface tagged with "@MXBean(true)".
              // Immediate case: Match on an interface not tagged with "@MXBean(false)"
              // and which ends with "MXBean".
              MXBean mxbean = nextInterface.getAnnotation(MXBean.class);
              if ( mxbean != null ) {
                  if ( mxbean.value() ) {
                      // System.out.println(methodName + ": RETURN [ " + mBean + " ] Direct match on @MXBean [ " + nextInterfaceName + " ]");                                    
                      return mBean;
                  } else {
                      // System.out.println(methodName + ": Ignoring interface [ " + nextInterfaceName + " ] with @MXBean(false)");                                                        
                      // "@MXBean(false)"
                  }
              } else {
                  if ( nextInterfaceName.endsWith("MXBean") ) {
                      // System.out.println(methodName + ": RETURN [ " + mBean + " ] Direct match on MXBean [ " + nextInterfaceName + " ]");
                      return mBean;
                  }
              }
  
              // Secondary case: Not a match on bean class name but ending with
              // "MBean".  Use as a fall back if the none of the immediate cases
              // triggers.
              if ( nextInterfaceName.endsWith("MBean") ) {
                  // System.out.println(methodName + ": Partial match on interface [ " + nextInterfaceName + " ]");                                                    
                  fallbackInterface = nextInterface; // Do NOT return immediately.
              }
          }
  
          // REVISIT: The object wasn't of the form we were expecting though
          // might still be an MBean.  For now let's reject it. We can support
          // more types of MBeans later.
  
          if ( fallbackInterface == null ) {
              // System.out.println(methodName + ": Failing with NonCompliantMBeanException");
  
              StringBuilder errorMessage = new StringBuilder();
              errorMessage.append("Unregisterable MBean: [ " + mBeanClass.getName() + " ]");
              for ( Class<?> nextInterface : mBeanClass.getInterfaces() ) {
                  errorMessage.append(" implements [ " + nextInterface.getName() + " ]");
              }
              for ( String publishedName : (String[]) serviceReference.getProperty(Constants.OBJECTCLASS) ) {
                  errorMessage.append(" published [ " + publishedName + " ]");
              }
              throw new NotCompliantMBeanException(errorMessage.toString());
          }
  
          Object standardMBean;
          if ( mBean instanceof NotificationEmitter ) {
              // System.out.println(methodName + ": RETURN [ " + mBean + " ] (Standard Emitter MBean)");
              standardMBean = new StandardEmitterMBean(mBean, (Class) fallbackInterface, (NotificationEmitter) mBean);
          } else {
              // System.out.println(methodName + ": RETURN [ " + mBean + " ] (Standard MBean)");            
              standardMBean = new StandardMBean(mBean, (Class) fallbackInterface);
          }
          return standardMBean;
      }