public String getSourceSetter()

in src/main/java/org/apache/commons/ognl/ObjectPropertyAccessor.java [264:327]


    public String getSourceSetter( OgnlContext context, Object target, Object index )
    {
        try
        {

            String methodName = index.toString().replace( "\"", "" );
            Method m = OgnlRuntime.getWriteMethod( target.getClass(), methodName );

            if ( m == null && context.getCurrentObject() != null && context.getCurrentObject().toString() != null )
            {
                m =
                    OgnlRuntime.getWriteMethod( target.getClass(),
                                                context.getCurrentObject().toString().replace( "\"", "" ) );
            }

            if ( m == null || m.getParameterTypes() == null || m.getParameterTypes().length <= 0 )
            {
                throw new UnsupportedCompilationException( "Unable to determine setting expression on "
                    + context.getCurrentObject() + " with index of " + index );
            }

            Class<?> parm = m.getParameterTypes()[0];
            String conversion;

            if ( m.getParameterTypes().length > 1 )
            {
                throw new UnsupportedCompilationException(
                    "Object property accessors can only support single parameter setters." );
            }

            final OgnlExpressionCompiler compiler = OgnlRuntime.getCompiler( context );
            if ( parm.isPrimitive() )
            {
                Class<?> wrapClass = OgnlRuntime.getPrimitiveWrapperClass( parm );
                conversion = compiler.createLocalReference( context, "((" + wrapClass.getName()
                    + ")org.apache.commons.ognl.OgnlOps#convertValue($3," + wrapClass.getName() + ".class, true))."
                    + OgnlRuntime.getNumericValueGetter( wrapClass ), parm );

            }
            else if ( parm.isArray() )
            {
                conversion = compiler.createLocalReference( context, "(" + ExpressionCompiler.getCastString( parm )
                    + ")org.apache.commons.ognl.OgnlOps#toArray($3," + parm.getComponentType().getName() + ".class)",
                                                            parm );

            }
            else
            {
                conversion = compiler.createLocalReference( context, "(" + parm.getName()
                    + ")org.apache.commons.ognl.OgnlOps#convertValue($3," + parm.getName() + ".class)", parm );
            }

            context.setCurrentType( m.getReturnType() );
            context.setCurrentAccessor(
                compiler.getSuperOrInterfaceClass( m, m.getDeclaringClass() ) );

            return "." + m.getName() + "(" + conversion + ")";

        }
        catch ( Throwable t )
        {
            throw OgnlOps.castToRuntime( t );
        }
    }