* that represents a complexType, simpleType or element (for ref=).
*/
private void createTypeFromDef(Node node, boolean isElement,
boolean belowSchemaLevel) throws IOException {
// Get the QName of the node's name attribute value
QName qName = Utils.getNodeNameQName(node);
if (qName != null) {
// If the qname is already registered as a base type,
// don't create a defining type/element.
if (!isElement && btm.getBaseName(qName)!=null) {
return;
}
// If the node has a type or ref attribute, get the
// qname representing the type
BooleanHolder forElement = new BooleanHolder();
QName refQName = Utils.getNodeTypeRefQName(node, forElement);
if (refQName != null) {
// Now get the TypeEntry
TypeEntry refType = getTypeEntry(refQName, forElement.value);
if (!belowSchemaLevel) {
symbolTablePut(new DefinedElement(qName, refType, node, ""));
}
}
else {
// Flow to here indicates no type= or ref= attribute.
// See if this is an array or simple type definition.
IntHolder numDims = new IntHolder();
numDims.value = 0;
QName arrayEQName = SchemaUtils.getArrayElementQName(node, numDims);
if (arrayEQName != null) {
// Get the TypeEntry for the array element type
refQName = arrayEQName;
TypeEntry refType = getTypeEntry(refQName, false);
if (refType == null) {
// Not defined yet, add one
String baseName = btm.getBaseName(refQName);
if (baseName != null)
refType = new BaseType(refQName);
else
refType = new UndefinedType(refQName);
symbolTablePut(refType);
}
// Create a defined type or element that references refType
String dims = "";
while (numDims.value > 0) {
dims += "[]";
numDims.value--;
}
TypeEntry defType = null;
if (isElement) {
if (!belowSchemaLevel) {
defType = new DefinedElement(qName, refType, node, dims);
}
} else {
defType = new DefinedType(qName, refType, node, dims);
}
if (defType != null) {
symbolTablePut(defType);
}
}
else {
// Create a TypeEntry representing this type/element
String baseName = btm.getBaseName(qName);
if (baseName != null) {
symbolTablePut(new BaseType(qName));
}
else {
// Create a type entry, set whether it should
// be mapped as a simple type, and put it in the
// symbol table.
TypeEntry te = null;
if (!isElement) {
te = new DefinedType(qName, node);
// check if we are an anonymous type underneath
// an element. If so, we point the refType of the
// element to us (the real type).
if (qName.getLocalPart().indexOf(ANON_TOKEN) >= 0 ) {
Node parent = node.getParentNode();
QName parentQName = Utils.getNodeNameQName(parent);
TypeEntry parentType = getElement(parentQName);
if (parentType != null) {
parentType.setRefType(te);
}
}