protected void setValueBody()

in src/main/java/org/apache/commons/ognl/ASTChain.java [150:238]


    protected void setValueBody( OgnlContext context, Object target, Object value )
        throws OgnlException
    {
        boolean handled = false;

        for ( int i = 0, ilast = children.length - 2; i <= ilast; ++i )
        {
            if ( (i <= ilast) && (children[i] instanceof ASTProperty) )
            {
                ASTProperty propertyNode = (ASTProperty) children[i];
                int indexType = propertyNode.getIndexedPropertyType( context, target );

                if ( ( indexType != OgnlRuntime.INDEXED_PROPERTY_NONE )
                    && ( children[i + 1] instanceof ASTProperty ) )
                {
                    ASTProperty indexNode = (ASTProperty) children[i + 1];

                    if ( indexNode.isIndexedAccess() )
                    {
                        Object index = indexNode.getProperty( context, target );

                        if ( index instanceof DynamicSubscript )
                        {
                            if ( indexType == OgnlRuntime.INDEXED_PROPERTY_INT )
                            {
                                Object array = propertyNode.getValue( context, target );
                                int len = Array.getLength( array );

                                switch ( ( (DynamicSubscript) index ).getFlag() )
                                {
                                    case DynamicSubscript.ALL:
                                        System.arraycopy( target, 0, value, 0, len );
                                        handled = true;
                                        i++;
                                        break;
                                    case DynamicSubscript.FIRST:
                                        index = ( len > 0 ) ? 0 : -1;
                                        break;
                                    case DynamicSubscript.MID:
                                        index = ( len > 0 ) ? ( len / 2 ) : -1;
                                        break;
                                    case DynamicSubscript.LAST:
                                        index = ( len > 0 ) ? ( len - 1 ) : -1;
                                        break;
                                    default:
                                        break;
                                }
                            }
                            else
                            {
                                if ( indexType == OgnlRuntime.INDEXED_PROPERTY_OBJECT )
                                {
                                    throw new OgnlException( "DynamicSubscript '" + indexNode
                                        + "' not allowed for object indexed property '" + propertyNode + "'" );
                                }
                            }
                        }
                        if ( !handled && i == ilast )
                        {
                            OgnlRuntime.setIndexedProperty( context, target,
                                                            propertyNode.getProperty( context, target ).toString(),
                                                            index, value );
                            handled = true;
                            i++;
                        }
                        else if ( !handled )
                        {
                            target =
                                OgnlRuntime.getIndexedProperty(
                                    context,
                                    target,
                                    propertyNode.getProperty( context, target ).toString(),
                                    index );
                            i++;
                            continue;
                        }
                    }
                }
            }
            if ( !handled )
            {
                target = children[i].getValue( context, target );
            }
        }
        if ( !handled )
        {
            children[children.length - 1].setValue( context, target, value );
        }
    }