use of com.sun.xml.xsom.XSListSimpleType in project schema2proto by entur.
the class SchemaParser method findFieldType.
public String findFieldType(XSType type) {
String typeName = type.getName();
if (typeName == null) {
if (type.asSimpleType().isRestriction()) {
try {
return findFieldType(type.asSimpleType().asRestriction().getBaseType());
} catch (ClassCastException e) {
LOGGER.warn("Error getting base type for restriction {}. Appears to be a bug in xsom. Fallback to string field type (best guess)", type);
return DEFAULT_PROTO_PRIMITIVE;
}
} else if (type.asSimpleType().isPrimitive()) {
typeName = type.asSimpleType().getName();
} else if (type.asSimpleType().isList()) {
XSListSimpleType asList = type.asSimpleType().asList();
XSSimpleType itemType = asList.getItemType();
typeName = itemType.getName();
} else if (type.asSimpleType().isUnion()) {
// Union always resolves to string
typeName = DEFAULT_PROTO_PRIMITIVE;
} else {
typeName = type.asSimpleType().getBaseType().getName();
}
} else {
if (type.isSimpleType() && type.asSimpleType().isList()) {
typeName = processSimpleType(type.asSimpleType().getBaseListType(), null);
} else if (!basicTypes.contains(typeName)) {
typeName = type.asSimpleType().getBaseType().getName();
}
}
if ((typeName == null || !basicTypes.contains(typeName)) && type.isSimpleType() && type.asSimpleType().isRestriction()) {
XSType restrictionBase = type.asSimpleType().asRestriction().getBaseType();
return findFieldType(restrictionBase);
}
return typeName;
}
Aggregations