001: //==============================================================================
002: //===
003: //=== AttributeEntry
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: class AttributeEntry {
039: public String name;
040: public String unqualifiedName;
041: public String namespacePrefix;
042: public String defValue;
043: public String reference;
044: public String referenceNS;
045: public String form = "unqualified";
046: public boolean required = false;
047:
048: public ArrayList alValues = new ArrayList();
049:
050: //---------------------------------------------------------------------------
051: //---
052: //--- Constructor
053: //---
054: //---------------------------------------------------------------------------
055:
056: public AttributeEntry(Element el, String file, String targetNS,
057: String targetNSPrefix) {
058: this (new ElementInfo(el, file, targetNS, targetNSPrefix));
059: }
060:
061: //---------------------------------------------------------------------------
062:
063: public AttributeEntry(ElementInfo ei) {
064: handleAttribs(ei);
065: handleChildren(ei);
066: }
067:
068: //---------------------------------------------------------------------------
069: //---
070: //--- Private methods
071: //---
072: //---------------------------------------------------------------------------
073:
074: private void handleAttribs(ElementInfo ei) {
075: List attribs = ei.element.getAttributes();
076:
077: for (int i = 0; i < attribs.size(); i++) {
078: Attribute at = (Attribute) attribs.get(i);
079:
080: String attrName = at.getName();
081: if (attrName.equals("name")) {
082: name = at.getValue();
083: unqualifiedName = name;
084: if (ei.targetNSPrefix != null) {
085: name = ei.targetNSPrefix + ":" + name;
086: namespacePrefix = ei.targetNSPrefix;
087: }
088:
089: //System.out.println("-- name is "+name);
090: } else if (attrName.equals("default")
091: || attrName.equals("fixed"))
092: defValue = at.getValue();
093:
094: else if (attrName.equals("ref")) {
095: reference = at.getValue();
096:
097: //System.out.println("-- ref is "+reference);
098: }
099:
100: else if (attrName.equals("use")) {
101: required = "required".equals(at.getValue());
102: //System.out.println("-- Required is "+required);
103: }
104:
105: else if (attrName.equals("type"))
106: ; //Logger.log("Skipping 'type' attribute in <attribute> element '"+ name +"'");
107:
108: else if (attrName.equals("form"))
109: form = at.getValue();
110:
111: else
112: Logger
113: .log("Unknown attribute '" + attrName
114: + "' in <attribute> element '" + name
115: + "'", ei);
116: }
117: }
118:
119: //---------------------------------------------------------------------------
120:
121: private void handleChildren(ElementInfo ei) {
122: List children = ei.element.getChildren();
123:
124: for (int i = 0; i < children.size(); i++) {
125: Element elChild = (Element) children.get(i);
126: String elName = elChild.getName();
127:
128: if (elName.equals("simpleType")) {
129: SimpleTypeEntry ste = new SimpleTypeEntry(elChild,
130: ei.file, ei.targetNS, ei.targetNSPrefix);
131:
132: for (int j = 0; j < ste.alEnum.size(); j++)
133: alValues.add(ste.alEnum.get(j));
134: }
135:
136: else if (elName.equals("annotation"))
137: ;
138:
139: else
140: Logger
141: .log("Unknown child '" + elName
142: + "' in <attribute> element '" + name
143: + "'", ei);
144: }
145: }
146: }
147:
148: //==============================================================================
|