xmlPath = xmlBindingAnnotation.path();
}
if( xmlPath == null )
{
final XmlValueBinding xmlValueBindingAnnotation = property.getAnnotation( XmlValueBinding.class );
if( xmlValueBindingAnnotation != null )
{
xmlPath = xmlValueBindingAnnotation.path();
}
}
if( xmlPath == null )
{
final XmlElementBinding xmlElementBindingAnnotation = property.getAnnotation( XmlElementBinding.class );
if( xmlElementBindingAnnotation != null )
{
final int mappingsCount = xmlElementBindingAnnotation.mappings().length;
if( mappingsCount == 0 )
{
xmlPath = xmlElementBindingAnnotation.path();
}
else if( mappingsCount == 1 )
{
xmlPath = xmlElementBindingAnnotation.mappings()[ 0 ].element();
if( xmlElementBindingAnnotation.path().length() > 0 )
{
xmlPath = xmlElementBindingAnnotation.path() + "/" + xmlPath;
}
}
else
{
continue; // todo: report unsupported
}
}
}
if( xmlPath == null )
{
final XmlListBinding xmlListBindingAnnotation = property.getAnnotation( XmlListBinding.class );
if( xmlListBindingAnnotation != null )
{
if( xmlListBindingAnnotation.mappings().length == 1 )
{
xmlPath = xmlListBindingAnnotation.mappings()[ 0 ].element();
if( xmlListBindingAnnotation.path().length() > 0 )
{
xmlPath = xmlListBindingAnnotation.path() + "/" + xmlPath;
}
}
else
{
continue; // todo: report unsupported
}
}
}
if( xmlPath != null )
{
properties.put( xmlPath, property );
}
}
// Write the summary document fragment
out.println( "<table>" );
out.println( " <tr>" );
out.println( " <th>Element</th>" );
out.println( " <th>Cardinality</th>" );
out.println( " <th>Description</th>" );
out.println( " </tr>" );
for( Map.Entry<String,PropertyDef> entry : properties.entrySet() )
{
final String xmlPath = entry.getKey();
final PropertyDef property = entry.getValue();
final String cardinality;
if( property instanceof ValueProperty )
{
if( property.hasAnnotation( Required.class ) )
{
cardinality = "1";
}
else
{
cardinality = "0 or 1";
}
}
else if( property instanceof ElementProperty )
{
cardinality = "0 or 1";
}
else if( property instanceof ListProperty )
{
cardinality = "0 or more";
}
else
{
throw new IllegalStateException();
}
out.println( " <tr>" );
out.println( td( xmlPath ) );
out.println( td( cardinality ) );
out.println( " <td>" );
if( property.hasAnnotation( Documentation.class ) )
{
documentation( out, property.getAnnotation( Documentation.class ) );
}
else
{
out.println( " " );
}
if( property instanceof ElementProperty || property instanceof ListProperty )
{
boolean skip = false;
final ElementType childType = property.service( PossibleTypesService.class ).types().first();
final SortedSet<PropertyDef> childTypeProperties = childType.properties();
if( childTypeProperties.size() == 1 )
{
final PropertyDef childTypeProperty = childTypeProperties.first();
if( childTypeProperty instanceof ValueProperty )
{
if( childTypeProperty.hasAnnotation( XmlBinding.class ) )
{
final XmlBinding b = childTypeProperty.getAnnotation( XmlBinding.class );
if( b != null && b.path().length() == 0 )
{
skip = true;
}
}
else if( childTypeProperty.hasAnnotation( XmlValueBinding.class ) )
{
final XmlValueBinding b = childTypeProperty.getAnnotation( XmlValueBinding.class );
if( b != null && b.path().length() == 0 )
{
skip = true;
}
}
}