private String getSourceBeanMethod()

in src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java [229:285]


    private String getSourceBeanMethod( OgnlContext context, Object target, Object index, String indexStr,
                                        boolean isSetter )
    {
        Object currentObject = context.getCurrentObject();
        Class<?> currentType = context.getCurrentType();
        if ( currentObject != null && !(currentObject instanceof Number))
        {
            try
            {
                if ( isSetter )
                {
                    if ( OgnlRuntime.getWriteMethod( target.getClass(), indexStr ) != null
                        || !currentType.isPrimitive() )
                    {
                        return super.getSourceSetter( context, target, index );
                    }
                }
                else
                {
                    if ( OgnlRuntime.getReadMethod( target.getClass(), indexStr ) != null )
                    {
                        return super.getSourceAccessor( context, target, index );
                    }
                }
            }
            catch ( Throwable t )
            {
                throw OgnlOps.castToRuntime( t );
            }
        }

        /*
         * if (String.class.isInstance(index)) { context.setCurrentAccessor(List.class); return ""; }
         */

        context.setCurrentAccessor( List.class );

        // need to convert to primitive for list index access

        if ( !currentType.isPrimitive() && Number.class.isAssignableFrom( currentType ) )
        {
            indexStr += "." + OgnlRuntime.getNumericValueGetter( currentType );
        }
        else if ( currentObject != null && Number.class.isAssignableFrom( currentObject.getClass() )
            && !currentType.isPrimitive() )
        {
            // means it needs to be cast first as well

            String toString = index instanceof String && currentType != Object.class ? "" : ".toString()";

            indexStr = "org.apache.commons.ognl.OgnlOps#getIntValue(" + indexStr + toString + ")";
        }

        context.setCurrentType( Object.class );

        return isSetter ? ".set(" + indexStr + ", $3)" : ".get(" + indexStr + ")";
    }