if (childDescriptors[i] instanceof ElementDescriptor) {
// Element content
ElementDescriptor childDescriptor = (ElementDescriptor) childDescriptors[i];
Context childContext = context;
childContext.pushOptions(childDescriptor.getOptions());
Expression childExpression = childDescriptor.getContextExpression();
if ( childExpression != null ) {
Object childBean = childExpression.evaluate( context );
if ( childBean != null ) {
String qualifiedName = childDescriptor.getQualifiedName();
String namespaceUri = childDescriptor.getURI();
String localName = childDescriptor.getLocalName();
// 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;
}
writeBean(
namespaceUri,
localName,
qualifiedName,
object,
childDescriptor,
context );
}
} else {
writeBean(
namespaceUri,
localName,
qualifiedName,
childBean,
childDescriptor,
context );
}
}
} else {
writeElement(
childDescriptor.getURI(),
childDescriptor.getLocalName(),
childDescriptor.getQualifiedName(),
childDescriptor,
childContext );
}
childContext.popOptions();
} else {
// Mixed text content
// evaluate the body text
Expression expression = childDescriptors[i].getTextExpression();
if ( expression != null ) {
Object value = expression.evaluate( context );
String text = convertToString(
value,
childDescriptors[i],
context );
if ( text != null && text.length() > 0 ) {;
bodyText( writeContext, text );
}
}
}
}
} else {
// evaluate the body text
Expression expression = elementDescriptor.getTextExpression();
if ( expression != null ) {
Object value = expression.evaluate( context );
String text = convertToString( value, elementDescriptor, context );
if ( text != null && text.length() > 0 ) {
bodyText( writeContext, text );
}
}