001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/framework/xml/schema/ElementDeclaration.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstraße 19
030: 53177 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042: ---------------------------------------------------------------------------*/
043: package org.deegree.framework.xml.schema;
044:
045: import org.deegree.datatypes.QualifiedName;
046:
047: /**
048: * Represents an XML element declaration in an {@link XMLSchema}.
049: *
050: * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
051: * @author last edited by: $Author: apoth $
052: *
053: * @version $Revision: 9339 $, $Date: 2007-12-27 04:31:52 -0800 (Thu, 27 Dec 2007) $
054: */
055: public class ElementDeclaration {
056:
057: private QualifiedName name;
058:
059: private boolean isAbstract;
060:
061: private TypeReference type;
062:
063: private int minOccurs;
064:
065: private int maxOccurs;
066:
067: private ElementReference substitutionGroup;
068:
069: /**
070: * Creates a new <code>ElementDeclaration</code> instance from the given parameters.
071: *
072: * @param name
073: * @param isAbstract
074: * @param type
075: * @param minOccurs
076: * @param maxOccurs
077: * @param substitutionGroup
078: */
079: public ElementDeclaration(QualifiedName name, boolean isAbstract,
080: TypeReference type, int minOccurs, int maxOccurs,
081: QualifiedName substitutionGroup) {
082: this .name = name;
083: this .isAbstract = isAbstract;
084: this .type = type;
085: this .minOccurs = minOccurs;
086: this .maxOccurs = maxOccurs;
087: if (substitutionGroup != null) {
088: this .substitutionGroup = new ElementReference(
089: substitutionGroup);
090: }
091: }
092:
093: /**
094: * Returns the qualified name of the declared XML element.
095: *
096: * @return the qualified name of the declared XML element
097: */
098: public QualifiedName getName() {
099: return this .name;
100: }
101:
102: /**
103: * Returns whether the element is declared abstract.
104: *
105: * @return true, if the element is abstract, false otherwise
106: */
107: public boolean isAbstract() {
108: return this .isAbstract;
109: }
110:
111: /**
112: * Returns a {@link TypeReference} that describes the content of the element.
113: *
114: * @return a TypeReference that describes the content of the element
115: */
116: public TypeReference getType() {
117: return this .type;
118: }
119:
120: /**
121: * Returns the minimum number of occurences of the element.
122: *
123: * @return the minimum number of occurences of the element, -1 if it is unconstrained
124: */
125: public int getMinOccurs() {
126: return this .minOccurs;
127: }
128:
129: /**
130: * Returns the maximum number of occurences of the element.
131: *
132: * @return the maximum number of occurences of the element, -1 if it is unconstrained
133: */
134: public int getMaxOccurs() {
135: return this .maxOccurs;
136: }
137:
138: /**
139: * Returns an {@link ElementReference} which the element may be substituted for.
140: *
141: * @return an ElementReference which the element may be substituted for
142: */
143: public ElementReference getSubstitutionGroup() {
144: return this .substitutionGroup;
145: }
146:
147: /**
148: * Returns whether this element is substitutable for the given element name.
149: * <p>
150: * This is true if the substitutionGroup equals the given element name, or if an element that
151: * this element is substitutable for may be substituted for the given element name.
152: *
153: * @param substitutionName
154: * @return true, if this element declaration is a valid substiution for elements with the
155: * given name
156: */
157: public boolean isSubstitutionFor(QualifiedName substitutionName) {
158: if (this .name.equals(substitutionName)) {
159: return true;
160: }
161: if (this .substitutionGroup == null) {
162: return false;
163: }
164: if (this .substitutionGroup.getElementDeclaration() == null) {
165: return this .substitutionGroup.getName().equals(
166: substitutionName);
167: }
168: return this .substitutionGroup.getElementDeclaration()
169: .isSubstitutionFor(substitutionName);
170: }
171:
172: /**
173: * Returns a string representation of the object (indented for better readablity,
174: * as this is part of a hierarchical structure).
175: *
176: * @param indent
177: * current indentation (as a whitespace string)
178: * @return an indented string representation of the object
179: */
180: public String toString(String indent) {
181: StringBuffer sb = new StringBuffer();
182: sb.append(indent);
183: sb.append("- element");
184: if (this .name != null) {
185: sb.append(" name=\"");
186: sb.append(this .name.getLocalName());
187: sb.append("\"");
188: }
189: if (!this .type.isAnonymous()) {
190: sb.append(" type=\"");
191: sb.append(this .type.getName());
192: sb.append("\"");
193: } else {
194: sb.append(" anonymous type");
195: }
196: if (this .substitutionGroup != null) {
197: sb.append(" substitutionGroup=\"");
198: sb.append(this .substitutionGroup.getName());
199: sb.append("\"");
200: }
201: sb.append("\n");
202: if (this .type.isAnonymous()) {
203: sb.append(this .type.getTypeDeclaration().toString(
204: indent + " "));
205: }
206: return sb.toString();
207: }
208: }
|