com.init.octo.schema.XSDAttributeGroup.java Source code

Java tutorial

Introduction

Here is the source code for com.init.octo.schema.XSDAttributeGroup.java

Source

/**
 *  This class represents an XSD 'attributeGroup' element.
 * 
 *  Copyright (C) 2007  Stephen Harding
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *  
 *  Please send inquiries to; steve@inverse2.com
 *
 * $Revision: 1.3 $
 * 
 * $Log: XSDAttributeGroup.java,v $
 * Revision 1.3  2008/07/01 17:26:46  stevewdh
 * Changed logging so that user can specify the type they want (Java, Log4J or HTML).
 *
 * Revision 1.2  2008/03/05 10:47:27  stevewdh
 * *** empty log message ***
 *
 * Revision 1.1  2007/10/04 11:06:40  stevewdh
 * *** empty log message ***
 *
 * Revision 1.2  2007/09/30 13:09:05  stephen harding
 * Added contact details to license header.
 *
 * Revision 1.1  2007/09/15 16:09:05  stephen harding
 * Added header.
 *
 *
 */

package com.init.octo.schema;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.jdom2.Element;

import com.init.octo.util.Logger;

public class XSDAttributeGroup extends XSDAttributeType {

    /**
     * Constructor for the "element" representation
     */

    public XSDAttributeGroup() {
        this.log = Logger.getLogger(XSDAttributeGroup.class.getName());
    }

    /**
     * This method builds the element definition
     *
     * @param root
     *            - the schema element that defines this element
     * @param cache
     *            - a list of pre-defined XML types
     */

    public boolean build(Element root, XSDCache cache, String parentName) {

        log.debug("Build representation of an AttributeGroup");

        id = root.getAttributeValue(XSDSchema.ID_ATT);
        name = root.getAttributeValue(XSDSchema.NAME_ATT);
        ref = root.getAttributeValue(XSDSchema.REF_ATT);

        if (name != null && name.equals("") == false) {
            cache.putAttributeGroup(name, this);
        }

        if (ref != null && ref.equals("") == false) {

            XSDAttributeGroup refAttGroup = (XSDAttributeGroup) cache.getAttributeGroup(ref);

            if (refAttGroup == null) {
                log.debug("Referenced attribute group not found [" + ref + "]");
                return (true);
            }

            attributeList = refAttGroup.getAttributeList();

            return (true);
        }

        log.debug("AttributeGroup <" + name + ">");

        Element element;
        String elementName;

        attributeList = new ArrayList<XSDAttributeType>();

        for (Iterator<?> i = (root.getChildren()).iterator(); i.hasNext();) {

            element = (Element) i.next();
            elementName = element.getName();

            log.debug("Child element <" + elementName + "> found");

            /** process the child elements that define this element... **/

            if (elementName.equals(XSDSchema.ANNOTATION)) {

            } else if (elementName.equals(XSDSchema.ATTRIBUTE)) {

                XSDAttribute attribute = new XSDAttribute();
                if (attribute.build(element, cache, parentName) != true) {
                    log.error("Error building an attribute object");
                    return (false);
                }

                attributeList.add(attribute);

            } else if (elementName.equals(XSDSchema.ATTRIBUTEGROUP)) {

                XSDAttributeGroup group = new XSDAttributeGroup();

                if (group.build(element, cache, parentName) != true) {
                    log.error("Error building a sub-attribute-group object");
                    return (false);
                }

                attributeList.add(group);

            } else {
                log.warn("Unexpected element <" + elementName + "> found and ignored");
            }

        } // end for all child elements of this <element> tag

        log.debug("Attribute built");

        return (true);

    } // end build

    public List<XSDAttributeType> getAllAttributes() {

        List<XSDAttributeType> list = new ArrayList<XSDAttributeType>();

        for (XSDAttributeType att : attributeList) {

            if (att instanceof XSDAttribute) {
                list.add(att);
            } else if (att instanceof XSDAttributeGroup) {
                list.addAll(((XSDAttributeGroup) att).getAllAttributes());
            }

        }

        return (list);

    }

    public List<XSDAttributeType> getAttributeList() {
        return (attributeList);
    }

    @Override
    public void show(int preIndent, boolean subCachedType, boolean htmlForm) {
        // TODO Auto-generated method stub

    }

    @Override
    public List<XMLType> getGroup() {
        // TODO Auto-generated method stub
        return null;
    }

} // end class XSDAttributeGroup