int attributeIndex = fDeferredDocumentImpl.createAttribute(fStringPool.addSymbol("content"), fStringPool.addString("elemOnly"), false);
fDeferredDocumentImpl.setAttributeNode(archetypeIndex, attributeIndex);
attributeIndex = fDeferredDocumentImpl.createAttribute(fStringPool.addSymbol("order"), fStringPool.addString("seq"), false);
fDeferredDocumentImpl.setAttributeNode(archetypeIndex, attributeIndex);
XMLContentSpecNode node = new XMLContentSpecNode();
int contentSpecIndex = contentSpec.getHandle();
contentSpec.getNode(contentSpecIndex, node);
Element model = createContentModel(contentSpec, node);
int modelIndex = createDeferredContentModel(model);
int firstChildIndex = getFirstChildElement(archetypeIndex);
fDeferredDocumentImpl.insertBefore(archetypeIndex, modelIndex, firstChildIndex);
}
else {
// REVISIT: Any chance of getting other than MIXED? -Ac
int attributeIndex = fDeferredDocumentImpl.createAttribute(fStringPool.addSymbol("content"), fStringPool.addString("mixed"), true);
fDeferredDocumentImpl.setAttributeNode(archetypeIndex, attributeIndex);
XMLContentSpecNode node = new XMLContentSpecNode();
int index = contentSpec.getHandle();
contentSpec.getNode(index, node);
if (node.type != 0) {
// skip '*' node
contentSpec.getNode(node.value, node);
// add leaves (on descent)
do {
index = node.value;
int handle = fAttrList.startAttrList();
contentSpec.getNode(node.otherValue, node);
String elementRefName = fStringPool.toString(node.value);
fAttrList.addAttr(
fStringPool.addSymbol("ref"),
fStringPool.addString(elementRefName),
fStringPool.addSymbol("NMTOKEN"),
true,
false); // search
fAttrList.endAttrList();
int elementRefIndex = fDeferredDocumentImpl.createElement(fStringPool.addSymbol("element"), fAttrList, handle);
fDeferredDocumentImpl.insertBefore(archetypeIndex, elementRefIndex, getFirstChildElement(archetypeIndex, "element"));
contentSpec.getNode(index, node);
} while (node.type != XMLContentSpecNode.CONTENTSPECNODE_LEAF);
}
}
} // if defer-node-expansion
else if (fDocumentImpl != null) {
// get element declaration; create if necessary
Element schema = XUtil.getFirstChildElement(fDocumentType, "schema");
String elementName = fStringPool.toString(elementTypeIndex);
Element element = XUtil.getFirstChildElement(schema, "element", "name", elementName);
if (element == null) {
element = fDocument.createElement("element");
element.setAttribute("name", elementName);
element.setAttribute("export", "true");
((AttrImpl)element.getAttributeNode("export")).setSpecified(false);
schema.appendChild(element);
}
// get archetype element; create if necessary
Element archetype = XUtil.getFirstChildElement(element, "archetype");
if (archetype == null) {
archetype = fDocument.createElement("archetype");
// REVISIT: Check for archetype redeclaration? -Ac
element.insertBefore(archetype, XUtil.getFirstChildElement(element));
}
// build content model
int contentType = contentSpec.getType();
String contentTypeName = fStringPool.toString(contentType);
if (contentTypeName.equals("EMPTY")) {
archetype.setAttribute("content", "empty");
}
else if (contentTypeName.equals("ANY")) {
archetype.setAttribute("content", "any");
}
else if (contentTypeName.equals("CHILDREN")) {
// build content model
archetype.setAttribute("content", "elemOnly");
((AttrImpl)archetype.getAttributeNode("content")).setSpecified(false);
archetype.setAttribute("order", "seq");
((AttrImpl)archetype.getAttributeNode("order")).setSpecified(false);
XMLContentSpecNode node = new XMLContentSpecNode();
int handle = contentSpec.getHandle();
contentSpec.getNode(handle, node);
Element model = createContentModel(contentSpec, node);
Element firstChild = XUtil.getFirstChildElement(archetype);
archetype.insertBefore(model, firstChild);
}
else {
// REVISIT: Any chance of getting other than MIXED? -Ac
archetype.setAttribute("content", "mixed");
XMLContentSpecNode node = new XMLContentSpecNode();
int handle = contentSpec.getHandle();
contentSpec.getNode(handle, node);
if (node.type != 0) {
// skip '*' node