int anyIndex = fDeferredDocumentImpl.createElement(fStringPool.addSymbol("any"), null, -1);
fDeferredDocumentImpl.insertBefore(typeIndex, anyIndex, getFirstChildElement(typeIndex));
break;
}
case XMLElementDecl.TYPE_MIXED: {
XMLContentSpec contentSpec = new XMLContentSpec();
contentSpecProvider.getContentSpec(contentSpecIndex, contentSpec);
contentSpecIndex = contentSpec.value;
if (contentSpecIndex == -1) {
int attributeIndex = fDeferredDocumentImpl.createAttribute(fStringPool.addSymbol("type"), fStringPool.addString("string"), true);
fDeferredDocumentImpl.setAttributeNode(elementIndex, attributeIndex);
}
else {
if (typeIndex == -1) {
typeIndex = fDeferredDocumentImpl.createElement(fStringPool.addSymbol("complexType"), null, -1);
// REVISIT: Check for type redeclaration? -Ac
fDeferredDocumentImpl.insertBefore(elementIndex, typeIndex, getFirstChildElement(elementIndex));
}
int attributeIndex = fDeferredDocumentImpl.createAttribute(fStringPool.addSymbol("content"), fStringPool.addString("mixed"), true);
fDeferredDocumentImpl.setAttributeNode(typeIndex, attributeIndex);
int handle = fAttrList.startAttrList();
fAttrList.addAttr(
fStringPool.addSymbol("minOccurs"),
fStringPool.addString("0"),
fStringPool.addSymbol("NMTOKEN"),
true,
false); // search
fAttrList.addAttr(
fStringPool.addSymbol("maxOccurs"),
fStringPool.addString("unbounded"),
fStringPool.addSymbol("CDATA"),
true,
false); // search
fAttrList.endAttrList();
int choiceIndex = fDeferredDocumentImpl.createElement(fStringPool.addSymbol("choice"), fAttrList, handle);
fDeferredDocumentImpl.appendChild(typeIndex, choiceIndex);
while (contentSpecIndex != -1) {
// get node
contentSpecProvider.getContentSpec(contentSpecIndex, contentSpec);
int type = contentSpec.type;
int left = contentSpec.value;
int right = contentSpec.otherValue;
// if leaf, skip "#PCDATA" and stop
if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) {
break;
}
// add right hand leaf
contentSpecProvider.getContentSpec(right, contentSpec);
handle = fAttrList.startAttrList();
fAttrList.addAttr(
fStringPool.addSymbol("ref"),
fStringPool.addString(fStringPool.toString(contentSpec.value)),
fStringPool.addSymbol("NMTOKEN"),
true,
false); //search
fAttrList.endAttrList();
int rightIndex = fDeferredDocumentImpl.createElement(fStringPool.addSymbol("element"), fAttrList, handle);
int refIndex = getFirstChildElement(choiceIndex);
fDeferredDocumentImpl.insertBefore(choiceIndex, rightIndex, refIndex);
// go to next node
contentSpecIndex = left;
}
}
break;
}
case XMLElementDecl.TYPE_CHILDREN: {
int attributeIndex = fDeferredDocumentImpl.createAttribute(fStringPool.addSymbol("content"), fStringPool.addString("elementOnly"), true);
fDeferredDocumentImpl.setAttributeNode(typeIndex, attributeIndex);
int children = createChildren(contentSpecProvider,
contentSpecIndex,
new XMLContentSpec(),
fDeferredDocumentImpl,
-1);
fDeferredDocumentImpl.insertBefore(typeIndex, children, getFirstChildElement(typeIndex));
break;
}
}
} // if defer-node-expansion
else if (fDocumentImpl != null) {
//
// Build element
//
// get element declaration; create if necessary
Element schema = XUtil.getLastChildElement(fDocumentType, "schema");
String elementName = fStringPool.toString(elementDecl.rawname);
Element element = XUtil.getLastChildElement(schema, "element", "name", elementName);
if (element == null) {
element = fDocumentImpl.createElement("element");
element.setAttribute("name", elementName);
element.setAttribute("minOccurs", "1");
((AttrImpl)element.getAttributeNode("minOccurs")).setSpecified(false);
element.setAttribute("nullable", "false");
((AttrImpl)element.getAttributeNode("nullable")).setSpecified(false);
element.setAttribute("abstract", "false");
((AttrImpl)element.getAttributeNode("abstract")).setSpecified(false);
element.setAttribute("final", "false");
((AttrImpl)element.getAttributeNode("final")).setSpecified(false);
schema.appendChild(element);
}
//
// Build content model
//
// get type element; create if necessary
Element type = XUtil.getLastChildElement(element, "complexType");
if (type == null && contentSpecType != XMLElementDecl.TYPE_MIXED) {
type = fDocumentImpl.createElement("complexType");
// REVISIT: Check for type redeclaration? -Ac
element.insertBefore(type, XUtil.getFirstChildElement(element));
}
// create models
switch (contentSpecType) {
case XMLElementDecl.TYPE_EMPTY: {
type.setAttribute("content", "empty");
break;
}
case XMLElementDecl.TYPE_ANY: {
Element any = fDocumentImpl.createElement("any");
type.insertBefore(any, XUtil.getFirstChildElement(type));
break;
}
case XMLElementDecl.TYPE_MIXED: {
XMLContentSpec contentSpec = new XMLContentSpec();
contentSpecProvider.getContentSpec(contentSpecIndex, contentSpec);
contentSpecIndex = contentSpec.value;
if (contentSpecIndex == -1) {
element.setAttribute("type", "string");
}
else {
if (type == null) {
type = fDocumentImpl.createElement("complexType");
// REVISIT: Check for type redeclaration? -Ac
element.insertBefore(type, XUtil.getFirstChildElement(element));
}
type.setAttribute("content", "mixed");
Element choice = fDocumentImpl.createElement("choice");
choice.setAttribute("minOccurs", "0");
choice.setAttribute("maxOccurs", "unbounded");
type.appendChild(choice);
while (contentSpecIndex != -1) {
// get node
contentSpecProvider.getContentSpec(contentSpecIndex, contentSpec);
int cstype = contentSpec.type;
int csleft = contentSpec.value;
int csright = contentSpec.otherValue;
// if leaf, skip "#PCDATA" and stop
if (cstype == XMLContentSpec.CONTENTSPECNODE_LEAF) {
break;
}
// add right hand leaf
contentSpecProvider.getContentSpec(csright, contentSpec);
Element right = fDocumentImpl.createElement("element");
right.setAttribute("ref", fStringPool.toString(contentSpec.value));
Element ref = XUtil.getFirstChildElement(choice);
choice.insertBefore(right, ref);
// go to next node
contentSpecIndex = csleft;
}
}
break;
}
case XMLElementDecl.TYPE_CHILDREN: {
type.setAttribute("content", "elementOnly");
Element children = createChildren(contentSpecProvider,
contentSpecIndex,
new XMLContentSpec(),
fDocumentImpl,
null);
type.insertBefore(children, XUtil.getFirstChildElement(type));
break;
}