in impl/src/main/java/org/apache/tuscany/sdo/helper/SchemaBuilder.java [87:171]
private QName addAttribute2ComplexType(String targetNamespace,
XSDComplexTypeDefinition complexType,
Property aProperty)
{
QName attributeSchemaType = null;
String prefix = null;
try
{
attributeSchemaType = buildSchema(aProperty.getType());
}
catch ( IllegalArgumentException e )
{
//schema cannot be generated for this type as there exists an xsd already
//so include that original XSD
attributeSchemaType = new QName(aProperty.getType().getURI(),
aProperty.getType().getName(),
generatePrefix());
if ( aProperty.getType().isDataType() )
{
typeTable.addSimpleSchemaType(aProperty.getType().getName(), attributeSchemaType);
XSDSimpleTypeDefinition simpleType = xsdFactory.createXSDSimpleTypeDefinition();
simpleType.setName(aProperty.getType().getName());
simpleType.setTargetNamespace(aProperty.getType().getURI());
typeTable.addXSDTypeDef(attributeSchemaType.getNamespaceURI(),
attributeSchemaType.getLocalPart(),
simpleType);
}
else
{
typeTable.addComplexSchemaType(aProperty.getType().getURI(),
aProperty.getType().getName(),
attributeSchemaType);
XSDComplexTypeDefinition extComplexType = xsdFactory.createXSDComplexTypeDefinition();
extComplexType.setName(aProperty.getType().getName());
extComplexType.setTargetNamespace(aProperty.getType().getURI());
typeTable.addXSDTypeDef(attributeSchemaType.getNamespaceURI(),
attributeSchemaType.getLocalPart(),
extComplexType);
}
includeExtXSD(aProperty.getType());
}
//ensure than an import is done rightaway so that the right prefixes will be used by the
//attribute whose type is set as 'this type'. Otherwise when setting the type for the attribute
//there will be a duplicate prefix (like Q1 or Q2... ) that will be created
prefix = addImports((XSDSchema)schemaMap.get(targetNamespace), attributeSchemaType);
XSDAttributeDeclaration attribute = xsdFactory.createXSDAttributeDeclaration();
attribute.setName(aProperty.getName());
XSDAttributeUse orderDateAttributeUse = xsdFactory.createXSDAttributeUse();
orderDateAttributeUse.setContent(attribute);
complexType.getAttributeContents().add(orderDateAttributeUse);
attribute.updateElement();
if ( aProperty.getType().isDataType() )
{
attribute.setTypeDefinition((XSDSimpleTypeDefinition)typeTable.getXSDTypeDef(attributeSchemaType.getNamespaceURI(),
attributeSchemaType.getLocalPart()));
}
else
{
attribute.setTypeDefinition((XSDSimpleTypeDefinition)typeTable.getXSDTypeDef(
typeTable.getSimpleSchemaTypeName("URI").getNamespaceURI(),
typeTable.getSimpleSchemaTypeName("URI").getLocalPart()));
}
if ( aProperty.getDefault() != null )
{
attribute.setConstraint(XSDConstraint.DEFAULT_LITERAL);
attribute.setLexicalValue(aProperty.getDefault().toString());
}
addAnnotations(attribute, aProperty );
if ( !aProperty.getType().isDataType() )
{
String value = prefix + COLON + attributeSchemaType.getLocalPart();
attribute.getElement().setAttribute(PROPERTY_TYPE, value);
}
return attributeSchemaType;
}