private void writeAssociation( XMLWriter writer, ModelAssociation association )
{
StoreAssociationMetadata am =
(StoreAssociationMetadata) association.getAssociationMetadata( StoreAssociationMetadata.ID );
JPoxAssociationMetadata jpoxMetadata =
(JPoxAssociationMetadata) association.getAssociationMetadata( JPoxAssociationMetadata.ID );
if ( am.isPart() != null )
{
// This gets added onto the <field> element
writer.addAttribute( "default-fetch-group", am.isPart().toString() );
}
if ( association.getType().equals( "java.util.List" ) || association.getType().equals( "java.util.Set" ) )
{
// Start <collection> element
writer.startElement( "collection" );
if ( association.getTo().equals( "String" ) )
{
writer.addAttribute( "element-type", "java.lang.String" );
}
else
{
writer.addAttribute( "element-type", association.getTo() );
}
if ( jpoxMetadata.isDependent() )
{
writer.addAttribute( "dependent-element", "true" );
}
else
{
writer.addAttribute( "dependent-element", "false" );
}
// End <collection> element
writer.endElement();
if ( jpoxMetadata.isJoin() )
{
writer.startElement( "join" );
writer.endElement();
}
}
else if ( association.getType().equals( "java.util.Map" ) )
{
writer.startElement( "map" );
writer.addAttribute( "key-type", am.getKeyType() );
if ( association.getTo().equals( "String" ) )
{
writer.addAttribute( "value-type", "java.lang.String" );
}
else
{
writer.addAttribute( "value-type", association.getTo() );
}
if ( jpoxMetadata.isDependent() )
{
writer.addAttribute( "dependent-key", "true" );
writer.addAttribute( "dependent-value", "true" );
}
else
{
writer.addAttribute( "dependent-key", "false" );
writer.addAttribute( "dependent-value", "false" );
}
writer.endElement();
if ( jpoxMetadata.isJoin() )
{
writer.startElement( "join" );
writer.endElement();
}
}
else if ( association.getType().equals( "java.util.Properties" ) )
{
writer.addAttribute( "embedded", "false" );
writer.startElement( "map" );
writer.addAttribute( "key-type", "java.lang.String" );
writer.addAttribute( "value-type", "java.lang.String" );
writer.addAttribute( "embedded-key", "true" );
writer.addAttribute( "embedded-value", "true" );
writer.addAttribute( "dependent-key", "true" );
writer.addAttribute( "dependent-value", "true" );
writer.endElement();
if ( jpoxMetadata.isJoin() )
{
writer.startElement( "join" );
writer.endElement();
}
}
else
// One association
{
if ( jpoxMetadata.isDependent() )
{
writer.addAttribute( "dependent", "true" );
}
}
}