| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.type; |
| 9 |
|
| 10 |
import com.saxonica.ee.schema.UserSimpleType; |
| 11 |
import net.sf.saxon.expr.Expression; |
| 12 |
import net.sf.saxon.expr.Literal; |
| 13 |
import net.sf.saxon.expr.StaticProperty; |
| 14 |
import net.sf.saxon.expr.instruct.ValueOf; |
| 15 |
import net.sf.saxon.lib.ConversionRules; |
| 16 |
import net.sf.saxon.lib.NamespaceConstant; |
| 17 |
import net.sf.saxon.om.*; |
| 18 |
import net.sf.saxon.trans.XPathException; |
| 19 |
import net.sf.saxon.value.*; |
| 20 |
|
| 21 |
import java.util.Collections; |
| 22 |
import java.util.HashMap; |
| 23 |
import java.util.Map; |
| 24 |
import java.util.Set; |
| 25 |
|
| 26 |
import static net.sf.saxon.type.SchemaComponent.ValidationStatus.VALIDATED; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public class BuiltInAtomicType implements AtomicType, ItemType.WithSequenceTypeCache { |
| 34 |
|
| 35 |
private int fingerprint; |
| 36 |
private int baseFingerprint; |
| 37 |
private int primitiveFingerprint; |
| 38 |
private UType uType; |
| 39 |
private String alphaCode; |
| 40 |
private boolean ordered = false; |
| 41 |
public StringConverter stringConverter; |
| 42 |
private SequenceType _one; |
| 43 |
private SequenceType _oneOrMore; |
| 44 |
private SequenceType _zeroOrOne; |
| 45 |
private SequenceType _zeroOrMore; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
private static Map<String, BuiltInAtomicType> lookupByAlphaCode = new HashMap<>(100); |
| 52 |
|
| 53 |
public final static BuiltInAtomicType ANY_ATOMIC = |
| 54 |
makeAtomicType(StandardNames.XS_ANY_ATOMIC_TYPE, AnySimpleType.getInstance(), "A", true); |
| 55 |
|
| 56 |
public final static BuiltInAtomicType STRING = |
| 57 |
makeAtomicType(StandardNames.XS_STRING, ANY_ATOMIC, "AS", true); |
| 58 |
|
| 59 |
public final static BuiltInAtomicType BOOLEAN = |
| 60 |
makeAtomicType(StandardNames.XS_BOOLEAN, ANY_ATOMIC, "AB", true); |
| 61 |
|
| 62 |
public final static BuiltInAtomicType DURATION = |
| 63 |
makeAtomicType(StandardNames.XS_DURATION, ANY_ATOMIC, "AR", false); |
| 64 |
|
| 65 |
public final static BuiltInAtomicType DATE_TIME = |
| 66 |
makeAtomicType(StandardNames.XS_DATE_TIME, ANY_ATOMIC, "AM", true); |
| 67 |
|
| 68 |
public final static BuiltInAtomicType DATE = |
| 69 |
makeAtomicType(StandardNames.XS_DATE, ANY_ATOMIC, "AA", true); |
| 70 |
|
| 71 |
public final static BuiltInAtomicType TIME = |
| 72 |
makeAtomicType(StandardNames.XS_TIME, ANY_ATOMIC, "AT", true); |
| 73 |
|
| 74 |
public final static BuiltInAtomicType G_YEAR_MONTH = |
| 75 |
makeAtomicType(StandardNames.XS_G_YEAR_MONTH, ANY_ATOMIC, "AH", false); |
| 76 |
|
| 77 |
public final static BuiltInAtomicType G_MONTH = |
| 78 |
makeAtomicType(StandardNames.XS_G_MONTH, ANY_ATOMIC, "AI", false); |
| 79 |
|
| 80 |
public final static BuiltInAtomicType G_MONTH_DAY = |
| 81 |
makeAtomicType(StandardNames.XS_G_MONTH_DAY, ANY_ATOMIC, "AJ", false); |
| 82 |
|
| 83 |
public final static BuiltInAtomicType G_YEAR = |
| 84 |
makeAtomicType(StandardNames.XS_G_YEAR, ANY_ATOMIC, "AG", false); |
| 85 |
|
| 86 |
public final static BuiltInAtomicType G_DAY = |
| 87 |
makeAtomicType(StandardNames.XS_G_DAY, ANY_ATOMIC, "AK", false); |
| 88 |
|
| 89 |
public final static BuiltInAtomicType HEX_BINARY = |
| 90 |
makeAtomicType(StandardNames.XS_HEX_BINARY, ANY_ATOMIC, "AX", true); |
| 91 |
|
| 92 |
public final static BuiltInAtomicType BASE64_BINARY = |
| 93 |
makeAtomicType(StandardNames.XS_BASE64_BINARY, ANY_ATOMIC, "A2", true); |
| 94 |
|
| 95 |
public final static BuiltInAtomicType ANY_URI = |
| 96 |
makeAtomicType(StandardNames.XS_ANY_URI, ANY_ATOMIC, "AU", true); |
| 97 |
|
| 98 |
public final static BuiltInAtomicType QNAME = |
| 99 |
makeAtomicType(StandardNames.XS_QNAME, ANY_ATOMIC, "AQ", false); |
| 100 |
|
| 101 |
public final static BuiltInAtomicType NOTATION = |
| 102 |
makeAtomicType(StandardNames.XS_NOTATION, ANY_ATOMIC, "AN", false); |
| 103 |
|
| 104 |
public final static BuiltInAtomicType UNTYPED_ATOMIC = |
| 105 |
makeAtomicType(StandardNames.XS_UNTYPED_ATOMIC, ANY_ATOMIC, "AZ", true); |
| 106 |
|
| 107 |
public final static BuiltInAtomicType DECIMAL = |
| 108 |
makeAtomicType(StandardNames.XS_DECIMAL, ANY_ATOMIC, "AD", true); |
| 109 |
|
| 110 |
public final static BuiltInAtomicType FLOAT = |
| 111 |
makeAtomicType(StandardNames.XS_FLOAT, ANY_ATOMIC, "AF", true); |
| 112 |
|
| 113 |
public final static BuiltInAtomicType DOUBLE = |
| 114 |
makeAtomicType(StandardNames.XS_DOUBLE, ANY_ATOMIC, "AO", true); |
| 115 |
|
| 116 |
public final static BuiltInAtomicType INTEGER = |
| 117 |
makeAtomicType(StandardNames.XS_INTEGER, DECIMAL, "ADI", true); |
| 118 |
|
| 119 |
public final static BuiltInAtomicType NON_POSITIVE_INTEGER = |
| 120 |
makeAtomicType(StandardNames.XS_NON_POSITIVE_INTEGER, INTEGER, "ADIN", true); |
| 121 |
|
| 122 |
public final static BuiltInAtomicType NEGATIVE_INTEGER = |
| 123 |
makeAtomicType(StandardNames.XS_NEGATIVE_INTEGER, NON_POSITIVE_INTEGER, "ADINN", true); |
| 124 |
|
| 125 |
public final static BuiltInAtomicType LONG = |
| 126 |
makeAtomicType(StandardNames.XS_LONG, INTEGER, "ADIL", true); |
| 127 |
|
| 128 |
public final static BuiltInAtomicType INT = |
| 129 |
makeAtomicType(StandardNames.XS_INT, LONG, "ADILI", true); |
| 130 |
|
| 131 |
public final static BuiltInAtomicType SHORT = |
| 132 |
makeAtomicType(StandardNames.XS_SHORT, INT, "ADILIS", true); |
| 133 |
|
| 134 |
public final static BuiltInAtomicType BYTE = |
| 135 |
makeAtomicType(StandardNames.XS_BYTE, SHORT, "ADILISB", true); |
| 136 |
|
| 137 |
public final static BuiltInAtomicType NON_NEGATIVE_INTEGER = |
| 138 |
makeAtomicType(StandardNames.XS_NON_NEGATIVE_INTEGER, INTEGER, "ADIP", true); |
| 139 |
|
| 140 |
public final static BuiltInAtomicType POSITIVE_INTEGER = |
| 141 |
makeAtomicType(StandardNames.XS_POSITIVE_INTEGER, NON_NEGATIVE_INTEGER, "ADIPP", true); |
| 142 |
|
| 143 |
public final static BuiltInAtomicType UNSIGNED_LONG = |
| 144 |
makeAtomicType(StandardNames.XS_UNSIGNED_LONG, NON_NEGATIVE_INTEGER, "ADIPL", true); |
| 145 |
|
| 146 |
public final static BuiltInAtomicType UNSIGNED_INT = |
| 147 |
makeAtomicType(StandardNames.XS_UNSIGNED_INT, UNSIGNED_LONG, "ADIPLI", true); |
| 148 |
|
| 149 |
public final static BuiltInAtomicType UNSIGNED_SHORT = |
| 150 |
makeAtomicType(StandardNames.XS_UNSIGNED_SHORT, UNSIGNED_INT, "ADIPLIS", true); |
| 151 |
|
| 152 |
public final static BuiltInAtomicType UNSIGNED_BYTE = |
| 153 |
makeAtomicType(StandardNames.XS_UNSIGNED_BYTE, UNSIGNED_SHORT, "ADIPLISB", true); |
| 154 |
|
| 155 |
public final static BuiltInAtomicType YEAR_MONTH_DURATION = |
| 156 |
makeAtomicType(StandardNames.XS_YEAR_MONTH_DURATION, DURATION, "ARY", true); |
| 157 |
|
| 158 |
public final static BuiltInAtomicType DAY_TIME_DURATION = |
| 159 |
makeAtomicType(StandardNames.XS_DAY_TIME_DURATION, DURATION, "ARD", true); |
| 160 |
|
| 161 |
public final static BuiltInAtomicType NORMALIZED_STRING = |
| 162 |
makeAtomicType(StandardNames.XS_NORMALIZED_STRING, STRING, "ASN", true); |
| 163 |
|
| 164 |
public final static BuiltInAtomicType TOKEN = |
| 165 |
makeAtomicType(StandardNames.XS_TOKEN, NORMALIZED_STRING, "ASNT", true); |
| 166 |
|
| 167 |
public final static BuiltInAtomicType LANGUAGE = |
| 168 |
makeAtomicType(StandardNames.XS_LANGUAGE, TOKEN, "ASNTL", true); |
| 169 |
|
| 170 |
public final static BuiltInAtomicType NAME = |
| 171 |
makeAtomicType(StandardNames.XS_NAME, TOKEN, "ASNTN", true); |
| 172 |
|
| 173 |
public final static BuiltInAtomicType NMTOKEN = |
| 174 |
makeAtomicType(StandardNames.XS_NMTOKEN, TOKEN, "ASNTK", true); |
| 175 |
|
| 176 |
public final static BuiltInAtomicType NCNAME = |
| 177 |
makeAtomicType(StandardNames.XS_NCNAME, NAME, "ASNTNC", true); |
| 178 |
|
| 179 |
public final static BuiltInAtomicType ID = |
| 180 |
makeAtomicType(StandardNames.XS_ID, NCNAME, "ASNTNCI", true); |
| 181 |
|
| 182 |
public final static BuiltInAtomicType IDREF = |
| 183 |
makeAtomicType(StandardNames.XS_IDREF, NCNAME, "ASNTNCR", true); |
| 184 |
|
| 185 |
public final static BuiltInAtomicType ENTITY = |
| 186 |
makeAtomicType(StandardNames.XS_ENTITY, NCNAME, "ASNTNCE", true); |
| 187 |
|
| 188 |
public final static BuiltInAtomicType DATE_TIME_STAMP = |
| 189 |
makeAtomicType(StandardNames.XS_DATE_TIME_STAMP, DATE_TIME, "AMP", true); |
| 190 |
|
| 191 |
static { |
| 192 |
|
| 193 |
ANY_ATOMIC .stringConverter = StringConverter.StringToString.INSTANCE; |
| 194 |
STRING .stringConverter = StringConverter.StringToString.INSTANCE; |
| 195 |
LANGUAGE .stringConverter = StringConverter.StringToLanguage.INSTANCE; |
| 196 |
NORMALIZED_STRING .stringConverter = StringConverter.StringToNormalizedString.INSTANCE; |
| 197 |
TOKEN .stringConverter = StringConverter.StringToToken.INSTANCE; |
| 198 |
NCNAME .stringConverter = StringConverter.StringToNCName.TO_NCNAME; |
| 199 |
NAME .stringConverter = StringConverter.StringToName.INSTANCE; |
| 200 |
NMTOKEN .stringConverter = StringConverter.StringToNMTOKEN.INSTANCE; |
| 201 |
ID .stringConverter = StringConverter.StringToNCName.TO_ID; |
| 202 |
IDREF .stringConverter = StringConverter.StringToNCName.TO_IDREF; |
| 203 |
ENTITY .stringConverter = StringConverter.StringToNCName.TO_ENTITY; |
| 204 |
DECIMAL .stringConverter = StringConverter.StringToDecimal.INSTANCE; |
| 205 |
INTEGER .stringConverter = StringConverter.StringToInteger.INSTANCE; |
| 206 |
DURATION .stringConverter = StringConverter.StringToDuration.INSTANCE; |
| 207 |
G_MONTH .stringConverter = StringConverter.StringToGMonth.INSTANCE; |
| 208 |
G_MONTH_DAY .stringConverter = StringConverter.StringToGMonthDay.INSTANCE; |
| 209 |
G_DAY .stringConverter = StringConverter.StringToGDay.INSTANCE; |
| 210 |
DAY_TIME_DURATION .stringConverter = StringConverter.StringToDayTimeDuration.INSTANCE; |
| 211 |
YEAR_MONTH_DURATION .stringConverter = StringConverter.StringToYearMonthDuration.INSTANCE; |
| 212 |
TIME .stringConverter = StringConverter.StringToTime.INSTANCE; |
| 213 |
BOOLEAN .stringConverter = StringConverter.StringToBoolean.INSTANCE; |
| 214 |
HEX_BINARY .stringConverter = StringConverter.StringToHexBinary.INSTANCE; |
| 215 |
BASE64_BINARY .stringConverter = StringConverter.StringToBase64Binary.INSTANCE; |
| 216 |
UNTYPED_ATOMIC .stringConverter = StringConverter.StringToUntypedAtomic.INSTANCE; |
| 217 |
|
| 218 |
NON_POSITIVE_INTEGER.stringConverter = new StringConverter.StringToIntegerSubtype(NON_POSITIVE_INTEGER); |
| 219 |
NEGATIVE_INTEGER .stringConverter = new StringConverter.StringToIntegerSubtype(NEGATIVE_INTEGER); |
| 220 |
LONG .stringConverter = new StringConverter.StringToIntegerSubtype(LONG); |
| 221 |
INT .stringConverter = new StringConverter.StringToIntegerSubtype(INT); |
| 222 |
SHORT .stringConverter = new StringConverter.StringToIntegerSubtype(SHORT); |
| 223 |
BYTE .stringConverter = new StringConverter.StringToIntegerSubtype(BYTE); |
| 224 |
NON_NEGATIVE_INTEGER.stringConverter = new StringConverter.StringToIntegerSubtype(NON_NEGATIVE_INTEGER); |
| 225 |
POSITIVE_INTEGER .stringConverter = new StringConverter.StringToIntegerSubtype(POSITIVE_INTEGER); |
| 226 |
UNSIGNED_LONG .stringConverter = new StringConverter.StringToIntegerSubtype(UNSIGNED_LONG); |
| 227 |
UNSIGNED_INT .stringConverter = new StringConverter.StringToIntegerSubtype(UNSIGNED_INT); |
| 228 |
UNSIGNED_SHORT .stringConverter = new StringConverter.StringToIntegerSubtype(UNSIGNED_SHORT); |
| 229 |
UNSIGNED_BYTE .stringConverter = new StringConverter.StringToIntegerSubtype(UNSIGNED_BYTE); |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
} |
| 235 |
|
| 236 |
private BuiltInAtomicType(int fingerprint) { |
| 237 |
this.fingerprint = fingerprint; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
public String getName() { |
| 249 |
return StandardNames.getLocalName(fingerprint); |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
public UType getUType() { |
| 259 |
return uType; |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
public String getTargetNamespace() { |
| 270 |
return NamespaceConstant.SCHEMA; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
public String getEQName() { |
| 279 |
return "Q{" + NamespaceConstant.SCHEMA + "}" + getName(); |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
public boolean isAbstract() { |
| 288 |
switch (fingerprint) { |
| 289 |
case StandardNames.XS_NOTATION: |
| 290 |
case StandardNames.XS_ANY_ATOMIC_TYPE: |
| 291 |
case StandardNames.XS_NUMERIC: |
| 292 |
case StandardNames.XS_ANY_SIMPLE_TYPE: |
| 293 |
return true; |
| 294 |
default: |
| 295 |
return false; |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
public boolean isExternalType() { |
| 305 |
return false; |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
public boolean isBuiltInType() { |
| 313 |
return true; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
public StructuredQName getTypeName() { |
| 325 |
return new StructuredQName( |
| 326 |
StandardNames.getPrefix(fingerprint), |
| 327 |
StandardNames.getURI(fingerprint), |
| 328 |
StandardNames.getLocalName(fingerprint) |
| 329 |
); |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
@Override |
| 340 |
public String getAlphaCode() { |
| 341 |
return alphaCode; |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
public SequenceType one() { |
| 351 |
if (_one == null) { |
| 352 |
_one = new SequenceType(this, StaticProperty.EXACTLY_ONE); |
| 353 |
} |
| 354 |
return _one; |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
public SequenceType zeroOrOne() { |
| 365 |
if (_zeroOrOne == null) { |
| 366 |
_zeroOrOne = new SequenceType(this, StaticProperty.ALLOWS_ZERO_OR_ONE); |
| 367 |
} |
| 368 |
return _zeroOrOne; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
public SequenceType oneOrMore() { |
| 379 |
if (_oneOrMore == null) { |
| 380 |
_oneOrMore = new SequenceType(this, StaticProperty.ALLOWS_ONE_OR_MORE); |
| 381 |
} |
| 382 |
return _oneOrMore; |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
public SequenceType zeroOrMore() { |
| 393 |
if (_zeroOrMore == null) { |
| 394 |
_zeroOrMore = new SequenceType(this, StaticProperty.ALLOWS_ZERO_OR_MORE); |
| 395 |
} |
| 396 |
return _zeroOrMore; |
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
public int getRedefinitionLevel() { |
| 410 |
return 0; |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
public boolean isOrdered(boolean optimistic) { |
| 424 |
return ordered || (optimistic && (this == DURATION || this == ANY_ATOMIC)); |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
public String getSystemId() { |
| 437 |
return null; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
public boolean isPrimitiveNumeric() { |
| 447 |
switch (getFingerprint()) { |
| 448 |
case StandardNames.XS_INTEGER: |
| 449 |
case StandardNames.XS_DECIMAL: |
| 450 |
case StandardNames.XS_DOUBLE: |
| 451 |
case StandardNames.XS_FLOAT: |
| 452 |
return true; |
| 453 |
default: |
| 454 |
return false; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
public final ValidationStatus getValidationStatus() { |
| 462 |
return VALIDATED; |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
public final int getBlock() { |
| 473 |
return 0; |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
public final int getDerivationMethod() { |
| 484 |
return SchemaType.DERIVATION_RESTRICTION; |
| 485 |
} |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
public final boolean allowsDerivation(int derivation) { |
| 496 |
return true; |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
public int getFinalProhibitions() { |
| 506 |
return 0; |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
public final void setBaseTypeFingerprint(int baseFingerprint) { |
| 516 |
this.baseFingerprint = baseFingerprint; |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
public final int getFingerprint() { |
| 526 |
return fingerprint; |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
public final StructuredQName getStructuredQName() { |
| 538 |
return new StructuredQName("xs", NamespaceConstant.SCHEMA, StandardNames.getLocalName(fingerprint)); |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
public String getDisplayName() { |
| 548 |
return StandardNames.getDisplayName(fingerprint); |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
public final boolean isPrimitiveType() { |
| 561 |
return Type.isPrimitiveAtomicType(fingerprint); |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
public final boolean isComplexType() { |
| 571 |
return false; |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
public final boolean isAnonymousType() { |
| 581 |
return false; |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
public boolean isPlainType() { |
| 591 |
return true; |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
public final SchemaType getBaseType() { |
| 605 |
if (baseFingerprint == -1) { |
| 606 |
return null; |
| 607 |
} else { |
| 608 |
return BuiltInType.getSchemaType(baseFingerprint); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
public boolean matches(Item item, TypeHierarchy th) { |
| 622 |
return item instanceof AtomicValue && Type.isSubType(((AtomicValue) item).getItemType(), this); |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
public BuiltInAtomicType getPrimitiveItemType() { |
| 636 |
if (isPrimitiveType()) { |
| 637 |
return this; |
| 638 |
} else { |
| 639 |
ItemType s = (ItemType) getBaseType(); |
| 640 |
assert s != null; |
| 641 |
if (s.isPlainType()) { |
| 642 |
return (BuiltInAtomicType)s.getPrimitiveItemType(); |
| 643 |
} else { |
| 644 |
return this; |
| 645 |
} |
| 646 |
} |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
public int getPrimitiveType() { |
| 659 |
return primitiveFingerprint; |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
public boolean isAllowedInXSD10() { |
| 669 |
return getFingerprint() != StandardNames.XS_DATE_TIME_STAMP; |
| 670 |
} |
| 671 |
|
| 672 |
public String toString() { |
| 673 |
return getDisplayName(); |
| 674 |
} |
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
public AtomicType getAtomizedItemType() { |
| 683 |
return this; |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
public boolean isAtomizable(TypeHierarchy th) { |
| 695 |
return true; |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
public SchemaType getKnownBaseType() { |
| 709 |
return getBaseType(); |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
public boolean isSameType(SchemaType other) { |
| 719 |
return other.getFingerprint() == getFingerprint(); |
| 720 |
} |
| 721 |
|
| 722 |
public String getDescription() { |
| 723 |
return getDisplayName(); |
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
public void checkTypeDerivationIsOK(SchemaType type, int block) throws SchemaException { |
| 736 |
if (type == AnySimpleType.getInstance()) { |
| 737 |
|
| 738 |
} else if (isSameType(type)) { |
| 739 |
|
| 740 |
} else { |
| 741 |
SchemaType base = getBaseType(); |
| 742 |
if (base == null) { |
| 743 |
throw new SchemaException("The type " + getDescription() + |
| 744 |
" is not validly derived from the type " + type.getDescription()); |
| 745 |
} |
| 746 |
try { |
| 747 |
base.checkTypeDerivationIsOK(type, block); |
| 748 |
} catch (SchemaException se) { |
| 749 |
throw new SchemaException("The type " + getDescription() + |
| 750 |
" is not validly derived from the type " + type.getDescription()); |
| 751 |
} |
| 752 |
} |
| 753 |
} |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
public final boolean isSimpleType() { |
| 762 |
return true; |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
public boolean isAtomicType() { |
| 772 |
return true; |
| 773 |
} |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
public boolean isIdType() { |
| 784 |
return fingerprint == StandardNames.XS_ID; |
| 785 |
} |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
public boolean isIdRefType() { |
| 794 |
return fingerprint == StandardNames.XS_IDREF; |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
public boolean isListType() { |
| 805 |
return false; |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
public boolean isUnionType() { |
| 815 |
return false; |
| 816 |
} |
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
public int getWhitespaceAction() { |
| 825 |
switch (getFingerprint()) { |
| 826 |
case StandardNames.XS_STRING: |
| 827 |
return Whitespace.PRESERVE; |
| 828 |
case StandardNames.XS_NORMALIZED_STRING: |
| 829 |
return Whitespace.REPLACE; |
| 830 |
default: |
| 831 |
return Whitespace.COLLAPSE; |
| 832 |
} |
| 833 |
} |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
public SchemaType getBuiltInBaseType() { |
| 842 |
BuiltInAtomicType base = this; |
| 843 |
while ((base != null) && (base.getFingerprint() > 1023)) { |
| 844 |
base = (BuiltInAtomicType) base.getBaseType(); |
| 845 |
} |
| 846 |
return base; |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
public boolean isNamespaceSensitive() { |
| 858 |
BuiltInAtomicType base = this; |
| 859 |
int fp = base.getFingerprint(); |
| 860 |
while (fp > 1023) { |
| 861 |
base = (BuiltInAtomicType) base.getBaseType(); |
| 862 |
assert base != null; |
| 863 |
fp = base.getFingerprint(); |
| 864 |
} |
| 865 |
|
| 866 |
return fp == StandardNames.XS_QNAME || fp == StandardNames.XS_NOTATION; |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
public ValidationFailure validateContent(CharSequence value, NamespaceResolver nsResolver, |
| 887 |
ConversionRules rules) { |
| 888 |
int f = getFingerprint(); |
| 889 |
if (f == StandardNames.XS_STRING || |
| 890 |
f == StandardNames.XS_ANY_SIMPLE_TYPE || |
| 891 |
f == StandardNames.XS_UNTYPED_ATOMIC || |
| 892 |
f == StandardNames.XS_ANY_ATOMIC_TYPE) { |
| 893 |
return null; |
| 894 |
} |
| 895 |
StringConverter converter = stringConverter; |
| 896 |
if (converter == null) { |
| 897 |
converter = getStringConverter(rules); |
| 898 |
if (isNamespaceSensitive()) { |
| 899 |
if (nsResolver == null) { |
| 900 |
throw new UnsupportedOperationException("Cannot validate a QName without a namespace resolver"); |
| 901 |
} |
| 902 |
converter = (StringConverter) converter.setNamespaceResolver(nsResolver); |
| 903 |
ConversionResult result = converter.convertString(value); |
| 904 |
if (result instanceof ValidationFailure) { |
| 905 |
return (ValidationFailure) result; |
| 906 |
} |
| 907 |
if (fingerprint == StandardNames.XS_NOTATION) { |
| 908 |
NotationValue nv = (NotationValue) result; |
| 909 |
|
| 910 |
|
| 911 |
if (!rules.isDeclaredNotation(nv.getNamespaceURI(), nv.getLocalName())) { |
| 912 |
return new ValidationFailure("Notation {" + nv.getNamespaceURI() + "}" + |
| 913 |
nv.getLocalName() + " is not declared in the schema"); |
| 914 |
} |
| 915 |
} |
| 916 |
return null; |
| 917 |
} |
| 918 |
} |
| 919 |
return converter.validate(value); |
| 920 |
} |
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
public StringConverter getStringConverter(ConversionRules rules) { |
| 932 |
if (stringConverter != null) { |
| 933 |
return stringConverter; |
| 934 |
} |
| 935 |
switch (fingerprint) { |
| 936 |
case StandardNames.XS_DOUBLE: |
| 937 |
case StandardNames.XS_NUMERIC: |
| 938 |
return rules.getStringToDoubleConverter(); |
| 939 |
case StandardNames.XS_FLOAT: |
| 940 |
return new StringConverter.StringToFloat(rules); |
| 941 |
case StandardNames.XS_DATE_TIME: |
| 942 |
return new StringConverter.StringToDateTime(rules); |
| 943 |
case StandardNames.XS_DATE_TIME_STAMP: |
| 944 |
return new StringConverter.StringToDateTimeStamp(rules); |
| 945 |
case StandardNames.XS_DATE: |
| 946 |
return new StringConverter.StringToDate(rules); |
| 947 |
case StandardNames.XS_G_YEAR: |
| 948 |
return new StringConverter.StringToGYear(rules); |
| 949 |
case StandardNames.XS_G_YEAR_MONTH: |
| 950 |
return new StringConverter.StringToGYearMonth(rules); |
| 951 |
case StandardNames.XS_ANY_URI: |
| 952 |
return new StringConverter.StringToAnyURI(rules); |
| 953 |
case StandardNames.XS_QNAME: |
| 954 |
return new StringConverter.StringToQName(rules); |
| 955 |
case StandardNames.XS_NOTATION: |
| 956 |
return new StringConverter.StringToNotation(rules); |
| 957 |
default: |
| 958 |
throw new AssertionError("No string converter available for " + this); |
| 959 |
} |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
public AtomicSequence atomize(NodeInfo node) throws XPathException { |
| 971 |
|
| 972 |
CharSequence stringValue = node.getStringValueCS(); |
| 973 |
if (stringValue.length() == 0 && node.isNilled()) { |
| 974 |
return AtomicArray.EMPTY_ATOMIC_ARRAY; |
| 975 |
} |
| 976 |
if (fingerprint == StandardNames.XS_STRING) { |
| 977 |
return StringValue.makeStringValue(stringValue); |
| 978 |
} else if (fingerprint == StandardNames.XS_UNTYPED_ATOMIC) { |
| 979 |
return new UntypedAtomicValue(stringValue); |
| 980 |
} |
| 981 |
StringConverter converter = stringConverter; |
| 982 |
if (converter == null) { |
| 983 |
converter = getStringConverter(node.getConfiguration().getConversionRules()); |
| 984 |
if (isNamespaceSensitive()) { |
| 985 |
converter = (StringConverter) converter.setNamespaceResolver(new InscopeNamespaceResolver(node)); |
| 986 |
} |
| 987 |
} |
| 988 |
return converter.convertString(stringValue).asAtomic(); |
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
public AtomicSequence getTypedValue(CharSequence value, NamespaceResolver resolver, ConversionRules rules) |
| 1009 |
throws ValidationException { |
| 1010 |
|
| 1011 |
if (fingerprint == StandardNames.XS_STRING) { |
| 1012 |
return StringValue.makeStringValue(value); |
| 1013 |
} else if (fingerprint == StandardNames.XS_UNTYPED_ATOMIC) { |
| 1014 |
return new UntypedAtomicValue(value); |
| 1015 |
} |
| 1016 |
StringConverter converter = getStringConverter(rules); |
| 1017 |
if (isNamespaceSensitive()) { |
| 1018 |
converter = (StringConverter) converter.setNamespaceResolver(resolver); |
| 1019 |
} |
| 1020 |
return converter.convertString(value).asAtomic(); |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
public boolean equals(Object obj) { |
| 1031 |
return obj instanceof BuiltInAtomicType && |
| 1032 |
getFingerprint() == ((BuiltInAtomicType) obj).getFingerprint(); |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
public int hashCode() { |
| 1040 |
return getFingerprint(); |
| 1041 |
} |
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
public ValidationFailure validate(AtomicValue primValue, CharSequence lexicalValue, ConversionRules rules) { |
| 1059 |
switch (fingerprint) { |
| 1060 |
case StandardNames.XS_NUMERIC: |
| 1061 |
case StandardNames.XS_STRING: |
| 1062 |
case StandardNames.XS_BOOLEAN: |
| 1063 |
case StandardNames.XS_DURATION: |
| 1064 |
case StandardNames.XS_DATE_TIME: |
| 1065 |
case StandardNames.XS_DATE: |
| 1066 |
case StandardNames.XS_TIME: |
| 1067 |
case StandardNames.XS_G_YEAR_MONTH: |
| 1068 |
case StandardNames.XS_G_MONTH: |
| 1069 |
case StandardNames.XS_G_MONTH_DAY: |
| 1070 |
case StandardNames.XS_G_YEAR: |
| 1071 |
case StandardNames.XS_G_DAY: |
| 1072 |
case StandardNames.XS_HEX_BINARY: |
| 1073 |
case StandardNames.XS_BASE64_BINARY: |
| 1074 |
case StandardNames.XS_ANY_URI: |
| 1075 |
case StandardNames.XS_QNAME: |
| 1076 |
case StandardNames.XS_NOTATION: |
| 1077 |
case StandardNames.XS_UNTYPED_ATOMIC: |
| 1078 |
case StandardNames.XS_DECIMAL: |
| 1079 |
case StandardNames.XS_FLOAT: |
| 1080 |
case StandardNames.XS_DOUBLE: |
| 1081 |
case StandardNames.XS_INTEGER: |
| 1082 |
return null; |
| 1083 |
case StandardNames.XS_NON_POSITIVE_INTEGER: |
| 1084 |
case StandardNames.XS_NEGATIVE_INTEGER: |
| 1085 |
case StandardNames.XS_LONG: |
| 1086 |
case StandardNames.XS_INT: |
| 1087 |
case StandardNames.XS_SHORT: |
| 1088 |
case StandardNames.XS_BYTE: |
| 1089 |
case StandardNames.XS_NON_NEGATIVE_INTEGER: |
| 1090 |
case StandardNames.XS_POSITIVE_INTEGER: |
| 1091 |
case StandardNames.XS_UNSIGNED_LONG: |
| 1092 |
case StandardNames.XS_UNSIGNED_INT: |
| 1093 |
case StandardNames.XS_UNSIGNED_SHORT: |
| 1094 |
case StandardNames.XS_UNSIGNED_BYTE: |
| 1095 |
return ((IntegerValue) primValue).validateAgainstSubType(this); |
| 1096 |
case StandardNames.XS_YEAR_MONTH_DURATION: |
| 1097 |
case StandardNames.XS_DAY_TIME_DURATION: |
| 1098 |
return null; |
| 1099 |
case StandardNames.XS_DATE_TIME_STAMP: |
| 1100 |
return ((CalendarValue) primValue).getTimezoneInMinutes() == CalendarValue.NO_TIMEZONE |
| 1101 |
? new ValidationFailure("xs:dateTimeStamp value must have a timezone") : null; |
| 1102 |
case StandardNames.XS_NORMALIZED_STRING: |
| 1103 |
case StandardNames.XS_TOKEN: |
| 1104 |
case StandardNames.XS_LANGUAGE: |
| 1105 |
case StandardNames.XS_NAME: |
| 1106 |
case StandardNames.XS_NMTOKEN: |
| 1107 |
case StandardNames.XS_NCNAME: |
| 1108 |
case StandardNames.XS_ID: |
| 1109 |
case StandardNames.XS_IDREF: |
| 1110 |
case StandardNames.XS_ENTITY: |
| 1111 |
return stringConverter.validate(primValue.getStringValueCS()); |
| 1112 |
default: |
| 1113 |
throw new IllegalArgumentException(); |
| 1114 |
} |
| 1115 |
} |
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
public void analyzeContentExpression(Expression expression, int kind) throws XPathException { |
| 1129 |
analyzeContentExpression(this, expression, kind); |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
public static void analyzeContentExpression(SimpleType simpleType, Expression expression, int kind) |
| 1145 |
throws XPathException { |
| 1146 |
if (kind == Type.ELEMENT) { |
| 1147 |
expression.checkPermittedContents(simpleType, true); |
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
} else if (kind == Type.ATTRIBUTE) { |
| 1158 |
|
| 1159 |
if (expression instanceof ValueOf || expression instanceof Literal) { |
| 1160 |
expression.checkPermittedContents(simpleType, true); |
| 1161 |
} |
| 1162 |
} |
| 1163 |
} |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
private static BuiltInAtomicType makeAtomicType(int fingerprint, SimpleType baseType, String code, boolean ordered) { |
| 1177 |
BuiltInAtomicType t = new BuiltInAtomicType(fingerprint); |
| 1178 |
t.setBaseTypeFingerprint(baseType.getFingerprint()); |
| 1179 |
if (t.isPrimitiveType()) { |
| 1180 |
t.primitiveFingerprint = fingerprint; |
| 1181 |
} else { |
| 1182 |
t.primitiveFingerprint = ((AtomicType) baseType).getPrimitiveType(); |
| 1183 |
} |
| 1184 |
t.uType = UType.fromTypeCode(t.primitiveFingerprint); |
| 1185 |
t.ordered = ordered; |
| 1186 |
t.alphaCode = code; |
| 1187 |
BuiltInType.register(fingerprint, t); |
| 1188 |
lookupByAlphaCode.put(code, t); |
| 1189 |
return t; |
| 1190 |
} |
| 1191 |
|
| 1192 |
public static BuiltInAtomicType getTypeWithAlphaCode(String alphaCode) { |
| 1193 |
return lookupByAlphaCode.get(alphaCode); |
| 1194 |
} |
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
public CharSequence preprocess(CharSequence input) { |
| 1205 |
return input; |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
public CharSequence postprocess(CharSequence input) { |
| 1219 |
return input; |
| 1220 |
} |
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
public Set<? extends PlainType> getPlainMemberTypes() { |
| 1230 |
return Collections.singleton(this); |
| 1231 |
} |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
public boolean isNumericType() { |
| 1239 |
ItemType p = getPrimitiveItemType(); |
| 1240 |
return p == NumericType.getInstance() || p == DECIMAL || |
| 1241 |
p == DOUBLE || p == FLOAT || |
| 1242 |
p == INTEGER; |
| 1243 |
} |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
@Override |
| 1255 |
public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) { |
| 1256 |
if (this == NOTATION) { |
| 1257 |
return "return false;"; |
| 1258 |
} |
| 1259 |
if (targetVersion == 1) { |
| 1260 |
return "return SaxonJS.U.Atomic." + getName() + ".matches(item);"; |
| 1261 |
} else if (targetVersion == 2) { |
| 1262 |
return "return SaxonJS.U.hasAtomicType(item, '" + getName() + "');"; |
| 1263 |
} else { |
| 1264 |
throw new IllegalArgumentException(); |
| 1265 |
} |
| 1266 |
} |
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
public String generateJavaScriptItemTypeAcceptor(String errorCode, int targetVersion) { |
| 1280 |
if (targetVersion == 1) { |
| 1281 |
return "return SaxonJS.U.Atomic." + getName() + ".cast(val);"; |
| 1282 |
} else if (targetVersion == 2) { |
| 1283 |
return "return SaxonJS.U.cast(val, '" + getName() + "');"; |
| 1284 |
} else { |
| 1285 |
throw new IllegalArgumentException(targetVersion+""); |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
public Function getComponentAsFunction() { |
| 1291 |
return UserSimpleType.getComponentAsFunction(this); |
| 1292 |
} |
| 1293 |
|
| 1294 |
|
| 1295 |
} |
| 1296 |
|