if( collection != null )
{
if( collection instanceof ElementList )
{
final ElementList<?> list = (ElementList<?>) collection;
final ListProperty listProperty = list.definition();
final ElementType listEntryType = listProperty.getType();
final ValueProperty listEntryProperty;
if( operands().size() > 1 )
{
final String listEntryPropertyName = cast( operand( 1 ), String.class );
final PropertyDef prop = listEntryType.property( listEntryPropertyName );
if( prop == null )
{
throw new FunctionException( missingProperty.format( listEntryType.getSimpleName(), listEntryPropertyName ) );
}
if( ! ( prop instanceof ValueProperty ) )
{
throw new FunctionException( notValueProperty.format( listEntryType.getSimpleName(), listEntryPropertyName ) );
}
listEntryProperty = (ValueProperty) prop;
}
else
{
ValueProperty prop = null;
for( PropertyDef p : listEntryType.properties() )
{
if( p instanceof ValueProperty )
{
prop = (ValueProperty) p;
break;
}
}
if( prop == null )
{
throw new FunctionException( noValueProperties.format( listEntryType.getSimpleName() ) );
}
listEntryProperty = prop;
}
for( Element item : list )
{
items.add( item.property( listEntryProperty ).content() );
}
final Element listParentElement = list.element();
final String listenerModelPath = listProperty.name() + "/" + listEntryProperty.name();
if( this.lastListParentElement != listParentElement || ! this.lastListenerModelPath.equals( listenerModelPath ) )
{
if( this.lastListParentElement != null )
{