}
if( persistName == null || persistName.isEmpty() )
{
persistName = fieldName;
}
final InfoNode node = InfoNode.createCompoundNode( fieldName, persistName, clazz );
// grab the annotations for this field and see if the persist name is specified
// does the class have a @PersistCollection( elementPersistName = "xxxx" )
String elementPersistName = null;
try
{
// grab the array annotation if the containing class isn't null. If the containing class is null,
// then later in the code we set the name for which to persist the elements to the classes simple
// name with the compound array name suffix
PersistArray arrayAnnotation = null;
if( containingClass != null && !containingClass.isArray() )
{
final Field field = ReflectionUtils.getDeclaredField( containingClass, fieldName );
arrayAnnotation = field.getAnnotation( PersistArray.class );
}
if( arrayAnnotation != null && !arrayAnnotation.elementPersistName().isEmpty() )
{
elementPersistName = arrayAnnotation.elementPersistName();
}
}
catch( ReflectiveOperationException e )
{
LOGGER.warn( "Field not found in containing class:" + Constants.NEW_LINE +
" Containing class: " + containingClass.getName() + Constants.NEW_LINE +
" Field name: " + fieldName + Constants.NEW_LINE, e );
}
// run through the Collection elements, recursively calling createNode(...) to create
// the appropriate node which to add to the newly created compound node.
for( int i = 0; i < Array.getLength( object ); ++i )
{
// grab the element of the array
final Class< ? > elementClazz = object.getClass().getComponentType();
String name;
if( elementPersistName == null )
{
name = elementClazz.getSimpleName();
if( elementClazz.isArray() )
{
name = name.replaceAll( "\\[\\]", compoundArrayNameSuffix );
}
}
else
{
name = elementPersistName;
}
// grab the element and create the node. however, because the element may be a primitive
// we need to set the node's class type to the actual element node. if we don't do this
// then, for example, all ints will become Integers and if we ask for the type to be
// set within the node, the type will be incorrect
final Object element = Array.get( object, i );
final InfoNode elementNode = createNode( clazz, element, name );
elementNode.setClazz( elementClazz );
// add the new node as a child to the parent
node.addChild( elementNode );
}