001: /*
002: * Copyright 2007 Keith Visco, Ralf Joachim
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package org.exolab.castor.builder.types;
017:
018: import java.util.Enumeration;
019:
020: import org.exolab.castor.xml.schema.Facet;
021: import org.exolab.castor.xml.schema.SimpleType;
022: import org.exolab.javasource.JSourceCode;
023: import org.exolab.javasource.JType;
024:
025: /**
026: * The base XML Schema Type class.
027: *
028: * @author <a href="mailto:keith AT kvisco DOT com">Keith Visco</a>
029: * @author <a href="mailto:ralf DOT joachim AT syscon DOT eu">Ralf Joachim</a>
030: * @version $Revision: 6907 $ $Date: 2005-03-05 06:42:06 -0700 (Sat, 05 Mar 2005) $
031: */
032: public abstract class XSType {
033: //--------------------------------------------------------------------------
034:
035: // special types
036:
037: /** Value meaning the type is unassigned. */
038: public static final short NULL = -1;
039:
040: /** A user-defined type. */
041: public static final short CLASS = 0;
042:
043: // primitive types
044:
045: /** xsd:string. */
046: public static final short STRING_TYPE = 1;
047:
048: /** xsd:duration. */
049: public static final short DURATION_TYPE = 2;
050:
051: /** xsd:dateTime. */
052: public static final short DATETIME_TYPE = 3;
053:
054: /** xsd:time. */
055: public static final short TIME_TYPE = 4;
056:
057: /** xsd:date. */
058: public static final short DATE_TYPE = 5;
059:
060: /** xsd:gYearMonth. */
061: public static final short GYEARMONTH_TYPE = 6;
062:
063: /** xsd:gYear. */
064: public static final short GYEAR_TYPE = 7;
065:
066: /** xsd:gMonthDay. */
067: public static final short GMONTHDAY_TYPE = 8;
068:
069: /** xsd:gDay. */
070: public static final short GDAY_TYPE = 9;
071:
072: /** xsd:gMonth. */
073: public static final short GMONTH_TYPE = 10;
074:
075: /** xsd:boolean. */
076: public static final short BOOLEAN_TYPE = 11;
077:
078: /** xsd:base64Binary. */
079: public static final short BASE64BINARY_TYPE = 12;
080:
081: /** xsd:hexBinary. */
082: public static final short HEXBINARY_TYPE = 13;
083:
084: /** xsd:float. */
085: public static final short FLOAT_TYPE = 14;
086:
087: /** xsd:double. */
088: public static final short DOUBLE_TYPE = 15;
089:
090: /** xsd:decimal. */
091: public static final short DECIMAL_TYPE = 16;
092:
093: /** xsd:anyURI. */
094: public static final short ANYURI_TYPE = 17;
095:
096: /** xsd:QName. */
097: public static final short QNAME_TYPE = 18;
098:
099: /** xsd:notation. */
100: public static final short NOTATION_TYPE = 19;
101:
102: // derived types
103:
104: /** xsd:normalizedString. */
105: public static final short NORMALIZEDSTRING_TYPE = 20;
106:
107: /** xsd:token. */
108: public static final short TOKEN_TYPE = 21;
109:
110: /** xsd:language. */
111: public static final short LANGUAGE_TYPE = 22;
112:
113: /** xsd:name. */
114: public static final short NAME_TYPE = 23;
115:
116: /** xsd:NCNAME. */
117: public static final short NCNAME_TYPE = 24;
118:
119: /** xsd:ID. */
120: public static final short ID_TYPE = 25;
121:
122: /** xsd:IDREF. */
123: public static final short IDREF_TYPE = 26;
124:
125: /** xsd:IDREFS. */
126: public static final short IDREFS_TYPE = 27;
127:
128: /** xsd:ENTITY. */
129: public static final short ENTITY = 28;
130:
131: /** xsd:ENTITIES. */
132: public static final short ENTITIES = 29;
133:
134: /** xsd:NMTOKEN. */
135: public static final short NMTOKEN_TYPE = 30;
136:
137: /** xsd:NMTOKENS. */
138: public static final short NMTOKENS_TYPE = 31;
139:
140: /** xsd:integer. */
141: public static final short INTEGER_TYPE = 32;
142:
143: /** xsd:nonPositiveInteger. */
144: public static final short NON_POSITIVE_INTEGER_TYPE = 33;
145:
146: /** xsd:negativeInteger. */
147: public static final short NEGATIVE_INTEGER_TYPE = 34;
148:
149: /** xsd:long. */
150: public static final short LONG_TYPE = 35;
151:
152: /** xsd:int. */
153: public static final short INT_TYPE = 36;
154:
155: /** xsd:short. */
156: public static final short SHORT_TYPE = 37;
157:
158: /** xsd:byte. */
159: public static final short BYTE_TYPE = 38;
160:
161: /** xsd:nonNegativeInteger. */
162: public static final short NON_NEGATIVE_INTEGER_TYPE = 39;
163:
164: /** xsd:positiveInteger. */
165: public static final short POSITIVE_INTEGER_TYPE = 44;
166:
167: /** A collection type. */
168: public static final short COLLECTION = 45;
169:
170: /** xsd:unsignedLong. */
171: public static final short UNSIGNED_LONG_TYPE = 46;
172:
173: /** xsd:unsignedShort. */
174: public static final short UNSIGNED_SHORT_TYPE = 47;
175:
176: /** xsd:unsignedByte. */
177: public static final short UNSIGNED_BYTE_TYPE = 48;
178:
179: /** xsd:unsignedInt. */
180: public static final short UNSIGNED_INT_TYPE = 49;
181:
182: //--------------------------------------------------------------------------
183:
184: /** Flag signaling an enumerated type. */
185: private boolean _enumerated = false;
186:
187: //--------------------------------------------------------------------------
188:
189: /**
190: * Returns true if this XSType represents an enumerated type.
191: *
192: * @return True if this XSType represents an enumerated type.
193: */
194: public final boolean isEnumerated() {
195: return _enumerated;
196: }
197:
198: /**
199: * Sets the enumerated flag for this XSClass.
200: *
201: * @param enumerated A boolean indicating whether or not this XSClass represents an
202: * enumerated type.
203: */
204: public final void setAsEnumerated(final boolean enumerated) {
205: _enumerated = enumerated;
206: }
207:
208: //--------------------------------------------------------------------------
209:
210: /**
211: * Returns the name of this XSType.
212: *
213: * @return The name of this XSType.
214: */
215: public abstract String getName();
216:
217: /**
218: * Returns the type of this XSType.
219: *
220: * @return the type of this XSType.
221: */
222: public abstract short getType();
223:
224: /**
225: * Returns true if this XSType represents a primitive type.
226: *
227: * @return True if this XSType represents a primitive type.
228: */
229: public abstract boolean isPrimitive();
230:
231: /**
232: * Returns true if the XSType represents an XML Schema date/time type.
233: *
234: * @return True if the XSType represents an XML Schema date/time type.
235: */
236: public abstract boolean isDateTime();
237:
238: /**
239: * Returns true if this XSType represents a collection.
240: *
241: * @return True if this XSType represents a collection.
242: */
243: public boolean isCollection() {
244: return false;
245: }
246:
247: /**
248: * Returns the JType that this XSType represents.
249: *
250: * @return The JType that this XSType represents.
251: */
252: public abstract JType getJType();
253:
254: /**
255: * Returns the Java code neccessary to create a new instance of the JType
256: * associated with this XSType.
257: *
258: * @return The Java code neccessary to create a new instance.
259: */
260: public abstract String newInstanceCode();
261:
262: /**
263: * Returns the string necessary to convert an instance of this XSType to an
264: * Object. This method is really only useful for primitive types.
265: *
266: * @param variableName The name of the instance variable.
267: * @return The String necessary to convert an instance of this XSType to an Object.
268: */
269: public abstract String createToJavaObjectCode(
270: final String variableName);
271:
272: /**
273: * Returns the string necessary to convert an Object to an instance of this
274: * XSType. This method is really only useful for primitive types.
275: *
276: * @param variableName The name of the Object.
277: * @return The String necessary to convert an Object to an instance of this XSType.
278: */
279: public abstract String createFromJavaObjectCode(
280: final String variableName);
281:
282: //--------------------------------------------------------------------------
283:
284: /**
285: * Reads and sets the facets for XSType.
286: *
287: * @param simpleType The SimpleType containing the facets.
288: */
289: public final void setFacets(final SimpleType simpleType) {
290: Enumeration enumeration = simpleType.getLocalFacets();
291: while (enumeration.hasMoreElements()) {
292: setFacet((Facet) enumeration.nextElement());
293: }
294: }
295:
296: /**
297: * Set the given facet for XSType if applicable.
298: *
299: * @param facet The facet to set for XSType.
300: */
301: protected abstract void setFacet(final Facet facet);
302:
303: /**
304: * Creates the validation code for an instance of this XSType. If necessary the validation
305: * code should create a newly configured TypeValidator, that should then be added to a
306: * FieldValidator instance whose name is provided.
307: *
308: * @param jsc The JSourceCode to fill in.
309: * @param fixedValue A fixed value to use if any.
310: * @param validatorInstanceName The name of the FieldValidator that the configured
311: * TypeValidator should be added to.
312: */
313: public abstract void validationCode(final JSourceCode jsc,
314: final String fixedValue, final String validatorInstanceName);
315:
316: //--------------------------------------------------------------------------
317: }
|