001: //==============================================================================
002: //===
003: //=== SimpleTypeEntry
004: //===
005: //==============================================================================
006: //=== Copyright (C) 2001-2005 Food and Agriculture Organization of the
007: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
008: //=== and United Nations Environment Programme (UNEP)
009: //===
010: //=== This program is free software; you can redistribute it and/or modify
011: //=== it under the terms of the GNU General Public License as published by
012: //=== the Free Software Foundation; either version 2 of the License, or (at
013: //=== your option) any later version.
014: //===
015: //=== This program is distributed in the hope that it will be useful, but
016: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
017: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018: //=== General Public License for more details.
019: //===
020: //=== You should have received a copy of the GNU General Public License
021: //=== along with this program; if not, write to the Free Software
022: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
023: //===
024: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
025: //=== Rome - Italy. email: geonetwork@osgeo.org
026: //==============================================================================
027:
028: package org.fao.geonet.kernel.schema;
029:
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: import org.jdom.Attribute;
034: import org.jdom.Element;
035:
036: //==============================================================================
037:
038: /** This class parses a "SimpleType" element. All attributes are ignored (a warning
039: * is logged). Only the "restriction" child is recognized and extracted.
040: */
041:
042: class SimpleTypeEntry {
043: public String name;
044:
045: public ArrayList alEnum = new ArrayList();
046:
047: //---------------------------------------------------------------------------
048: //---
049: //--- Constructor
050: //---
051: //---------------------------------------------------------------------------
052:
053: public SimpleTypeEntry(Element el, String file, String targetNS,
054: String targetNSPrefix) {
055: this (new ElementInfo(el, file, targetNS, targetNSPrefix));
056: }
057:
058: //---------------------------------------------------------------------------
059:
060: public SimpleTypeEntry(ElementInfo ei) {
061: handleAttribs(ei);
062: handleChildren(ei);
063: }
064:
065: //---------------------------------------------------------------------------
066: //---
067: //--- Private methods
068: //---
069: //---------------------------------------------------------------------------
070:
071: private void handleAttribs(ElementInfo ei) {
072: List attribs = ei.element.getAttributes();
073: for (int i = 0; i < attribs.size(); i++) {
074: Attribute at = (Attribute) attribs.get(i);
075:
076: String attrName = at.getName();
077:
078: if (attrName.equals("name")) {
079: name = at.getValue();
080: if ((name.indexOf(":") == -1)
081: && (ei.targetNSPrefix != null))
082: name = ei.targetNSPrefix + ":" + at.getValue();
083: } else
084: Logger.log("Unknown attribute '" + attrName
085: + "' in <simpleType> element", ei);
086: }
087: }
088:
089: //---------------------------------------------------------------------------
090:
091: private void handleChildren(ElementInfo ei) {
092: List children = ei.element.getChildren();
093:
094: for (int i = 0; i < children.size(); i++) {
095: Element elChild = (Element) children.get(i);
096: String elName = elChild.getName();
097:
098: if (elName.equals("restriction")) {
099: List restrictions = elChild.getChildren();
100:
101: for (int j = 0; j < restrictions.size(); j++) {
102: Element elEnum = (Element) restrictions.get(j);
103: String elemName = elEnum.getName();
104:
105: if (elemName.equals("enumeration"))
106: alEnum.add(elEnum.getAttributeValue("value"));
107:
108: else if (elemName.equals("minInclusive")
109: || elemName.equals("maxInclusive")
110: || elemName.equals("minExclusive")
111: || elemName.equals("maxExclusive")
112: || elemName.equals("pattern"))
113: //--- we are not interested in type's domain so we skip these specifications
114: ;
115:
116: else
117: Logger.log("Unknown child '" + elEnum.getName()
118: + "' in <restriction> element", ei);
119: }
120: }
121:
122: else if (elName.equals("union"))
123: Logger
124: .log("Skipping 'union' child in <simpleType> element '"
125: + name + "'");
126:
127: else if (elName.equals("annotation"))
128: ;
129: else
130: Logger.log("Unknown child '" + elName
131: + "' in <simpleType> element ", ei);
132: }
133: }
134: }
135:
136: //==============================================================================
|