Java tutorial
/** * This class represents an XSD group 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: XSDGroup.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:47 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.Iterator; import java.util.LinkedList; import org.jdom2.Element; import com.init.octo.util.Logger; public abstract class XSDGroupType extends XSDStructureType { private static Logger log = Logger.getLogger(XSDGroupType.class.getName()); public XSDGroupType() { this(1); } public XSDGroupType(int indent) { this.indent = indent; groupType = "XSDGroup"; } public boolean build(Element root, XSDCache cache, String parentName) { log.debug("" + indent + ": " + "Build representation of a group"); id = root.getAttributeValue(XSDSchema.ID_ATT); maxOccurs = root.getAttributeValue(XSDSchema.MAXOCCURS_ATT); minOccurs = root.getAttributeValue(XSDSchema.MINOCCURS_ATT); name = root.getAttributeValue(XSDSchema.NAME_ATT); ref = root.getAttributeValue(XSDSchema.REF_ATT); /* If this group is named then add it to the cache... */ /* if (name != null && name.equals("") == false) { cache.putGroup(name, this); } */ /* If this group is a reference then lookup the reference... */ /* if (ref != null && ref.equals("") == false) { List<XSDGroup> cachedGroup = cache.getGroup(ref); if (cachedGroup != null) { group return (true); } } */ group = new LinkedList<XMLType>(); Element element; String elementName; for (Iterator<?> i = (root.getChildren()).iterator(); i.hasNext();) { element = (Element) i.next(); elementName = element.getName(); log.debug("" + indent + ": " + "Child element <" + elementName + "> found"); /** process the child elements that define this element... **/ if (elementName.equals(XSDSchema.ANNOTATION)) { annotation = element.getTextTrim(); } else if (elementName.equals(XSDSchema.ALL)) { log.debug("" + indent + ": " + "Adding ALL to the list of child elements"); XsdAll a = new XsdAll(indent); // child elements will be at the same level if (a.build(element, cache, parentName) != true) { log.error("Error building a ALL element"); return (false); } group.add(a); } else if (elementName.equals(XSDSchema.CHOICE)) { log.debug("" + indent + ": " + "Adding choice to the list of child elements"); XSDChoice c = new XSDChoice(indent); // child elements will be // at the same level if (c.build(element, cache, parentName) != true) { log.error("Error building a choice"); return (false); } group.add(c); } else if (elementName.equals(XSDSchema.SEQUENCE)) { log.debug("" + indent + ": " + "Adding sequence to the list of child elements"); XSDSequence s = new XSDSequence(indent); if (s.build(element, cache, parentName) != true) { log.error("Error building a sequence"); return (false); } group.add(s); } else { log.warn("" + indent + ": " + "Unexpected element <" + elementName + "> found and ignored"); } } // end for all child elements of this <group> tag return (true); } } // end class XSDGroup