001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.axi.datatype;
043:
044: import java.util.Collections;
045: import java.util.List;
046: import org.netbeans.modules.xml.axi.AXIType;
047: import org.netbeans.modules.xml.axi.visitor.AXIVisitor;
048: import org.netbeans.modules.xml.schema.model.*;
049:
050: /**
051: * Class represents a datatype in AXI model, contains a reference its peer in
052: * schema ie., a simpleType (either a primitive datatype or a derived type)
053: *
054: * @author Ayub Khan
055: */
056: public abstract class Datatype implements AXIType {
057:
058: public enum Kind {
059: STRING("string"), NORMALIZED_STRING("normalizedString"), TOKEN(
060: "token"), LANGUAGE("language"), NAME("Name"), NMTOKEN(
061: "NMTOKEN"), NCNAME("NCName"), NMTOKENS("NMTOKENS"), ID(
062: "ID"), IDREF("IDREF"), ENTITY("ENTITY"), IDREFS(
063: "IDREFS"), ENTITIES("ENTITIES"), DECIMAL("decimal"), INTEGER(
064: "integer"), NON_POSITIVE_INTEGER("nonPositiveInteger"), LONG(
065: "long"), NON_NEGATIVE_INTEGER("nonNegativeInteger"), NEGATIVE_INTEGER(
066: "negativeInteger"), INT("int"), SHORT("short"), BYTE(
067: "byte"), UNSIGNED_LONG("unsignedLong"), UNSIGNED_INT(
068: "unsignedInt"), UNSIGNED_SHORT("unsignedShort"), UNSIGNED_BYTE(
069: "unsignedByte"), POSITIVE_INTEGER("positiveInteger"), DURATION(
070: "duration"), DATE_TIME("dateTime"), TIME("time"), DATE(
071: "date"), G_YEAR_MONTH("gYearMonth"), G_YEAR("gYear"), G_MONTH_DAY(
072: "gMonthDay"), G_DAY("gDay"), G_MONTH("gMonth"), BOOLEAN(
073: "boolean"), BASE64_BINARY("base64Binary"), HEX_BINARY(
074: "hexBinary"), FLOAT("float"), DOUBLE("double"), ANYURI(
075: "anyURI"), ANYTYPE("anyType"), QNAME("QName"), NOTATION(
076: "NOTATION"), UNION("UNION");
077:
078: String name;
079:
080: Kind(String name) {
081: this .name = name;
082: }
083:
084: public String getName() {
085: return name;
086: }
087: }
088:
089: public enum Facet {
090: LENGTH("length", Length.class), MINLENGTH("minLength",
091: MinLength.class), MAXLENGTH("maxLength",
092: MaxLength.class), PATTERN("pattern", Pattern.class), ENUMERATION(
093: "enumeration", Enumeration.class), WHITESPACE(
094: "whiteSpace", Whitespace.class), TOTATDIGITS(
095: "totalDigits", TotalDigits.class), FRACTIONDIGITS(
096: "fractionDigits", FractionDigits.class), MAXINCLUSIVE(
097: "maxInclusive", MaxInclusive.class), MAXEXCLUSIVE(
098: "maxExclusive", MaxExclusive.class), MININCLUSIVE(
099: "minInclusive", MinInclusive.class), MINEXCLUSIVE(
100: "minExclusive", MinExclusive.class);
101:
102: String name;
103: Class<? extends SchemaComponent> type;
104:
105: Facet(String name, Class<? extends SchemaComponent> type) {
106: this .name = name;
107: this .type = type;
108: }
109:
110: public String getName() {
111: return name;
112: }
113:
114: public Class<? extends SchemaComponent> getComponentType() {
115: return type;
116: }
117: }
118:
119: /*
120: * returns the kind of this datatype
121: *
122: * @return qName
123: */
124: public abstract Kind getKind();
125:
126: /*
127: * returns the name of this datatype
128: *
129: * @return name
130: */
131: public String getName() {
132: return getKind().getName();
133: }
134:
135: /**
136: * Allows a visitor to visit this Element.
137: */
138: public void accept(AXIVisitor visitor) {
139: visitor.visit(this );
140: }
141:
142: public abstract List<Facet> getApplicableFacets();
143:
144: public abstract boolean hasFacets();
145:
146: public abstract boolean isList();
147:
148: public abstract void setIsList(boolean b);
149:
150: public boolean isPrimitive() {
151: return !hasFacets() && !(this instanceof UnionType);
152: }
153:
154: /*
155: * returns pattern value (this corresponds to the value of pattern facet in schema)
156: *
157: * @return pattern
158: */
159: public List<? extends String> getPatterns() {
160: return Collections.emptyList();
161: }
162:
163: /*
164: * returns enumeration values (this corresponds to the values of enumeration facets in schema)
165: *
166: * @return enumeration
167: */
168: public List<? extends Object> getEnumerations() {
169: return Collections.emptyList();
170: }
171:
172: /*
173: * returns whitespace value (this corresponds to the value of whitespace facet in schema)
174: *
175: * @return whitespaces
176: */
177: public List<Whitespace.Treatment> getWhiteSpaces() {
178: return Collections.emptyList();
179: }
180:
181: /*
182: * returns total digits value (this corresponds to the value of totalDigits facet in schema)
183: *
184: * @return totalDigits
185: */
186: public List<? extends Number> getTotalDigits() {
187: return Collections.emptyList();
188: }
189:
190: /*
191: * returns fraction digits value (this corresponds to the value of fractionDigits facet in schema)
192: *
193: * @return fractionDigits
194: */
195: public List<? extends Number> getFractionDigits() {
196: return Collections.emptyList();
197: }
198:
199: /*
200: * returns maximum Inclusive value (this corresponds to the value of maxInclusive facet in schema)
201: *
202: * @return maxInclusive
203: */
204: public List<? extends Object> getMaxInclusives() {
205: return Collections.emptyList();
206: }
207:
208: /*
209: * returns maximum Exclusive value (this corresponds to the value of maxExclusive facet in schema)
210: *
211: * @return maxExclusive
212: */
213: public List<? extends Object> getMaxExclusives() {
214: return Collections.emptyList();
215: }
216:
217: /*
218: * returns minimum Inclusive value (this corresponds to the value of minInclusive facet in schema)
219: *
220: * @return minInclusive
221: */
222: public List<? extends Object> getMinInclusives() {
223: return Collections.emptyList();
224: }
225:
226: /*
227: * returns minExclusive value (this corresponds to the value of minExclusive facet in schema)
228: *
229: * @return minExclusive
230: */
231: public List<? extends Object> getMinExclusives() {
232: return Collections.emptyList();
233: }
234:
235: /*
236: * returns length (this corresponds to the value of length facet in schema)
237: *
238: * @return length
239: */
240: public List<? extends Number> getLengths() {
241: return Collections.emptyList();
242: }
243:
244: /*
245: * returns minimum length value (this corresponds to the value of minlength facet in schema)
246: *
247: * @return minLength
248: */
249: public List<? extends Number> getMinLengths() {
250: return Collections.emptyList();
251: }
252:
253: /*
254: * returns maximum length value (this corresponds to the value of maxlength facet in schema)
255: *
256: * @return maxLength
257: */
258: public List<? extends Number> getMaxLengths() {
259: return Collections.emptyList();
260: }
261:
262: /*
263: * set pattern value (this corresponds to the value of pattern facet in schema)
264: *
265: * @param pattern
266: */
267: public void addPattern(String pattern) {
268: }
269:
270: /*
271: * set enumeration values (this corresponds to the values of enumeration facets in schema)
272: *
273: * @param enumeration
274: */
275: public void addEnumeration(Object enumeration) {
276: }
277:
278: /*
279: * set whitespace value (this corresponds to the value of whitespace facet in schema)
280: *
281: * @param whitespace
282: */
283: public void addWhitespace(Whitespace.Treatment whitespace) {
284: }
285:
286: /*
287: * set total digits value (this corresponds to the value of totalDigits facet in schema)
288: *
289: * @param totalDigits
290: */
291: public void addTotalDigits(int totalDigits) {
292: }
293:
294: /*
295: * set fraction digits value (this corresponds to the value of fractionDigits facet in schema)
296: *
297: * @param fractionDigits
298: */
299: public void addFractionDigits(int fractionDigits) {
300: }
301:
302: /*
303: * set maximum Inclusive value (this corresponds to the value of maxInclusive facet in schema)
304: *
305: * @param maxInclusive
306: */
307: public void addMaxInclusive(Object maxInclusive) {
308: }
309:
310: /*
311: * set maximum Exclusive value (this corresponds to the value of maxExclusive facet in schema)
312: *
313: * @param maxExclusive
314: */
315: public void addMaxExclusive(Object maxExclusive) {
316: }
317:
318: /*
319: * set minimum Inclusive value (this corresponds to the value of minInclusive facet in schema)
320: *
321: * @param minInclusive
322: */
323: public void addMinInclusive(Object minInclusive) {
324: }
325:
326: /*
327: * set minExclusive value (this corresponds to the value of minExclusive facet in schema)
328: *
329: * @param minExclusive
330: */
331: public void addMinExclusive(Object minExclusive) {
332: }
333:
334: /*
335: * set length (this corresponds to the value of length facet in schema)
336: *
337: * @param length
338: */
339: public void addLength(int length) {
340: }
341:
342: /*
343: * set minimum length value (this corresponds to the value of minlength facet in schema)
344: *
345: * @param minLength
346: */
347: public void addMinLength(int minLength) {
348: }
349:
350: /*
351: * set maximum length value (this corresponds to the value of maxlength facet in schema)
352: *
353: * @param maxLength
354: */
355: public void addMaxLength(int maxLength) {
356: }
357:
358: /*
359: * remove pattern value (this corresponds to the value of pattern facet in schema)
360: *
361: * @param pattern
362: */
363: public void removePattern(String pattern) {
364: }
365:
366: /*
367: * remove enumeration values (this corresponds to the values of enumeration facets in schema)
368: *
369: * @param enumeration
370: */
371: public void removeEnumeration(Object enumeration) {
372: }
373:
374: /*
375: * remove whitespace value (this corresponds to the value of whitespace facet in schema)
376: *
377: * @param whitespace
378: */
379: public void removeWhitespace(Whitespace.Treatment whitespace) {
380: }
381:
382: /*
383: * remove total digits value (this corresponds to the value of totalDigits facet in schema)
384: *
385: * @param totalDigits
386: */
387: public void removeTotalDigits(Number totalDigits) {
388: }
389:
390: /*
391: * remove fraction digits value (this corresponds to the value of fractionDigits facet in schema)
392: *
393: * @param fractionDigits
394: */
395: public void removeFractionDigits(Number fractionDigits) {
396: }
397:
398: /*
399: * remove maximum Inclusive value (this corresponds to the value of maxInclusive facet in schema)
400: *
401: * @param maxInclusive
402: */
403: public void removeMaxInclusive(Object maxInclusive) {
404: }
405:
406: /*
407: * remove maximum Exclusive value (this corresponds to the value of maxExclusive facet in schema)
408: *
409: * @param maxExclusive
410: */
411: public void removeMaxExclusive(Object maxExclusive) {
412: }
413:
414: /*
415: * remove minimum Inclusive value (this corresponds to the value of minInclusive facet in schema)
416: *
417: * @param minInclusive
418: */
419: public void removeMinInclusive(Object minInclusive) {
420: }
421:
422: /*
423: * remove minExclusive value (this corresponds to the value of minExclusive facet in schema)
424: *
425: * @param minExclusive
426: */
427: public void removeMinExclusive(Object minExclusive) {
428: }
429:
430: /*
431: * remove length (this corresponds to the value of length facet in schema)
432: *
433: * @param length
434: */
435: public void removeLength(Number length) {
436: }
437:
438: /*
439: * remove minimum length value (this corresponds to the value of minlength facet in schema)
440: *
441: * @param minLength
442: */
443: public void removeMinLength(Number minLength) {
444: }
445:
446: /*
447: * remove maximum length value (this corresponds to the value of maxlength facet in schema)
448: *
449: * @param maxLength
450: */
451: public void removeMaxLength(Number maxLength) {
452: }
453:
454: public String toString() {
455: return getName();
456: }
457: }
|