001: //==============================================================================
002: //===
003: //=== GroupEntry
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 GroupEntry {
039: public String name;
040: boolean isChoice;
041: public ArrayList alElements = new ArrayList();
042:
043: //---------------------------------------------------------------------------
044: //---
045: //--- Constructor
046: //---
047: //---------------------------------------------------------------------------
048:
049: public GroupEntry(Element el, String file, String targetNS,
050: String targetNSPrefix) {
051: this (new ElementInfo(el, file, targetNS, targetNSPrefix));
052: }
053:
054: //---------------------------------------------------------------------------
055:
056: public GroupEntry(ElementInfo ei) {
057: handleAttribs(ei);
058: handleChildren(ei);
059: }
060:
061: //---------------------------------------------------------------------------
062: //---
063: //--- Private methods
064: //---
065: //---------------------------------------------------------------------------
066:
067: private void handleAttribs(ElementInfo ei) {
068: List attribs = ei.element.getAttributes();
069:
070: for (int i = 0; i < attribs.size(); i++) {
071: Attribute at = (Attribute) attribs.get(i);
072:
073: String attrName = at.getName();
074: if (attrName.equals("name")) {
075: name = at.getValue();
076: if ((name.indexOf(":") == -1)
077: && (ei.targetNSPrefix != null))
078: name = ei.targetNSPrefix + ":" + at.getValue();
079: } else
080: Logger.log("Unknown attribute '" + attrName
081: + "' in <group> element", ei);
082: }
083: }
084:
085: //---------------------------------------------------------------------------
086:
087: private void handleChildren(ElementInfo ei) {
088: List children = ei.element.getChildren();
089:
090: for (int i = 0; i < children.size(); i++) {
091: Element elChild = (Element) children.get(i);
092: String elName = elChild.getName();
093:
094: if (elName.equals("sequence")) {
095: List sequence = elChild.getChildren();
096:
097: for (int j = 0; j < sequence.size(); j++) {
098: Element elElem = (Element) sequence.get(j);
099:
100: if (elElem.getName().equals("choice")
101: || elElem.getName().equals("element")
102: || elElem.getName().equals("group")
103: || elElem.getName().equals("sequence"))
104: alElements
105: .add(new ElementEntry(elElem, ei.file,
106: ei.targetNS, ei.targetNSPrefix));
107:
108: else
109: Logger.log("Unknown child '" + elElem.getName()
110: + "' in <sequence> element", ei);
111: }
112: } else if (elName.equals("choice"))
113: alElements.add(new ElementEntry(elChild, ei.file,
114: ei.targetNS, ei.targetNSPrefix));
115:
116: else if (elName.equals("annotation"))
117: ;
118:
119: else
120: Logger.log("Unknown child '" + elName
121: + "' in <group> element", ei);
122: }
123: }
124:
125: }
126:
127: //==============================================================================
|