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