public static Object createProxyBean ( Class < ? > clazz , BeanBox box , BeanBoxContext ctx ) { BeanBoxException . assureNotNull ( clazz , "Try to create a proxy bean, but beanClass not found." ) ; Enhancer enhancer = new Enhancer ( ) ; enhancer . setSuperclass ( clazz ) ; if ( box . getConstructorParams ( ) != null && box . getConstructorParams ( ) . length > 0 ) { BeanBox [ ] boxes = box . getConstructorParams ( ) ; Class < ? > [ ] argsTypes = new Class < ? > [ boxes . length ] ; Object [ ] realArgsValue = new Object [ boxes . length ] ; for ( int i = 0 ; i < boxes . length ; i ++ ) { argsTypes [ i ] = boxes [ i ] . getType ( ) ; Object realValue = ctx . getBean ( boxes [ i ] ) ; if ( realValue != null && realValue instanceof String ) realValue = ctx . getValueTranslator ( ) . translate ( ( String ) realValue , boxes [ i ] . getType ( ) ) ; realArgsValue [ i ] = realValue ; } enhancer . setCallback ( new ProxyBean ( box , ctx ) ) ; return enhancer . create ( argsTypes , realArgsValue ) ; } else { enhancer . setCallback ( new ProxyBean ( box , ctx ) ) ; return enhancer . create ( ) ; } }
Create a ProxyBean