Element serializeComplexContentRestriction()

in xmlschema-core/src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java [795:855]


    Element serializeComplexContentRestriction(Document doc,
                                               XmlSchemaComplexContentRestriction restrictionObj,
                                               XmlSchema schema) throws XmlSchemaSerializerException {

        Element restriction = createNewElement(doc, "restriction", schema.getSchemaNamespacePrefix(),
                                               XmlSchema.SCHEMA_NS);

        if (restrictionObj.getBaseTypeName() != null) {
            String baseTypeName = resolveQName(restrictionObj.getBaseTypeName(), schema);
            restriction.setAttributeNS(null, "base", baseTypeName);
        }

        if (restrictionObj.getId() != null) {
            restriction.setAttributeNS(null, "id", restrictionObj.getId());
        }

        if (restrictionObj.getAnnotation() != null) {
            Element annotation = serializeAnnotation(doc, restrictionObj.getAnnotation(), schema);
            restriction.appendChild(annotation);
        }

        if (restrictionObj.getParticle() instanceof XmlSchemaSequence) {
            Element sequenceParticle = serializeSequence(doc, (XmlSchemaSequence)restrictionObj.getParticle(),
                                                         schema);
            restriction.appendChild(sequenceParticle);
        } else if (restrictionObj.getParticle() instanceof XmlSchemaChoice) {
            Element choiceParticle = serializeChoice(doc,
                                                     (XmlSchemaChoice)restrictionObj.getParticle(), schema);
            restriction.appendChild(choiceParticle);
        } else if (restrictionObj.getParticle() instanceof XmlSchemaAll) {
            Element allParticle = serializeAll(doc, (XmlSchemaAll)restrictionObj.getParticle(), schema);
            restriction.appendChild(allParticle);
        } else if (restrictionObj.getParticle() instanceof XmlSchemaGroupRef) {
            Element groupRefParticle = serializeGroupRef(doc, (XmlSchemaGroupRef)restrictionObj.getParticle(),
                                                         schema);
            restriction.appendChild(groupRefParticle);
        }

        int attributesLength = restrictionObj.getAttributes().size();
        for (int i = 0; i < attributesLength; i++) {
            XmlSchemaAttributeOrGroupRef obj = restrictionObj.getAttributes().get(i);

            if (obj instanceof XmlSchemaAttribute) {
                Element attr = serializeAttribute(doc, (XmlSchemaAttribute)obj, schema);
                restriction.appendChild(attr);
            } else if (obj instanceof XmlSchemaAttributeGroupRef) {
                Element attrGroup = serializeAttributeGroupRef(doc, (XmlSchemaAttributeGroupRef)obj, schema);
                restriction.appendChild(attrGroup);
            }
        }

        if (restrictionObj.getAnyAttribute() != null) {
            Element anyAttribute = serializeAnyAttribute(doc, restrictionObj.getAnyAttribute(), schema);
            restriction.appendChild(anyAttribute);
        }

        // process extension
        processExtensibilityComponents(restrictionObj, restriction);

        return restriction;
    }