String targetNamespacePrefix = (String) targetNamespacePrefixMap.get(targetNameSpace);
schemaTypeName = new QName(targetNameSpace, simpleName, targetNamespacePrefix);
if (dataType instanceof EnumType) {
XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(xmlSchema, false);
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
restriction.setBaseTypeName(typeTable.getSimpleSchemaTypeName("java.lang.String"));
simpleType.setContent(restriction);
simpleType.setName(simpleName);
List<XmlSchemaFacet> facets = restriction.getFacets();
EnumType enumType = (EnumType) dataType;
List enumMembers = enumType.getEnumMembers();
for (int i = 0; i < enumMembers.size(); i++) {
facets.add(new XmlSchemaEnumerationFacet(enumMembers.get(i), false));
}
XmlSchemaElement eltOuter = new XmlSchemaElement(xmlSchema, false);
eltOuter.setName(simpleName);
eltOuter.setSchemaTypeName(schemaTypeName);
xmlSchema.getItems().add(eltOuter);
xmlSchema.getElements().put(schemaTypeName, eltOuter);
eltOuter.setSchemaTypeName(simpleType.getQName());
xmlSchema.getItems().add(simpleType);
xmlSchema.getSchemaTypes().put(schemaTypeName, simpleType);
// adding this type to the table
typeTable.addComplexSchema(name, eltOuter.getQName());
} else if (dataType instanceof UnionType) {
XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema, false);
XmlSchemaChoice choice = new XmlSchemaChoice();
List<XmlSchemaObject> items = choice.getItems();
UnionType unionType = (UnionType) dataType;
Member[] members = unionType.getMembers();
for (int i = 0; i < members.length; i++) {
items.add(generateSchemaforFieldsandProperties(xmlSchema, members[i].getDataType(),
members[i].getName(), true));
}
complexType.setParticle(choice);
complexType.setName(simpleName);
XmlSchemaElement eltOuter = new XmlSchemaElement(xmlSchema, false);
eltOuter.setName(simpleName);
eltOuter.setSchemaTypeName(schemaTypeName);
xmlSchema.getItems().add(eltOuter);
xmlSchema.getElements().put(schemaTypeName, eltOuter);
eltOuter.setSchemaTypeName(complexType.getQName());
xmlSchema.getItems().add(complexType);
xmlSchema.getSchemaTypes().put(schemaTypeName, complexType);
typeTable.addComplexSchema(name, eltOuter.getQName());
} else {
if (dataType instanceof Typedef) {
Typedef typedef = (Typedef) dataType;
DataType aliasType = typedef.getDataType();
if (aliasType instanceof FixedType) {
XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType(xmlSchema, false);
XmlSchemaElement eltOuter = new XmlSchemaElement(xmlSchema, false);
eltOuter.setName(simpleName);
eltOuter.setSchemaTypeName(schemaTypeName);
simpleType.setName(simpleName);
xmlSchema.getItems().add(eltOuter);
xmlSchema.getElements().put(schemaTypeName, eltOuter);
eltOuter.setSchemaTypeName(simpleType.getQName());
xmlSchema.getItems().add(simpleType);
xmlSchema.getSchemaTypes().put(schemaTypeName, simpleType);
typeTable.addComplexSchema(name, eltOuter.getQName());
XmlSchemaElement elt1 = new XmlSchemaElement(xmlSchema, false);
elt1.setName(name);
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
restriction.setBaseTypeName(typeTable.getSimpleSchemaTypeName(BigDecimal.class.getName()));
FixedType fixedType = (FixedType) aliasType;
XmlSchemaTotalDigitsFacet totalDigits = new XmlSchemaTotalDigitsFacet(fixedType.getDigits(), false);
restriction.getFacets().add(totalDigits);
XmlSchemaFractionDigitsFacet fractionDigits = new XmlSchemaFractionDigitsFacet(fixedType.getScale(), true);
restriction.getFacets().add(fractionDigits);
simpleType.setContent(restriction);
} else {
XmlSchemaComplexType complexType = new XmlSchemaComplexType(xmlSchema, false);
XmlSchemaSequence sequence = new XmlSchemaSequence();