public Message createMessage ( final String messageName ) { final Message [ ] message = { null } ; for ( final Object messageCreator : messageCreators ) { ReflectionUtils . doWithMethods ( messageCreator . getClass ( ) , new ReflectionUtils . MethodCallback ( ) { @ Override public void doWith ( Method method ) throws IllegalArgumentException , IllegalAccessException { if ( method . getAnnotation ( MessageCreator . class ) . value ( ) . equals ( messageName ) ) { try { message [ 0 ] = ( Message ) method . invoke ( messageCreator ) ; } catch ( InvocationTargetException e ) { throw new CitrusRuntimeException ( "Unsupported message creator method: " + method . getName ( ) , e ) ; } } } } , new ReflectionUtils . MethodFilter ( ) { @ Override public boolean matches ( Method method ) { return method . getAnnotationsByType ( MessageCreator . class ) . length > 0 ; } } ) ; } if ( message [ 0 ] == null ) { throw new CitrusRuntimeException ( "Unable to find message creator for message: " + messageName ) ; } return message [ 0 ] ; }
Create message by delegating message creation to known message creators that are able to create message with given name .