private SimpleTypeSGChain newSimpleTypeSG(TypeSG pController, SGFactory pFactory,
SchemaSG pSchema, XSType pType) throws SAXException {
if (!pType.isSimple()) {
throw new IllegalStateException("Expected a simple type");
}
XSSimpleType simpleType = pType.getSimpleType();
if (simpleType.isAtomic()) {
if (pType.isGlobal()) {
XsQName myName = pType.getName();
if (myName.equals(XSEntity.getInstance().getName()) ||
myName.equals(XSNotation.getInstance().getName()) ||
myName.equals(XSGYearMonth.getInstance().getName()) ||
myName.equals(XSGYear.getInstance().getName()) ||
myName.equals(XSGMonthDay.getInstance().getName()) ||
myName.equals(XSGMonth.getInstance().getName()) ||
myName.equals(XSGDay.getInstance().getName())) {
throw new SAXException("The type " + myName + " is not supported.");
} else if (myName.equals(XSIDREF.getInstance().getName())) {
return new IDREFSG(pFactory, pSchema, pType);
} else if (myName.equals(XSID.getInstance().getName())) {
return new IDSG(pFactory, pSchema, pType);
} else if (myName.equals(XSByte.getInstance().getName())) {
return new ByteSG(pFactory, pSchema, pType);
} else if (myName.equals(XSShort.getInstance().getName())) {
return new ShortSG(pFactory, pSchema, pType);
} else if (myName.equals(XSInt.getInstance().getName())) {
return new IntSG(pFactory, pSchema, pType);
} else if (myName.equals(XSLong.getInstance().getName())) {
return new LongSG(pFactory, pSchema, pType);
} else if (myName.equals(XSUnsignedByte.getInstance().getName()) ||
myName.equals(XSUnsignedShort.getInstance().getName())) {
return new UnsignedShortSG(pFactory, pSchema, pType);
} else if (myName.equals(XSUnsignedInt.getInstance().getName())) {
return new UnsignedIntSG(pFactory, pSchema, pType);
} else if (myName.equals(XSInteger.getInstance().getName()) ||
myName.equals(XSNonPositiveInteger.getInstance().getName()) ||
myName.equals(XSNegativeInteger.getInstance().getName()) ||
myName.equals(XSUnsignedLong.getInstance().getName()) ||
myName.equals(XSPositiveInteger.getInstance().getName()) ||
myName.equals(XSNonNegativeInteger.getInstance().getName())) {
return new IntegerSG(pFactory, pSchema, pType);
} else if (myName.equals(XSDecimal.getInstance().getName())) {
return new DecimalSG(pFactory, pSchema, pType);
} else if (myName.equals(XSQName.getInstance().getName())) {
return new QNameSG(pFactory, pSchema, pType);
} else if (myName.equals(XSDouble.getInstance().getName())) {
return new DoubleSG(pFactory, pSchema, pType);
} else if (myName.equals(XSFloat.getInstance().getName())) {
return new FloatSG(pFactory, pSchema, pType);
} else if (myName.equals(XSHexBinary.getInstance().getName())) {
return new HexBinarySG(pFactory, pSchema, pType);
} else if (myName.equals(XSBase64Binary.getInstance().getName())) {
return new Base64BinarySG(pFactory, pSchema, pType);
} else if (myName.equals(XSBoolean.getInstance().getName())) {
return new BooleanSG(pFactory, pSchema, pType);
} else if (myName.equals(XSDate.getInstance().getName())) {
return new DateSG(pFactory, pSchema, pType);
} else if (myName.equals(XSDateTime.getInstance().getName())) {
return new DateTimeSG(pFactory, pSchema, pType);
} else if (myName.equals(XSTime.getInstance().getName())) {
return new TimeSG(pFactory, pSchema, pType);
} else if (myName.equals(XSDuration.getInstance().getName())) {
return new DurationSG(pFactory, pSchema, pType);
} else if (myName.equals(XSAnySimpleType.getInstance().getName()) ||
myName.equals(XSString.getInstance().getName()) ||
myName.equals(XSAnyURI.getInstance().getName()) ||
myName.equals(XSNormalizedString.getInstance().getName()) ||
myName.equals(XSToken.getInstance().getName()) ||
myName.equals(XSLanguage.getInstance().getName()) ||
myName.equals(XSName.getInstance().getName()) ||
myName.equals(XSNMToken.getInstance().getName()) ||
myName.equals(XSNCName.getInstance().getName())) {
return new StringSG(pFactory, pSchema, pType);
}
}
SimpleTypeSGChain result = newSimpleTypeSG(pController, pFactory, pSchema, simpleType.getRestrictedType());
result = new SimpleTypeRestrictionSG(result, pType, simpleType);
if (simpleType.getEnumerations().length > 0) {
boolean generateTypesafeEnumClass = false;
String className = null;
String packageName = null;
if (simpleType instanceof JAXBSimpleType) {
JAXBSimpleType jaxbSimpleType = (JAXBSimpleType) simpleType;
JAXBTypesafeEnumClass jaxbTypesafeEnumClass = jaxbSimpleType.getJAXBTypesafeEnumClass();
if (jaxbTypesafeEnumClass != null) {
generateTypesafeEnumClass = true;
className = jaxbTypesafeEnumClass.getName();
}
}
if (!generateTypesafeEnumClass) {
XSEnumeration[] enumerations = simpleType.getEnumerations();
for (int i = 0; i < enumerations.length; i++) {
XSEnumeration enumeration = enumerations[i];
if (enumeration instanceof JAXBEnumeration) {
JAXBEnumeration jaxbEnumeration = (JAXBEnumeration) enumeration;
if (jaxbEnumeration.getJAXBTypesafeEnumMember() != null) {
generateTypesafeEnumClass = true;
break;
}
}
}
}
if (!generateTypesafeEnumClass && pType.isGlobal()) {
XsQName[] qNames = new XsQName[]{XSNMToken.getInstance().getName()};
XSSchema xsSchema = xsType.getXSSchema();
if (xsSchema instanceof JAXBSchema) {
JAXBSchema jaxbSchema = (JAXBSchema) xsSchema;
JAXBGlobalBindings globalBindings = jaxbSchema.getJAXBGlobalBindings();
if (globalBindings != null) {
qNames = globalBindings.getTypesafeEnumBase();
}
}
for (XSType restrType = xsType; !generateTypesafeEnumClass; ) {
restrType = restrType.getSimpleType().getRestrictedType();
if (restrType.isGlobal()) {
for (int i = 0; i < qNames.length; i++) {
if (qNames[i].equals(restrType.getName())) {
generateTypesafeEnumClass = true;
break;
}
}
if (XSAnySimpleType.getInstance().getName().equals(restrType.getName())) {
break;
}
}
}
}
JAXBSchemaBindings jaxbSchemaBindings;
if (xsType instanceof JAXBType) {
jaxbSchemaBindings = ((JAXBType) xsType).getJAXBSchemaBindings();
} else {
jaxbSchemaBindings = null;
}
packageName = AbstractContext.getPackageName(pSchema, jaxbSchemaBindings,
pController.getLocator(),
pController.getName());
if (generateTypesafeEnumClass) {
if (className == null) {
XsQName qName = pType.isGlobal() ? pType.getName() : pController.getName();
className = AbstractContext.getClassNameFromLocalName(pController.getLocator(),
qName.getLocalName(),
pSchema) + "Class";
}
result = new EnumerationSG(result, JavaQNameImpl.getInstance(packageName, className), pType);
}
}
return result;
} else if (simpleType.isList()) {
return new ListTypeSGImpl(pFactory, pSchema, pType, classContext, pController.getName());
} else if (simpleType.isUnion()) {
return new UnionTypeSGImpl(pFactory, pSchema, pType, classContext, pController.getName());
} else {
throw new IllegalStateException("Simple type " + pType + " is neither of atomic, list, or union");
}
}