1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488
|
/*******************************************************************************
* Copyright (c) 1998, 2015 Oracle, IBM Corporation and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
* 09/30/2014-2.6.0 Dalia Abo Sheasha
* - 445546: NullPointerException thrown when an Array of Bytes contains null values
******************************************************************************/
package org.eclipse.persistence.internal.helper;
import java.math.*;
import java.net.URL;
import java.util.*;
import java.io.*;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.sql.*;
import org.eclipse.persistence.exceptions.*;
import org.eclipse.persistence.internal.core.helper.CoreConversionManager;
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
import org.eclipse.persistence.internal.security.PrivilegedGetClassLoaderForClass;
import org.eclipse.persistence.internal.security.PrivilegedGetContextClassLoader;
/**
* <p>
* <b>Purpose</b>: Contains the conversion routines for some common classes in the system.
* Primarily used to convert objects from a given database type to a different type in Java.
* Uses a singleton instance, this is also used from the platform.
* <p>
* <b>Responsibilities</b>:
* <ul>
* <li> Execute the appropriate conversion routine.
* </ul>
*/
public class ConversionManager extends CoreConversionManager implements Serializable, Cloneable {
protected Map defaultNullValues;
/**
* This flag is here if the Conversion Manager should use the class loader on the
* thread when loading classes.
*/
protected boolean shouldUseClassLoaderFromCurrentThread = false;
protected static ConversionManager defaultManager;
/** Allows the setting of a global default if no instance-level loader is set. */
private static ClassLoader defaultLoader;
protected ClassLoader loader;
/** Store the list of Classes that can be converted to from the key. */
protected Hashtable dataTypesConvertedFromAClass;
/** Store the list of Classes that can be converted from to the key. */
protected Hashtable dataTypesConvertedToAClass;
public ConversionManager() {
this.dataTypesConvertedFromAClass = new Hashtable();
this.dataTypesConvertedToAClass = new Hashtable();
}
/**
* INTERNAL:
*/
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException exception) {
return null;
}
}
/**
* Convert the object to the appropriate type by invoking the appropriate
* ConversionManager method
* @param object - the object that must be converted
* @param javaClass - the class that the object must be converted to
* @exception - ConversionException, all exceptions will be thrown as this type.
* @return - the newly converted object
*/
@Override
public Object convertObject(Object sourceObject, Class javaClass) throws ConversionException {
if (sourceObject == null) {
// Check for default null conversion.
// i.e. allow for null to be defaulted to "", or 0 etc.
if (javaClass != null ) {
return getDefaultNullValue(javaClass);
} else {
return null;
}
}
if ((sourceObject.getClass() == javaClass) || (javaClass == null) || (javaClass == ClassConstants.OBJECT) || (javaClass == ClassConstants.BLOB) || (javaClass == ClassConstants.CLOB)) {
return sourceObject;
}
try {
if (javaClass == ClassConstants.STRING) {
return convertObjectToString(sourceObject);
} else if (javaClass == ClassConstants.UTILDATE) {
return convertObjectToUtilDate(sourceObject);
} else if (javaClass == ClassConstants.SQLDATE) {
return convertObjectToDate(sourceObject);
} else if (javaClass == ClassConstants.TIME) {
return convertObjectToTime(sourceObject);
} else if (javaClass == ClassConstants.TIMESTAMP) {
return convertObjectToTimestamp(sourceObject);
} else if ((javaClass == ClassConstants.CALENDAR) || (javaClass == ClassConstants.GREGORIAN_CALENDAR)) {
return convertObjectToCalendar(sourceObject);
} else if ((javaClass == ClassConstants.CHAR) || (javaClass == ClassConstants.PCHAR && !(sourceObject instanceof Character))) {
return convertObjectToChar(sourceObject);
} else if ((javaClass == ClassConstants.INTEGER) || (javaClass == ClassConstants.PINT && !(sourceObject instanceof Integer))) {
return convertObjectToInteger(sourceObject);
} else if ((javaClass == ClassConstants.DOUBLE) || (javaClass == ClassConstants.PDOUBLE && !(sourceObject instanceof Double))) {
return convertObjectToDouble(sourceObject);
} else if ((javaClass == ClassConstants.FLOAT) || (javaClass == ClassConstants.PFLOAT && !(sourceObject instanceof Float))) {
return convertObjectToFloat(sourceObject);
} else if ((javaClass == ClassConstants.LONG) || (javaClass == ClassConstants.PLONG && !(sourceObject instanceof Long))) {
return convertObjectToLong(sourceObject);
} else if ((javaClass == ClassConstants.SHORT) || (javaClass == ClassConstants.PSHORT && !(sourceObject instanceof Short))) {
return convertObjectToShort(sourceObject);
} else if ((javaClass == ClassConstants.BYTE) || (javaClass == ClassConstants.PBYTE && !(sourceObject instanceof Byte))) {
return convertObjectToByte(sourceObject);
} else if (javaClass == ClassConstants.BIGINTEGER) {
return convertObjectToBigInteger(sourceObject);
} else if (javaClass == ClassConstants.BIGDECIMAL) {
return convertObjectToBigDecimal(sourceObject);
} else if (javaClass == ClassConstants.NUMBER) {
return convertObjectToNumber(sourceObject);
} else if ((javaClass == ClassConstants.BOOLEAN) || (javaClass == ClassConstants.PBOOLEAN && !(sourceObject instanceof Boolean))) {
return convertObjectToBoolean(sourceObject);
} else if (javaClass == ClassConstants.APBYTE) {
return convertObjectToByteArray(sourceObject);
} else if (javaClass == ClassConstants.ABYTE) {
return convertObjectToByteObjectArray(sourceObject);
} else if (javaClass == ClassConstants.APCHAR) {
return convertObjectToCharArray(sourceObject);
} else if (javaClass == ClassConstants.ACHAR) {
return convertObjectToCharacterArray(sourceObject);
} else if ((sourceObject.getClass() == ClassConstants.STRING) && (javaClass == ClassConstants.CLASS)) {
return convertObjectToClass(sourceObject);
} else if(javaClass == ClassConstants.URL_Class) {
return convertObjectToUrl(sourceObject);
}
} catch (ConversionException ce) {
throw ce;
} catch (Exception e) {
throw ConversionException.couldNotBeConverted(sourceObject, javaClass, e);
}
// Check if object is instance of the real class for the primitive class.
if ((((javaClass == ClassConstants.PBOOLEAN) && (sourceObject instanceof Boolean) ) ||
((javaClass == ClassConstants.PLONG) && (sourceObject instanceof Long) ) ||
((javaClass == ClassConstants.PINT) && (sourceObject instanceof Integer) ) ||
((javaClass == ClassConstants.PFLOAT) && (sourceObject instanceof Float)) ||
((javaClass == ClassConstants.PDOUBLE) && (sourceObject instanceof Double) ) ||
((javaClass == ClassConstants.PBYTE) && (sourceObject instanceof Byte)) ||
((javaClass == ClassConstants.PCHAR) && (sourceObject instanceof Character)) ||
((javaClass == ClassConstants.PSHORT) && (sourceObject instanceof Short)))) {
return sourceObject;
}
// Delay this check as poor performance.
if (javaClass.isInstance(sourceObject)) {
return sourceObject;
}
if (ClassConstants.NOCONVERSION.isAssignableFrom(javaClass)) {
return sourceObject;
}
throw ConversionException.couldNotBeConverted(sourceObject, javaClass);
}
/**
* Build a valid instance of BigDecimal from the given sourceObject
* @param sourceObject Valid instance of String, BigInteger, any Number
*/
protected BigDecimal convertObjectToBigDecimal(Object sourceObject) throws ConversionException {
BigDecimal bigDecimal = null;
try {
if (sourceObject instanceof String) {
bigDecimal = new BigDecimal((String)sourceObject);
} else if (sourceObject instanceof BigInteger) {
bigDecimal = new BigDecimal((BigInteger)sourceObject);
} else if (sourceObject instanceof Number) {
// Doubles do not maintain scale, because of this it is
// impossible to distinguish between 1 and 1.0. In order to
// maintain backwards compatibility both 1 and 1.0 will be
// treated as BigDecimal(1).
String numberString = String.valueOf(sourceObject);
if(numberString.endsWith(".0") || numberString.contains(".0E+")) {
bigDecimal = new BigDecimal(((Number)sourceObject).doubleValue());
} else {
bigDecimal = new BigDecimal(numberString);
}
} else {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BIGDECIMAL);
}
} catch (NumberFormatException exception) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BIGDECIMAL, exception);
}
return bigDecimal;
}
/**
* Build a valid instance of BigInteger from the provided sourceObject.
* @param sourceObject Valid instance of String, BigDecimal, or any Number
*/
protected BigInteger convertObjectToBigInteger(Object sourceObject) throws ConversionException {
BigInteger bigInteger = null;
try {
if (sourceObject instanceof BigInteger) {
bigInteger = (BigInteger)sourceObject;
} else if (sourceObject instanceof String) {
bigInteger = new BigInteger((String)sourceObject);
} else if (sourceObject instanceof BigDecimal) {
bigInteger = ((BigDecimal)sourceObject).toBigInteger();
} else if (sourceObject instanceof Number) {
bigInteger = new BigInteger(String.valueOf(((Number)sourceObject).longValue()));
} else if (sourceObject instanceof Byte[]) {
Byte[] objectBytes = (Byte[])sourceObject;
byte[] bytes = new byte[objectBytes.length];
for (int index = 0; index < objectBytes.length; index++) {
bytes[index] = objectBytes[index].byteValue();
}
bigInteger = new BigInteger(bytes);
} else if (sourceObject instanceof byte[]) {
bigInteger = new BigInteger((byte[]) sourceObject);
} else {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BIGINTEGER);
}
} catch (NumberFormatException exception) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BIGINTEGER, exception);
}
return bigInteger;
}
/**
* Build a valid instance of Boolean from the source object.
* 't', 'T', "true", "TRUE", 1,'1' -> Boolean(true)
* 'f', 'F', "false", "FALSE", 0 ,'0' -> Boolean(false)
*/
protected Boolean convertObjectToBoolean(Object sourceObject) {
if (sourceObject instanceof Character) {
switch (Character.toLowerCase(((Character)sourceObject).charValue())) {
case '1':
case 't':
return Boolean.TRUE;
case '0':
case 'f':
return Boolean.FALSE;
}
}
if (sourceObject instanceof String) {
String stringValue = ((String)sourceObject).toLowerCase();
if (stringValue.equals("t") || stringValue.equals("true") || stringValue.equals("1")) {
return Boolean.TRUE;
} else if (stringValue.equals("f") || stringValue.equals("false") || stringValue.equals("0")) {
return Boolean.FALSE;
}
}
if (sourceObject instanceof Number) {
int intValue = ((Number)sourceObject).intValue();
if (intValue != 0) {
return Boolean.TRUE;
} else if (intValue == 0) {
return Boolean.FALSE;
}
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BOOLEAN);
}
/**
* Build a valid instance of Byte from the provided sourceObject
* @param sourceObject Valid instance of String or any Number
* @caught exception The Byte(String) constructor throws a
* NumberFormatException if the String does not contain a
* parsable byte.
*
*/
protected Byte convertObjectToByte(Object sourceObject) throws ConversionException {
try {
if (sourceObject instanceof String) {
return Byte.valueOf((String)sourceObject);
}
if (sourceObject instanceof Number) {
return Byte.valueOf(((Number)sourceObject).byteValue());
}
} catch (NumberFormatException exception) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BYTE, exception);
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BYTE);
}
/**
* Build a valid instance of a byte array from the given object.
* This method does hex conversion of the string values. Some
* databases have problems with storing blobs unless the blob
* is stored as a hex string.
*/
protected byte[] convertObjectToByteArray(Object sourceObject) throws ConversionException {
//Bug#3128838 Used when converted to Byte[]
if (sourceObject instanceof byte[]) {
return (byte[])sourceObject;
//Related to Bug#3128838. Add support to convert to Byte[]
} else if (sourceObject instanceof Byte[]) {
Byte[] objectBytes = (Byte[])sourceObject;
byte[] bytes = new byte[objectBytes.length];
for (int index = 0; index < objectBytes.length; index++) {
Byte value = objectBytes[index];
if (value != null) {
bytes[index] = value.byteValue();
}
}
return bytes;
} else if (sourceObject instanceof String) {
return Helper.buildBytesFromHexString((String)sourceObject);
} else if (sourceObject instanceof Blob) {
Blob blob = (Blob)sourceObject;
try {
return blob.getBytes(1L, (int)blob.length());
} catch (SQLException exception) {
throw DatabaseException.sqlException(exception);
}
} else if (sourceObject instanceof InputStream) {
InputStream inputStream = (InputStream)sourceObject;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
int tempInt = inputStream.read();
while (tempInt != -1) {
outputStream.write(tempInt);
tempInt = inputStream.read();
}
return outputStream.toByteArray();
} catch (IOException ioException) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.APBYTE, ioException);
}
} else if (sourceObject instanceof BigInteger) {
return ((BigInteger)sourceObject).toByteArray();
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.APBYTE);
}
/**
* Build a valid instance of a Byte array from the given object.
* This method does hex conversion of the string values. Some
* databases have problems with storing blobs unless the blob
* is stored as a hex string.
*/
protected Byte[] convertObjectToByteObjectArray(Object sourceObject) throws ConversionException {
byte[] bytes = convertObjectToByteArray(sourceObject);
Byte[] objectBytes = new Byte[bytes.length];
for (int index = 0; index < bytes.length; index++) {
objectBytes[index] = Byte.valueOf(bytes[index]);
}
return objectBytes;
}
/**
* Build a valid instance of java.util.Calendar from the given source object.
* @param sourceObject Valid instance of java.util.Date, String, java.sql.Timestamp, or Long
*/
protected Calendar convertObjectToCalendar(Object sourceObject) throws ConversionException {
if (sourceObject instanceof Calendar) {
return (Calendar)sourceObject;
} else if (sourceObject instanceof java.util.Date) {
// PERF: Avoid double conversion for date subclasses.
return Helper.calendarFromUtilDate((java.util.Date)sourceObject);
}
return Helper.calendarFromUtilDate(convertObjectToUtilDate(sourceObject));
}
/**
* Build a valid instance of Character from the provided sourceObject.
* @param sourceObject Valid instance of String or any Number
*/
protected Character convertObjectToChar(Object sourceObject) throws ConversionException {
if (sourceObject instanceof String) {
if (((String)sourceObject).length() < 1) {
// ELBug336192 - Return default null value of char instead of returning null.
return (Character)getDefaultNullValue(ClassConstants.PCHAR);
}
return Character.valueOf(((String)sourceObject).charAt(0));
}
if (sourceObject instanceof Number) {
return Character.valueOf((char)((Number)sourceObject).byteValue());
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.CHAR);
}
/**
* Build a valid instance of a Character array from the given object.
*/
protected Character[] convertObjectToCharacterArray(Object sourceObject) throws ConversionException {
String stringValue = convertObjectToString(sourceObject);
Character[] chars = new Character[stringValue.length()];
for (int index = 0; index < stringValue.length(); index++) {
chars[index] = Character.valueOf(stringValue.charAt(index));
}
return chars;
}
/**
* Build a valid instance of a char array from the given object.
*/
protected char[] convertObjectToCharArray(Object sourceObject) throws ConversionException {
if (sourceObject instanceof Character[]) {
Character[] objectChars = (Character[])sourceObject;
char[] chars = new char[objectChars.length];
for (int index = 0; index < objectChars.length; index++) {
chars[index] = objectChars[index].charValue();
}
return chars;
}
String stringValue = convertObjectToString(sourceObject);
char[] chars = new char[stringValue.length()];
for (int index = 0; index < stringValue.length(); index++) {
chars[index] = stringValue.charAt(index);
}
return chars;
}
/**
* Build a valid Class from the string that is passed in
* @param sourceObject Valid instance of String
*/
protected Class convertObjectToClass(Object sourceObject) throws ConversionException {
Class theClass = null;
if (!(sourceObject instanceof String)) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.CLASS);
}
try {
// bug # 2799318
theClass = getPrimitiveClass((String)sourceObject);
if (theClass == null) {
theClass = Class.forName((String)sourceObject, true, getLoader());
}
} catch (Exception exception) {
throw ConversionException.couldNotBeConvertedToClass(sourceObject, ClassConstants.CLASS, exception);
}
return theClass;
}
/**
* Convert the object to an instance of java.sql.Date.
* @param sourceObject Object of type java.sql.Timestamp, java.util.Date, String or Long
*/
protected java.sql.Date convertObjectToDate(Object sourceObject) throws ConversionException {
java.sql.Date date = null;
if (sourceObject instanceof java.sql.Date) {
date = (java.sql.Date)sourceObject;//Helper date is not caught on class check.
} else if (sourceObject instanceof java.sql.Timestamp) {
date = Helper.dateFromTimestamp((java.sql.Timestamp)sourceObject);
} else if (sourceObject.getClass() == ClassConstants.UTILDATE) {
date = Helper.sqlDateFromUtilDate((java.util.Date)sourceObject);
} else if (sourceObject instanceof Calendar) {
return Helper.dateFromCalendar((Calendar)sourceObject);
} else if (sourceObject instanceof String) {
date = Helper.dateFromString((String)sourceObject);
} else if (sourceObject instanceof Long) {
date = Helper.dateFromLong((Long)sourceObject);
} else {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.SQLDATE);
}
return date;
}
/**
* Convert the object to an instance of Double.
* @param sourceObject Object of type String or Number.
* @caught exception The Double(String) constructor throws a
* NumberFormatException if the String does not contain a
* parsable double.
*/
protected Double convertObjectToDouble(Object sourceObject) throws ConversionException {
try {
if (sourceObject instanceof String) {
return Double.valueOf((String)sourceObject);
}
if (sourceObject instanceof Number) {
return Double.valueOf(((Number)sourceObject).doubleValue());
}
} catch (NumberFormatException exception) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.DOUBLE, exception);
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.DOUBLE);
}
/**
* Build a valid Float instance from a String or another Number instance.
* @caught exception The Float(String) constructor throws a
* NumberFormatException if the String does not contain a
* parsable Float.
*/
protected Float convertObjectToFloat(Object sourceObject) throws ConversionException {
try {
if (sourceObject instanceof String) {
return Float.valueOf((String)sourceObject);
}
if (sourceObject instanceof Number) {
return Float.valueOf(((Number)sourceObject).floatValue());
}
} catch (NumberFormatException exception) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.FLOAT, exception);
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.FLOAT);
}
/**
* Build a valid Integer instance from a String or another Number instance.
* @caught exception The Integer(String) constructor throws a
* NumberFormatException if the String does not contain a
* parsable integer.
*/
protected Integer convertObjectToInteger(Object sourceObject) throws ConversionException {
try {
if (sourceObject instanceof String) {
return Integer.valueOf((String)sourceObject);
}
if (sourceObject instanceof Number) {
return Integer.valueOf(((Number)sourceObject).intValue());
}
if (sourceObject instanceof Boolean) {
if (((Boolean)sourceObject).booleanValue()) {
return Integer.valueOf(1);
} else {
return Integer.valueOf(0);
}
}
} catch (NumberFormatException exception) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.INTEGER, exception);
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.INTEGER);
}
/**
* Build a valid Long instance from a String or another Number instance.
* @caught exception The Long(String) constructor throws a
* NumberFormatException if the String does not contain a
* parsable long.
*
*/
protected Long convertObjectToLong(Object sourceObject) throws ConversionException {
try {
if (sourceObject instanceof String) {
return Long.valueOf((String)sourceObject);
}
if (sourceObject instanceof Number) {
return Long.valueOf(((Number)sourceObject).longValue());
}
if (sourceObject instanceof java.util.Date) {
return Long.valueOf(((java.util.Date)sourceObject).getTime());
}
if (sourceObject instanceof java.util.Calendar) {
return Long.valueOf(((java.util.Calendar)sourceObject).getTimeInMillis());
}
if (sourceObject instanceof Boolean) {
if (((Boolean)sourceObject).booleanValue()) {
return Long.valueOf(1);
} else {
return Long.valueOf(0);
}
}
} catch (NumberFormatException exception) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.LONG, exception);
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.LONG);
}
/**
* INTERNAL:
* Build a valid BigDecimal instance from a String or another
* Number instance. BigDecimal is the most general type so is
* must be returned when an object is converted to a number.
* @caught exception The BigDecimal(String) constructor throws a
* NumberFormatException if the String does not contain a
* parsable BigDecimal.
*/
protected BigDecimal convertObjectToNumber(Object sourceObject) throws ConversionException {
try {
if (sourceObject instanceof String) {
return new BigDecimal((String)sourceObject);
}
if (sourceObject instanceof Number) {
return new BigDecimal(((Number)sourceObject).doubleValue());
}
if (sourceObject instanceof Boolean) {
if (((Boolean)sourceObject).booleanValue()) {
return BigDecimal.valueOf(1);
} else {
return BigDecimal.valueOf(0);
}
}
} catch (NumberFormatException exception) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.NUMBER, exception);
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.NUMBER);
}
/**
* INTERNAL:
* Build a valid Short instance from a String or another Number instance.
* @caught exception The Short(String) constructor throws a
* NumberFormatException if the String does not contain a
* parsable short.
*/
protected Short convertObjectToShort(Object sourceObject) throws ConversionException {
try {
if (sourceObject instanceof String) {
return Short.valueOf((String)sourceObject);
}
if (sourceObject instanceof Number) {
return Short.valueOf(((Number)sourceObject).shortValue());
}
if (sourceObject instanceof Boolean) {
if (((Boolean)sourceObject).booleanValue()) {
return Short.valueOf((short)1);
} else {
return Short.valueOf((short)0);
}
}
} catch (Exception exception) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.SHORT, exception);
}
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.SHORT);
}
/**
* INTERNAL:
* Converts objects to their string representations. java.util.Date
* is converted to a timestamp first and then to a string. An array
* of bytes is converted to a hex string.
*/
protected String convertObjectToString(Object sourceObject) throws ConversionException {
Class sourceObjectClass = sourceObject.getClass();
if (sourceObject instanceof java.lang.Number) {
return sourceObject.toString();
} else if (sourceObjectClass == ClassConstants.BOOLEAN) {
return sourceObject.toString();
} else if (sourceObjectClass == ClassConstants.UTILDATE) {
return Helper.printTimestamp(Helper.timestampFromDate((java.util.Date)sourceObject));
} else if (sourceObject instanceof java.util.Calendar) {
return Helper.printCalendar((Calendar)sourceObject);
} else if (sourceObjectClass == ClassConstants.TIMESTAMP) {
return Helper.printTimestamp((java.sql.Timestamp)sourceObject);
} else if (sourceObject instanceof java.sql.Date) {
return Helper.printDate((java.sql.Date)sourceObject);
} else if (sourceObject instanceof java.sql.Time) {
return Helper.printTime((java.sql.Time)sourceObject);
} else if (sourceObjectClass == ClassConstants.APBYTE) {
return Helper.buildHexStringFromBytes((byte[])sourceObject);
//Bug#3854296 Added support to convert Byte[], char[] and Character[] to String correctly
} else if (sourceObjectClass == ClassConstants.ABYTE) {
return Helper.buildHexStringFromBytes(convertObjectToByteArray(sourceObject));
} else if (sourceObjectClass == ClassConstants.APCHAR) {
return new String((char[])sourceObject);
} else if (sourceObjectClass == ClassConstants.ACHAR) {
return new String(convertObjectToCharArray(sourceObject));
} else if (sourceObject instanceof Class) {
return ((Class)sourceObject).getName();
} else if (sourceObjectClass == ClassConstants.CHAR) {
return sourceObject.toString();
} else if (sourceObject instanceof Clob) {
Clob clob = (Clob)sourceObject;
try {
return clob.getSubString(1L, (int)clob.length());
} catch (SQLException exception) {
throw DatabaseException.sqlException(exception);
}
}
return sourceObject.toString();
}
/**
* INTERNAL:
* Build a valid instance of java.sql.Time from the given source object.
* @param sourceObject Valid instance of java.sql.Time, String, java.util.Date, java.sql.Timestamp, or Long
*/
protected java.sql.Time convertObjectToTime(Object sourceObject) throws ConversionException {
java.sql.Time time = null;
if (sourceObject instanceof java.sql.Time) {
return (java.sql.Time)sourceObject;//Helper timestamp is not caught on class check.
}
if (sourceObject instanceof String) {
time = Helper.timeFromString((String)sourceObject);
} else if (sourceObject.getClass() == ClassConstants.UTILDATE) {
time = Helper.timeFromDate((java.util.Date)sourceObject);
} else if (sourceObject instanceof java.sql.Timestamp) {
time = Helper.timeFromTimestamp((java.sql.Timestamp)sourceObject);
} else if (sourceObject instanceof Calendar) {
return Helper.timeFromCalendar((Calendar)sourceObject);
} else if (sourceObject instanceof Long) {
time = Helper.timeFromLong((Long)sourceObject);
} else {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.TIME);
}
return time;
}
/**
* INTERNAL:
* Build a valid instance of java.sql.Timestamp from the given source object.
* @param sourceObject Valid obejct of class java.sql.Timestamp, String, java.util.Date, or Long
*/
protected java.sql.Timestamp convertObjectToTimestamp(Object sourceObject) throws ConversionException {
java.sql.Timestamp timestamp = null;
if (sourceObject instanceof java.sql.Timestamp) {
return (java.sql.Timestamp)sourceObject;// Helper timestamp is not caught on class check.
}
if (sourceObject instanceof String) {
timestamp = Helper.timestampFromString((String)sourceObject);
} else if (sourceObject instanceof java.util.Date) {// This handles all date and subclasses, sql.Date, sql.Time conversions.
timestamp = Helper.timestampFromDate((java.util.Date)sourceObject);
} else if (sourceObject instanceof Calendar) {
return Helper.timestampFromCalendar((Calendar)sourceObject);
} else if (sourceObject instanceof Long) {
timestamp = Helper.timestampFromLong((Long)sourceObject);
} else {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.TIMESTAMP);
}
return timestamp;
}
/**
* INTERNAL:
* Build a valid instance of java.net.URL from the given source object.
* @param sourceObject Valid instance of java.net.URL, or String
*/
protected URL convertObjectToUrl(Object sourceObject) throws ConversionException {
if(sourceObject.getClass() == ClassConstants.URL_Class) {
return (URL) sourceObject;
} else if (sourceObject.getClass() == ClassConstants.STRING) {
try {
return new URL((String) sourceObject);
} catch(Exception e) {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.URL_Class, e);
}
} else {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.URL_Class);
}
}
/**
* INTERNAL:
* Build a valid instance of java.util.Date from the given source object.
* @param sourceObject Valid instance of java.util.Date, String, java.sql.Timestamp, or Long
*/
protected java.util.Date convertObjectToUtilDate(Object sourceObject) throws ConversionException {
java.util.Date date = null;
if (sourceObject.getClass() == java.util.Date.class) {
date = (java.util.Date)sourceObject;//used when converting util.Date to Calendar
} else if (sourceObject instanceof java.sql.Date) {
date = Helper.utilDateFromSQLDate((java.sql.Date)sourceObject);
} else if (sourceObject instanceof java.sql.Time) {
date = Helper.utilDateFromTime((java.sql.Time)sourceObject);
} else if (sourceObject instanceof String) {
date = Helper.utilDateFromTimestamp(Helper.timestampFromString((String)sourceObject));
} else if (sourceObject instanceof java.sql.Timestamp) {
date = Helper.utilDateFromTimestamp((java.sql.Timestamp)sourceObject);
} else if (sourceObject instanceof Calendar) {
return ((Calendar)sourceObject).getTime();
} else if (sourceObject instanceof Long) {
date = Helper.utilDateFromLong((Long)sourceObject);
} else if (sourceObject instanceof java.util.Date) {
date = new java.util.Date(((java.util.Date) sourceObject).getTime());
} else {
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.UTILDATE);
}
return date;
}
/**
* PUBLIC:
* Resolve the given String className into a class using this
* ConversionManager's classloader.
*/
public Class convertClassNameToClass(String className) throws ConversionException {
return convertObjectToClass(className);
}
/**
* A singleton conversion manager is used to handle generic conversions.
* This should not be used for conversion under the session context, these must go through the platform.
* This allows for the singleton to be customized through setting the default to a user defined subclass.
*/
public static ConversionManager getDefaultManager() {
if (defaultManager == null) {
setDefaultManager(new ConversionManager());
defaultManager.setShouldUseClassLoaderFromCurrentThread(true);
}
return defaultManager;
}
/**
* INTERNAL:
* Allow for the null values for classes to be defaulted in one place.
* Any nulls read from the database to be converted to the class will be given the specified null value.
*/
public Object getDefaultNullValue(Class theClass) {
if (this.defaultNullValues == null) return null;
return getDefaultNullValues().get(theClass);
}
/**
* INTERNAL:
* Allow for the null values for classes to be defaulted in one place.
* Any nulls read from the database to be converted to the class will be given the specified null value.
*/
public Map getDefaultNullValues() {
return defaultNullValues;
}
/**
* INTERNAL:
*/
@Override
public ClassLoader getLoader() {
if (shouldUseClassLoaderFromCurrentThread()) {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
return AccessController.doPrivileged(new PrivilegedGetContextClassLoader(Thread.currentThread()));
} catch (PrivilegedActionException exception) {
// should not be thrown
}
} else {
return PrivilegedAccessHelper.getContextClassLoader(Thread.currentThread());
}
}
if (loader == null) {
if (defaultLoader == null) {
//CR 2621
ClassLoader loader = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try{
loader = AccessController.doPrivileged(new PrivilegedGetClassLoaderForClass(ClassConstants.ConversionManager_Class));
} catch (PrivilegedActionException exc){
// will not be thrown
}
} else {
loader = PrivilegedAccessHelper.getClassLoaderForClass(ClassConstants.ConversionManager_Class);
}
setLoader(loader);
} else {
setLoader(getDefaultLoader());
}
}
return loader;
}
/**
* INTERNAL
*/
public boolean hasDefaultNullValues(){
return this.defaultNullValues != null;
}
/**
* INTERNAL:
* Load the class using the default managers class loader.
* This is a thread based class loader by default.
* This should be used to load all classes as Class.forName can only
* see classes on the same classpath as the eclipselink.jar.
*/
public static Class loadClass(String className) {
return (Class)getDefaultManager().convertObject(className, ClassConstants.CLASS);
}
/**
* INTERNAL:
* This is used to determine the wrapper class for a primitive.
*/
public static Class getObjectClass(Class javaClass) {
// Null means unknown always for classifications.
if (javaClass == null) {
return null;
}
if (javaClass.isPrimitive()) {
if (javaClass == ClassConstants.PCHAR) {
return ClassConstants.CHAR;
}
if (javaClass == ClassConstants.PINT) {
return ClassConstants.INTEGER;
}
if (javaClass == ClassConstants.PDOUBLE) {
return ClassConstants.DOUBLE;
}
if (javaClass == ClassConstants.PFLOAT) {
return ClassConstants.FLOAT;
}
if (javaClass == ClassConstants.PLONG) {
return ClassConstants.LONG;
}
if (javaClass == ClassConstants.PSHORT) {
return ClassConstants.SHORT;
}
if (javaClass == ClassConstants.PBYTE) {
return ClassConstants.BYTE;
}
if (javaClass == ClassConstants.PBOOLEAN) {
return ClassConstants.BOOLEAN;
}
} else if (javaClass == ClassConstants.APBYTE) {
return ClassConstants.APBYTE;
} else if (javaClass == ClassConstants.APCHAR) {
return ClassConstants.APCHAR;
} else {
return javaClass;
}
return javaClass;
}
/**
* INTERNAL:
* Returns a class based on the passed in string.
*/
public static Class getPrimitiveClass(String classType) {
if (classType.equals("int")) {
return Integer.TYPE;
} else if (classType.equals("boolean")) {
return Boolean.TYPE;
} else if (classType.equals("char")) {
return Character.TYPE;
} else if (classType.equals("short")) {
return Short.TYPE;
} else if (classType.equals("byte")) {
return Byte.TYPE;
} else if (classType.equals("float")) {
return Float.TYPE;
} else if (classType.equals("double")) {
return Double.TYPE;
} else if (classType.equals("long")) {
return Long.TYPE;
}
return null;
}
/**
* A singleton conversion manager is used to handle generic conversions.
* This should not be used for conversion under the session context, these must go through the platform.
* This allows for the singleton to be customized through setting the default to a user defined subclass.
*/
public static void setDefaultManager(ConversionManager theManager) {
defaultManager = theManager;
}
/**
* INTERNAL:
* Allow for the null values for classes to be defaulted in one place.
* Any nulls read from the database to be converted to the class will be given the specified null value.
* Primitive null values should be set to the wrapper class.
*/
public void setDefaultNullValue(Class theClass, Object theValue) {
if (this.defaultNullValues == null){
this.defaultNullValues = new HashMap(5);
}
getDefaultNullValues().put(theClass, theValue);
}
/**
* INTERNAL:
* Allow for the null values for classes to be defaulted in one place.
* Any nulls read from the database to be converted to the class will be given the specified null value.
*/
public void setDefaultNullValues(Map defaultNullValues) {
this.defaultNullValues = defaultNullValues;
}
/**
* INTERNAL:
* @parameter java.lang.ClassLoader
*/
public void setLoader(ClassLoader classLoader) {
shouldUseClassLoaderFromCurrentThread = false;
loader = classLoader;
}
/**
* INTERNAL:
* Set the default class loader to use if no instance-level loader is set
* @parameter java.lang.ClassLoader
*/
public static void setDefaultLoader(ClassLoader classLoader) {
defaultLoader = classLoader;
}
/**
* INTERNAL:
* Get the default class loader to use if no instance-level loader is set
* @return java.lang.ClassLoader
*/
public static ClassLoader getDefaultLoader() {
return defaultLoader;
}
/**
* ADVANCED:
* This flag should be set if the current thread classLoader should be used.
* This is the case in certain Application Servers were the class loader must be
* retrieved from the current Thread. If classNotFoundExceptions are being thrown then set
* this flag. In certain cases it will resolve the problem
*/
public void setShouldUseClassLoaderFromCurrentThread(boolean useCurrentThread) {
this.shouldUseClassLoaderFromCurrentThread = useCurrentThread;
}
/**
* ADVANCED:
* This flag should be set if the current thread classLoader should be used.
* This is the case in certain Application Servers were the class loader must be
* retrieved from the current Thread. If classNotFoundExceptions are being thrown then set
* this flag. In certain cases it will resolve the problem
*/
public boolean shouldUseClassLoaderFromCurrentThread() {
return this.shouldUseClassLoaderFromCurrentThread;
}
/**
* PUBLIC:
* Return the list of Classes that can be converted to from the passed in javaClass.
* @param javaClass - the class that is converted from
* @return - a vector of classes
*/
public Vector getDataTypesConvertedFrom(Class javaClass) {
if (dataTypesConvertedFromAClass.isEmpty()) {
buildDataTypesConvertedFromAClass();
}
return (Vector)dataTypesConvertedFromAClass.get(javaClass);
}
/**
* PUBLIC:
* Return the list of Classes that can be converted from to the passed in javaClass.
* @param javaClass - the class that is converted to
* @return - a vector of classes
*/
public Vector getDataTypesConvertedTo(Class javaClass) {
if (dataTypesConvertedToAClass.isEmpty()) {
buildDataTypesConvertedToAClass();
}
return (Vector)dataTypesConvertedToAClass.get(javaClass);
}
protected Vector buildNumberVec() {
Vector vec = new Vector();
vec.addElement(BigInteger.class);
vec.addElement(BigDecimal.class);
vec.addElement(Byte.class);
vec.addElement(Double.class);
vec.addElement(Float.class);
vec.addElement(Integer.class);
vec.addElement(Long.class);
vec.addElement(Short.class);
vec.addElement(Number.class);
return vec;
}
protected Vector buildDateTimeVec() {
Vector vec = new Vector();
vec.addElement(java.util.Date.class);
vec.addElement(Timestamp.class);
vec.addElement(Calendar.class);
return vec;
}
protected void buildDataTypesConvertedFromAClass() {
dataTypesConvertedFromAClass.put(BigDecimal.class, buildFromBigDecimalVec());
dataTypesConvertedFromAClass.put(BigInteger.class, buildFromBigIntegerVec());
dataTypesConvertedFromAClass.put(Blob.class, buildFromBlobVec());
dataTypesConvertedFromAClass.put(Boolean.class, buildFromBooleanVec());
dataTypesConvertedFromAClass.put(byte[].class, buildFromByteArrayVec());
dataTypesConvertedFromAClass.put(Byte.class, buildFromByteVec());
dataTypesConvertedFromAClass.put(Calendar.class, buildFromCalendarVec());
dataTypesConvertedFromAClass.put(Character.class, buildFromCharacterVec());
dataTypesConvertedFromAClass.put(Clob.class, buildFromClobVec());
dataTypesConvertedFromAClass.put(java.sql.Date.class, buildFromDateVec());
dataTypesConvertedFromAClass.put(Double.class, buildFromDoubleVec());
dataTypesConvertedFromAClass.put(Float.class, buildFromFloatVec());
dataTypesConvertedFromAClass.put(Integer.class, buildFromIntegerVec());
dataTypesConvertedFromAClass.put(Long.class, buildFromLongVec());
dataTypesConvertedFromAClass.put(Number.class, buildFromNumberVec());
dataTypesConvertedFromAClass.put(Short.class, buildFromShortVec());
dataTypesConvertedFromAClass.put(String.class, buildFromStringVec());
dataTypesConvertedFromAClass.put(Timestamp.class, buildFromTimestampVec());
dataTypesConvertedFromAClass.put(Time.class, buildFromTimeVec());
dataTypesConvertedFromAClass.put(java.util.Date.class, buildFromUtilDateVec());
dataTypesConvertedFromAClass.put(Byte[].class, buildFromByteObjectArraryVec());
dataTypesConvertedFromAClass.put(char[].class, buildFromCharArrayVec());
dataTypesConvertedFromAClass.put(Character[].class, buildFromCharacterArrayVec());
}
protected Vector buildFromBooleanVec() {
Vector vec = new Vector();
vec.addElement(String.class);
vec.addElement(Boolean.class);
vec.addElement(Integer.class);
vec.addElement(Long.class);
vec.addElement(Short.class);
vec.addElement(Number.class);
vec.addElement(Character[].class);
vec.addElement(char[].class);
vec.addElement(boolean.class);
vec.addElement(int.class);
vec.addElement(long.class);
vec.addElement(short.class);
return vec;
}
protected Vector buildFromNumberVec() {
Vector vec = buildNumberVec();
vec.addElement(String.class);
vec.addElement(Character.class);
vec.addElement(Boolean.class);
vec.addElement(Character[].class);
vec.addElement(char[].class);
vec.addElement(char.class);
vec.addElement(int.class);
vec.addElement(double.class);
vec.addElement(float.class);
vec.addElement(long.class);
vec.addElement(short.class);
vec.addElement(byte.class);
vec.addElement(boolean.class);
return vec;
}
protected Vector buildFromBigDecimalVec() {
return buildFromNumberVec();
}
protected Vector buildFromBigIntegerVec() {
return buildFromNumberVec();
}
protected Vector buildFromIntegerVec() {
return buildFromNumberVec();
}
protected Vector buildFromFloatVec() {
return buildFromNumberVec();
}
protected Vector buildFromDoubleVec() {
return buildFromNumberVec();
}
protected Vector buildFromShortVec() {
return buildFromNumberVec();
}
protected Vector buildFromByteVec() {
return buildFromNumberVec();
}
protected Vector buildFromLongVec() {
Vector vec = buildFromNumberVec();
vec.addAll(buildDateTimeVec());
vec.addElement(java.sql.Date.class);
vec.addElement(Time.class);
return vec;
}
protected Vector buildFromStringVec() {
Vector vec = buildFromLongVec();
vec.addElement(Byte[].class);
vec.addElement(byte[].class);
vec.addElement(Clob.class);
return vec;
}
protected Vector buildFromCharacterVec() {
Vector vec = new Vector();
vec.addElement(String.class);
vec.addElement(Boolean.class);
vec.addElement(Character[].class);
vec.addElement(Character.class);
vec.addElement(char[].class);
vec.addElement(char.class);
vec.addElement(boolean.class);
return vec;
}
protected Vector buildFromByteArrayVec() {
Vector vec = new Vector();
vec.addElement(String.class);
vec.addElement(byte[].class);
vec.addElement(Byte[].class);
vec.addElement(Character[].class);
vec.addElement(char[].class);
return vec;
}
protected Vector buildFromClobVec() {
Vector vec = new Vector();
vec.addElement(String.class);
vec.addElement(Character[].class);
vec.addElement(char[].class);
return vec;
}
protected Vector buildFromBlobVec() {
Vector vec = new Vector();
vec.addElement(String.class);
vec.addElement(Byte[].class);
vec.addElement(byte[].class);
vec.addElement(Character[].class);
vec.addElement(char[].class);
return vec;
}
protected Vector buildFromUtilDateVec() {
Vector vec = buildDateTimeVec();
vec.addElement(String.class);
vec.addElement(Long.class);
vec.addElement(java.sql.Date.class);
vec.addElement(Time.class);
vec.addElement(long.class);
vec.addElement(Character[].class);
vec.addElement(char[].class);
return vec;
}
protected Vector buildFromTimestampVec() {
return buildFromUtilDateVec();
}
protected Vector buildFromCalendarVec() {
return buildFromUtilDateVec();
}
protected Vector buildFromDateVec() {
Vector vec = buildDateTimeVec();
vec.addElement(String.class);
vec.addElement(Long.class);
vec.addElement(java.sql.Date.class);
vec.addElement(long.class);
vec.addElement(Character[].class);
vec.addElement(char[].class);
return vec;
}
protected Vector buildFromTimeVec() {
Vector vec = buildDateTimeVec();
vec.addElement(String.class);
vec.addElement(Long.class);
vec.addElement(Time.class);
vec.addElement(long.class);
vec.addElement(Character[].class);
vec.addElement(char[].class);
return vec;
}
protected Vector buildFromByteObjectArraryVec() {
Vector vec = new Vector();
vec.addElement(Blob.class);
vec.addElement(byte[].class);
return vec;
}
protected Vector buildFromCharArrayVec() {
Vector vec = new Vector();
vec.addElement(Clob.class);
return vec;
}
protected Vector buildFromCharacterArrayVec() {
Vector vec = new Vector();
vec.addElement(Clob.class);
return vec;
}
protected void buildDataTypesConvertedToAClass() {
dataTypesConvertedToAClass.put(BigDecimal.class, buildToBigDecimalVec());
dataTypesConvertedToAClass.put(BigInteger.class, buildToBigIntegerVec());
dataTypesConvertedToAClass.put(Boolean.class, buildToBooleanVec());
dataTypesConvertedToAClass.put(Byte.class, buildToByteVec());
dataTypesConvertedToAClass.put(byte[].class, buildToByteArrayVec());
dataTypesConvertedToAClass.put(Byte[].class, buildToByteObjectArrayVec());
dataTypesConvertedToAClass.put(Calendar.class, buildToCalendarVec());
dataTypesConvertedToAClass.put(Character.class, buildToCharacterVec());
dataTypesConvertedToAClass.put(Character[].class, buildToCharacterArrayVec());
dataTypesConvertedToAClass.put(char[].class, buildToCharArrayVec());
dataTypesConvertedToAClass.put(java.sql.Date.class, buildToDateVec());
dataTypesConvertedToAClass.put(Double.class, buildToDoubleVec());
dataTypesConvertedToAClass.put(Float.class, buildToFloatVec());
dataTypesConvertedToAClass.put(Integer.class, buildToIntegerVec());
dataTypesConvertedToAClass.put(Long.class, buildToLongVec());
dataTypesConvertedToAClass.put(Number.class, buildToNumberVec());
dataTypesConvertedToAClass.put(Short.class, buildToShortVec());
dataTypesConvertedToAClass.put(String.class, buildToStringVec());
dataTypesConvertedToAClass.put(Timestamp.class, buildToTimestampVec());
dataTypesConvertedToAClass.put(Time.class, buildToTimeVec());
dataTypesConvertedToAClass.put(java.util.Date.class, buildToUtilDateVec());
dataTypesConvertedToAClass.put(Clob.class, buildToClobVec());
dataTypesConvertedToAClass.put(Blob.class, buildToBlobVec());
}
protected Vector buildAllTypesToAClassVec() {
Vector vec = new Vector();
vec.addElement(String.class);
vec.addElement(Integer.class);
vec.addElement(java.util.Date.class);
vec.addElement(java.sql.Date.class);
vec.addElement(Time.class);
vec.addElement(Timestamp.class);
vec.addElement(Calendar.class);
vec.addElement(Character.class);
vec.addElement(Double.class);
vec.addElement(Float.class);
vec.addElement(Long.class);
vec.addElement(Short.class);
vec.addElement(Byte.class);
vec.addElement(BigInteger.class);
vec.addElement(BigDecimal.class);
vec.addElement(Number.class);
vec.addElement(Boolean.class);
vec.addElement(Character[].class);
vec.addElement(Blob.class);
vec.addElement(Clob.class);
return vec;
}
protected Vector buildToBigDecimalVec() {
Vector vec = buildNumberVec();
vec.addElement(String.class);
return vec;
}
protected Vector buildToBigIntegerVec() {
return buildToBigDecimalVec();
}
protected Vector buildToBooleanVec() {
Vector vec = buildToBigDecimalVec();
vec.addElement(Character.class);
vec.addElement(Boolean.class);
return vec;
}
protected Vector buildToByteVec() {
return buildToBigDecimalVec();
}
protected Vector buildToDoubleVec() {
return buildToBigDecimalVec();
}
protected Vector buildToFloatVec() {
return buildToBigDecimalVec();
}
protected Vector buildToIntegerVec() {
Vector vec = buildToBigDecimalVec();
vec.addElement(Boolean.class);
return vec;
}
protected Vector buildToLongVec() {
Vector vec = buildToIntegerVec();
vec.addElement(Calendar.class);
vec.addElement(java.util.Date.class);
return vec;
}
protected Vector buildToNumberVec() {
return buildToIntegerVec();
}
protected Vector buildToShortVec() {
return buildToIntegerVec();
}
protected Vector buildToByteArrayVec() {
Vector vec = new Vector();
vec.addElement(String.class);
vec.addElement(Blob.class);
vec.addElement(byte[].class);
vec.addElement(Byte[].class);
return vec;
}
protected Vector buildToByteObjectArrayVec() {
Vector vec = buildToByteArrayVec();
vec.addElement(Byte[].class);
return vec;
}
protected Vector buildToCharacterVec() {
Vector vec = buildToBigDecimalVec();
vec.addElement(Character.class);
return vec;
}
protected Vector buildToCharacterArrayVec() {
return buildAllTypesToAClassVec();
}
protected Vector buildToCharArrayVec() {
return buildAllTypesToAClassVec();
}
protected Vector buildToStringVec() {
return buildAllTypesToAClassVec();
}
protected Vector buildToCalendarVec() {
Vector vec = buildDateTimeVec();
vec.addElement(String.class);
vec.addElement(Long.class);
vec.addElement(java.sql.Date.class);
vec.addElement(Time.class);
return vec;
}
protected Vector buildToTimestampVec() {
return buildToCalendarVec();
}
protected Vector buildToUtilDateVec() {
return buildToCalendarVec();
}
protected Vector buildToDateVec() {
Vector vec = buildDateTimeVec();
vec.addElement(String.class);
vec.addElement(Long.class);
vec.addElement(java.sql.Date.class);
return vec;
}
protected Vector buildToTimeVec() {
Vector vec = buildDateTimeVec();
vec.addElement(String.class);
vec.addElement(Long.class);
vec.addElement(Time.class);
return vec;
}
protected Vector buildToBlobVec() {
Vector vec = new Vector();
vec.addElement(Byte[].class);
vec.addElement(byte[].class);
return vec;
}
protected Vector buildToClobVec() {
Vector vec = new Vector();
vec.addElement(String.class);
vec.addElement(char[].class);
vec.addElement(Character[].class);
return vec;
}
}
|