private < T > void invoke ( Map < Object , Set < Method > > methods , T instance ) { for ( Map . Entry < Object , Set < Method > > entry : methods . entrySet ( ) ) { Object listener = entry . getKey ( ) ; Set < Method > listenerMethods = entry . getValue ( ) ; if ( listenerMethods != null ) { for ( Method method : listenerMethods ) { Class < ? > parameterType = method . getParameterTypes ( ) [ 0 ] ; if ( parameterType . isAssignableFrom ( instance . getClass ( ) ) ) { try { method . invoke ( listener , instance ) ; } catch ( IllegalAccessException e ) { throw new XOException ( "Cannot access instance listener method " + method . toGenericString ( ) , e ) ; } catch ( InvocationTargetException e ) { throw new XOException ( "Cannot invoke instance listener method " + method . toGenericString ( ) , e ) ; } } } } } }
Invokes all registered lifecycle methods on a given instance .