1 3 9 10 package javax.xml.datatype; 11 12 import java.math.BigInteger ; 13 import java.math.BigDecimal ; 14 import java.util.GregorianCalendar ; 15 16 48 public abstract class DatatypeFactory { 49 50 55 public static final String DATATYPEFACTORY_PROPERTY = "javax.xml.datatype.DatatypeFactory"; 56 57 62 public static final String DATATYPEFACTORY_IMPLEMENTATION_CLASS = "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl"; 63 64 69 protected DatatypeFactory() { 70 } 71 72 83 public static DatatypeFactory newInstance() 84 throws DatatypeConfigurationException { 85 86 try { 87 return (DatatypeFactory ) FactoryFinder.find( 88 89 DATATYPEFACTORY_PROPERTY, 90 91 DATATYPEFACTORY_IMPLEMENTATION_CLASS); 92 } catch (FactoryFinder.ConfigurationError e) { 93 throw new DatatypeConfigurationException (e.getMessage(), e.getException()); 94 } 95 } 96 97 125 public abstract Duration newDuration(final String lexicalRepresentation); 126 127 162 public abstract Duration newDuration(final long durationInMilliSeconds); 163 164 189 public abstract Duration newDuration( 190 final boolean isPositive, 191 final BigInteger years, 192 final BigInteger months, 193 final BigInteger days, 194 final BigInteger hours, 195 final BigInteger minutes, 196 final BigDecimal seconds); 197 198 226 public Duration newDuration( 227 final boolean isPositive, 228 final int years, 229 final int months, 230 final int days, 231 final int hours, 232 final int minutes, 233 final int seconds) { 234 235 BigInteger realYears = (years != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) years) : null; 237 238 BigInteger realMonths = (months != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) months) : null; 240 241 BigInteger realDays = (days != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) days) : null; 243 244 BigInteger realHours = (hours != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) hours) : null; 246 247 BigInteger realMinutes = (minutes != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) minutes) : null; 249 250 BigDecimal realSeconds = (seconds != DatatypeConstants.FIELD_UNDEFINED) ? BigDecimal.valueOf((long) seconds) : null; 252 253 return newDuration( 254 isPositive, 255 realYears, 256 realMonths, 257 realDays, 258 realHours, 259 realMinutes, 260 realSeconds 261 ); 262 } 263 264 288 public Duration newDurationDayTime(final String lexicalRepresentation) { 289 290 return newDuration(lexicalRepresentation); 291 } 292 293 330 public Duration newDurationDayTime(final long durationInMilliseconds) { 331 332 return newDuration(durationInMilliseconds); 333 } 334 335 365 public Duration newDurationDayTime( 366 final boolean isPositive, 367 final BigInteger day, 368 final BigInteger hour, 369 final BigInteger minute, 370 final BigInteger second) { 371 372 return newDuration( 373 isPositive, 374 null, null, day, 377 hour, 378 minute, 379 (second != null)? new BigDecimal (second):null 380 ); 381 } 382 383 407 public Duration newDurationDayTime( 408 final boolean isPositive, 409 final int day, 410 final int hour, 411 final int minute, 412 final int second) { 413 414 return newDurationDayTime( 415 isPositive, 416 BigInteger.valueOf((long) day), 417 BigInteger.valueOf((long) hour), 418 BigInteger.valueOf((long) minute), 419 BigInteger.valueOf((long) second) 420 ); 421 } 422 423 447 public Duration newDurationYearMonth(final String lexicalRepresentation) { 448 449 return newDuration(lexicalRepresentation); 450 } 451 452 486 public Duration newDurationYearMonth(final long durationInMilliseconds) { 487 488 return newDuration(durationInMilliseconds); 489 } 490 491 514 public Duration newDurationYearMonth( 515 final boolean isPositive, 516 final BigInteger year, 517 final BigInteger month) { 518 519 return newDuration( 520 isPositive, 521 year, 522 month, 523 null, null, null, null ); 528 } 529 530 547 public Duration newDurationYearMonth( 548 final boolean isPositive, 549 final int year, 550 final int month) { 551 552 return newDurationYearMonth( 553 isPositive, 554 BigInteger.valueOf((long) year), 555 BigInteger.valueOf((long) month)); 556 } 557 558 566 public abstract XMLGregorianCalendar newXMLGregorianCalendar(); 567 568 593 public abstract XMLGregorianCalendar newXMLGregorianCalendar(final String lexicalRepresentation); 594 595 657 public abstract XMLGregorianCalendar newXMLGregorianCalendar(final GregorianCalendar cal); 658 659 684 public abstract XMLGregorianCalendar newXMLGregorianCalendar( 685 final BigInteger year, 686 final int month, 687 final int day, 688 final int hour, 689 final int minute, 690 final int second, 691 final BigDecimal fractionalSecond, 692 final int timezone); 693 694 720 public XMLGregorianCalendar newXMLGregorianCalendar( 721 final int year, 722 final int month, 723 final int day, 724 final int hour, 725 final int minute, 726 final int second, 727 final int millisecond, 728 final int timezone) { 729 730 BigInteger realYear = (year != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) year) : null; 732 733 BigDecimal realMillisecond = null; if (millisecond != DatatypeConstants.FIELD_UNDEFINED) { 737 if (millisecond < 0 || millisecond > 1000) { 738 throw new IllegalArgumentException ( 739 "javax.xml.datatype.DatatypeFactory#newXMLGregorianCalendar(" 740 + "int year, int month, int day, int hour, int minute, int second, int millisecond, int timezone)" 741 + "with invalid millisecond: " + millisecond 742 ); 743 } 744 745 realMillisecond = BigDecimal.valueOf((long) millisecond).movePointLeft(3); 746 } 747 748 return newXMLGregorianCalendar( 749 realYear, 750 month, 751 day, 752 hour, 753 minute, 754 second, 755 realMillisecond, 756 timezone 757 ); 758 } 759 760 783 public XMLGregorianCalendar newXMLGregorianCalendarDate( 784 final int year, 785 final int month, 786 final int day, 787 final int timezone) { 788 789 return newXMLGregorianCalendar( 790 year, 791 month, 792 day, 793 DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, timezone); 798 } 799 800 819 public XMLGregorianCalendar newXMLGregorianCalendarTime( 820 final int hours, 821 final int minutes, 822 final int seconds, 823 final int timezone) { 824 825 return newXMLGregorianCalendar( 826 DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, hours, 830 minutes, 831 seconds, 832 DatatypeConstants.FIELD_UNDEFINED, timezone); 834 } 835 836 857 public XMLGregorianCalendar newXMLGregorianCalendarTime( 858 final int hours, 859 final int minutes, 860 final int seconds, 861 final BigDecimal fractionalSecond, 862 final int timezone) { 863 864 return newXMLGregorianCalendar( 865 null, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED, hours, 869 minutes, 870 seconds, 871 fractionalSecond, 872 timezone); 873 } 874 875 895 public XMLGregorianCalendar newXMLGregorianCalendarTime( 896 final int hours, 897 final int minutes, 898 final int seconds, 899 final int milliseconds, 900 final int timezone) { 901 902 BigDecimal realMilliseconds = null; if (milliseconds != DatatypeConstants.FIELD_UNDEFINED) { 906 if (milliseconds < 0 || milliseconds > 1000) { 907 throw new IllegalArgumentException ( 908 "javax.xml.datatype.DatatypeFactory#newXMLGregorianCalendarTime(" 909 + "int hours, int minutes, int seconds, int milliseconds, int timezone)" 910 + "with invalid milliseconds: " + milliseconds 911 ); 912 } 913 914 realMilliseconds = BigDecimal.valueOf((long) milliseconds).movePointLeft(3); 915 } 916 917 return newXMLGregorianCalendarTime( 918 hours, 919 minutes, 920 seconds, 921 realMilliseconds, 922 timezone 923 ); 924 } 925 } 926 | Popular Tags |