private Object getObjectInstanceFromClass ( TestContext context ) throws ClassNotFoundException , SecurityException , NoSuchMethodException , IllegalArgumentException , InstantiationException , IllegalAccessException , InvocationTargetException { if ( ! StringUtils . hasText ( className ) ) { throw new CitrusRuntimeException ( "Neither class name nor object instance reference " + "is set for Java reflection call" ) ; } log . info ( "Instantiating class for name '" + className + "'" ) ; Class < ? > classToRun = Class . forName ( className ) ; Class < ? > [ ] constructorTypes = new Class < ? > [ constructorArgs . size ( ) ] ; Object [ ] constructorObjects = new Object [ constructorArgs . size ( ) ] ; for ( int i = 0 ; i < constructorArgs . size ( ) ; i ++ ) { constructorTypes [ i ] = constructorArgs . get ( i ) . getClass ( ) ; if ( constructorArgs . get ( i ) . getClass ( ) . equals ( String . class ) ) { constructorObjects [ i ] = context . replaceDynamicContentInString ( constructorArgs . get ( i ) . toString ( ) ) ; } else { constructorObjects [ i ] = constructorArgs . get ( i ) ; } } Constructor < ? > constr = classToRun . getConstructor ( constructorTypes ) ; return constr . newInstance ( constructorObjects ) ; }
Instantiate class for name . Constructor arguments are supported if specified .