return b;
}
private Column toColumn( final XSComponent xs )
{
Column col = null;
boolean columnEmpty = true;
XSSimpleType type = null;
if ( xs instanceof XSParticle )
{
col = new Column();
col.setNullable( ( (XSParticle) xs ).getMinOccurs() == 0 );
columnEmpty = false;
}
else if ( xs instanceof XSSimpleType )
{
col = new Column();
type = (XSSimpleType) xs;
}
else if ( xs instanceof XSAttributeDecl )
{
col = new Column();
type = ( (XSAttributeDecl) xs ).getType();
}
else if ( xs instanceof XSAttributeUse )
{
final XSAttributeUse au = (XSAttributeUse) xs;
col = new Column();
col.setNullable( !au.isRequired() );
columnEmpty = false;
type = ( (XSAttributeUse) xs ).getDecl().getType();
}
else if ( xs instanceof XSElementDecl )
{
col = new Column();
final XSElementDecl decl = (XSElementDecl) xs;
col.setNullable( decl.isNillable() );
columnEmpty = false;
type = ( (XSElementDecl) xs ).getType().asSimpleType();
}
if ( type != null )
{
final XSFacet length = type.getFacet( XSFacet.FACET_LENGTH );
final XSFacet maxLength = type.getFacet( XSFacet.FACET_MAXLENGTH );
final XSFacet fractionDigits = type.getFacet( XSFacet.FACET_FRACTIONDIGITS );
final XSFacet totalDigits = type.getFacet( XSFacet.FACET_TOTALDIGITS );
if ( length != null )
{
col.setLength( new Integer( length.getValue().value ) );
columnEmpty = false;
}
else if ( maxLength != null )
{
col.setLength( new Integer( maxLength.getValue().value ) );
columnEmpty = false;
}
if ( fractionDigits != null )
{
col.setScale( new Integer( fractionDigits.getValue().value ) );
columnEmpty = false;
}
if ( totalDigits != null )
{
col.setPrecision( new Integer( totalDigits.getValue().value ) );
columnEmpty = false;
}
if ( this.getSchemaSimpleType( type, "decimal" ) != null
&& ( col.getScale() == null || col.getPrecision() == null ) )
{
XSSimpleType schemaType = this.getSchemaSimpleType( type, "integer" );
if ( schemaType != null && col.getScale() == null )
{
col.setScale( new Integer( 0 ) );
columnEmpty = false;
}
if ( col.getPrecision() == null )
{
schemaType = this.getSchemaSimpleType( type, "long" );
if ( schemaType != null )
{
col.setPrecision( new Integer( 20 ) );
columnEmpty = false;
}
schemaType = this.getSchemaSimpleType( type, "int" );
if ( schemaType != null )
{
col.setPrecision( new Integer( 10 ) );
columnEmpty = false;
}
schemaType = this.getSchemaSimpleType( type, "short" );
if ( schemaType != null )
{
col.setPrecision( new Integer( 5 ) );
columnEmpty = false;
}
schemaType = this.getSchemaSimpleType( type, "byte" );
if ( schemaType != null )
{
col.setPrecision( new Integer( 3 ) );
columnEmpty = false;
}
schemaType = this.getSchemaSimpleType( type, "unsignedLong" );
if ( schemaType != null )
{
col.setPrecision( new Integer( 20 ) );
columnEmpty = false;
}
schemaType = this.getSchemaSimpleType( type, "unsignedInt" );
if ( schemaType != null )
{
col.setPrecision( new Integer( 10 ) );
columnEmpty = false;
}
schemaType = this.getSchemaSimpleType( type, "unsignedShort" );
if ( schemaType != null )
{
col.setPrecision( new Integer( 5 ) );
columnEmpty = false;
}
schemaType = this.getSchemaSimpleType( type, "unsignedByte" );
if ( schemaType != null )
{
col.setPrecision( new Integer( 3 ) );
columnEmpty = false;
}
}
}
}