public String toSetSourceString()

in src/main/java/org/apache/commons/ognl/ASTAnd.java [175:231]


    public String toSetSourceString( OgnlContext context, Object target )
    {
        if ( children.length != 2 )
        {
            throw new UnsupportedCompilationException( "Can only compile boolean expressions with two children." );
        }

        String pre = (String) context.get( "_currentChain" );
        if ( pre == null )
        {
            pre = "";
        }

        String result = "";

        try
        {

            if ( !OgnlOps.booleanValue( children[0].getValue( context, target ) ) )
            {
                throw new UnsupportedCompilationException(
                    "And expression can't be compiled until all conditions are true." );
            }

            String first =
                ExpressionCompiler.getRootExpression( children[0], context.getRoot(), context ) + pre
                    + children[0].toGetSourceString( context, target );

            children[1].getValue( context, target );

            String second =
                ExpressionCompiler.getRootExpression( children[1], context.getRoot(), context ) + pre
                    + children[1].toSetSourceString( context, target );

            if ( !OgnlRuntime.isBoolean( first ) )
            {
                result += "if(org.apache.commons.ognl.OgnlOps.booleanValue(" + first + ")){";
            }
            else
            {
                result += "if(" + first + "){";
            }

            result += second;
            result += "; } ";

            context.setCurrentObject( target );
            context.setCurrentType( Object.class );

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

        return result;
    }