{
injectedField.set( instance, value );
}
catch( IllegalAccessException e )
{
throw new InjectionException( e );
}
catch( IllegalArgumentException e )
{
String valueClassName;
if( Proxy.isProxyClass( value.getClass() ) )
{
InvocationHandler invocationHandler = Proxy.getInvocationHandler( value );
if( invocationHandler instanceof TransientInstance )
{
TransientInstance handler = (TransientInstance) invocationHandler;
valueClassName = Classes.toString( handler.descriptor().types() )
+ " in [" + handler.module().name() + "] of [" + handler.module()
.layerInstance()
.name() + "]";
}
else
{
valueClassName = invocationHandler.toString();
}
}
else
{
valueClassName = value.getClass().getName();
}
StringBuilder annotBuilder = new StringBuilder();
for( Annotation annot : injectedField.getAnnotations() )
{
String s = annot.toString();
annotBuilder.append( "@" ).append( s.substring( s.lastIndexOf( '.' ) + 1, s.length() - 2 ) );
annotBuilder.append( " " );
}
String annots = annotBuilder.toString();
String message = "Can not inject the field\n "
+ injectedField.getDeclaringClass()
+ "\n {\n " + annots + "\n "
+ injectedField.getType().getSimpleName() + " " + injectedField.getName()
+ "\n }\nwith value \n " + value + "\nof type\n "
+ valueClassName;
throw new InjectionException( message, e );
}
}