Element serializeAttributeGroup()

in src/main/java/org/apache/ws/commons/schema/XmlSchemaSerializer.java [496:538]


    Element serializeAttributeGroup(Document doc, XmlSchemaAttributeGroup attributeGroupObj, XmlSchema schema)
        throws XmlSchemaSerializerException {

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

        if (!attributeGroupObj.isAnonymous()) {
            String attGroupName = attributeGroupObj.getName();
            attributeGroup.setAttribute("name", attGroupName);
        } else {
            throw new XmlSchemaSerializerException("Attribute group must" + "have name");
        }
        if (attributeGroupObj.getId() != null) {
            attributeGroup.setAttribute("id", attributeGroupObj.getId());
        }

        if (attributeGroupObj.getAnnotation() != null) {
            Element annotation = serializeAnnotation(doc, attributeGroupObj.getAnnotation(), schema);
            attributeGroup.appendChild(annotation);
        }
        int attributesLength = attributeGroupObj.getAttributes().size();
        for (int i = 0; i < attributesLength; i++) {
            XmlSchemaAttributeGroupMember obj = attributeGroupObj.getAttributes().get(i);

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

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

        // process extension
        processExtensibilityComponents(attributeGroupObj, attributeGroup);

        return attributeGroup;
    }