| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.type; |
| 9 |
|
| 10 |
import net.sf.saxon.lib.ConversionRules; |
| 11 |
import net.sf.saxon.om.NamespaceResolver; |
| 12 |
import net.sf.saxon.value.*; |
| 13 |
|
| 14 |
import java.math.BigDecimal; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public abstract class Converter { |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public static AtomicValue convert(AtomicValue value, AtomicType targetType, ConversionRules rules) |
| 43 |
throws ValidationException { |
| 44 |
Converter converter = rules.getConverter(value.getPrimitiveType(), targetType); |
| 45 |
if (converter == null) { |
| 46 |
ValidationFailure ve = new ValidationFailure("Cannot convert value from " + value.getPrimitiveType() + " to " + targetType); |
| 47 |
ve.setErrorCode("FORG0001"); |
| 48 |
throw ve.makeException(); |
| 49 |
} |
| 50 |
return converter.convert(value).asAtomic(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
private ConversionRules conversionRules; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
protected Converter() { |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
protected Converter(ConversionRules rules) { |
| 68 |
setConversionRules(rules); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public abstract ConversionResult convert(AtomicValue input); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public final void setConversionRules(ConversionRules rules) { |
| 93 |
this.conversionRules = rules; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public final ConversionRules getConversionRules() { |
| 104 |
return conversionRules; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public boolean isAlwaysSuccessful() { |
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
public Converter setNamespaceResolver(NamespaceResolver resolver) { |
| 127 |
return this; |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public NamespaceResolver getNamespaceResolver() { |
| 139 |
return null; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public static abstract class UnfailingConverter extends Converter { |
| 147 |
@Override |
| 148 |
public abstract AtomicValue convert(AtomicValue input); |
| 149 |
|
| 150 |
@Override |
| 151 |
public final boolean isAlwaysSuccessful() { |
| 152 |
return true; |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
public static class IdentityConverter extends Converter { |
| 161 |
public final static IdentityConverter INSTANCE = new IdentityConverter(); |
| 162 |
|
| 163 |
public ConversionResult convert(AtomicValue input) { |
| 164 |
return input; |
| 165 |
} |
| 166 |
|
| 167 |
public boolean isAlwaysSuccessful() { |
| 168 |
return true; |
| 169 |
} |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
public static class UpCastingConverter extends UnfailingConverter { |
| 181 |
private AtomicType newTypeAnnotation; |
| 182 |
|
| 183 |
public UpCastingConverter(AtomicType annotation) { |
| 184 |
this.newTypeAnnotation = annotation; |
| 185 |
} |
| 186 |
|
| 187 |
public AtomicValue convert( AtomicValue input) { |
| 188 |
return input.copyAsSubType(newTypeAnnotation); |
| 189 |
} |
| 190 |
|
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
public static class DownCastingConverter extends Converter { |
| 199 |
private AtomicType newType; |
| 200 |
|
| 201 |
public DownCastingConverter(AtomicType annotation, ConversionRules rules) { |
| 202 |
this.newType = annotation; |
| 203 |
setConversionRules(rules); |
| 204 |
} |
| 205 |
|
| 206 |
public AtomicType getTargetType() { |
| 207 |
return newType; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
public ConversionResult convert( AtomicValue input) { |
| 212 |
return convert(input, input.getCanonicalLexicalRepresentation()); |
| 213 |
} |
| 214 |
|
| 215 |
public ConversionResult convert(AtomicValue input, CharSequence lexicalForm) { |
| 216 |
ValidationFailure f = newType.validate(input, lexicalForm, getConversionRules()); |
| 217 |
if (f == null) { |
| 218 |
|
| 219 |
return input.copyAsSubType(newType); |
| 220 |
} else { |
| 221 |
|
| 222 |
return f; |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
public ValidationFailure validate(AtomicValue input, CharSequence lexicalForm) { |
| 227 |
return newType.validate(input, lexicalForm, getConversionRules()); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public static class TwoPhaseConverter extends Converter { |
| 236 |
private Converter phaseOne; |
| 237 |
private Converter phaseTwo; |
| 238 |
|
| 239 |
public TwoPhaseConverter(Converter phaseOne, Converter phaseTwo) { |
| 240 |
this.phaseOne = phaseOne; |
| 241 |
this.phaseTwo = phaseTwo; |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
public static TwoPhaseConverter makeTwoPhaseConverter( |
| 246 |
AtomicType inputType, AtomicType viaType, AtomicType outputType, ConversionRules rules) { |
| 247 |
return new TwoPhaseConverter( |
| 248 |
rules.getConverter(inputType, viaType), |
| 249 |
rules.getConverter(viaType, outputType)); |
| 250 |
} |
| 251 |
|
| 252 |
@Override |
| 253 |
public Converter setNamespaceResolver(NamespaceResolver resolver) { |
| 254 |
return new TwoPhaseConverter(phaseOne.setNamespaceResolver(resolver), phaseTwo.setNamespaceResolver(resolver)); |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
public ConversionResult convert(AtomicValue input) { |
| 259 |
ConversionResult temp = phaseOne.convert(input); |
| 260 |
if (temp instanceof ValidationFailure) { |
| 261 |
return temp; |
| 262 |
} |
| 263 |
AtomicValue aTemp = (AtomicValue)temp; |
| 264 |
if (phaseTwo instanceof DownCastingConverter) { |
| 265 |
return ((DownCastingConverter) phaseTwo).convert(aTemp, aTemp.getCanonicalLexicalRepresentation()); |
| 266 |
} else { |
| 267 |
return phaseTwo.convert(aTemp); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
public static class ToUntypedAtomicConverter extends UnfailingConverter { |
| 278 |
public static final ToUntypedAtomicConverter INSTANCE = new ToUntypedAtomicConverter(); |
| 279 |
public UntypedAtomicValue convert(AtomicValue input) { |
| 280 |
return new UntypedAtomicValue(input.getStringValueCS()); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
public static class ToStringConverter extends UnfailingConverter { |
| 289 |
public static final ToStringConverter INSTANCE = new ToStringConverter(); |
| 290 |
public StringValue convert(AtomicValue input) { |
| 291 |
return new StringValue(input.getStringValueCS()); |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
public static class NumericToFloat extends UnfailingConverter { |
| 300 |
public final static NumericToFloat INSTANCE = new NumericToFloat(); |
| 301 |
public FloatValue convert(AtomicValue input) { |
| 302 |
return new FloatValue(((NumericValue)input).getFloatValue()); |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
public static class BooleanToFloat extends UnfailingConverter { |
| 311 |
public final static BooleanToFloat INSTANCE = new BooleanToFloat(); |
| 312 |
public FloatValue convert(AtomicValue input) { |
| 313 |
return new FloatValue(((BooleanValue)input).getBooleanValue() ? 1.0f : 0.0f); |
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
public static class NumericToDouble extends UnfailingConverter { |
| 322 |
public static final NumericToDouble INSTANCE = new NumericToDouble(); |
| 323 |
public DoubleValue convert(AtomicValue input) { |
| 324 |
if (input instanceof DoubleValue) { |
| 325 |
return (DoubleValue)input; |
| 326 |
} else { |
| 327 |
return new DoubleValue(((NumericValue)input).getDoubleValue()); |
| 328 |
} |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
public static class BooleanToDouble extends UnfailingConverter { |
| 337 |
public final static BooleanToDouble INSTANCE = new BooleanToDouble(); |
| 338 |
public DoubleValue convert(AtomicValue input) { |
| 339 |
return new DoubleValue(((BooleanValue) input).getBooleanValue() ? 1.0e0 : 0.0e0); |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
public static class DoubleToDecimal extends Converter { |
| 348 |
public final static DoubleToDecimal INSTANCE = new DoubleToDecimal(); |
| 349 |
public ConversionResult convert(AtomicValue input) { |
| 350 |
try { |
| 351 |
return new BigDecimalValue(((DoubleValue) input).getDoubleValue()); |
| 352 |
} catch (ValidationException e) { |
| 353 |
return e.getValidationFailure(); |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
public static class FloatToDecimal extends Converter { |
| 363 |
public final static FloatToDecimal INSTANCE = new FloatToDecimal(); |
| 364 |
public ConversionResult convert(AtomicValue input) { |
| 365 |
try { |
| 366 |
return new BigDecimalValue(((FloatValue) input).getFloatValue()); |
| 367 |
} catch (ValidationException e) { |
| 368 |
return e.getValidationFailure(); |
| 369 |
} |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
public static class IntegerToDecimal extends UnfailingConverter { |
| 378 |
public final static IntegerToDecimal INSTANCE = new IntegerToDecimal(); |
| 379 |
public BigDecimalValue convert(AtomicValue input) { |
| 380 |
if (input instanceof Int64Value) { |
| 381 |
return new BigDecimalValue(((Int64Value) input).longValue()); |
| 382 |
} else { |
| 383 |
return new BigDecimalValue(((BigIntegerValue) input).asDecimal()); |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
public static class NumericToDecimal extends Converter { |
| 393 |
public final static NumericToDecimal INSTANCE = new NumericToDecimal(); |
| 394 |
public ConversionResult convert(AtomicValue input) { |
| 395 |
try { |
| 396 |
BigDecimal decimal = ((NumericValue) input).getDecimalValue(); |
| 397 |
return new BigDecimalValue(decimal); |
| 398 |
} catch (ValidationException e) { |
| 399 |
return e.getValidationFailure(); |
| 400 |
} |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
public static class BooleanToDecimal extends UnfailingConverter { |
| 409 |
public final static BooleanToDecimal INSTANCE = new BooleanToDecimal(); |
| 410 |
public BigDecimalValue convert(AtomicValue input) { |
| 411 |
return ((BooleanValue) input).getBooleanValue() ? BigDecimalValue.ONE : BigDecimalValue.ZERO; |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
public static class DoubleToInteger extends Converter { |
| 421 |
public final static DoubleToInteger INSTANCE = new DoubleToInteger(); |
| 422 |
public ConversionResult convert(AtomicValue input) { |
| 423 |
return IntegerValue.makeIntegerValue((DoubleValue)input); |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
public static class FloatToInteger extends Converter { |
| 432 |
public final static FloatToInteger INSTANCE = new FloatToInteger(); |
| 433 |
public ConversionResult convert(AtomicValue input) { |
| 434 |
return IntegerValue.makeIntegerValue(new DoubleValue(((FloatValue) input).getDoubleValue())); |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
public static class DecimalToInteger extends UnfailingConverter { |
| 444 |
public final static DecimalToInteger INSTANCE = new DecimalToInteger(); |
| 445 |
public IntegerValue convert(AtomicValue input) { |
| 446 |
if (input instanceof IntegerValue) { |
| 447 |
return (IntegerValue)input; |
| 448 |
} |
| 449 |
return BigIntegerValue.makeIntegerValue(((BigDecimalValue) input).getDecimalValue().toBigInteger()); |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
public static class NumericToInteger extends Converter { |
| 458 |
public final static NumericToInteger INSTANCE = new NumericToInteger(); |
| 459 |
public ConversionResult convert(AtomicValue input) { |
| 460 |
NumericValue in = (NumericValue) input; |
| 461 |
try { |
| 462 |
if (in instanceof IntegerValue) { |
| 463 |
return in; |
| 464 |
} else if (in instanceof DoubleValue) { |
| 465 |
return IntegerValue.makeIntegerValue((DoubleValue) in); |
| 466 |
} else if (in instanceof FloatValue) { |
| 467 |
return IntegerValue.makeIntegerValue(new DoubleValue(in.getDoubleValue())); |
| 468 |
} else { |
| 469 |
return BigIntegerValue.makeIntegerValue(in.getDecimalValue().toBigInteger()); |
| 470 |
} |
| 471 |
} catch (ValidationException e) { |
| 472 |
return e.getValidationFailure(); |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
public static class BooleanToInteger extends UnfailingConverter { |
| 482 |
public final static BooleanToInteger INSTANCE = new BooleanToInteger(); |
| 483 |
public Int64Value convert(AtomicValue input) { |
| 484 |
return ((BooleanValue) input).getBooleanValue() ? Int64Value.PLUS_ONE : Int64Value.ZERO; |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
public static class DurationToDayTimeDuration extends UnfailingConverter { |
| 493 |
public final static DurationToDayTimeDuration INSTANCE = new DurationToDayTimeDuration(); |
| 494 |
public DayTimeDurationValue convert(AtomicValue duration) { |
| 495 |
DurationValue d = (DurationValue)duration; |
| 496 |
if (d.signum() < 0) { |
| 497 |
return new DayTimeDurationValue(-d.getDays(), -d.getHours(), -d.getMinutes(), -d.getSeconds(), -d.getNanoseconds()); |
| 498 |
} else { |
| 499 |
return new DayTimeDurationValue(d.getDays(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getNanoseconds()); |
| 500 |
} |
| 501 |
} |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
public static class DurationToYearMonthDuration extends UnfailingConverter { |
| 509 |
public final static DurationToYearMonthDuration INSTANCE = new DurationToYearMonthDuration(); |
| 510 |
public YearMonthDurationValue convert(AtomicValue input) { |
| 511 |
return YearMonthDurationValue.fromMonths(((DurationValue) input).getTotalMonths()); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
public static class DateToDateTime extends UnfailingConverter { |
| 520 |
public final static DateToDateTime INSTANCE = new DateToDateTime(); |
| 521 |
public DateTimeValue convert(AtomicValue input) { |
| 522 |
return ((DateValue) input).toDateTime(); |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
public static class DateTimeToDate extends UnfailingConverter { |
| 531 |
public final static DateTimeToDate INSTANCE = new DateTimeToDate(); |
| 532 |
public DateValue convert(AtomicValue input) { |
| 533 |
DateTimeValue dt = (DateTimeValue)input; |
| 534 |
return new DateValue(dt.getYear(), dt.getMonth(), dt.getDay(), dt.getTimezoneInMinutes(), dt.isXsd10Rules()); |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
public static class DateTimeToGMonth extends UnfailingConverter { |
| 543 |
public static final DateTimeToGMonth INSTANCE = new DateTimeToGMonth(); |
| 544 |
public GMonthValue convert(AtomicValue input) { |
| 545 |
DateTimeValue dt = (DateTimeValue) input; |
| 546 |
return new GMonthValue(dt.getMonth(), dt.getTimezoneInMinutes()); |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
public static class DateTimeToGYearMonth extends UnfailingConverter { |
| 555 |
public static final DateTimeToGYearMonth INSTANCE = new DateTimeToGYearMonth(); |
| 556 |
public GYearMonthValue convert(AtomicValue input) { |
| 557 |
DateTimeValue dt = (DateTimeValue) input; |
| 558 |
return new GYearMonthValue(dt.getYear(), dt.getMonth(), dt.getTimezoneInMinutes(), dt.isXsd10Rules()); |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
public static class DateTimeToGYear extends UnfailingConverter { |
| 567 |
public static final DateTimeToGYear INSTANCE = new DateTimeToGYear(); |
| 568 |
public GYearValue convert(AtomicValue input) { |
| 569 |
DateTimeValue dt = (DateTimeValue) input; |
| 570 |
return new GYearValue(dt.getYear(), dt.getTimezoneInMinutes(), dt.isXsd10Rules()); |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
public static class DateTimeToGMonthDay extends UnfailingConverter { |
| 579 |
public static final DateTimeToGMonthDay INSTANCE = new DateTimeToGMonthDay(); |
| 580 |
public GMonthDayValue convert(AtomicValue input) { |
| 581 |
DateTimeValue dt = (DateTimeValue) input; |
| 582 |
return new GMonthDayValue(dt.getMonth(), dt.getDay(), dt.getTimezoneInMinutes()); |
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
public static class DateTimeToGDay extends UnfailingConverter { |
| 591 |
public final static DateTimeToGDay INSTANCE = new DateTimeToGDay(); |
| 592 |
public GDayValue convert(AtomicValue input) { |
| 593 |
DateTimeValue dt = (DateTimeValue) input; |
| 594 |
return new GDayValue(dt.getDay(), dt.getTimezoneInMinutes()); |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
public static class DateTimeToTime extends UnfailingConverter { |
| 603 |
public final static DateTimeToTime INSTANCE = new DateTimeToTime(); |
| 604 |
public TimeValue convert(AtomicValue input) { |
| 605 |
DateTimeValue dt = (DateTimeValue) input; |
| 606 |
return new TimeValue(dt.getHour(), dt.getMinute(), dt.getSecond(), dt.getNanosecond(), dt.getTimezoneInMinutes(), ""); |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
public static class NumericToBoolean extends UnfailingConverter { |
| 615 |
public static final NumericToBoolean INSTANCE = new NumericToBoolean(); |
| 616 |
public BooleanValue convert(AtomicValue input) { |
| 617 |
return BooleanValue.get(((NumericValue)input).effectiveBooleanValue()); |
| 618 |
} |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
public static class Base64BinaryToHexBinary extends UnfailingConverter { |
| 626 |
public static final Base64BinaryToHexBinary INSTANCE = new Base64BinaryToHexBinary(); |
| 627 |
public HexBinaryValue convert(AtomicValue input) { |
| 628 |
return new HexBinaryValue(((Base64BinaryValue)input).getBinaryValue()); |
| 629 |
} |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
public static class HexBinaryToBase64Binary extends UnfailingConverter { |
| 638 |
public static final HexBinaryToBase64Binary INSTANCE = new HexBinaryToBase64Binary(); |
| 639 |
public Base64BinaryValue convert(AtomicValue input) { |
| 640 |
return new Base64BinaryValue(((HexBinaryValue)input).getBinaryValue()); |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
public static class NotationToQName extends UnfailingConverter { |
| 649 |
public static final NotationToQName INSTANCE = new NotationToQName(); |
| 650 |
public QNameValue convert(AtomicValue input) { |
| 651 |
return new QNameValue(((NotationValue)input).getStructuredQName(), BuiltInAtomicType.QNAME); |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
public static class QNameToNotation extends UnfailingConverter { |
| 660 |
public static final QNameToNotation INSTANCE = new QNameToNotation(); |
| 661 |
public NotationValue convert(AtomicValue input) { |
| 662 |
return new NotationValue(((QNameValue)input).getStructuredQName(), BuiltInAtomicType.NOTATION); |
| 663 |
} |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
public static class PromoterToDouble extends Converter { |
| 671 |
|
| 672 |
private StringConverter stringToDouble = null; |
| 673 |
|
| 674 |
|
| 675 |
@Override |
| 676 |
public ConversionResult convert(AtomicValue input) { |
| 677 |
if (input instanceof DoubleValue) { |
| 678 |
return input; |
| 679 |
} else if (input instanceof NumericValue) { |
| 680 |
return new DoubleValue(((NumericValue) input).getDoubleValue()); |
| 681 |
} else if (input instanceof UntypedAtomicValue) { |
| 682 |
if (stringToDouble == null) { |
| 683 |
stringToDouble = BuiltInAtomicType.DOUBLE.getStringConverter(getConversionRules()); |
| 684 |
} |
| 685 |
return stringToDouble.convert((UntypedAtomicValue)input); |
| 686 |
} else { |
| 687 |
ValidationFailure err = new ValidationFailure( |
| 688 |
"Cannot promote non-numeric value to xs:double"); |
| 689 |
err.setErrorCode("XPTY0004"); |
| 690 |
return err; |
| 691 |
} |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
public static class PromoterToFloat extends Converter { |
| 700 |
|
| 701 |
private StringConverter stringToFloat = null; |
| 702 |
|
| 703 |
|
| 704 |
@Override |
| 705 |
public ConversionResult convert( AtomicValue input) { |
| 706 |
if (input instanceof FloatValue) { |
| 707 |
return input; |
| 708 |
} else if (input instanceof DoubleValue) { |
| 709 |
ValidationFailure err = new ValidationFailure( |
| 710 |
"Cannot promote from xs:double to xs:float"); |
| 711 |
err.setErrorCode("XPTY0004"); |
| 712 |
return err; |
| 713 |
} else if (input instanceof NumericValue) { |
| 714 |
return new FloatValue((float) ((NumericValue) input).getDoubleValue()); |
| 715 |
} else if (input instanceof UntypedAtomicValue) { |
| 716 |
if (stringToFloat == null) { |
| 717 |
stringToFloat = BuiltInAtomicType.FLOAT.getStringConverter(getConversionRules()); |
| 718 |
} |
| 719 |
return stringToFloat.convert((UntypedAtomicValue)input); |
| 720 |
} else { |
| 721 |
ValidationFailure err = new ValidationFailure( |
| 722 |
"Cannot promote non-numeric value to xs:double"); |
| 723 |
err.setErrorCode("XPTY0004"); |
| 724 |
return err; |
| 725 |
} |
| 726 |
} |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
} |
| 731 |
|