private Object toMBean ( Object object ) throws IllegalArgumentException , NotCompliantMBeanException { JmxBean jmxBean = AnnotationUtils . getAnnotation ( object . getClass ( ) , JmxBean . class ) ; if ( DynamicMBean . class . isAssignableFrom ( object . getClass ( ) ) ) { return object ; } ClassIntrospector classIntrospector = new ClassIntrospectorImpl ( object . getClass ( ) ) ; Class < ? > mBeanInterface = classIntrospector . getInterface ( new ClassFilterBuilder ( ) . name ( object . getClass ( ) . getName ( ) . replace ( "." , "\\." ) + "MBean" ) . build ( ) ) ; if ( mBeanInterface != null ) { return new AnnotatedStandardMBean ( object , mBeanInterface ) ; } Class < ? > mxBeanInterface = classIntrospector . getInterface ( new ClassFilterBuilder ( ) . name ( ".*MXBean" ) . or ( ) . annotated ( MXBean . class ) . build ( ) ) ; if ( mxBeanInterface != null ) { return new AnnotatedStandardMBean ( object , mxBeanInterface , true ) ; } // Interface set on JmxBean annotation if ( ! jmxBean . managedInterface ( ) . equals ( EmptyInterface . class ) ) { if ( implementsInterface ( object , jmxBean . managedInterface ( ) ) ) { return new AnnotatedStandardMBean ( object , jmxBean . managedInterface ( ) ) ; } else { throw new IllegalArgumentException ( JmxBean . class + " attribute managedInterface is set to " + jmxBean . managedInterface ( ) + " but " + object . getClass ( ) + " does not implement that interface" ) ; } } // Search for an implemented interface annotated with JmxInterface Class < ? > annotatedInterface = classIntrospector . getInterface ( new ClassFilterBuilder ( ) . annotated ( JmxInterface . class ) . build ( ) ) ; if ( annotatedInterface != null ) { return new AnnotatedStandardMBean ( object , jmxBean . managedInterface ( ) ) ; } // Create DynamicMBean by using reflection and inspecting annotations return dynamicBeanFactory . getMBeanFor ( object ) ; }
Returns either a AnnotatedStandardMBean or a DynamicMBean implementation .