001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.xml.schema.impl;
017:
018: import java.net.URI;
019:
020: import org.geotools.xml.schema.Choice;
021: import org.geotools.xml.schema.Element;
022: import org.geotools.xml.schema.ElementGrouping;
023:
024: /**
025: * <p>
026: * DOCUMENT ME!
027: * </p>
028: *
029: * @author dzwiers
030: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/main/java/org/geotools/xml/schema/impl/ChoiceGT.java $
031: */
032: public class ChoiceGT implements Choice {
033: private String id;
034: private int min;
035: private int max;
036: private ElementGrouping[] children;
037:
038: private ChoiceGT() {
039: // do nothing
040: }
041:
042: /**
043: * Creates a new ChoiceGT object.
044: *
045: * @param id DOCUMENT ME!
046: * @param min DOCUMENT ME!
047: * @param max DOCUMENT ME!
048: * @param children DOCUMENT ME!
049: */
050: public ChoiceGT(String id, int min, int max,
051: ElementGrouping[] children) {
052: this .id = id;
053: this .min = min;
054: this .max = max;
055: this .children = children;
056: }
057:
058: public ChoiceGT(ElementGrouping[] children) {
059: this .min = 1;
060: this .max = 1;
061: this .children = children;
062: }
063:
064: /**
065: * @see org.geotools.xml.schema.Choice#getId()
066: */
067: public String getId() {
068: return id;
069: }
070:
071: /**
072: * @see org.geotools.xml.schema.ElementGrouping#getMaxOccurs()
073: */
074: public int getMaxOccurs() {
075: return max;
076: }
077:
078: /**
079: * @see org.geotools.xml.schema.ElementGrouping#getMinOccurs()
080: */
081: public int getMinOccurs() {
082: return min;
083: }
084:
085: /**
086: * @see org.geotools.xml.schema.Choice#getChildren()
087: */
088: public ElementGrouping[] getChildren() {
089: return children;
090: }
091:
092: /**
093: * @see org.geotools.xml.schema.ElementGrouping#getGrouping()
094: */
095: public int getGrouping() {
096: return CHOICE;
097: }
098:
099: /**
100: * @see org.geotools.xml.schema.ElementGrouping#findChildElement(java.lang.String)
101: */
102: public Element findChildElement(String name) {
103: if (children == null) {
104: return null;
105: }
106:
107: for (int i = 0; i < children.length; i++) {
108: Element e = children[i].findChildElement(name);
109:
110: if (e != null) {
111: return e;
112: }
113: }
114:
115: return null;
116: }
117:
118: public Element findChildElement(String localName, URI namespaceURI) {
119: if (children == null) {
120: return null;
121: }
122:
123: for (int i = 0; i < children.length; i++) {
124: Element e = children[i].findChildElement(localName,
125: namespaceURI);
126:
127: if (e != null) {
128: return e;
129: }
130: }
131:
132: return null;
133: }
134: }
|