if ( childDescriptors != null && childDescriptors.length > 0 ) {
// process child elements
for ( int i = 0, size = childDescriptors.length; i < size; i++ ) {
ElementDescriptor childDescriptor = childDescriptors[i];
Context childContext = context;
Expression childExpression = childDescriptor.getContextExpression();
if ( childExpression != null ) {
Object childBean = childExpression.evaluate( context );
if ( childBean != null ) {
String qualifiedName = childDescriptor.getQualifiedName();
// XXXX: should we handle nulls better
if ( childBean instanceof Iterator ) {
for ( Iterator iter = (Iterator) childBean; iter.hasNext(); ) {
Object object = iter.next();
if (object == null) {
continue;
}
if ( ! writtenContent ) {
writtenContent = true;
if (elementDescriptor.isWrapCollectionsInElement()) {
expressTagClose();
}
}
++indentLevel;
write( qualifiedName, object );
--indentLevel;
}
} else {
if ( ! writtenContent ) {
writtenContent = true;
expressTagClose();
}
++indentLevel;
write( qualifiedName, childBean );
--indentLevel;
}
}
} else {
if ( ! writtenContent ) {
writtenContent = true;
expressTagClose();
}
if (childDescriptor.isWrapCollectionsInElement()) {
++indentLevel;
}
write( childDescriptor.getQualifiedName(), childDescriptor, childContext );
if (childDescriptor.isWrapCollectionsInElement()) {
--indentLevel;
}
}
}
if ( writtenContent ) {
writePrintln();
writeIndent();
}
} else {
// evaluate the body text
Expression expression = elementDescriptor.getTextExpression();
if ( expression != null ) {
Object value = expression.evaluate( context );
if ( value != null ) {
String text = value.toString();
if ( text != null && text.length() > 0 ) {
if ( ! writtenContent ) {
writtenContent = true;