in xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java [1029:1115]
Element serializeElement(Document doc, XmlSchemaElement elementObj, XmlSchema schema)
throws XmlSchemaSerializerException {
Element serializedEl = createNewElement(doc, "element", schema.getSchemaNamespacePrefix(),
XmlSchema.SCHEMA_NS);
if (elementObj.getRef().getTargetQName() != null) {
String resolvedName = resolveQName(elementObj.getRef().getTargetQName(), schema);
serializedEl.setAttributeNS(null, "ref", resolvedName);
} else if (!elementObj.isAnonymous()) {
serializedEl.setAttributeNS(null, "name", elementObj.getName());
}
if (elementObj.isAbstractElement()) {
serializedEl.setAttributeNS(null, "abstract", "true");
}
if (elementObj.getBlock() != null && elementObj.getBlock() != XmlSchemaDerivationMethod.NONE) {
serializedEl.setAttributeNS(null, "block", elementObj.getBlock().toString());
}
if (elementObj.getDefaultValue() != null) {
serializedEl.setAttributeNS(null, "default", elementObj.getDefaultValue());
}
if (elementObj.getFinalDerivation() != null
&& elementObj.getFinalDerivation() != XmlSchemaDerivationMethod.NONE) {
serializedEl.setAttributeNS(null, "final", elementObj.getFinalDerivation().toString());
}
if (elementObj.getFixedValue() != null) {
serializedEl.setAttributeNS(null, "fixed", elementObj.getFixedValue());
}
if (elementObj.isFormSpecified()) {
serializedEl.setAttributeNS(null, "form", elementObj.getForm().toString());
}
if (elementObj.getId() != null) {
serializedEl.setAttributeNS(null, "id", elementObj.getId());
}
serializeMaxMinOccurs(elementObj, serializedEl);
if (elementObj.getSubstitutionGroup() != null) {
String resolvedQName = resolveQName(elementObj.getSubstitutionGroup(), schema);
serializedEl.setAttributeNS(null, "substitutionGroup", resolvedQName);
}
if (elementObj.getSchemaTypeName() != null) {
String resolvedName = resolveQName(elementObj.getSchemaTypeName(), schema);
serializedEl.setAttributeNS(null, "type", resolvedName);
}
if (elementObj.getAnnotation() != null) {
Element annotationEl = serializeAnnotation(doc, elementObj.getAnnotation(), schema);
serializedEl.appendChild(annotationEl);
}
if (elementObj.getSchemaType() != null && elementObj.getSchemaTypeName() == null) {
if (elementObj.getSchemaType() instanceof XmlSchemaComplexType) {
Element complexType =
serializeComplexType(doc,
(XmlSchemaComplexType)elementObj.getSchemaType(),
schema);
serializedEl.appendChild(complexType);
} else if (elementObj.getSchemaType() instanceof XmlSchemaSimpleType) {
Element simpleType = serializeSimpleType(doc, (XmlSchemaSimpleType)elementObj.getSchemaType(),
schema);
serializedEl.appendChild(simpleType);
}
}
if (elementObj.getConstraints().size() > 0) {
for (int i = 0; i < elementObj.getConstraints().size(); i++) {
Element constraint = serializeIdentityConstraint(
doc,
(XmlSchemaIdentityConstraint)
elementObj.getConstraints()
.get(i), schema);
serializedEl.appendChild(constraint);
}
}
if (elementObj.isNillable()) {
serializedEl.setAttributeNS(null, "nillable", "true");
}
// process extension
processExtensibilityComponents(elementObj, serializedEl);
return serializedEl;
}