001: /**
002: * Redistribution and use of this software and associated documentation
003: * ("Software"), with or without modification, are permitted provided
004: * that the following conditions are met:
005: *
006: * 1. Redistributions of source code must retain copyright
007: * statements and notices. Redistributions must also contain a
008: * copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the
011: * above copyright notice, this list of conditions and the
012: * following disclaimer in the documentation and/or other
013: * materials provided with the distribution.
014: *
015: * 3. The name "Exolab" must not be used to endorse or promote
016: * products derived from this Software without prior written
017: * permission of Intalio, Inc. For written permission,
018: * please contact info@exolab.org.
019: *
020: * 4. Products derived from this Software may not be called "Exolab"
021: * nor may "Exolab" appear in their names without prior written
022: * permission of Intalio, Inc. Exolab is a registered
023: * trademark of Intalio, Inc.
024: *
025: * 5. Due credit should be given to the Exolab Project
026: * (http://www.exolab.org/).
027: *
028: * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
029: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
030: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
031: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
032: * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
033: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
034: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
035: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
036: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
037: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
038: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
039: * OF THE POSSIBILITY OF SUCH DAMAGE.
040: *
041: * Copyright 1999-2000 (C) Intalio Inc. All Rights Reserved.
042: *
043: * $Id: XMLType.java 6230 2006-09-19 07:56:07Z wguttmn $
044: */package org.exolab.castor.xml.schema;
045:
046: /**
047: * The base type for XML Schema types, such as complex types
048: * and simple types.
049: * <BR />
050: * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
051: * @version $Revision: 6230 $ $Date: 2006-04-14 04:14:43 -0600 (Fri, 14 Apr 2006) $
052: **/
053: public abstract class XMLType extends Annotated {
054: /**
055: * Error message for a null argument
056: */
057: protected static String NULL_ARGUMENT = "A null argument was passed to "
058: + XMLType.class.getName();
059:
060: /**
061: * The ID of this datatype
062: **/
063: private String _id = null;
064:
065: /**
066: * The name of this type
067: */
068: private String name = null;
069:
070: /**
071: * The base datatype reference
072: **/
073: private XMLType baseType = null;
074:
075: /**
076: * The owning Schema to which this type belongs
077: **/
078: private Schema schema = null;
079:
080: /**
081: * The name of the derivation method (if any)
082: */
083: private String derivationMethod = null;
084:
085: /**
086: * Default constructor
087: **/
088: public XMLType() {
089: super ();
090: } //-- XMLType
091:
092: /**
093: * Returns the Id for this ComplexType, or null if no Id has been set.
094: *
095: * @return the Id for this ComplexType, or null if no Id has been set.
096: **/
097: public String getId() {
098: return _id;
099: } //-- getId
100:
101: /**
102: * Returns the name of this type (null if none was defined)
103: * @return the name of this type (null if none was defined)
104: **/
105: public String getName() {
106: return name;
107: }
108:
109: /**
110: * Sets the name of this type
111: * @param name of the type
112: **/
113: public synchronized void setName(String name) {
114: this .name = name;
115:
116: //-- Patch to handle name changes....we should
117: //-- change this in the future to something
118: //-- less heavy.
119: if (schema != null) {
120: try {
121: if (isComplexType()) {
122: if (schema.removeComplexType((ComplexType) this )) {
123: schema.addComplexType((ComplexType) this );
124: }
125: } else if (isSimpleType()) {
126: if (schema.removeSimpleType((SimpleType) this )) {
127: schema.addSimpleType((SimpleType) this );
128: }
129: }
130: } catch (SchemaException ex) {
131: //-- If this is ever thrown then we've
132: //-- had some nasty synchronization error! :-(
133: throw new IllegalStateException(ex.toString());
134: }
135: }
136: //-- end name-change patch
137:
138: } //-- setName
139:
140: /**
141: * Returns true if this XMLType is an AnyType
142: * @return true if this XMLType is an AnyType
143: **/
144: public final boolean isAnyType() {
145: return (getStructureType() == Structure.ANYTYPE);
146: } //-- isComplexType
147:
148: /**
149: * Returns true if this XMLType is a ComplexType
150: * @return true if this XMLType is a ComplexType
151: **/
152: public final boolean isComplexType() {
153: return (getStructureType() == Structure.COMPLEX_TYPE);
154: } //-- isComplexType
155:
156: /**
157: * Returns true if this XMLType is a SimpleType
158: * @return true if this XMLType is a SimpleType
159: **/
160: public final boolean isSimpleType() {
161: return ((getStructureType() == Structure.SIMPLE_TYPE) || (getStructureType() == Structure.UNION));
162: } //-- isSimpleType
163:
164: /**
165: * Returns the schema to which this type belongs
166: * @return the Schema to which this type belongs
167: **/
168: public Schema getSchema() {
169: return schema;
170: } //-- getSchema
171:
172: /**
173: * Sets the name of this SimpleType
174: * @param schema the Schema to which this Simpletype belongs
175: **/
176: public void setSchema(Schema schema) {
177: if (schema == null) {
178: String err = NULL_ARGUMENT + "; 'schema' must not be null.";
179: throw new IllegalArgumentException(err);
180: }
181: this .schema = schema;
182: }
183:
184: /**
185: * Returns the base type that this type inherits from.
186: * If this type is a Simpletype that is a built in primitive type then null is returned.
187: * @return the parent type.
188: **/
189: public XMLType getBaseType() {
190: return baseType;
191: } //-- getBaseType
192:
193: /**
194: * Sets the base type for this datatype
195: * @param baseType the base type which this datatype inherits from
196: **/
197: public void setBaseType(XMLType baseType) {
198: this .baseType = baseType;
199: } //-- setBaseType
200:
201: /**
202: * Gets the name of the derivation method used to derive this type from its
203: * parent. null for primitive types.
204: */
205: public String getDerivationMethod() {
206: return derivationMethod;
207: }
208:
209: /**
210: * Sets the derivation method name
211: */
212: public void setDerivationMethod(String derivationMethod) {
213: this .derivationMethod = derivationMethod;
214: }
215:
216: /**
217: * Sets the Id for this XMLType. The Id must be globally unique
218: * within the Schema. Use a null value to remove the Id.
219: *
220: * @param id the unique Id for this XMLType
221: **/
222: public void setId(String id) {
223: _id = id;
224: } //-- setId
225:
226: /**
227: * Sets the parent for this XMLType
228: *
229: * @param parent the parent Structure for this XMLType
230: **/
231: protected abstract void setParent(Structure parent);
232:
233: /**
234: * Returns the type this type "really" represents
235: * ("this" in most cases), provides the indirection needed by references
236: * and forward declarations.
237: * @return the type this type "really" represents
238: */
239: XMLType getType() {
240: return this ;
241: }
242:
243: } //-- XMLType
|