16 package org.zorbaxquery.api.xqj;
19 import javax.xml.namespace.QName;
20 import javax.xml.xquery.XQException;
21 import javax.xml.xquery.XQSequenceType;
22 import org.zorbaxquery.api.IdentTypes.Kind;
23 import org.zorbaxquery.api.Item;
24 import org.zorbaxquery.api.TypeIdentifier;
47 private int itemKind = 0;
48 private int baseType = 0;
49 private QName nodeName = null;
50 private QName typeName = null;
51 private URI schemaURI = null;
52 private boolean allowNill =
false;
53 private String piTarget = null;
56 TypeIdentifier result = null;
58 case XQITEMKIND_ATOMIC:
59 result = TypeIdentifier.createEmptyType();
61 case XQITEMKIND_ATTRIBUTE:
62 result = TypeIdentifier.createAttributeType(schemaURI.toString(),
true, nodeName.getLocalPart(),
true, TypeIdentifier.createAnyNodeType());
64 case XQITEMKIND_COMMENT:
65 result = TypeIdentifier.createCommentType();
67 case XQITEMKIND_DOCUMENT:
68 case XQITEMKIND_DOCUMENT_ELEMENT:
69 case XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT:
70 result = TypeIdentifier.createDocumentType();
72 case XQITEMKIND_ELEMENT:
73 result = TypeIdentifier.createElementType(schemaURI.toString(),
true, nodeName.getLocalPart(),
true, TypeIdentifier.createAnyNodeType());
76 result = TypeIdentifier.createItemType();
79 result = TypeIdentifier.createAnyNodeType();
82 result = TypeIdentifier.createPIType();
85 result = TypeIdentifier.createTextType();
87 case XQITEMKIND_SCHEMA_ATTRIBUTE:
88 case XQITEMKIND_SCHEMA_ELEMENT:
90 throw new XQException(
"Item kind is not valid.");
97 switch (typeIdentifier.getKind()) {
98 case Kind.ANY_NODE_TYPE:
99 itemKind = XQITEMKIND_NODE;
101 case Kind.ATTRIBUTE_TYPE:
102 itemKind = XQITEMKIND_ATTRIBUTE;
104 case Kind.COMMENT_TYPE:
105 itemKind = XQITEMKIND_COMMENT;
107 case Kind.DOCUMENT_TYPE:
108 itemKind = XQITEMKIND_DOCUMENT;
110 case Kind.ELEMENT_TYPE:
111 itemKind = XQITEMKIND_ELEMENT;
113 case Kind.EMPTY_TYPE:
114 case Kind.INVALID_TYPE:
116 case Kind.NAMED_TYPE:
117 itemKind = XQITEMKIND_ITEM;
120 itemKind = XQITEMKIND_PI;
123 itemKind = XQITEMKIND_TEXT;
126 itemKind = XQITEMKIND_NODE;
130 String type = typeIdentifier.getLocalName();
132 if (type.indexOf(
"anyAtomicType")>=0){
134 }
else if (type.indexOf(
"anySimpleType")>=0){
136 }
else if (type.indexOf(
"anyType")>=0){
138 }
else if (type.indexOf(
"anyURI")>=0){
140 }
else if (type.indexOf(
"base64Binary")>=0){
142 }
else if (type.indexOf(
"boolean")>=0){
144 }
else if (type.indexOf(
"byte")>=0){
146 }
else if (type.indexOf(
"dateTime")>=0){
148 }
else if (type.indexOf(
"date")>=0){
150 }
else if (type.indexOf(
"dayTimeDuration")>=0){
152 }
else if (type.indexOf(
"decimal")>=0){
154 }
else if (type.indexOf(
"double")>=0){
156 }
else if (type.indexOf(
"duration")>=0){
158 }
else if (type.indexOf(
"ENTITIES")>=0){
160 }
else if (type.indexOf(
"ENTITY")>=0){
162 }
else if (type.indexOf(
"float")>=0){
164 }
else if (type.indexOf(
"gDay")>=0){
166 }
else if (type.indexOf(
"gMonthDay")>=0){
168 }
else if (type.indexOf(
"gMonth")>=0){
170 }
else if (type.indexOf(
"gYear")>=0){
172 }
else if (type.indexOf(
"hexBinary")>=0){
174 }
else if (type.indexOf(
"IDREFS")>=0){
176 }
else if (type.indexOf(
"IDREF")>=0){
178 }
else if (type.indexOf(
"ID")>=0){
180 }
else if (type.indexOf(
"integer")>=0){
182 }
else if (type.indexOf(
"int")>=0){
184 }
else if (type.indexOf(
"language")>=0){
186 }
else if (type.indexOf(
"long")>=0){
188 }
else if (type.indexOf(
"QName")>=0){
190 }
else if (type.indexOf(
"NCName")>=0){
192 }
else if (type.indexOf(
"Name")>=0){
194 }
else if (type.indexOf(
"negativeInteger")>=0){
196 }
else if (type.indexOf(
"NMTOKENS")>=0){
198 }
else if (type.indexOf(
"NMTOKEN")>=0){
200 }
else if (type.indexOf(
"nonNegativeInteger")>=0){
202 }
else if (type.indexOf(
"nonPositiveInteger")>=0){
204 }
else if (type.indexOf(
"normalizedString")>=0){
206 }
else if (type.indexOf(
"NOTATION")>=0){
208 }
else if (type.indexOf(
"positiveInteger")>=0){
210 }
else if (type.indexOf(
"short")>=0){
212 }
else if (type.indexOf(
"string")>=0){
214 }
else if (type.indexOf(
"time")>=0){
216 }
else if (type.indexOf(
"token")>=0){
218 }
else if (type.indexOf(
"unsignedByte")>=0){
220 }
else if (type.indexOf(
"unsignedInt")>=0){
222 }
else if (type.indexOf(
"unsignedLong")>=0){
224 }
else if (type.indexOf(
"unsignedShort")>=0){
226 }
else if (type.indexOf(
"untypedAtomic")>=0){
228 }
else if (type.indexOf(
"untyped")>=0){
230 }
else if (type.indexOf(
"yearMonthDuration")>=0){
238 if (zorbaItem.isNode()) {
239 switch (zorbaItem.getNodeKind()) {
241 itemKind = XQITEMKIND_ELEMENT;
244 itemKind = XQITEMKIND_ATTRIBUTE;
247 itemKind = XQITEMKIND_COMMENT;
250 itemKind = XQITEMKIND_DOCUMENT;
253 itemKind = XQITEMKIND_ELEMENT;
256 itemKind = XQITEMKIND_PI;
259 itemKind = XQITEMKIND_TEXT;
262 itemKind = XQITEMKIND_ELEMENT;
266 }
else if (zorbaItem.isAtomic()) {
267 itemKind = XQITEMKIND_ATOMIC;
268 type = zorbaItem.getType().getStringValue();
271 if (type.indexOf(
"anyAtomicType")>=0){
273 }
else if (type.indexOf(
"anySimpleType")>=0){
275 }
else if (type.indexOf(
"anyType")>=0){
277 }
else if (type.indexOf(
"anyURI")>=0){
279 }
else if (type.indexOf(
"base64Binary")>=0){
281 }
else if (type.indexOf(
"boolean")>=0){
283 }
else if (type.indexOf(
"byte")>=0){
285 }
else if (type.indexOf(
"dateTime")>=0){
287 }
else if (type.indexOf(
"date")>=0){
289 }
else if (type.indexOf(
"dayTimeDuration")>=0){
291 }
else if (type.indexOf(
"decimal")>=0){
293 }
else if (type.indexOf(
"double")>=0){
295 }
else if (type.indexOf(
"duration")>=0){
297 }
else if (type.indexOf(
"ENTITIES")>=0){
299 }
else if (type.indexOf(
"ENTITY")>=0){
301 }
else if (type.indexOf(
"float")>=0){
303 }
else if (type.indexOf(
"gDay")>=0){
305 }
else if (type.indexOf(
"gMonthDay")>=0){
307 }
else if (type.indexOf(
"gMonth")>=0){
309 }
else if (type.indexOf(
"gYear")>=0){
311 }
else if (type.indexOf(
"hexBinary")>=0){
313 }
else if (type.indexOf(
"IDREFS")>=0){
315 }
else if (type.indexOf(
"IDREF")>=0){
317 }
else if (type.indexOf(
"ID")>=0){
319 }
else if (type.indexOf(
"integer")>=0){
321 }
else if (type.indexOf(
"int")>=0){
323 }
else if (type.indexOf(
"language")>=0){
325 }
else if (type.indexOf(
"long")>=0){
327 }
else if (type.indexOf(
"QName")>=0){
329 }
else if (type.indexOf(
"NCName")>=0){
331 }
else if (type.indexOf(
"Name")>=0){
333 }
else if (type.indexOf(
"negativeInteger")>=0){
335 }
else if (type.indexOf(
"NMTOKENS")>=0){
337 }
else if (type.indexOf(
"NMTOKEN")>=0){
339 }
else if (type.indexOf(
"nonNegativeInteger")>=0){
341 }
else if (type.indexOf(
"nonPositiveInteger")>=0){
343 }
else if (type.indexOf(
"normalizedString")>=0){
345 }
else if (type.indexOf(
"NOTATION")>=0){
347 }
else if (type.indexOf(
"positiveInteger")>=0){
349 }
else if (type.indexOf(
"short")>=0){
351 }
else if (type.indexOf(
"string")>=0){
353 }
else if (type.indexOf(
"time")>=0){
355 }
else if (type.indexOf(
"token")>=0){
357 }
else if (type.indexOf(
"unsignedByte")>=0){
359 }
else if (type.indexOf(
"unsignedInt")>=0){
361 }
else if (type.indexOf(
"unsignedLong")>=0){
363 }
else if (type.indexOf(
"unsignedShort")>=0){
365 }
else if (type.indexOf(
"untypedAtomic")>=0){
367 }
else if (type.indexOf(
"untyped")>=0){
369 }
else if (type.indexOf(
"yearMonthDuration")>=0){
376 this.itemKind = itemkind;
377 this.piTarget = piTarget;
381 this.itemKind = itemkind;
385 this.itemKind = itemkind;
386 this.baseType = basetype;
390 this.itemKind = itemkind;
391 this.nodeName = nodename;
392 this.baseType = basetype;
395 public ZorbaXQItemType(
int itemkind, QName nodename,
int basetype, QName
typename, URI schemaURI,
boolean allowNill)
throws XQException {
396 this.itemKind = itemkind;
397 this.nodeName = nodename;
398 this.baseType = basetype;
399 this.typeName =
typename;
400 this.schemaURI = schemaURI;
401 this.allowNill = allowNill;
403 public ZorbaXQItemType(
int itemkind, QName nodename,
int basetype, URI schemaURI)
throws XQException {
404 this.itemKind = itemkind;
405 this.nodeName = nodename;
406 this.baseType = basetype;
407 this.schemaURI = schemaURI;
412 private void generateTypeName() {
413 String namespaceURI =
"http://www.w3.org/2001/XMLSchema";
414 String localPart =
"untyped";
419 localPart =
"anyAtomicType";
422 localPart =
"anySimpleType";
425 localPart =
"anyType";
428 localPart =
"anyURI";
431 localPart =
"base64Binary";
434 localPart =
"boolean";
443 localPart =
"dateTime";
446 localPart =
"dayTimeDuration";
449 localPart =
"decimal";
452 localPart =
"double";
455 localPart =
"duration";
458 localPart =
"ENTITIES";
461 localPart =
"ENTITY";
470 localPart =
"gMonth";
473 localPart =
"gMonthDay";
479 localPart =
"gYearMonth";
482 localPart =
"hexBinary";
491 localPart =
"IDREFS";
497 localPart =
"integer";
500 localPart =
"language";
509 localPart =
"NCName";
512 localPart =
"negativeInteger";
515 localPart =
"NMTOKEN";
518 localPart =
"NMTOKENS";
521 localPart =
"nonNegativeInteger";
524 localPart =
"nonPositiveInteger";
527 localPart =
"normalizedString";
530 localPart =
"NOTATION";
533 localPart =
"positiveInteger";
542 localPart =
"string";
551 localPart =
"unsignedByte";
554 localPart =
"unsignedInt";
557 localPart =
"unsignedLong";
560 localPart =
"unsignedShort";
563 localPart =
"untyped";
566 localPart =
"untypedAtomic";
569 localPart =
"yearMonthDuration";
572 localPart =
"untyped";
575 typeName =
new QName(namespaceURI, localPart, prefix);
596 throw new XQException(
"Item kind is not valid for a Base Type.");
620 return XQSequenceType.OCC_EXACTLY_ONE;
638 throw new XQException(
"Item kind is not valid for a Type Name.");
670 throw new XQException(
"Item kind is not valid for a Type Name.");
681 return (itemKind==0);
703 throw new XQException(
"Item kind is not a PI.");
736 boolean result =
false;
737 boolean supportBaseType =
false;
738 boolean supportNodeName =
false;
739 boolean supportTypeName =
false;
740 boolean supportPIName =
false;
748 }
catch (Exception e) {
749 supportBaseType =
true;
753 }
catch (Exception e) {
754 supportNodeName =
true;
758 }
catch (Exception e) {
759 supportTypeName =
true;
763 }
catch (Exception e) {
764 supportPIName =
true;
768 result = supportBaseType && supportNodeName && supportTypeName && supportPIName;
800 hashCode = 31*hashCode + this.
getSchemaURI().hashCode();
804 hashCode = 31*hashCode + basetype;
805 }
catch (Exception e) {}
808 if (nodename!=null) {
809 hashCode = 31*hashCode + nodename.hashCode();
811 }
catch (Exception e) {}
814 hashCode = 31*hashCode +
typename.hashCode();
815 }
catch(Exception e) {}
818 if (piname != null) {
819 hashCode = 31*hashCode + piname.hashCode();
821 }
catch (Exception e) {}
831 StringBuffer result =
new StringBuffer();
834 for (java.lang.reflect.Field field:
ZorbaXQItemType.class.getFields()) {
835 if (field.getName().startsWith(
"XQITEMKIND_")) {
836 if (field.getInt(
this)==itemKind) {
837 result.append(
"Item Kind: ").append(field.getName().substring(11));
840 if (field.getName().startsWith(
"XQBASETYPE_")) {
841 if (field.getInt(
this)==baseType) {
842 result.append(
" Base Type: ").append(field.getName().substring(11));
846 }
catch (Exception e){
847 result.append(
"Item Kind or Base Type error: ").append(e.getLocalizedMessage());
850 return result.toString();