/**
* If the specified node represents a 'normal' non-enumeration simpleType,
* the QName of the simpleType base is returned.
*/
public static QName getSimpleTypeBase(Node node, SymbolTable symbolTable) {
QName baseQName = null;
if (node == null) {
return null;
}
// If the node kind is an element, dive into it.
QName nodeKind = Utils.getNodeQName(node);
if (nodeKind != null &&
nodeKind.getLocalPart().equals("element") &&
Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
NodeList children = node.getChildNodes();
Node simpleNode = null;
for (int j = 0; j < children.getLength() && simpleNode == null; j++) {
QName simpleKind = Utils.getNodeQName(children.item(j));
if (simpleKind != null &&
simpleKind.getLocalPart().equals("simpleType") &&
Constants.isSchemaXSD(simpleKind.getNamespaceURI())) {
simpleNode = children.item(j);
node = simpleNode;
}
}
}
// Get the node kind, expecting a schema simpleType
nodeKind = Utils.getNodeQName(node);
if (nodeKind != null &&
nodeKind.getLocalPart().equals("simpleType") &&
Constants.isSchemaXSD(nodeKind.getNamespaceURI())) {
// Under the simpleType there should be a restriction.
// (There may be other #text nodes, which we will ignore).
NodeList children = node.getChildNodes();
Node restrictionNode = null;
for (int j = 0; j < children.getLength() && restrictionNode == null; j++) {
QName restrictionKind = Utils.getNodeQName(children.item(j));
if (restrictionKind != null &&
restrictionKind.getLocalPart().equals("restriction") &&
Constants.isSchemaXSD(restrictionKind.getNamespaceURI()))
restrictionNode = children.item(j);
}
// The restriction node indicates the type being restricted
// (the base attribute contains this type).
if (restrictionNode != null) {
baseQName = Utils.getNodeTypeRefQName(restrictionNode, "base");
}
// Look for enumeration elements underneath the restriction node
if (baseQName != null && restrictionNode != null) {
NodeList enums = restrictionNode.getChildNodes();
for (int i=0; i < enums.getLength(); i++) {
QName enumKind = Utils.getNodeQName(enums.item(i));
if (enumKind != null &&
enumKind.getLocalPart().equals("enumeration") &&
Constants.isSchemaXSD(enumKind.getNamespaceURI())) {
// Found an enumeration, this isn't a
// 'normal' simple type.
return null;
}