ElementDecl schemaElement = new ElementDecl(schema, name);
// start converting content of the element
ComplexType complexType = schema.createComplexType();
ContentType contentType = null;
Group group = null; // auxiliary
Iterator mixedChildrenIterator = null; // auxiliary
String elementRef = null; // auxiliary
ElementDecl elem = null; // auxiliary
if (dtdElement.isEmptyContent()) {
// mixed="false"
contentType = ContentType.elemOnly;
//-- mixed="false"
} else if (dtdElement.isAnyContent()) {
// mixed="true"
contentType = ContentType.mixed;
//-- mixed="true"
group = new Group();
group.setOrder(Order.sequence);
group.setMinOccurs(0);
group.setMaxOccurs(-1);
Wildcard any = new Wildcard(group);
group.addWildcard(any);
complexType.addGroup(group);
} else if (dtdElement.isElemOnlyContent()) {
// mixed="false"
contentType = ContentType.elemOnly;
//-- mixed="false"
ContentParticle dtdContent = dtdElement.getContent();
if (dtdContent == null) { // content is not specified
String err = "DTD to Schema converter: element \"" + dtdElement.getName();
err += "\" has no content.";
throw new DTDException(err);
}
Particle content = null;
try {
content = convertContentParticle(dtdContent, schema);
}
catch (DTDException e) {
String err = "DTD to Schema converter: content of DTD element \"" + dtdElement.getName();
err += "\", represented by a Content Particle, is malformed.";
throw new DTDException(err);
}
if (content instanceof ElementDecl) {
group = new Group();
group.setOrder(Order.sequence);
group.addElementDecl((ElementDecl)content);
complexType.addGroup(group);
} else {
complexType.addGroup((Group)content);
}
} else if (dtdElement.isMixedContent()) {
// mixed="true"
contentType = ContentType.mixed;
//-- mixed="true"
mixedChildrenIterator = dtdElement.getMixedContentChildren();
if ((mixedChildrenIterator != null) && (mixedChildrenIterator.hasNext())) {
group = new Group();
group.setOrder(Order.choice);
group.setMinOccurs(0);
group.setMaxOccurs(-1);
while (mixedChildrenIterator.hasNext()) {
elementRef = (String)mixedChildrenIterator.next();
elem = new ElementDecl(schema);
elem.setReferenceName(elementRef);
group.addElementDecl(elem);
}
complexType.addGroup(group);
}
} else { // the type of the element has not been specified