public static MessageParser createMessageParser ( String className , SecorConfig config ) throws Exception { Class < ? > clazz = Class . forName ( className ) ; if ( ! MessageParser . class . isAssignableFrom ( clazz ) ) { throw new IllegalArgumentException ( String . format ( "The class '%s' is not assignable to '%s'." , className , MessageParser . class . getName ( ) ) ) ; } // Assume that subclass of MessageParser has a constructor with the same signature as MessageParser return ( MessageParser ) clazz . getConstructor ( SecorConfig . class ) . newInstance ( config ) ; }
Create a MessageParser from it s fully qualified class name . The class passed in by name must be assignable to MessageParser and have 1 - parameter constructor accepting a SecorConfig . Allows the MessageParser to be pluggable by providing the class name of a desired MessageParser in config .