SchemaSG pSchema, XSType pType) throws SAXException {
if (!pType.isSimple()) {
throw new IllegalStateException("Expected a simple type");
}
JAXBJavaType javaType = findJavaType(pSchema, pType);
SimpleTypeSGChain result;
if (javaType == null || javaType.getName() == null) {
XSSimpleType simpleType = pType.getSimpleType();
JavaQName runtimeType;
if (simpleType.isAtomic()) {
result = newGlobalAtomicTypeSG(pFactory, pSchema, pType);
if (result == null) {
if (!simpleType.isRestriction()) {
throw new SAXParseException("Atomic type must be either a builtin or a restriction of another atomic type",
pType.getLocator());
}
TypeSG type = pSchema.getType(simpleType.getRestrictedType().getName());
runtimeType = type.getSimpleTypeSG().getRuntimeType();
result = newAtomicTypeRestriction(pController, pFactory, pSchema, pType);
} else {
SimpleTypeSG simpleTypeSG = new SimpleTypeSGImpl(result);
simpleTypeSG.init();
runtimeType = simpleTypeSG.getRuntimeType();
}
if (javaType == null) {
JAXBJavaType[] globalJavaTypes = pSchema.getJAXBJavaTypes();
for (int i = 0; i < globalJavaTypes.length; i++) {
if (runtimeType.equals(globalJavaTypes[i].getName())) {
javaType = globalJavaTypes[i];
break;
}
}
}
} else if (simpleType.isList()) {
result = new ListTypeSGImpl(pFactory, pSchema, pType, classContext, pController.getName());
} else if (simpleType.isUnion()) {
result = new UnionTypeSGImpl(pFactory, pSchema, pType, classContext, pController.getName());
} else {
throw new IllegalStateException("Simple type " + pType + " is neither of atomic, list, or union");
}
} else {
result = newSimpleTypeSGByJavaType(javaType, pFactory, pSchema, pType);
}
if (javaType != null &&
(javaType.getParseMethod() != null || javaType.getPrintMethod() != null)) {
result = new ParsePrintSG(result, javaType);
}
return result;
}