in src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java [95:150]
public void setProperty( Map<String, Object> context, Object target, Object name, Object value )
throws OgnlException
{
if ( name instanceof String && !( (String) name ).contains( "$" ) )
{
super.setProperty( context, target, name, value );
return;
}
@SuppressWarnings( "unchecked" ) // check performed by the invoker
List<Object> list = (List<Object>) target;
if ( name instanceof Number )
{
list.set( ( (Number) name ).intValue(), value );
return;
}
if ( name instanceof DynamicSubscript )
{
int len = list.size();
switch ( ( (DynamicSubscript) name ).getFlag() )
{
case DynamicSubscript.FIRST:
if ( len > 0 )
{
list.set( 0, value );
}
return;
case DynamicSubscript.MID:
if ( len > 0 )
{
list.set( len / 2, value );
}
return;
case DynamicSubscript.LAST:
if ( len > 0 )
{
list.set( len - 1, value );
}
return;
case DynamicSubscript.ALL:
if ( !( value instanceof Collection ) )
{
throw new OgnlException( "Value must be a collection" );
}
list.clear();
list.addAll( (Collection<?>) value );
return;
default:
return;
}
}
throw new NoSuchPropertyException( target, name );
}