|
Lines 53-70
Link Here
|
| 53 |
// we will try to parse it for Locale.US |
53 |
// we will try to parse it for Locale.US |
| 54 |
private static ULocale DEFAULT_LOCALE = ULocale.US; |
54 |
private static ULocale DEFAULT_LOCALE = ULocale.US; |
| 55 |
private static ULocale JRE_DEFAULT_LOCALE = ULocale.getDefault( ); |
55 |
private static ULocale JRE_DEFAULT_LOCALE = ULocale.getDefault( ); |
| 56 |
|
56 |
|
| 57 |
// cache DateFormatter of ICU |
57 |
// cache DateFormatter of ICU |
| 58 |
private static Map dfMap = new HashMap( ); |
58 |
private static Map dfMap = new HashMap( ); |
| 59 |
private static Map nfMap = new HashMap( ); |
59 |
private static Map nfMap = new HashMap( ); |
| 60 |
// Default Date/Time Style |
60 |
// Default Date/Time Style |
| 61 |
private static int DEFAULT_DATE_STYLE = DateFormat.FULL; |
61 |
private static int DEFAULT_DATE_STYLE = DateFormat.FULL; |
| 62 |
|
62 |
|
| 63 |
// resource bundle for exception messages |
63 |
// resource bundle for exception messages |
| 64 |
public static ResourceBundle resourceBundle = ( new ResourceHandle( JRE_DEFAULT_LOCALE ) ).getUResourceBundle( ); |
64 |
public static ResourceBundle resourceBundle = ( new ResourceHandle( JRE_DEFAULT_LOCALE ) ).getUResourceBundle( ); |
| 65 |
|
65 |
|
| 66 |
public static long count = 0; |
66 |
public static long count = 0; |
| 67 |
|
67 |
|
| 68 |
/** |
68 |
/** |
| 69 |
* convert an object to given type |
69 |
* convert an object to given type |
| 70 |
* Types supported: |
70 |
* Types supported: |
|
Lines 77-82
Link Here
|
| 77 |
* DataType.BLOB_TYPE |
77 |
* DataType.BLOB_TYPE |
| 78 |
* DataType.SQL_DATE_TYPE |
78 |
* DataType.SQL_DATE_TYPE |
| 79 |
* DataType.SQL_TIME_TYPE |
79 |
* DataType.SQL_TIME_TYPE |
|
|
80 |
* DataType.OBJECT_TYPE |
| 80 |
* @param source |
81 |
* @param source |
| 81 |
* @param toType |
82 |
* @param toType |
| 82 |
* @return |
83 |
* @return |
|
Lines 86-92
Link Here
|
| 86 |
throws BirtException |
87 |
throws BirtException |
| 87 |
{ |
88 |
{ |
| 88 |
source = JavascriptEvalUtil.convertJavascriptValue( source ); |
89 |
source = JavascriptEvalUtil.convertJavascriptValue( source ); |
| 89 |
|
90 |
|
| 90 |
// here we assume the efficiency of if else is higher than switch case |
91 |
// here we assume the efficiency of if else is higher than switch case |
| 91 |
if ( toType == DataType.UNKNOWN_TYPE || toType == DataType.ANY_TYPE ) |
92 |
if ( toType == DataType.UNKNOWN_TYPE || toType == DataType.ANY_TYPE ) |
| 92 |
return source; |
93 |
return source; |
|
Lines 106-118
Link Here
|
| 106 |
case DataType.STRING_TYPE : |
107 |
case DataType.STRING_TYPE : |
| 107 |
return toString( source ); |
108 |
return toString( source ); |
| 108 |
case DataType.BLOB_TYPE : |
109 |
case DataType.BLOB_TYPE : |
| 109 |
return toBytes( source ); |
110 |
return toBytes( source ); |
| 110 |
case DataType.BINARY_TYPE : |
111 |
case DataType.BINARY_TYPE : |
| 111 |
return toBytes( source ); |
112 |
return toBytes( source ); |
| 112 |
case DataType.SQL_DATE_TYPE: |
113 |
case DataType.SQL_DATE_TYPE: |
| 113 |
return toSqlDate( source ); |
114 |
return toSqlDate( source ); |
| 114 |
case DataType.SQL_TIME_TYPE: |
115 |
case DataType.SQL_TIME_TYPE: |
| 115 |
return toSqlTime( source ); |
116 |
return toSqlTime( source ); |
|
|
117 |
case DataType.OBJECT_TYPE: |
| 118 |
return source; |
| 116 |
default : |
119 |
default : |
| 117 |
throw new CoreException( ResourceConstants.INVALID_TYPE, |
120 |
throw new CoreException( ResourceConstants.INVALID_TYPE, |
| 118 |
resourceBundle ); |
121 |
resourceBundle ); |
|
Lines 142-148
Link Here
|
| 142 |
{ |
145 |
{ |
| 143 |
return source; |
146 |
return source; |
| 144 |
} |
147 |
} |
| 145 |
|
148 |
|
| 146 |
if ( toTypeClass == DataType.getClass( DataType.ANY_TYPE ) ) |
149 |
if ( toTypeClass == DataType.getClass( DataType.ANY_TYPE ) ) |
| 147 |
return source; |
150 |
return source; |
| 148 |
if ( toTypeClass == Integer.class ) |
151 |
if ( toTypeClass == Integer.class ) |
|
Lines 155-163
Link Here
|
| 155 |
return toSqlTime( source ); |
158 |
return toSqlTime( source ); |
| 156 |
if ( toTypeClass == java.sql.Date.class) |
159 |
if ( toTypeClass == java.sql.Date.class) |
| 157 |
return toSqlDate( source ); |
160 |
return toSqlDate( source ); |
| 158 |
if ( toTypeClass == java.sql.Timestamp.class ) |
161 |
if ( toTypeClass == java.sql.Timestamp.class ) |
| 159 |
return toTimestamp( source ); |
162 |
return toTimestamp( source ); |
| 160 |
if ( toTypeClass == Date.class ) |
163 |
if ( toTypeClass == Date.class ) |
| 161 |
return toDate( source ); |
164 |
return toDate( source ); |
| 162 |
if ( toTypeClass == Double.class ) |
165 |
if ( toTypeClass == Double.class ) |
| 163 |
return toDouble( source ); |
166 |
return toDouble( source ); |
|
Lines 168-176
Link Here
|
| 168 |
if ( source instanceof byte[] ) |
171 |
if ( source instanceof byte[] ) |
| 169 |
return source; |
172 |
return source; |
| 170 |
else |
173 |
else |
| 171 |
return toBlob( source ); |
174 |
return toBlob( source ); |
| 172 |
} |
175 |
} |
| 173 |
if ( toTypeClass == byte[].class ) |
176 |
if ( toTypeClass == byte[].class || |
|
|
177 |
toTypeClass == Object.class ) |
| 174 |
return source; |
178 |
return source; |
| 175 |
|
179 |
|
| 176 |
throw new CoreException( ResourceConstants.INVALID_TYPE, |
180 |
throw new CoreException( ResourceConstants.INVALID_TYPE, |
|
Lines 180-186
Link Here
|
| 180 |
/** |
184 |
/** |
| 181 |
* Boolean -> Integer |
185 |
* Boolean -> Integer |
| 182 |
* true -> 1 |
186 |
* true -> 1 |
| 183 |
* others -> 0 |
187 |
* others -> 0 |
| 184 |
* Date -> Integer |
188 |
* Date -> Integer |
| 185 |
* Date.getTime(); |
189 |
* Date.getTime(); |
| 186 |
* String -> Integer |
190 |
* String -> Integer |
|
Lines 200-206
Link Here
|
| 200 |
} |
204 |
} |
| 201 |
else if ( source instanceof Number ) |
205 |
else if ( source instanceof Number ) |
| 202 |
{ |
206 |
{ |
| 203 |
// This takes care of BigDecimal, BigInteger, Byte, Double, |
207 |
// This takes care of BigDecimal, BigInteger, Byte, Double, |
| 204 |
// Float, Long, Short |
208 |
// Float, Long, Short |
| 205 |
if ( !isConvertableToInteger( (Number) source ) ) |
209 |
if ( !isConvertableToInteger( (Number) source ) ) |
| 206 |
{ |
210 |
{ |
|
Lines 252-258
Link Here
|
| 252 |
} |
256 |
} |
| 253 |
return new Integer( number.intValue( )); |
257 |
return new Integer( number.intValue( )); |
| 254 |
} |
258 |
} |
| 255 |
|
259 |
|
| 256 |
throw new CoreException( ResourceConstants.CONVERT_FAILS, |
260 |
throw new CoreException( ResourceConstants.CONVERT_FAILS, |
| 257 |
new Object[]{ |
261 |
new Object[]{ |
| 258 |
source.toString( ), "Integer" |
262 |
source.toString( ), "Integer" |
|
Lines 279-285
Link Here
|
| 279 |
/** |
283 |
/** |
| 280 |
* Boolean -> BigDecimal |
284 |
* Boolean -> BigDecimal |
| 281 |
* true -> 1 |
285 |
* true -> 1 |
| 282 |
* others -> 0 |
286 |
* others -> 0 |
| 283 |
* Date -> BigDecimal |
287 |
* Date -> BigDecimal |
| 284 |
* Date.getTime(); |
288 |
* Date.getTime(); |
| 285 |
* String -> BigDecimal |
289 |
* String -> BigDecimal |
|
Lines 299-305
Link Here
|
| 299 |
} |
303 |
} |
| 300 |
else if ( source instanceof Number ) |
304 |
else if ( source instanceof Number ) |
| 301 |
{ |
305 |
{ |
| 302 |
// This takes care of BigDecimal, BigInteger, Byte, Double, |
306 |
// This takes care of BigDecimal, BigInteger, Byte, Double, |
| 303 |
// Float, Long, Short, Integer |
307 |
// Float, Long, Short, Integer |
| 304 |
// An intermediate conversion using String is preferrable per JavaDoc |
308 |
// An intermediate conversion using String is preferrable per JavaDoc |
| 305 |
// comment in BigDecimal(String) constructor |
309 |
// comment in BigDecimal(String) constructor |
|
Lines 310-316
Link Here
|
| 310 |
} |
314 |
} |
| 311 |
catch ( NumberFormatException e ) |
315 |
catch ( NumberFormatException e ) |
| 312 |
{ |
316 |
{ |
| 313 |
throw new CoreException( |
317 |
throw new CoreException( |
| 314 |
ResourceConstants.CONVERT_FAILS, |
318 |
ResourceConstants.CONVERT_FAILS, |
| 315 |
new Object[]{ |
319 |
new Object[]{ |
| 316 |
str, "BigDecimal" |
320 |
str, "BigDecimal" |
|
Lines 342-348
Link Here
|
| 342 |
.parse( (String) source ); |
346 |
.parse( (String) source ); |
| 343 |
if( number != null ) |
347 |
if( number != null ) |
| 344 |
return new BigDecimal( number.toString( ) ); |
348 |
return new BigDecimal( number.toString( ) ); |
| 345 |
|
349 |
|
| 346 |
throw new CoreException( ResourceConstants.CONVERT_FAILS, |
350 |
throw new CoreException( ResourceConstants.CONVERT_FAILS, |
| 347 |
new Object[]{ |
351 |
new Object[]{ |
| 348 |
source.toString( ), "BigDecimal" |
352 |
source.toString( ), "BigDecimal" |
|
Lines 424-430
Link Here
|
| 424 |
} |
428 |
} |
| 425 |
else |
429 |
else |
| 426 |
{ |
430 |
{ |
| 427 |
throw new CoreException( |
431 |
throw new CoreException( |
| 428 |
ResourceConstants.CONVERT_FAILS, |
432 |
ResourceConstants.CONVERT_FAILS, |
| 429 |
new Object[]{ |
433 |
new Object[]{ |
| 430 |
source.toString( ), "Boolean" |
434 |
source.toString( ), "Boolean" |
|
Lines 436-442
Link Here
|
| 436 |
* Number -> Date |
440 |
* Number -> Date |
| 437 |
* new Date((long)Number) |
441 |
* new Date((long)Number) |
| 438 |
* String -> Date |
442 |
* String -> Date |
| 439 |
* toDate(String) |
443 |
* toDate(String) |
| 440 |
* @param source |
444 |
* @param source |
| 441 |
* @return |
445 |
* @return |
| 442 |
* @throws BirtException |
446 |
* @throws BirtException |
|
Lines 463-471
Link Here
|
| 463 |
}); |
467 |
}); |
| 464 |
} |
468 |
} |
| 465 |
} |
469 |
} |
| 466 |
|
470 |
|
| 467 |
/** |
471 |
/** |
| 468 |
* |
472 |
* |
| 469 |
* @param source |
473 |
* @param source |
| 470 |
* @return |
474 |
* @return |
| 471 |
* @throws BirtException |
475 |
* @throws BirtException |
|
Lines 477-483
Link Here
|
| 477 |
return null; |
481 |
return null; |
| 478 |
return new Timestamp( date.getTime( )); |
482 |
return new Timestamp( date.getTime( )); |
| 479 |
} |
483 |
} |
| 480 |
|
484 |
|
| 481 |
/** |
485 |
/** |
| 482 |
* Date -> Time |
486 |
* Date -> Time |
| 483 |
* String -> Time |
487 |
* String -> Time |
|
Lines 508-514
Link Here
|
| 508 |
} |
512 |
} |
| 509 |
catch ( Exception e1 ) |
513 |
catch ( Exception e1 ) |
| 510 |
{ |
514 |
{ |
| 511 |
|
515 |
|
| 512 |
} |
516 |
} |
| 513 |
} |
517 |
} |
| 514 |
} |
518 |
} |
|
Lines 521-527
Link Here
|
| 521 |
} |
525 |
} |
| 522 |
|
526 |
|
| 523 |
/** |
527 |
/** |
| 524 |
* |
528 |
* |
| 525 |
* @param value |
529 |
* @param value |
| 526 |
* @return |
530 |
* @return |
| 527 |
*/ |
531 |
*/ |
|
Lines 534-540
Link Here
|
| 534 |
int firstColon; |
538 |
int firstColon; |
| 535 |
int secondColon; |
539 |
int secondColon; |
| 536 |
int marker; |
540 |
int marker; |
| 537 |
|
541 |
|
| 538 |
if ( s == null ) |
542 |
if ( s == null ) |
| 539 |
throw new java.lang.IllegalArgumentException( ); |
543 |
throw new java.lang.IllegalArgumentException( ); |
| 540 |
|
544 |
|
|
Lines 584-595
Link Here
|
| 584 |
second = Integer.parseInt( s.substring( secondColon + 1 ) ); |
588 |
second = Integer.parseInt( s.substring( secondColon + 1 ) ); |
| 585 |
if( second < 0 || second > 60 ) |
589 |
if( second < 0 || second > 60 ) |
| 586 |
throw new java.lang.IllegalArgumentException( ); |
590 |
throw new java.lang.IllegalArgumentException( ); |
| 587 |
|
591 |
|
| 588 |
return toSqlTime( hour, minute, second ); |
592 |
return toSqlTime( hour, minute, second ); |
| 589 |
} |
593 |
} |
| 590 |
|
594 |
|
| 591 |
/** |
595 |
/** |
| 592 |
* |
596 |
* |
| 593 |
* @param hour |
597 |
* @param hour |
| 594 |
* @param minute |
598 |
* @param minute |
| 595 |
* @param second |
599 |
* @param second |
|
Lines 604-612
Link Here
|
| 604 |
calendar.set( Calendar.SECOND, second ); |
608 |
calendar.set( Calendar.SECOND, second ); |
| 605 |
return new java.sql.Time( calendar.getTimeInMillis( ) ); |
609 |
return new java.sql.Time( calendar.getTimeInMillis( ) ); |
| 606 |
} |
610 |
} |
| 607 |
|
611 |
|
| 608 |
/** |
612 |
/** |
| 609 |
* |
613 |
* |
| 610 |
* @param c |
614 |
* @param c |
| 611 |
* @return |
615 |
* @return |
| 612 |
*/ |
616 |
*/ |
|
Lines 616-624
Link Here
|
| 616 |
return true; |
620 |
return true; |
| 617 |
return false; |
621 |
return false; |
| 618 |
} |
622 |
} |
| 619 |
|
623 |
|
| 620 |
/** |
624 |
/** |
| 621 |
* |
625 |
* |
| 622 |
* @param date |
626 |
* @param date |
| 623 |
* @return |
627 |
* @return |
| 624 |
*/ |
628 |
*/ |
|
Lines 632-638
Link Here
|
| 632 |
calendar.set( Calendar.DAY_OF_MONTH, 1 ); |
636 |
calendar.set( Calendar.DAY_OF_MONTH, 1 ); |
| 633 |
return new java.sql.Time( calendar.getTimeInMillis( ) ); |
637 |
return new java.sql.Time( calendar.getTimeInMillis( ) ); |
| 634 |
} |
638 |
} |
| 635 |
|
639 |
|
| 636 |
/** |
640 |
/** |
| 637 |
* Date -> Time |
641 |
* Date -> Time |
| 638 |
* String -> Time |
642 |
* String -> Time |
|
Lines 663-669
Link Here
|
| 663 |
} |
667 |
} |
| 664 |
catch ( Exception e1 ) |
668 |
catch ( Exception e1 ) |
| 665 |
{ |
669 |
{ |
| 666 |
|
670 |
|
| 667 |
} |
671 |
} |
| 668 |
} |
672 |
} |
| 669 |
} |
673 |
} |
|
Lines 674-682
Link Here
|
| 674 |
source.toString( ), "java.sql.Date" |
678 |
source.toString( ), "java.sql.Date" |
| 675 |
} ); |
679 |
} ); |
| 676 |
} |
680 |
} |
| 677 |
|
681 |
|
| 678 |
/** |
682 |
/** |
| 679 |
* |
683 |
* |
| 680 |
* @param date |
684 |
* @param date |
| 681 |
* @return |
685 |
* @return |
| 682 |
*/ |
686 |
*/ |
|
Lines 688-701
Link Here
|
| 688 |
calendar.set( Calendar.HOUR_OF_DAY, 0 ); |
692 |
calendar.set( Calendar.HOUR_OF_DAY, 0 ); |
| 689 |
calendar.set( Calendar.MINUTE, 0 ); |
693 |
calendar.set( Calendar.MINUTE, 0 ); |
| 690 |
calendar.set( Calendar.SECOND, 0 ); |
694 |
calendar.set( Calendar.SECOND, 0 ); |
| 691 |
calendar.set( Calendar.MILLISECOND, 0 ); |
695 |
calendar.set( Calendar.MILLISECOND, 0 ); |
| 692 |
return new java.sql.Date( calendar.getTimeInMillis( ) ); |
696 |
return new java.sql.Date( calendar.getTimeInMillis( ) ); |
| 693 |
} |
697 |
} |
| 694 |
|
698 |
|
| 695 |
/** |
699 |
/** |
| 696 |
* A temp solution to the adoption of ICU4J to BIRT. Simply delegate |
700 |
* A temp solution to the adoption of ICU4J to BIRT. Simply delegate |
| 697 |
* toDate( String, Locale) method. |
701 |
* toDate( String, Locale) method. |
| 698 |
* |
702 |
* |
| 699 |
* @param source |
703 |
* @param source |
| 700 |
* the String to be convert |
704 |
* the String to be convert |
| 701 |
* @param locate |
705 |
* @param locate |
|
Lines 710-716
Link Here
|
| 710 |
|
714 |
|
| 711 |
/** |
715 |
/** |
| 712 |
* convert String with the specified locale to java.util.Date |
716 |
* convert String with the specified locale to java.util.Date |
| 713 |
* |
717 |
* |
| 714 |
* @param source |
718 |
* @param source |
| 715 |
* the String to be convert |
719 |
* the String to be convert |
| 716 |
* @param locate |
720 |
* @param locate |
|
Lines 722-730
Link Here
|
| 722 |
{ |
726 |
{ |
| 723 |
return toDate( source, locale, null ); |
727 |
return toDate( source, locale, null ); |
| 724 |
} |
728 |
} |
| 725 |
|
729 |
|
| 726 |
/** |
730 |
/** |
| 727 |
* |
731 |
* |
| 728 |
* @param source |
732 |
* @param source |
| 729 |
* @param locale |
733 |
* @param locale |
| 730 |
* @param timeZone |
734 |
* @param timeZone |
|
Lines 739-745
Link Here
|
| 739 |
|
743 |
|
| 740 |
DateFormat dateFormat = null; |
744 |
DateFormat dateFormat = null; |
| 741 |
Date resultDate = null; |
745 |
Date resultDate = null; |
| 742 |
|
746 |
|
| 743 |
boolean existTime = source.matches( ".*[0-9]+:[0-9]+:[0-9]+.*" ) |
747 |
boolean existTime = source.matches( ".*[0-9]+:[0-9]+:[0-9]+.*" ) |
| 744 |
|| source.matches( ".*[0-9]+:[0-9]+.*" ); |
748 |
|| source.matches( ".*[0-9]+:[0-9]+.*" ); |
| 745 |
|
749 |
|
|
Lines 748-754
Link Here
|
| 748 |
for ( int j = DEFAULT_DATE_STYLE; j <= DateFormat.SHORT; j++ ) |
752 |
for ( int j = DEFAULT_DATE_STYLE; j <= DateFormat.SHORT; j++ ) |
| 749 |
{ |
753 |
{ |
| 750 |
dateFormat = DateFormatFactory.getDateTimeInstance( i, j, locale ); |
754 |
dateFormat = DateFormatFactory.getDateTimeInstance( i, j, locale ); |
| 751 |
TimeZone savedTimeZone = null; |
755 |
TimeZone savedTimeZone = null; |
| 752 |
if( timeZone != null ) |
756 |
if( timeZone != null ) |
| 753 |
{ |
757 |
{ |
| 754 |
savedTimeZone = dateFormat.getTimeZone( ); |
758 |
savedTimeZone = dateFormat.getTimeZone( ); |
|
Lines 762-779
Link Here
|
| 762 |
catch ( ParseException e1 ) |
766 |
catch ( ParseException e1 ) |
| 763 |
{ |
767 |
{ |
| 764 |
} |
768 |
} |
| 765 |
finally |
769 |
finally |
| 766 |
{ |
770 |
{ |
| 767 |
if( savedTimeZone != null ) |
771 |
if( savedTimeZone != null ) |
| 768 |
dateFormat.setTimeZone( savedTimeZone ); |
772 |
dateFormat.setTimeZone( savedTimeZone ); |
| 769 |
} |
773 |
} |
| 770 |
} |
774 |
} |
| 771 |
|
775 |
|
| 772 |
// only Date, no Time |
776 |
// only Date, no Time |
| 773 |
if ( !existTime ) |
777 |
if ( !existTime ) |
| 774 |
{ |
778 |
{ |
| 775 |
dateFormat = DateFormatFactory.getDateInstance( i, locale ); |
779 |
dateFormat = DateFormatFactory.getDateInstance( i, locale ); |
| 776 |
TimeZone savedTimeZone = null; |
780 |
TimeZone savedTimeZone = null; |
| 777 |
if( timeZone != null ) |
781 |
if( timeZone != null ) |
| 778 |
{ |
782 |
{ |
| 779 |
savedTimeZone = dateFormat.getTimeZone( ); |
783 |
savedTimeZone = dateFormat.getTimeZone( ); |
|
Lines 787-793
Link Here
|
| 787 |
catch ( ParseException e1 ) |
791 |
catch ( ParseException e1 ) |
| 788 |
{ |
792 |
{ |
| 789 |
} |
793 |
} |
| 790 |
finally |
794 |
finally |
| 791 |
{ |
795 |
{ |
| 792 |
if( savedTimeZone != null ) |
796 |
if( savedTimeZone != null ) |
| 793 |
dateFormat.setTimeZone( savedTimeZone ); |
797 |
dateFormat.setTimeZone( savedTimeZone ); |
|
Lines 798-804
Link Here
|
| 798 |
// for the String can not be parsed, throws a BirtException |
802 |
// for the String can not be parsed, throws a BirtException |
| 799 |
if ( resultDate == null ) |
803 |
if ( resultDate == null ) |
| 800 |
{ |
804 |
{ |
| 801 |
throw new CoreException( |
805 |
throw new CoreException( |
| 802 |
ResourceConstants.CONVERT_FAILS, |
806 |
ResourceConstants.CONVERT_FAILS, |
| 803 |
new Object[]{ |
807 |
new Object[]{ |
| 804 |
source.toString( ), "Date" |
808 |
source.toString( ), "Date" |
|
Lines 811-817
Link Here
|
| 811 |
|
815 |
|
| 812 |
/** |
816 |
/** |
| 813 |
* Convert a string to a Date instance according to the TimeZone value |
817 |
* Convert a string to a Date instance according to the TimeZone value |
| 814 |
* |
818 |
* |
| 815 |
* @param source |
819 |
* @param source |
| 816 |
* @param timeZone |
820 |
* @param timeZone |
| 817 |
* @return |
821 |
* @return |
|
Lines 838-848
Link Here
|
| 838 |
} |
842 |
} |
| 839 |
} |
843 |
} |
| 840 |
} |
844 |
} |
| 841 |
|
845 |
|
| 842 |
/** |
846 |
/** |
| 843 |
* A temp solution to the adoption of ICU4J in BIRT. It is a simple |
847 |
* A temp solution to the adoption of ICU4J in BIRT. It is a simple |
| 844 |
* delegation to toDateWithCheck( String, Locale ). |
848 |
* delegation to toDateWithCheck( String, Locale ). |
| 845 |
* |
849 |
* |
| 846 |
* @param source |
850 |
* @param source |
| 847 |
* @param locale |
851 |
* @param locale |
| 848 |
* @return Date |
852 |
* @return Date |
|
Lines 863-869
Link Here
|
| 863 |
* in DateFormat.SHORT case instead of all cases. |
867 |
* in DateFormat.SHORT case instead of all cases. |
| 864 |
* Year is not lower than 0. |
868 |
* Year is not lower than 0. |
| 865 |
* Month is from 1 to 12. |
869 |
* Month is from 1 to 12. |
| 866 |
* Day is from 1 to 31. |
870 |
* Day is from 1 to 31. |
| 867 |
* @param source |
871 |
* @param source |
| 868 |
* @param locale |
872 |
* @param locale |
| 869 |
* @return Date |
873 |
* @return Date |
|
Lines 887-893
Link Here
|
| 887 |
// check whether conversion is correct |
891 |
// check whether conversion is correct |
| 888 |
if ( DateUtil.checkValid( dateFormat, source ) == false ) |
892 |
if ( DateUtil.checkValid( dateFormat, source ) == false ) |
| 889 |
{ |
893 |
{ |
| 890 |
throw new CoreException( |
894 |
throw new CoreException( |
| 891 |
ResourceConstants.CONVERT_FAILS, |
895 |
ResourceConstants.CONVERT_FAILS, |
| 892 |
new Object[]{ |
896 |
new Object[]{ |
| 893 |
source.toString( ), "Date" |
897 |
source.toString( ), "Date" |
|
Lines 900-906
Link Here
|
| 900 |
/** |
904 |
/** |
| 901 |
* Boolean -> Double |
905 |
* Boolean -> Double |
| 902 |
* true -> 1 |
906 |
* true -> 1 |
| 903 |
* others -> 0 |
907 |
* others -> 0 |
| 904 |
* Date -> Double |
908 |
* Date -> Double |
| 905 |
* Date.getTime(); |
909 |
* Date.getTime(); |
| 906 |
* String -> Double |
910 |
* String -> Double |
|
Lines 964-970
Link Here
|
| 964 |
} |
968 |
} |
| 965 |
return new Double( number.doubleValue( )); |
969 |
return new Double( number.doubleValue( )); |
| 966 |
} |
970 |
} |
| 967 |
|
971 |
|
| 968 |
throw new CoreException( ResourceConstants.CONVERT_FAILS, |
972 |
throw new CoreException( ResourceConstants.CONVERT_FAILS, |
| 969 |
new Object[]{ |
973 |
new Object[]{ |
| 970 |
source.toString( ), "Double" |
974 |
source.toString( ), "Double" |
|
Lines 989-995
Link Here
|
| 989 |
} |
993 |
} |
| 990 |
} |
994 |
} |
| 991 |
|
995 |
|
| 992 |
|
996 |
|
| 993 |
/** |
997 |
/** |
| 994 |
* Number -> String |
998 |
* Number -> String |
| 995 |
* Number.toString() |
999 |
* Number.toString() |
|
Lines 1021-1027
Link Here
|
| 1021 |
|
1025 |
|
| 1022 |
/** |
1026 |
/** |
| 1023 |
* Convert an object to an locale neutral String value. For Date values we will convert to ISO8601 format. |
1027 |
* Convert an object to an locale neutral String value. For Date values we will convert to ISO8601 format. |
| 1024 |
* |
1028 |
* |
| 1025 |
* @param source |
1029 |
* @param source |
| 1026 |
* @return |
1030 |
* @return |
| 1027 |
* @throws BirtException |
1031 |
* @throws BirtException |
|
Lines 1050-1061
Link Here
|
| 1050 |
{ |
1054 |
{ |
| 1051 |
return ((Number) source).toString( ); |
1055 |
return ((Number) source).toString( ); |
| 1052 |
} |
1056 |
} |
| 1053 |
else |
1057 |
else |
| 1054 |
{ |
1058 |
{ |
| 1055 |
return toLimitedSizeString( source ); |
1059 |
return toLimitedSizeString( source ); |
| 1056 |
} |
1060 |
} |
| 1057 |
} |
1061 |
} |
| 1058 |
|
1062 |
|
| 1059 |
/** |
1063 |
/** |
| 1060 |
* Number -> String |
1064 |
* Number -> String |
| 1061 |
* Number.toString() |
1065 |
* Number.toString() |
|
Lines 1092-1105
Link Here
|
| 1092 |
{ |
1096 |
{ |
| 1093 |
return toString( (Number) source, locale ); |
1097 |
return toString( (Number) source, locale ); |
| 1094 |
} |
1098 |
} |
| 1095 |
else |
1099 |
else |
| 1096 |
{ |
1100 |
{ |
| 1097 |
return toLimitedSizeString( source ); |
1101 |
return toLimitedSizeString( source ); |
| 1098 |
} |
1102 |
} |
| 1099 |
} |
1103 |
} |
| 1100 |
|
1104 |
|
| 1101 |
/** |
1105 |
/** |
| 1102 |
* |
1106 |
* |
| 1103 |
* @param source |
1107 |
* @param source |
| 1104 |
* @return |
1108 |
* @return |
| 1105 |
*/ |
1109 |
*/ |
|
Lines 1131-1137
Link Here
|
| 1131 |
} |
1135 |
} |
| 1132 |
|
1136 |
|
| 1133 |
/** |
1137 |
/** |
| 1134 |
* |
1138 |
* |
| 1135 |
* @param source |
1139 |
* @param source |
| 1136 |
* @param locale |
1140 |
* @param locale |
| 1137 |
* @return |
1141 |
* @return |
|
Lines 1153-1159
Link Here
|
| 1153 |
} |
1157 |
} |
| 1154 |
return nf.format( source ); |
1158 |
return nf.format( source ); |
| 1155 |
} |
1159 |
} |
| 1156 |
|
1160 |
|
| 1157 |
/** |
1161 |
/** |
| 1158 |
* Converting Blob to/from other types is not currently supported |
1162 |
* Converting Blob to/from other types is not currently supported |
| 1159 |
* @param source |
1163 |
* @param source |
|
Lines 1227-1233
Link Here
|
| 1227 |
|
1231 |
|
| 1228 |
/** |
1232 |
/** |
| 1229 |
* Converts a Java class to its corresponding data type constant |
1233 |
* Converts a Java class to its corresponding data type constant |
| 1230 |
* defined in DataType |
1234 |
* defined in DataType |
| 1231 |
*/ |
1235 |
*/ |
| 1232 |
public static int toApiDataType( Class clazz ) |
1236 |
public static int toApiDataType( Class clazz ) |
| 1233 |
{ |
1237 |
{ |
|
Lines 1263-1276
Link Here
|
| 1263 |
else if ( clazz == Boolean.class ) |
1267 |
else if ( clazz == Boolean.class ) |
| 1264 |
return DataType.BOOLEAN_TYPE; |
1268 |
return DataType.BOOLEAN_TYPE; |
| 1265 |
else if ( clazz == Object.class ) |
1269 |
else if ( clazz == Object.class ) |
| 1266 |
return DataType.STRING_TYPE; |
1270 |
return DataType.OBJECT_TYPE; |
| 1267 |
|
1271 |
|
| 1268 |
// any other types are not recognized nor supported; |
1272 |
// any other types are not recognized nor supported; |
| 1269 |
return DataType.UNKNOWN_TYPE; |
1273 |
return DataType.UNKNOWN_TYPE; |
| 1270 |
} |
1274 |
} |
| 1271 |
|
1275 |
|
| 1272 |
/** |
1276 |
/** |
| 1273 |
* Converts an ODA data type code to its |
1277 |
* Converts an ODA data type code to its |
| 1274 |
* corresponding Data Engine API data type constant |
1278 |
* corresponding Data Engine API data type constant |
| 1275 |
* defined in DataType. |
1279 |
* defined in DataType. |
| 1276 |
* @param odaDataTypeCode an ODA data type code |
1280 |
* @param odaDataTypeCode an ODA data type code |
|
Lines 1284-1290
Link Here
|
| 1284 |
} |
1288 |
} |
| 1285 |
|
1289 |
|
| 1286 |
/** |
1290 |
/** |
| 1287 |
* Convert object to a suitable type from its value |
1291 |
* Convert object to a suitable type from its value |
| 1288 |
* Object -> Integer -> Double -> BigDecimal -> Date -> String |
1292 |
* Object -> Integer -> Double -> BigDecimal -> Date -> String |
| 1289 |
*/ |
1293 |
*/ |
| 1290 |
public static Object toAutoValue( Object evaValue ) |
1294 |
public static Object toAutoValue( Object evaValue ) |
|
Lines 1331-1337
Link Here
|
| 1331 |
} |
1335 |
} |
| 1332 |
|
1336 |
|
| 1333 |
/** |
1337 |
/** |
| 1334 |
* convert object to Integer. If fails, return null. |
1338 |
* convert object to Integer. If fails, return null. |
| 1335 |
* Object -> Integer |
1339 |
* Object -> Integer |
| 1336 |
*/ |
1340 |
*/ |
| 1337 |
public static Integer toIntegerValue( Object evaValue ) |
1341 |
public static Integer toIntegerValue( Object evaValue ) |
|
Lines 1376-1382
Link Here
|
| 1376 |
/** |
1380 |
/** |
| 1377 |
* Convert String without specified locale to java.util.Date |
1381 |
* Convert String without specified locale to java.util.Date |
| 1378 |
* Try to format the given String for JRE default Locale, |
1382 |
* Try to format the given String for JRE default Locale, |
| 1379 |
* if it fails, try to format the String for Locale.US |
1383 |
* if it fails, try to format the String for Locale.US |
| 1380 |
* @param source |
1384 |
* @param source |
| 1381 |
* the String to be convert |
1385 |
* the String to be convert |
| 1382 |
* @param locate |
1386 |
* @param locate |
|
Lines 1406-1412
Link Here
|
| 1406 |
|
1410 |
|
| 1407 |
/** |
1411 |
/** |
| 1408 |
* convert String with ISO8601 date format to java.util.Date |
1412 |
* convert String with ISO8601 date format to java.util.Date |
| 1409 |
* |
1413 |
* |
| 1410 |
* @param source |
1414 |
* @param source |
| 1411 |
* the String to be convert |
1415 |
* the String to be convert |
| 1412 |
* @param locate |
1416 |
* @param locate |
|
Lines 1424-1430
Link Here
|
| 1424 |
} |
1428 |
} |
| 1425 |
catch ( ParseException e1 ) |
1429 |
catch ( ParseException e1 ) |
| 1426 |
{ |
1430 |
{ |
| 1427 |
throw new CoreException( |
1431 |
throw new CoreException( |
| 1428 |
ResourceConstants.CONVERT_FAILS, |
1432 |
ResourceConstants.CONVERT_FAILS, |
| 1429 |
new Object[]{ |
1433 |
new Object[]{ |
| 1430 |
source.toString( ), "Date" |
1434 |
source.toString( ), "Date" |
|
Lines 1434-1440
Link Here
|
| 1434 |
|
1438 |
|
| 1435 |
/** |
1439 |
/** |
| 1436 |
* Call org.eclipse.birt.core.format.DateFormatter |
1440 |
* Call org.eclipse.birt.core.format.DateFormatter |
| 1437 |
* |
1441 |
* |
| 1438 |
* @param source |
1442 |
* @param source |
| 1439 |
* @return |
1443 |
* @return |
| 1440 |
*/ |
1444 |
*/ |
|
Lines 1477-1483
Link Here
|
| 1477 |
* JavaObject -> java.lang.Object<br> |
1481 |
* JavaObject -> java.lang.Object<br> |
| 1478 |
* </i> |
1482 |
* </i> |
| 1479 |
* @param odaDataTypeCode an ODA data type code |
1483 |
* @param odaDataTypeCode an ODA data type code |
| 1480 |
* @return the ODI type class that corresponds with |
1484 |
* @return the ODI type class that corresponds with |
| 1481 |
* the specified ODA data type |
1485 |
* the specified ODA data type |
| 1482 |
* @throws BirtException if the specified ODA data type is not a supported type |
1486 |
* @throws BirtException if the specified ODA data type is not a supported type |
| 1483 |
*/ |
1487 |
*/ |
|
Lines 1556-1562
Link Here
|
| 1556 |
} |
1560 |
} |
| 1557 |
|
1561 |
|
| 1558 |
/** |
1562 |
/** |
| 1559 |
* Converts an ODI type class to its corresponding |
1563 |
* Converts an ODI type class to its corresponding |
| 1560 |
* ODA data type code. <br> |
1564 |
* ODA data type code. <br> |
| 1561 |
* <b>ODI Type Class -> ODA Data Type</b><br> |
1565 |
* <b>ODI Type Class -> ODA Data Type</b><br> |
| 1562 |
* <i>java.lang.Integer -> Integer<br> |
1566 |
* <i>java.lang.Integer -> Integer<br> |
|
Lines 1597-1603
Link Here
|
| 1597 |
else if ( odiTypeClass == java.sql.Date.class ) |
1601 |
else if ( odiTypeClass == java.sql.Date.class ) |
| 1598 |
odaType = Types.DATE; |
1602 |
odaType = Types.DATE; |
| 1599 |
else if ( odiTypeClass == java.util.Date.class ) |
1603 |
else if ( odiTypeClass == java.util.Date.class ) |
| 1600 |
odaType = Types.TIMESTAMP; |
1604 |
odaType = Types.TIMESTAMP; |
| 1601 |
else if ( odiTypeClass == Blob.class ) |
1605 |
else if ( odiTypeClass == Blob.class ) |
| 1602 |
odaType = Types.BLOB; |
1606 |
odaType = Types.BLOB; |
| 1603 |
else if ( odiTypeClass == Clob.class ) |
1607 |
else if ( odiTypeClass == Clob.class ) |
|
Lines 1609-1631
Link Here
|
| 1609 |
|
1613 |
|
| 1610 |
return odaType; |
1614 |
return odaType; |
| 1611 |
} |
1615 |
} |
| 1612 |
|
1616 |
|
| 1613 |
private static boolean isConvertableToInteger( Number n ) |
1617 |
private static boolean isConvertableToInteger( Number n ) |
| 1614 |
{ |
1618 |
{ |
| 1615 |
assert n != null; |
1619 |
assert n != null; |
| 1616 |
|
1620 |
|
| 1617 |
long longValue = n.longValue( ); |
1621 |
long longValue = n.longValue( ); |
| 1618 |
return longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE; |
1622 |
return longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE; |
| 1619 |
|
1623 |
|
| 1620 |
} |
1624 |
} |
| 1621 |
|
1625 |
|
| 1622 |
private static boolean isConvertableToDouble( Number n ) |
1626 |
private static boolean isConvertableToDouble( Number n ) |
| 1623 |
{ |
1627 |
{ |
| 1624 |
assert n != null; |
1628 |
assert n != null; |
| 1625 |
|
1629 |
|
| 1626 |
double doubleValue = n.doubleValue( ); |
1630 |
double doubleValue = n.doubleValue( ); |
| 1627 |
return !Double.isInfinite( doubleValue ); |
1631 |
return !Double.isInfinite( doubleValue ); |
| 1628 |
|
1632 |
|
| 1629 |
} |
1633 |
} |
| 1630 |
} |
1634 |
} |
| 1631 |
|
1635 |
|