Java tutorial
/** * This class represents an XSD 'attribute' 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: XSDAttribute.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:39 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.List; import org.apache.ws.commons.schema.XmlSchemaException; import org.jdom2.Element; import com.init.octo.util.Logger; public class XSDAttribute extends XSDAttributeType { private Logger log; // logging object private XSDElementType elementType; // object to define the type of the element private String ref; // ref atribute private String type; // type atribute private String defaultAtt; // default attribute private String use; // use attribute private String parentName; // full name of attribute /** * Constructor for the "element" representation */ public XSDAttribute() { this.log = Logger.getLogger(XSDAttribute.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 */ //log.debug("Build representation of an Attribute"); public boolean build(Element root, XSDCache cache, String parentName) { this.parentName = parentName; name = root.getAttributeValue(XSDSchema.NAME_ATT); ref = root.getAttributeValue(XSDSchema.REF_ATT); type = root.getAttributeValue(XSDSchema.TYPE_ATT); defaultAtt = root.getAttributeValue(XSDSchema.DEFAULT_ATT); use = root.getAttributeValue(XSDSchema.USE_ATT); if (use == null) { use = "optional"; } if (defaultAtt == null) { defaultAtt = ""; } if (notEmpty(name)) { cache.putAttribute(name, this); } if (notEmpty(ref)) { XSDAttribute refAtt = (XSDAttribute) cache.getAttribute(ref); if (refAtt == null) { log.warn("Referenced attribute not found [" + ref + "]"); return (true); } name = refAtt.getName(); use = refAtt.getUse(); defaultAtt = refAtt.getDefault(); type = refAtt.getType(); return (true); } for (Element child : root.getChildren()) { String childElementType = child.getName(); if (childElementType.equals(XSDSchema.ANNOTATION)) { annotation = child.getTextTrim(); } else if (childElementType.equals(XSDSchema.SIMPLETYPE)) { if (elementType != null) { throw new XmlSchemaException("Cannot define the type of an attribute more than once"); } elementType = new XSDElementTypeSimple(); elementType.build(child, cache, parentName); } } // end for all child elements of this <element> tag log.debug("Attribute built"); return true; } public String getFullName() { return (((parentName.equals("")) ? "" : parentName + ".@") + name); } public boolean isMandatory() { return (use.equals("required")); } public String getDefault() { return (defaultAtt); } public String getUse() { return (use); } public String getType() { return (type); } public String toString() { return ("XSDAttribute: " + (type == null ? "" : ("[" + type + "] ")) + name); } @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 XSDAttribute