public String toGetSourceString()

in src/main/java/org/apache/commons/ognl/ASTStaticMethod.java [84:195]


    public String toGetSourceString( OgnlContext context, Object target )
    {
        StringBuilder result = new StringBuilder(className + "#" + methodName + "(");

        try
        {
            Class clazz = OgnlRuntime.classForName( context, className );
            Method m = OgnlRuntime.getMethod( context, clazz, methodName, children, true );

            if ( m == null )
            {
                throw new UnsupportedCompilationException(
                    "Unable to find class/method combo " + className + " / " + methodName );
            }

            if ( !context.getMemberAccess().isAccessible( context, clazz, m, methodName ) )
            {
                throw new UnsupportedCompilationException(
                    "Method is not accessible, check your jvm runtime security settings. " + "For static class method "
                        + className + " / " + methodName );
            }

            OgnlExpressionCompiler compiler = OgnlRuntime.getCompiler( context );
            if ( ( children != null ) && ( children.length > 0 ) )
            {
                Class[] parms = m.getParameterTypes();

                for ( int i = 0; i < children.length; i++ )
                {
                    if ( i > 0 )
                    {
                        result.append(", ");
                    }

                    Class prevType = context.getCurrentType();

                    Node child = children[i];
                    Object root = context.getRoot();

                    String parmString = ASTMethodUtil.getParmString( context, root, child, prevType );

                    Class valueClass = ASTMethodUtil.getValueClass( context, root, child );

                    if ( valueClass != parms[i] )
                    {
                        if ( parms[i].isArray() )
                        {
                            parmString = compiler.createLocalReference( context, "(" + ExpressionCompiler.getCastString(
                                parms[i] ) + ")org.apache.commons.ognl.OgnlOps.toArray(" + parmString + ", "
                                + parms[i].getComponentType().getName() + ".class, true)", parms[i] );

                        }
                        else if ( parms[i].isPrimitive() )
                        {
                            Class wrapClass = OgnlRuntime.getPrimitiveWrapperClass( parms[i] );

                            parmString = compiler.createLocalReference( context, "((" + wrapClass.getName()
                                + ")org.apache.commons.ognl.OgnlOps.convertValue(" + parmString + ","
                                + wrapClass.getName() + ".class, true))." + OgnlRuntime.getNumericValueGetter(
                                wrapClass ), parms[i] );

                        }
                        else if ( parms[i] != Object.class )
                        {
                            parmString = compiler.createLocalReference( context, "(" + parms[i].getName()
                                + ")org.apache.commons.ognl.OgnlOps.convertValue(" + parmString + ","
                                + parms[i].getName() + ".class)", parms[i] );
                        }
                        else if ( ( child instanceof NodeType && ( (NodeType) child ).getGetterClass() != null
                            && Number.class.isAssignableFrom( ( (NodeType) child ).getGetterClass() ) )
                            || valueClass.isPrimitive() )
                        {
                            parmString = " ($w) " + parmString;
                        }
                        else if ( valueClass.isPrimitive() )
                        {
                            parmString = "($w) " + parmString;
                        }
                    }

                    result.append(parmString);
                }
            }

            result.append(")");

            try
            {
                Object contextObj = getValueBody( context, target );
                context.setCurrentObject( contextObj );
            }
            catch ( Throwable t )
            {
                // ignore
            }

            if ( m != null )
            {
                getterClass = m.getReturnType();

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

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

        return result.toString();
    }