String localName = getDefaultRootElementAsQName(desc, table.getName()).getLocalPart();
// don't overwrite existing top level elements
if (workingSchema.getTopLevelElements().get(localName) != null) {
continue;
}
Element topLevelElement = new Element();
topLevelElement.setName(localName);
QName qname = schemaRef.getSchemaContextAsQName(workingSchema.getNamespaceResolver());
String elementType = qname.getLocalPart();
String elementTypeUri = qname.getNamespaceURI();
String elementTypePrefix = workingSchema.getNamespaceResolver().resolveNamespaceURI(elementTypeUri);
if (elementTypePrefix != null) {
elementType = elementTypePrefix + XMLConstants.COLON + elementType;
}
topLevelElement.setType(elementType);
workingSchema.addTopLevelElement(topLevelElement);
}
} else {
// here we have a descriptor that does not have a schema reference set, but since
// there is a default root element set we need to generate a global element
for (DatabaseTable table : desc.getTables()) {
String localName = getDefaultRootElementAsQName(desc, table.getName()).getLocalPart();
// a global element may have been created while generating an element ref
if (workingSchema.getTopLevelElements().get(localName) == null) {
Element topLevelElement = new Element();
topLevelElement.setName(localName);
if (simple) {
if (isComplexTypeWithSimpleContentRequired(desc)) {
topLevelElement.setComplexType(buildComplexTypeWithSimpleContent(desc, schemaForNamespace, workingSchema, properties, descriptors));
} else {
topLevelElement.setSimpleType(buildSimpleType(desc, workingSchema, false));
}
} else {
topLevelElement.setComplexType(buildComplexType(true, desc, schemaForNamespace, workingSchema, properties, descriptors));
}
workingSchema.addTopLevelElement(topLevelElement);
}
}
}