// 4. the object is an array, and the array class hasn't been specified in the node
// builder map, then we must treat it as a generic array.
// the first two cases are handled by the info node builders in the info node builders map. even
// the leaf node info node builders may need to be overridden. the third case is handled
// by the compound node
InfoNode node = null;
if( containsAnnotatedNodeBuilder( containingClass, fieldName ) )
{
final NodeBuilder builder = getAnnotatedNodeBuilder( containingClass, fieldName );
try
{
node = builder.createInfoNode( containingClass, object, fieldName );
}
catch( ReflectiveOperationException e )
{
final StringBuffer message = new StringBuffer();
message.append( "Node Builder failed to create InfoNode:" + Constants.NEW_LINE );
message.append( " Builder: " + builder.getClass().getName() + Constants.NEW_LINE );
message.append( " Containing Class Name: " + containingClass.getName() + Constants.NEW_LINE );
message.append( " Object: " + clazz.getName() + Constants.NEW_LINE );
message.append( " Field Name: " + fieldName + Constants.NEW_LINE );
LOGGER.error( message.toString() );
throw new IllegalStateException( message.toString(), e );
}
}
else if( containsNodeBuilder( clazz ) )
{
final NodeBuilder builder = getNodeBuilder( clazz );
try
{
// if the containing class is null, then this is a root object and we
// must use the root object version of the createInfoNode method
if( containingClass == null )
{
node = builder.createInfoNode( object, fieldName );
}
else
{
node = builder.createInfoNode( containingClass, object, fieldName );
}
}
catch( ReflectiveOperationException e )
{
final StringBuffer message = new StringBuffer();
message.append( "Node Builder failed to create InfoNode:" + Constants.NEW_LINE );
message.append( " Builder: " + builder.getClass().getName() + Constants.NEW_LINE );
message.append( " Containing Class Name: " + containingClass.getName() + Constants.NEW_LINE );
message.append( " Object: " + clazz.getName() + Constants.NEW_LINE );
message.append( " Field Name: " + fieldName + Constants.NEW_LINE );
LOGGER.error( message.toString() );
throw new IllegalStateException( message.toString(), e );
}
}
else if( clazz.isArray() )
{
try
{
node = genaralArrayNodeBuilder.createInfoNode( containingClass, object, fieldName );
}
catch( ReflectiveOperationException e )
{
final StringBuffer message = new StringBuffer();
message.append( "Default Array Node Builder failed to create InfoNode:" + Constants.NEW_LINE );
message.append( " Builder: " + genaralArrayNodeBuilder.getClass().getName() + Constants.NEW_LINE );
message.append( " Containing Class Name: " + containingClass.getName() + Constants.NEW_LINE );
message.append( " Object: " + clazz.getName() + Constants.NEW_LINE );
message.append( " Field Name: " + fieldName + Constants.NEW_LINE );
LOGGER.error( message.toString() );
throw new IllegalStateException( message.toString(), e );
}
}
else
{
// create a new compound node to holds this, since it isn't a leaf node, and
// call (recursively) the addNodes(...) method to add the nodes representing the
// fields of this object to the newly created compound node.
final InfoNode compoundNode = InfoNode.createCompoundNode( fieldName, fieldName, clazz );
node = addNodes( compoundNode, object );
}
// then call addNodes(...) with the newly created node
return node;