001: //==============================================================================
002: //===
003: //=== ComplexContentEntry
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: import java.io.*;
033:
034: import org.jdom.Attribute;
035: import org.jdom.Element;
036:
037: //==============================================================================
038:
039: class ComplexContentEntry {
040: public String base;
041: public ArrayList alAttribGroups = new ArrayList();
042: public ArrayList alElements = new ArrayList();
043: public ArrayList alAttribs = new ArrayList();
044: boolean restriction = false;
045:
046: //---------------------------------------------------------------------------
047: //---
048: //--- Constructor
049: //---
050: //---------------------------------------------------------------------------
051:
052: public ComplexContentEntry(Element el, String file,
053: String targetNS, String targetNSPrefix) {
054: this (new ElementInfo(el, file, targetNS, targetNSPrefix));
055: }
056:
057: //---------------------------------------------------------------------------
058:
059: public ComplexContentEntry(ElementInfo ei) {
060: handleAttribs(ei);
061: handleChildren(ei);
062: }
063:
064: //---------------------------------------------------------------------------
065: //---
066: //--- Private methods
067: //---
068: //---------------------------------------------------------------------------
069:
070: private void handleAttribs(ElementInfo ei) {
071: List attribs = ei.element.getAttributes();
072:
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("mixed"))
079: Logger
080: .log("Skipping 'mixed' attribute in <complexContent> element");
081: else
082: Logger.log("Unknown attribute '" + attrName
083: + "' in <complexContent> element", ei);
084: }
085: }
086:
087: //---------------------------------------------------------------------------
088:
089: private void handleChildren(ElementInfo ei) {
090: List children = ei.element.getChildren();
091:
092: for (int i = 0; i < children.size(); i++) {
093: Element elChild = (Element) children.get(i);
094: String elName = elChild.getName();
095:
096: if (elChild.getName().equals("extension"))
097: handleExtension(elChild, ei);
098:
099: else if (elChild.getName().equals("restriction")) {
100: handleRestriction(elChild, ei);
101: restriction = true;
102: }
103:
104: else
105: Logger.log("Unknown child '" + elName
106: + "' in <complexContent> element", ei);
107: }
108: }
109:
110: //---------------------------------------------------------------------------
111:
112: private void handleExtension(Element el, ElementInfo ei) {
113: base = el.getAttributeValue("base");
114:
115: List extension = el.getChildren();
116:
117: for (int j = 0; j < extension.size(); j++) {
118: Element elExt = (Element) extension.get(j);
119:
120: if (elExt.getName().equals("sequence")) {
121: List sequence = elExt.getChildren();
122:
123: for (int k = 0; k < sequence.size(); k++) {
124: Element elSeq = (Element) sequence.get(k);
125:
126: if (elSeq.getName().equals("element")
127: || elSeq.getName().equals("choice")
128: || elSeq.getName().equals("group")
129: || elSeq.getName().equals("sequence"))
130: alElements.add(new ElementEntry(elSeq, ei.file,
131: ei.targetNS, ei.targetNSPrefix));
132:
133: else
134: Logger.log("Unknown child '" + elSeq.getName()
135: + "' in <sequence> element" + ei);
136: }
137: } else if (elExt.getName().equals("group")) {
138: alElements.add(new ElementEntry(elExt, ei.file,
139: ei.targetNS, ei.targetNSPrefix));
140: } else if (elExt.getName().equals("choice")) {
141: alElements.add(new ElementEntry(elExt, ei.file,
142: ei.targetNS, ei.targetNSPrefix));
143: } else if (elExt.getName().equals("attribute"))
144: alAttribs.add(new AttributeEntry(elExt, ei.file,
145: ei.targetNS, ei.targetNSPrefix));
146: else if (elExt.getName().equals("attributeGroup")) {
147: String attribGroup = elExt.getAttributeValue("ref");
148:
149: if (attribGroup == null)
150: throw new IllegalArgumentException(
151: "'ref' is null for element in <attributeGroup> of ComplexContent with extension base "
152: + base);
153: alAttribGroups.add(attribGroup);
154: }
155:
156: else
157: Logger.log("Unknown child '" + elExt.getName()
158: + "' in <extension> element " + ei);
159: }
160: }
161:
162: //---------------------------------------------------------------------------
163:
164: private void handleRestriction(Element el, ElementInfo ei) {
165: base = el.getAttributeValue("base");
166:
167: //--- handle children
168:
169: List restriction = el.getChildren();
170:
171: for (int i = 0; i < restriction.size(); i++) {
172: Element elRes = (Element) restriction.get(i);
173: String elName = elRes.getName();
174:
175: if (elRes.getName().equals("sequence")) {
176: List sequence = elRes.getChildren();
177:
178: for (int k = 0; k < sequence.size(); k++) {
179: Element elSeq = (Element) sequence.get(k);
180:
181: if (elSeq.getName().equals("element")
182: || elSeq.getName().equals("choice")
183: || elSeq.getName().equals("group")
184: || elSeq.getName().equals("sequence"))
185: alElements.add(new ElementEntry(elSeq, ei.file,
186: ei.targetNS, ei.targetNSPrefix));
187: else
188: Logger.log("Unknown child '" + elSeq.getName()
189: + "' in <sequence> element" + ei);
190: }
191: }
192:
193: else if (elRes.getName().equals("group")) {
194: alElements.add(new ElementEntry(elRes, ei.file,
195: ei.targetNS, ei.targetNSPrefix));
196: }
197:
198: else if (elName.equals("attribute"))
199: alAttribs.add(new AttributeEntry(elRes, ei.file,
200: ei.targetNS, ei.targetNSPrefix));
201:
202: else if (elName.equals("attributeGroup")) {
203: String attribGroup = elRes.getAttributeValue("ref");
204:
205: if (attribGroup == null)
206: throw new IllegalArgumentException(
207: "'ref' is null for element in <attributeGroup> of ComplexContent with restriction base "
208: + base);
209: alAttribGroups.add(attribGroup);
210: }
211:
212: else
213: Logger.log("Unknown child '" + elName
214: + "' in <restriction> element", ei);
215:
216: }
217: }
218: }
219:
220: //==============================================================================
|