KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > helper > ConversionManager


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.helper;
23
24 import java.math.*;
25 import java.util.*;
26 import java.io.*;
27 import java.security.AccessController JavaDoc;
28 import java.security.PrivilegedActionException JavaDoc;
29 import java.sql.*;
30
31 import oracle.toplink.essentials.exceptions.*;
32 import oracle.toplink.essentials.internal.security.PrivilegedAccessHelper;
33 import oracle.toplink.essentials.internal.security.PrivilegedGetClassLoaderForClass;
34 import oracle.toplink.essentials.internal.security.PrivilegedGetContextClassLoader;
35
36 /**
37  * <p>
38  * <b>Purpose</b>: Contains the conversion routines for some common classes in the system.
39  * Primarly used to convert objects from a given database type to a different type in Java.
40  * Uses a singleton instance, this is also used from the platform.
41  * <p>
42  * <b>Responsibilities</b>:
43  * <ul>
44  * <li> Execute the appropriate conversion routine.
45  * </ul>
46  */

47 public class ConversionManager implements Serializable, Cloneable JavaDoc {
48     protected Map defaultNullValues;
49
50     /**
51      * This flag is here if the Conversion Manager should use the class loader on the
52      * thread when loading classes.
53      */

54     protected boolean shouldUseClassLoaderFromCurrentThread = false;
55     protected static ConversionManager defaultManager;
56
57     /** Allows the setting of a global default if no instance-level loader is set. */
58     private static ClassLoader JavaDoc defaultLoader;
59     protected ClassLoader JavaDoc loader;
60
61     /** Store the list of Classes that can be converted to from the key. */
62     protected Hashtable dataTypesConvertedFromAClass;
63
64     /** Store the list of Classes that can be converted from to the key. */
65     protected Hashtable dataTypesConvertedToAClass;
66
67     public ConversionManager() {
68         this.defaultNullValues = new HashMap(5);
69         this.dataTypesConvertedFromAClass = new Hashtable();
70         this.dataTypesConvertedToAClass = new Hashtable();
71     }
72
73     /**
74      * INTERNAL:
75      */

76     public Object JavaDoc clone() {
77         try {
78             return super.clone();
79         } catch (CloneNotSupportedException JavaDoc exception) {
80             return null;
81         }
82     }
83
84     /**
85      * Convert the object to the appropriate type by invoking the appropriate
86      * ConversionManager method
87      * @param object - the object that must be converted
88      * @param javaClass - the class that the object must be converted to
89      * @exception - ConversionException, all exceptions will be thrown as this type.
90      * @return - the newly converted object
91      */

92     public Object JavaDoc convertObject(Object JavaDoc sourceObject, Class JavaDoc javaClass) throws ConversionException {
93         if (sourceObject == null) {
94             // Check for default null conversion.
95
// i.e. allow for null to be defaulted to "", or 0 etc.
96
if (javaClass != null) {
97                 return getDefaultNullValue(javaClass);
98             } else {
99                 return null;
100             }
101         }
102
103         if ((sourceObject.getClass() == javaClass) || (javaClass == null) || (javaClass == ClassConstants.OBJECT) || (javaClass == ClassConstants.BLOB) || (javaClass == ClassConstants.CLOB) || ClassConstants.NOCONVERSION.isAssignableFrom(javaClass)) {
104             return sourceObject;
105         }
106
107         // Check if object is instance of the real class for the primitive class.
108
if (javaClass.isPrimitive() && (((sourceObject instanceof Boolean JavaDoc) && (javaClass == ClassConstants.PBOOLEAN)) || ((sourceObject instanceof Long JavaDoc) && (javaClass == ClassConstants.PLONG)) || ((sourceObject instanceof Integer JavaDoc) && (javaClass == ClassConstants.PINT)) || ((sourceObject instanceof Float JavaDoc) && (javaClass == ClassConstants.PFLOAT)) || ((sourceObject instanceof Double JavaDoc) && (javaClass == ClassConstants.PDOUBLE)) || ((sourceObject instanceof Byte JavaDoc) && (javaClass == ClassConstants.PBYTE)) || ((sourceObject instanceof Character JavaDoc) && (javaClass == ClassConstants.PCHAR)) || ((sourceObject instanceof Short JavaDoc) && (javaClass == ClassConstants.PSHORT)))) {
109             return sourceObject;
110         }
111
112         try {
113             if (javaClass == ClassConstants.STRING) {
114                 return convertObjectToString(sourceObject);
115             } else if (javaClass == ClassConstants.UTILDATE) {
116                 return convertObjectToUtilDate(sourceObject);
117             } else if (javaClass == ClassConstants.SQLDATE) {
118                 return convertObjectToDate(sourceObject);
119             } else if (javaClass == ClassConstants.TIME) {
120                 return convertObjectToTime(sourceObject);
121             } else if (javaClass == ClassConstants.TIMESTAMP) {
122                 return convertObjectToTimestamp(sourceObject);
123             } else if ((javaClass == ClassConstants.CALENDAR) || (javaClass == ClassConstants.GREGORIAN_CALENDAR)) {
124                 return convertObjectToCalendar(sourceObject);
125             } else if ((javaClass == ClassConstants.CHAR) || (javaClass == ClassConstants.PCHAR)) {
126                 return convertObjectToChar(sourceObject);
127             } else if ((javaClass == ClassConstants.INTEGER) || (javaClass == ClassConstants.PINT)) {
128                 return convertObjectToInteger(sourceObject);
129             } else if ((javaClass == ClassConstants.DOUBLE) || (javaClass == ClassConstants.PDOUBLE)) {
130                 return convertObjectToDouble(sourceObject);
131             } else if ((javaClass == ClassConstants.FLOAT) || (javaClass == ClassConstants.PFLOAT)) {
132                 return convertObjectToFloat(sourceObject);
133             } else if ((javaClass == ClassConstants.LONG) || (javaClass == ClassConstants.PLONG)) {
134                 return convertObjectToLong(sourceObject);
135             } else if ((javaClass == ClassConstants.SHORT) || (javaClass == ClassConstants.PSHORT)) {
136                 return convertObjectToShort(sourceObject);
137             } else if ((javaClass == ClassConstants.BYTE) || (javaClass == ClassConstants.PBYTE)) {
138                 return convertObjectToByte(sourceObject);
139             } else if (javaClass == ClassConstants.BIGINTEGER) {
140                 return convertObjectToBigInteger(sourceObject);
141             } else if (javaClass == ClassConstants.BIGDECIMAL) {
142                 return convertObjectToBigDecimal(sourceObject);
143             } else if (javaClass == ClassConstants.NUMBER) {
144                 return convertObjectToNumber(sourceObject);
145             } else if ((javaClass == ClassConstants.BOOLEAN) || (javaClass == ClassConstants.PBOOLEAN)) {
146                 return convertObjectToBoolean(sourceObject);
147             } else if (javaClass == ClassConstants.APBYTE) {
148                 return convertObjectToByteArray(sourceObject);
149             } else if (javaClass == ClassConstants.ABYTE) {
150                 return convertObjectToByteObjectArray(sourceObject);
151             } else if (javaClass == ClassConstants.APCHAR) {
152                 return convertObjectToCharArray(sourceObject);
153             } else if (javaClass == ClassConstants.ACHAR) {
154                 return convertObjectToCharacterArray(sourceObject);
155             } else if ((sourceObject.getClass() == ClassConstants.STRING) && (javaClass == ClassConstants.CLASS)) {
156                 return convertObjectToClass(sourceObject);
157             }
158         } catch (ConversionException ce) {
159             throw ce;
160         } catch (Exception JavaDoc e) {
161             throw ConversionException.couldNotBeConverted(sourceObject, javaClass, e);
162         }
163
164         // Delay this check as poor performance.
165
if (javaClass.isInstance(sourceObject)) {
166             return sourceObject;
167         }
168
169         throw ConversionException.couldNotBeConverted(sourceObject, javaClass);
170     }
171
172     /**
173      * Build a valid instance of BigDecimal from the given sourceObject
174      * @param sourceObject Valid instance of String, BigInteger, any Number
175      */

176     protected BigDecimal convertObjectToBigDecimal(Object JavaDoc sourceObject) throws ConversionException {
177         BigDecimal bigDecimal = null;
178
179         try {
180             if (sourceObject instanceof String JavaDoc) {
181                 bigDecimal = new BigDecimal((String JavaDoc)sourceObject);
182             } else if (sourceObject instanceof BigInteger) {
183                 bigDecimal = new BigDecimal((BigInteger)sourceObject);
184             } else if (sourceObject instanceof Number JavaDoc) {
185                 bigDecimal = new BigDecimal(((Number JavaDoc)sourceObject).doubleValue());
186             } else {
187                 throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BIGDECIMAL);
188             }
189         } catch (NumberFormatException JavaDoc exception) {
190             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BIGDECIMAL, exception);
191         }
192         return bigDecimal;
193     }
194
195     /**
196      * Build a valid instance of BigInteger from the provided sourceObject.
197      * @param sourceObject Valid instance of String, BigDecimal, or any Number
198      */

199     protected BigInteger convertObjectToBigInteger(Object JavaDoc sourceObject) throws ConversionException {
200         BigInteger bigInteger = null;
201
202         try {
203             if (sourceObject instanceof BigInteger) {
204                 bigInteger = (BigInteger)sourceObject;
205             } else if (sourceObject instanceof String JavaDoc) {
206                 bigInteger = new BigInteger((String JavaDoc)sourceObject);
207             } else if (sourceObject instanceof BigDecimal) {
208                 bigInteger = ((BigDecimal)sourceObject).toBigInteger();
209             } else if (sourceObject instanceof Number JavaDoc) {
210                 bigInteger = new BigInteger(new Long JavaDoc(((Number JavaDoc)sourceObject).longValue()).toString());
211             } else {
212                 throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BIGINTEGER);
213             }
214         } catch (NumberFormatException JavaDoc exception) {
215             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BIGINTEGER, exception);
216         }
217
218         return bigInteger;
219     }
220
221     /**
222      * Build a valid instance of Boolean from the source object.
223      * 't', 'T', "true", "TRUE", 1,'1' -> Boolean(true)
224      * 'f', 'F', "false", "FALSE", 0 ,'0' -> Boolean(false)
225      */

226     protected Boolean JavaDoc convertObjectToBoolean(Object JavaDoc sourceObject) {
227         if (sourceObject instanceof Character JavaDoc) {
228             switch (Character.toLowerCase(((Character JavaDoc)sourceObject).charValue())) {
229             case '1':
230             case 't':
231                 return new Boolean JavaDoc(true);
232             case '0':
233             case 'f':
234                 return new Boolean JavaDoc(false);
235             }
236         }
237         if (sourceObject instanceof String JavaDoc) {
238             String JavaDoc stringValue = ((String JavaDoc)sourceObject).toLowerCase();
239             if (stringValue.equals("t") || stringValue.equals("true") || stringValue.equals("1")) {
240                 return new Boolean JavaDoc(true);
241             } else if (stringValue.equals("f") || stringValue.equals("false") || stringValue.equals("0")) {
242                 return new Boolean JavaDoc(false);
243             }
244         }
245         if (sourceObject instanceof Number JavaDoc) {
246             int intValue = ((Number JavaDoc)sourceObject).intValue();
247             if (intValue != 0) {
248                 return new Boolean JavaDoc(true);
249             } else if (intValue == 0) {
250                 return new Boolean JavaDoc(false);
251             }
252         }
253         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BOOLEAN);
254     }
255
256     /**
257      * Build a valid instance of Byte from the provided sourceObject
258      * @param sourceObject Valid instance of String or any Number
259      * @caught exception The Byte(String) constructer throws a
260      * NumberFormatException if the String does not contain a
261      * parsable byte.
262      *
263      */

264     protected Byte JavaDoc convertObjectToByte(Object JavaDoc sourceObject) throws ConversionException {
265         try {
266             if (sourceObject instanceof String JavaDoc) {
267                 return new Byte JavaDoc((String JavaDoc)sourceObject);
268             }
269             if (sourceObject instanceof Number JavaDoc) {
270                 return new Byte JavaDoc(((Number JavaDoc)sourceObject).byteValue());
271             }
272         } catch (NumberFormatException JavaDoc exception) {
273             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BYTE, exception);
274         }
275
276         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.BYTE);
277     }
278
279     /**
280       * Build a valid instance of a byte array from the given object.
281       * This method does hex conversion of the string values. Some
282       * databases have problems with storing blobs unless the blob
283       * is stored as a hex string.
284       */

285     protected byte[] convertObjectToByteArray(Object JavaDoc sourceObject) throws ConversionException {
286         //Bug#3128838 Used when converted to Byte[]
287
if (sourceObject instanceof byte[]) {
288             return (byte[])sourceObject;
289             //Related to Bug#3128838. Add support to convert to Byte[]
290
} else if (sourceObject instanceof Byte JavaDoc[]) {
291             Byte JavaDoc[] objectBytes = (Byte JavaDoc[])sourceObject;
292             byte[] bytes = new byte[objectBytes.length];
293             for (int index = 0; index < objectBytes.length; index++) {
294                 bytes[index] = objectBytes[index].byteValue();
295             }
296             return bytes;
297         } else if (sourceObject instanceof String JavaDoc) {
298             return Helper.buildBytesFromHexString((String JavaDoc)sourceObject);
299         } else if (sourceObject instanceof Blob) {
300             Blob blob = (Blob)sourceObject;
301             try {
302                 return blob.getBytes(1L, (int)blob.length());
303             } catch (SQLException exception) {
304                 throw DatabaseException.sqlException(exception);
305             }
306         }
307
308         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.APBYTE);
309     }
310
311     /**
312       * Build a valid instance of a Byte array from the given object.
313       * This method does hex conversion of the string values. Some
314       * databases have problems with storing blobs unless the blob
315       * is stored as a hex string.
316       */

317     protected Byte JavaDoc[] convertObjectToByteObjectArray(Object JavaDoc sourceObject) throws ConversionException {
318         byte[] bytes = convertObjectToByteArray(sourceObject);
319         Byte JavaDoc[] objectBytes = new Byte JavaDoc[bytes.length];
320         for (int index = 0; index < bytes.length; index++) {
321             objectBytes[index] = new Byte JavaDoc(bytes[index]);
322         }
323         return objectBytes;
324     }
325
326     /**
327      * Build a valid instance of java.util.Calendar from the given source object.
328      * @param sourceObject Valid instance of java.util.Date, String, java.sql.Timestamp, or Long
329      */

330     protected Calendar convertObjectToCalendar(Object JavaDoc sourceObject) throws ConversionException {
331         if (sourceObject instanceof Calendar) {
332             return (Calendar)sourceObject;
333         } else if (sourceObject instanceof java.util.Date JavaDoc) {
334             // PERF: Avoid double conversion for date subclasses.
335
return Helper.calendarFromUtilDate((java.util.Date JavaDoc)sourceObject);
336         }
337         return Helper.calendarFromUtilDate(convertObjectToUtilDate(sourceObject));
338     }
339
340     /**
341      * Build a valid instance of Character from the provided sourceObject.
342      * @param sourceObject Valid instance of String or any Number
343      */

344     protected Character JavaDoc convertObjectToChar(Object JavaDoc sourceObject) throws ConversionException {
345         if (sourceObject instanceof String JavaDoc) {
346             if (((String JavaDoc)sourceObject).length() < 1) {
347                 return null;
348             }
349             return new Character JavaDoc(((String JavaDoc)sourceObject).charAt(0));
350         }
351
352         if (sourceObject instanceof Number JavaDoc) {
353             return new Character JavaDoc((char)((Number JavaDoc)sourceObject).byteValue());
354         }
355
356         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.CHAR);
357     }
358
359     /**
360       * Build a valid instance of a Character array from the given object.
361       */

362     protected Character JavaDoc[] convertObjectToCharacterArray(Object JavaDoc sourceObject) throws ConversionException {
363         String JavaDoc stringValue = convertObjectToString(sourceObject);
364         Character JavaDoc[] chars = new Character JavaDoc[stringValue.length()];
365         for (int index = 0; index < stringValue.length(); index++) {
366             chars[index] = new Character JavaDoc(stringValue.charAt(index));
367         }
368         return chars;
369     }
370
371     /**
372       * Build a valid instance of a char array from the given object.
373       */

374     protected char[] convertObjectToCharArray(Object JavaDoc sourceObject) throws ConversionException {
375         if (sourceObject instanceof Character JavaDoc[]) {
376             Character JavaDoc[] objectChars = (Character JavaDoc[])sourceObject;
377             char[] chars = new char[objectChars.length];
378             for (int index = 0; index < objectChars.length; index++) {
379                 chars[index] = objectChars[index].charValue();
380             }
381             return chars;
382         }
383         String JavaDoc stringValue = convertObjectToString(sourceObject);
384         char[] chars = new char[stringValue.length()];
385         for (int index = 0; index < stringValue.length(); index++) {
386             chars[index] = stringValue.charAt(index);
387         }
388         return chars;
389     }
390
391     /**
392      * Build a valid Class from the string that is passed in
393      * @param sourceObject Valid instance of String
394      */

395     protected Class JavaDoc convertObjectToClass(Object JavaDoc sourceObject) throws ConversionException {
396         Class JavaDoc theClass = null;
397         if (!(sourceObject instanceof String JavaDoc)) {
398             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.CLASS);
399         }
400         try {
401             // bug # 2799318
402
theClass = getPrimitiveClass((String JavaDoc)sourceObject);
403             if (theClass == null) {
404                 theClass = getLoader().loadClass((String JavaDoc)sourceObject);
405             }
406         } catch (Exception JavaDoc exception) {
407             throw ConversionException.couldNotBeConvertedToClass(sourceObject, ClassConstants.CLASS, exception);
408         }
409         return theClass;
410     }
411
412     /**
413       * Convert the object to an instance of java.sql.Date.
414       * @param sourceObject Object of type java.sql.Timestamp, java.util.Date, String or Long
415       */

416     protected java.sql.Date JavaDoc convertObjectToDate(Object JavaDoc sourceObject) throws ConversionException {
417         java.sql.Date JavaDoc date = null;
418         Class JavaDoc sourceClass = sourceObject.getClass();
419
420         if (sourceObject instanceof java.sql.Date JavaDoc) {
421             date = (java.sql.Date JavaDoc)sourceObject;//Helper date is not caught on class check.
422
} else if (sourceObject instanceof java.sql.Timestamp JavaDoc) {
423             date = Helper.dateFromTimestamp((java.sql.Timestamp JavaDoc)sourceObject);
424         } else if (sourceObject.getClass() == ClassConstants.UTILDATE) {
425             date = Helper.sqlDateFromUtilDate((java.util.Date JavaDoc)sourceObject);
426         } else if (sourceObject instanceof Calendar) {
427             return Helper.dateFromCalendar((Calendar)sourceObject);
428         } else if (sourceObject instanceof String JavaDoc) {
429             date = Helper.dateFromString((String JavaDoc)sourceObject);
430         } else if (sourceObject instanceof Long JavaDoc) {
431             date = Helper.dateFromLong((Long JavaDoc)sourceObject);
432         } else {
433             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.SQLDATE);
434         }
435         return date;
436     }
437
438     /**
439       * Convert the object to an instance of Double.
440       * @param sourceObject Object of type String or Number.
441       * @caught exception The Double(String) constructer throws a
442       * NumberFormatException if the String does not contain a
443       * parsable double.
444       */

445     protected Double JavaDoc convertObjectToDouble(Object JavaDoc sourceObject) throws ConversionException {
446         try {
447             if (sourceObject instanceof String JavaDoc) {
448                 return new Double JavaDoc((String JavaDoc)sourceObject);
449             }
450             if (sourceObject instanceof Number JavaDoc) {
451                 return new Double JavaDoc(((Number JavaDoc)sourceObject).doubleValue());
452             }
453         } catch (NumberFormatException JavaDoc exception) {
454             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.DOUBLE, exception);
455         }
456         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.DOUBLE);
457     }
458
459     /**
460      * Build a valid Float instance from a String or another Number instance.
461      * @caught exception The Float(String) constructer throws a
462      * NumberFormatException if the String does not contain a
463      * parsable Float.
464      */

465     protected Float JavaDoc convertObjectToFloat(Object JavaDoc sourceObject) throws ConversionException {
466         try {
467             if (sourceObject instanceof String JavaDoc) {
468                 return new Float JavaDoc((String JavaDoc)sourceObject);
469             }
470             if (sourceObject instanceof Number JavaDoc) {
471                 return new Float JavaDoc(((Number JavaDoc)sourceObject).floatValue());
472             }
473         } catch (NumberFormatException JavaDoc exception) {
474             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.FLOAT, exception);
475         }
476
477         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.FLOAT);
478     }
479
480     /**
481      * Build a valid Integer instance from a String or another Number instance.
482      * @caught exception The Integer(String) constructer throws a
483      * NumberFormatException if the String does not contain a
484      * parsable integer.
485      */

486     protected Integer JavaDoc convertObjectToInteger(Object JavaDoc sourceObject) throws ConversionException {
487         try {
488             if (sourceObject instanceof String JavaDoc) {
489                 return new Integer JavaDoc((String JavaDoc)sourceObject);
490             }
491
492             if (sourceObject instanceof Number JavaDoc) {
493                 return new Integer JavaDoc(((Number JavaDoc)sourceObject).intValue());
494             }
495
496             if (sourceObject instanceof Boolean JavaDoc) {
497                 if (((Boolean JavaDoc)sourceObject).booleanValue()) {
498                     return new Integer JavaDoc(1);
499                 } else {
500                     return new Integer JavaDoc(0);
501                 }
502             }
503         } catch (NumberFormatException JavaDoc exception) {
504             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.INTEGER, exception);
505         }
506
507         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.INTEGER);
508     }
509
510     /**
511       * Build a valid Long instance from a String or another Number instance.
512       * @caught exception The Long(String) constructer throws a
513       * NumberFormatException if the String does not contain a
514       * parsable long.
515       *
516       */

517     protected Long JavaDoc convertObjectToLong(Object JavaDoc sourceObject) throws ConversionException {
518         try {
519             if (sourceObject instanceof String JavaDoc) {
520                 return new Long JavaDoc((String JavaDoc)sourceObject);
521             }
522             if (sourceObject instanceof Number JavaDoc) {
523                 return new Long JavaDoc(((Number JavaDoc)sourceObject).longValue());
524             }
525             if (sourceObject instanceof java.util.Date JavaDoc) {
526                 return new Long JavaDoc(((java.util.Date JavaDoc)sourceObject).getTime());
527             }
528             if (sourceObject instanceof java.util.Calendar JavaDoc) {
529                 return new Long JavaDoc(JavaPlatform.getTimeInMillis(((java.util.Calendar JavaDoc)sourceObject)));
530             }
531
532             if (sourceObject instanceof Boolean JavaDoc) {
533                 if (((Boolean JavaDoc)sourceObject).booleanValue()) {
534                     return new Long JavaDoc(1);
535                 } else {
536                     return new Long JavaDoc(0);
537                 }
538             }
539         } catch (NumberFormatException JavaDoc exception) {
540             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.LONG, exception);
541         }
542
543         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.LONG);
544     }
545
546     /**
547      * INTERNAL:
548      * Build a valid BigDecimal instance from a String or another
549      * Number instance. BigDecimal is the most general type so is
550      * must be returned when an object is converted to a number.
551      * @caught exception The BigDecimal(String) constructer throws a
552      * NumberFormatException if the String does not contain a
553      * parsable BigDecimal.
554      */

555     protected BigDecimal convertObjectToNumber(Object JavaDoc sourceObject) throws ConversionException {
556         try {
557             if (sourceObject instanceof String JavaDoc) {
558                 return new BigDecimal((String JavaDoc)sourceObject);
559             }
560
561             if (sourceObject instanceof Number JavaDoc) {
562                 return new BigDecimal(((Number JavaDoc)sourceObject).doubleValue());
563             }
564
565             if (sourceObject instanceof Boolean JavaDoc) {
566                 if (((Boolean JavaDoc)sourceObject).booleanValue()) {
567                     return new BigDecimal(1);
568                 } else {
569                     return new BigDecimal(0);
570                 }
571             }
572         } catch (NumberFormatException JavaDoc exception) {
573             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.NUMBER, exception);
574         }
575
576         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.NUMBER);
577     }
578
579     /**
580      * INTERNAL:
581      * Build a valid Short instance from a String or another Number instance.
582      * @caught exception The Short(String) constructer throws a
583      * NumberFormatException if the String does not contain a
584      * parsable short.
585      */

586     protected Short JavaDoc convertObjectToShort(Object JavaDoc sourceObject) throws ConversionException {
587         try {
588             if (sourceObject instanceof String JavaDoc) {
589                 return new Short JavaDoc((String JavaDoc)sourceObject);
590             }
591
592             if (sourceObject instanceof Number JavaDoc) {
593                 return new Short JavaDoc(((Number JavaDoc)sourceObject).shortValue());
594             }
595
596             if (sourceObject instanceof Boolean JavaDoc) {
597                 if (((Boolean JavaDoc)sourceObject).booleanValue()) {
598                     return new Short JavaDoc((short)1);
599                 } else {
600                     return new Short JavaDoc((short)0);
601                 }
602             }
603         } catch (Exception JavaDoc exception) {
604             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.SHORT, exception);
605         }
606
607         throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.SHORT);
608     }
609
610     /**
611      * INTERNAL:
612      * Converts objects to thier string representations. java.util.Date
613      * is converted to a timestamp first and then to a string. An array
614      * of bytes is converted to a hex string.
615      */

616     protected String JavaDoc convertObjectToString(Object JavaDoc sourceObject) throws ConversionException {
617         if (sourceObject.getClass() == ClassConstants.UTILDATE) {
618             return Helper.printTimestamp(Helper.timestampFromDate((java.util.Date JavaDoc)sourceObject));
619         } else if (sourceObject instanceof Calendar) {
620             return Helper.printCalendar((Calendar)sourceObject);
621         } else if (sourceObject instanceof java.sql.Timestamp JavaDoc) {
622             return Helper.printTimestamp((java.sql.Timestamp JavaDoc)sourceObject);
623         } else if (sourceObject instanceof java.sql.Date JavaDoc) {
624             return Helper.printDate((java.sql.Date JavaDoc)sourceObject);
625         } else if (sourceObject instanceof java.sql.Time JavaDoc) {
626             return Helper.printTime((java.sql.Time JavaDoc)sourceObject);
627         } else if (sourceObject instanceof byte[]) {
628             return Helper.buildHexStringFromBytes((byte[])sourceObject);
629             //Bug#3854296 Added support to convert Byte[], char[] and Character[] to String correctly
630
} else if (sourceObject instanceof Byte JavaDoc[]) {
631             return Helper.buildHexStringFromBytes(convertObjectToByteArray(sourceObject));
632         } else if (sourceObject instanceof char[]) {
633             return new String JavaDoc((char[])sourceObject);
634         } else if (sourceObject instanceof Character JavaDoc[]) {
635             return new String JavaDoc(convertObjectToCharArray(sourceObject));
636         } else if (sourceObject instanceof Class JavaDoc) {
637             return ((Class JavaDoc)sourceObject).getName();
638         } else if (sourceObject instanceof Character JavaDoc) {
639             return sourceObject.toString();
640         } else if (sourceObject instanceof Clob) {
641             Clob clob = (Clob)sourceObject;
642             try {
643                 return clob.getSubString(1L, (int)clob.length());
644             } catch (SQLException exception) {
645                 throw DatabaseException.sqlException(exception);
646             }
647         }
648
649         return sourceObject.toString();
650     }
651
652     /**
653      * INTERNAL:
654      * Build a valid instance of java.sql.Time from the given source object.
655      * @param sourceObject Valid instance of java.sql.Time, String, java.util.Date, java.sql.Timestamp, or Long
656      */

657     protected java.sql.Time JavaDoc convertObjectToTime(Object JavaDoc sourceObject) throws ConversionException {
658         java.sql.Time JavaDoc time = null;
659
660         if (sourceObject instanceof java.sql.Time JavaDoc) {
661             return (java.sql.Time JavaDoc)sourceObject;//Helper timestamp is not caught on class check.
662
}
663
664         if (sourceObject instanceof String JavaDoc) {
665             time = Helper.timeFromString((String JavaDoc)sourceObject);
666         } else if (sourceObject.getClass() == ClassConstants.UTILDATE) {
667             time = Helper.timeFromDate((java.util.Date JavaDoc)sourceObject);
668         } else if (sourceObject instanceof java.sql.Timestamp JavaDoc) {
669             time = Helper.timeFromTimestamp((java.sql.Timestamp JavaDoc)sourceObject);
670         } else if (sourceObject instanceof Calendar) {
671             return Helper.timeFromCalendar((Calendar)sourceObject);
672         } else if (sourceObject instanceof Long JavaDoc) {
673             time = Helper.timeFromLong((Long JavaDoc)sourceObject);
674         } else {
675             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.TIME);
676         }
677         return time;
678     }
679
680     /**
681      * INTERNAL:
682      * Build a valid instance of java.sql.Timestamp from the given source object.
683      * @param sourceObject Valid obejct of class java.sql.Timestamp, String, java.util.Date, or Long
684      */

685     protected java.sql.Timestamp JavaDoc convertObjectToTimestamp(Object JavaDoc sourceObject) throws ConversionException {
686         java.sql.Timestamp JavaDoc timestamp = null;
687
688         if (sourceObject instanceof java.sql.Timestamp JavaDoc) {
689             return (java.sql.Timestamp JavaDoc)sourceObject;// Helper timestamp is not caught on class check.
690
}
691
692         if (sourceObject instanceof String JavaDoc) {
693             timestamp = Helper.timestampFromString((String JavaDoc)sourceObject);
694         } else if (sourceObject instanceof java.util.Date JavaDoc) {// This handles all date and subclasses, sql.Date, sql.Time conversions.
695
timestamp = Helper.timestampFromDate((java.util.Date JavaDoc)sourceObject);
696         } else if (sourceObject instanceof Calendar) {
697             return Helper.timestampFromCalendar((Calendar)sourceObject);
698         } else if (sourceObject instanceof Long JavaDoc) {
699             timestamp = Helper.timestampFromLong((Long JavaDoc)sourceObject);
700         } else {
701             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.TIMESTAMP);
702         }
703         return timestamp;
704     }
705
706     /**
707      * INTERNAL:
708      * Build a valid instance of java.util.Date from the given source object.
709      * @param sourceObject Valid instance of java.util.Date, String, java.sql.Timestamp, or Long
710      */

711     protected java.util.Date JavaDoc convertObjectToUtilDate(Object JavaDoc sourceObject) throws ConversionException {
712         java.util.Date JavaDoc date = null;
713
714         if (sourceObject.getClass() == java.util.Date JavaDoc.class) {
715             date = (java.util.Date JavaDoc)sourceObject;//used when converting util.Date to Calendar
716
} else if (sourceObject instanceof java.sql.Date JavaDoc) {
717             date = Helper.utilDateFromSQLDate((java.sql.Date JavaDoc)sourceObject);
718         } else if (sourceObject instanceof java.sql.Time JavaDoc) {
719             date = Helper.utilDateFromTime((java.sql.Time JavaDoc)sourceObject);
720         } else if (sourceObject instanceof String JavaDoc) {
721             date = Helper.utilDateFromTimestamp(Helper.timestampFromString((String JavaDoc)sourceObject));
722         } else if (sourceObject instanceof java.sql.Timestamp JavaDoc) {
723             date = Helper.utilDateFromTimestamp((java.sql.Timestamp JavaDoc)sourceObject);
724         } else if (sourceObject instanceof Calendar) {
725             return ((Calendar)sourceObject).getTime();
726         } else if (sourceObject instanceof Long JavaDoc) {
727             date = Helper.utilDateFromLong((Long JavaDoc)sourceObject);
728         } else {
729             throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.UTILDATE);
730         }
731         return date;
732     }
733
734     /**
735      * PUBLIC:
736      * Resolve the given String className into a class using this
737      * ConversionManager's classloader.
738      */

739     public Class JavaDoc convertClassNameToClass(String JavaDoc className) throws ConversionException {
740         return convertObjectToClass(className);
741     }
742
743     /**
744      * A singleton conversion manager is used to handle generic converisons.
745      * This should not be used for conversion under the session context, thse must go through the platform.
746      * This allows for the singleton to be customized through setting the default to a user defined subclass.
747      */

748     public static ConversionManager getDefaultManager() {
749         if (defaultManager == null) {
750             setDefaultManager(new ConversionManager());
751             defaultManager.setShouldUseClassLoaderFromCurrentThread(true);
752         }
753         return defaultManager;
754     }
755
756     /**
757      * INTERNAL:
758      * Allow for the null values for classes to be defaulted in one place.
759      * Any nulls read from the database to be converted to the class will be given the specified null value.
760      */

761     public Object JavaDoc getDefaultNullValue(Class JavaDoc theClass) {
762         return getDefaultNullValues().get(theClass);
763     }
764
765     /**
766      * INTERNAL:
767      * Allow for the null values for classes to be defaulted in one place.
768      * Any nulls read from the database to be converted to the class will be given the specified null value.
769      */

770     public Map getDefaultNullValues() {
771         return defaultNullValues;
772     }
773
774     /**
775      * INTERNAL:
776      */

777     public ClassLoader JavaDoc getLoader() {
778         if (shouldUseClassLoaderFromCurrentThread()) {
779             if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
780                 try {
781                     return (ClassLoader JavaDoc)AccessController.doPrivileged(new PrivilegedGetContextClassLoader(Thread.currentThread()));
782                 } catch (PrivilegedActionException JavaDoc exception) {
783                     // should not be thrown
784
}
785             } else {
786                 return PrivilegedAccessHelper.getContextClassLoader(Thread.currentThread());
787             }
788         }
789         if (loader == null) {
790             if (defaultLoader == null) {
791                 //CR 2621
792
ClassLoader JavaDoc loader = null;
793                 if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
794                     try{
795                         loader = (ClassLoader JavaDoc)AccessController.doPrivileged(new PrivilegedGetClassLoaderForClass(ClassConstants.ConversionManager_Class));
796                     } catch (PrivilegedActionException JavaDoc exc){
797                         // will not be thrown
798
}
799                 } else {
800                     loader = PrivilegedAccessHelper.getClassLoaderForClass(ClassConstants.ConversionManager_Class);
801                 }
802                 setLoader(loader);
803             } else {
804                 setLoader(getDefaultLoader());
805             }
806         }
807         return loader;
808     }
809
810     /**
811      * INTERNAL:
812      * Load the class using the default managers class loader.
813      * This is a thread based class loader by default.
814      * This should be used to load all classes as Class.forName can only
815      * see classes on the same classpath as the toplink.jar.
816      */

817     public static Class JavaDoc loadClass(String JavaDoc className) {
818         return (Class JavaDoc)getDefaultManager().convertObject(className, ClassConstants.CLASS);
819     }
820
821     /**
822      * INTERNAL:
823      * This is used to determine the wrapper class for a primitive.
824      */

825     public static Class JavaDoc getObjectClass(Class JavaDoc javaClass) {
826         // Null means unknown always for classifications.
827
if (javaClass == null) {
828             return null;
829         }
830
831         if (javaClass.isPrimitive()) {
832             if (javaClass == ClassConstants.PCHAR) {
833                 return ClassConstants.CHAR;
834             }
835             if (javaClass == ClassConstants.PINT) {
836                 return ClassConstants.INTEGER;
837             }
838             if (javaClass == ClassConstants.PDOUBLE) {
839                 return ClassConstants.DOUBLE;
840             }
841             if (javaClass == ClassConstants.PFLOAT) {
842                 return ClassConstants.FLOAT;
843             }
844             if (javaClass == ClassConstants.PLONG) {
845                 return ClassConstants.LONG;
846             }
847             if (javaClass == ClassConstants.PSHORT) {
848                 return ClassConstants.SHORT;
849             }
850             if (javaClass == ClassConstants.PBYTE) {
851                 return ClassConstants.BYTE;
852             }
853             if (javaClass == ClassConstants.PBOOLEAN) {
854                 return ClassConstants.BOOLEAN;
855             }
856         } else if (javaClass == ClassConstants.APBYTE) {
857             return ClassConstants.APBYTE;
858         } else if (javaClass == ClassConstants.APCHAR) {
859             return ClassConstants.APCHAR;
860         } else {
861             return javaClass;
862         }
863
864         return javaClass;
865     }
866
867     /**
868      * INTERNAL:
869      * Returns a class based on the passed in string.
870      */

871     public static Class JavaDoc getPrimitiveClass(String JavaDoc classType) {
872         if (classType.equals("int")) {
873             return Integer.TYPE;
874         } else if (classType.equals("boolean")) {
875             return Boolean.TYPE;
876         } else if (classType.equals("char")) {
877             return Character.TYPE;
878         } else if (classType.equals("short")) {
879             return Short.TYPE;
880         } else if (classType.equals("byte")) {
881             return Byte.TYPE;
882         } else if (classType.equals("float")) {
883             return Float.TYPE;
884         } else if (classType.equals("double")) {
885             return Double.TYPE;
886         } else if (classType.equals("long")) {
887             return Long.TYPE;
888         }
889
890         return null;
891     }
892
893     /**
894      * A singleton conversion manager is used to handle generic converisons.
895      * This should not be used for conversion under the session context, thse must go through the platform.
896      * This allows for the singleton to be customized through setting the default to a user defined subclass.
897      */

898     public static void setDefaultManager(ConversionManager theManager) {
899         defaultManager = theManager;
900     }
901
902     /**
903      * INTERNAL:
904      * Allow for the null values for classes to be defaulted in one place.
905      * Any nulls read from the database to be converted to the class will be given the specified null value.
906      * Primitive null values should be set to the wrapper class.
907      */

908     public void setDefaultNullValue(Class JavaDoc theClass, Object JavaDoc theValue) {
909         getDefaultNullValues().put(theClass, theValue);
910     }
911
912     /**
913      * INTERNAL:
914      * Allow for the null values for classes to be defaulted in one place.
915      * Any nulls read from the database to be converted to the class will be given the specified null value.
916      */

917     public void setDefaultNullValues(Map defaultNullValues) {
918         this.defaultNullValues = defaultNullValues;
919     }
920
921     /**
922      * INTERNAL:
923      * @parameter java.lang.ClassLoader
924      */

925     public void setLoader(ClassLoader JavaDoc classLoader) {
926         shouldUseClassLoaderFromCurrentThread = false;
927         loader = classLoader;
928     }
929
930     /**
931      * INTERNAL:
932      * Set the default class loader to use if no instance-level loader is set
933      * @parameter java.lang.ClassLoader
934      */

935     public static void setDefaultLoader(ClassLoader JavaDoc classLoader) {
936         defaultLoader = classLoader;
937     }
938
939     /**
940      * INTERNAL:
941      * Get the default class loader to use if no instance-level loader is set
942      * @return java.lang.ClassLoader
943      */

944     public static ClassLoader JavaDoc getDefaultLoader() {
945         return defaultLoader;
946     }
947
948     /**
949      * ADVANCED:
950      * This flag should be set if the current thread classLoader should be used.
951      * This is the case in certain Application Servers were the class loader must be
952      * retreived from the current Thread. If classNotFoundExceptions are being thrown then set
953      * this flag. In certain cases it will resolve the problem
954      */

955     public void setShouldUseClassLoaderFromCurrentThread(boolean useCurrentThread) {
956         this.shouldUseClassLoaderFromCurrentThread = useCurrentThread;
957     }
958
959     /**
960      * ADVANCED:
961      * This flag should be set if the current thread classLoader should be used.
962      * This is the case in certain Application Servers were the class loader must be
963      * retreived from the current Thread. If classNotFoundExceptions are being thrown then set
964      * this flag. In certain cases it will resolve the problem
965      */

966     public boolean shouldUseClassLoaderFromCurrentThread() {
967         return this.shouldUseClassLoaderFromCurrentThread;
968     }
969
970     /**
971      * PUBLIC:
972      * Return the list of Classes that can be converted to from the passed in javaClass.
973      * @param javaClass - the class that is converted from
974      * @return - a vector of classes
975      */

976     public Vector getDataTypesConvertedFrom(Class JavaDoc javaClass) {
977         if (dataTypesConvertedFromAClass.isEmpty()) {
978             buildDataTypesConvertedFromAClass();
979         }
980         return (Vector)dataTypesConvertedFromAClass.get(javaClass);
981     }
982
983     /**
984      * PUBLIC:
985      * Return the list of Classes that can be converted from to the passed in javaClass.
986      * @param javaClass - the class that is converted to
987      * @return - a vector of classes
988      */

989     public Vector getDataTypesConvertedTo(Class JavaDoc javaClass) {
990         if (dataTypesConvertedToAClass.isEmpty()) {
991             buildDataTypesConvertedToAClass();
992         }
993         return (Vector)dataTypesConvertedToAClass.get(javaClass);
994     }
995
996     protected Vector buildNumberVec() {
997         Vector vec = new Vector();
998         vec.addElement(BigInteger.class);
999         vec.addElement(BigDecimal.class);
1000        vec.addElement(Byte JavaDoc.class);
1001        vec.addElement(Double JavaDoc.class);
1002        vec.addElement(Float JavaDoc.class);
1003        vec.addElement(Integer JavaDoc.class);
1004        vec.addElement(Long JavaDoc.class);
1005        vec.addElement(Short JavaDoc.class);
1006        vec.addElement(Number JavaDoc.class);
1007        return vec;
1008    }
1009
1010    protected Vector buildDateTimeVec() {
1011        Vector vec = new Vector();
1012        vec.addElement(java.util.Date JavaDoc.class);
1013        vec.addElement(Timestamp.class);
1014        vec.addElement(Calendar.class);
1015        return vec;
1016    }
1017
1018    protected void buildDataTypesConvertedFromAClass() {
1019        dataTypesConvertedFromAClass.put(BigDecimal.class, buildFromBigDecimalVec());
1020        dataTypesConvertedFromAClass.put(BigInteger.class, buildFromBigIntegerVec());
1021        dataTypesConvertedFromAClass.put(Blob.class, buildFromBlobVec());
1022        dataTypesConvertedFromAClass.put(Boolean JavaDoc.class, buildFromBooleanVec());
1023        dataTypesConvertedFromAClass.put(byte[].class, buildFromByteArrayVec());
1024        dataTypesConvertedFromAClass.put(Byte JavaDoc.class, buildFromByteVec());
1025        dataTypesConvertedFromAClass.put(Calendar.class, buildFromCalendarVec());
1026        dataTypesConvertedFromAClass.put(Character JavaDoc.class, buildFromCharacterVec());
1027        dataTypesConvertedFromAClass.put(Clob.class, buildFromClobVec());
1028        dataTypesConvertedFromAClass.put(java.sql.Date JavaDoc.class, buildFromDateVec());
1029        dataTypesConvertedFromAClass.put(Double JavaDoc.class, buildFromDoubleVec());
1030        dataTypesConvertedFromAClass.put(Float JavaDoc.class, buildFromFloatVec());
1031        dataTypesConvertedFromAClass.put(Integer JavaDoc.class, buildFromIntegerVec());
1032        dataTypesConvertedFromAClass.put(Long JavaDoc.class, buildFromLongVec());
1033        dataTypesConvertedFromAClass.put(Number JavaDoc.class, buildFromNumberVec());
1034        dataTypesConvertedFromAClass.put(Short JavaDoc.class, buildFromShortVec());
1035        dataTypesConvertedFromAClass.put(String JavaDoc.class, buildFromStringVec());
1036        dataTypesConvertedFromAClass.put(Timestamp.class, buildFromTimestampVec());
1037        dataTypesConvertedFromAClass.put(Time.class, buildFromTimeVec());
1038        dataTypesConvertedFromAClass.put(java.util.Date JavaDoc.class, buildFromUtilDateVec());
1039        dataTypesConvertedFromAClass.put(Byte JavaDoc[].class, buildFromByteObjectArraryVec());
1040        dataTypesConvertedFromAClass.put(char[].class, buildFromCharArrayVec());
1041        dataTypesConvertedFromAClass.put(Character JavaDoc[].class, buildFromCharacterArrayVec());
1042    }
1043
1044    protected Vector buildFromBooleanVec() {
1045        Vector vec = new Vector();
1046        vec.addElement(String JavaDoc.class);
1047        vec.addElement(Boolean JavaDoc.class);
1048        vec.addElement(Integer JavaDoc.class);
1049        vec.addElement(Long JavaDoc.class);
1050        vec.addElement(Short JavaDoc.class);
1051        vec.addElement(Number JavaDoc.class);
1052        vec.addElement(Character JavaDoc[].class);
1053        vec.addElement(char[].class);
1054        vec.addElement(boolean.class);
1055        vec.addElement(int.class);
1056        vec.addElement(long.class);
1057        vec.addElement(short.class);
1058        return vec;
1059    }
1060
1061    protected Vector buildFromNumberVec() {
1062        Vector vec = buildNumberVec();
1063        vec.addElement(String JavaDoc.class);
1064        vec.addElement(Character JavaDoc.class);
1065        vec.addElement(Boolean JavaDoc.class);
1066        vec.addElement(Character JavaDoc[].class);
1067        vec.addElement(char[].class);
1068        vec.addElement(char.class);
1069        vec.addElement(int.class);
1070        vec.addElement(double.class);
1071        vec.addElement(float.class);
1072        vec.addElement(long.class);
1073        vec.addElement(short.class);
1074        vec.addElement(byte.class);
1075        vec.addElement(boolean.class);
1076        return vec;
1077    }
1078
1079    protected Vector buildFromBigDecimalVec() {
1080        return buildFromNumberVec();
1081    }
1082
1083    protected Vector buildFromBigIntegerVec() {
1084        return buildFromNumberVec();
1085    }
1086
1087    protected Vector buildFromIntegerVec() {
1088        return buildFromNumberVec();
1089    }
1090
1091    protected Vector buildFromFloatVec() {
1092        return buildFromNumberVec();
1093    }
1094
1095    protected Vector buildFromDoubleVec() {
1096        return buildFromNumberVec();
1097    }
1098
1099    protected Vector buildFromShortVec() {
1100        return buildFromNumberVec();
1101    }
1102
1103    protected Vector buildFromByteVec() {
1104        return buildFromNumberVec();
1105    }
1106
1107    protected Vector buildFromLongVec() {
1108        Vector vec = buildFromNumberVec();
1109        vec.addAll(buildDateTimeVec());
1110        vec.addElement(java.sql.Date JavaDoc.class);
1111        vec.addElement(Time.class);
1112        return vec;
1113    }
1114
1115    protected Vector buildFromStringVec() {
1116        Vector vec = buildFromLongVec();
1117        vec.addElement(Byte JavaDoc[].class);
1118        vec.addElement(byte[].class);
1119        vec.addElement(Clob.class);
1120        return vec;
1121    }
1122
1123    protected Vector buildFromCharacterVec() {
1124        Vector vec = new Vector();
1125        vec.addElement(String JavaDoc.class);
1126        vec.addElement(Boolean JavaDoc.class);
1127        vec.addElement(Character JavaDoc[].class);
1128        vec.addElement(Character JavaDoc.class);
1129        vec.addElement(char[].class);
1130        vec.addElement(char.class);
1131        vec.addElement(boolean.class);
1132        return vec;
1133    }
1134
1135    protected Vector buildFromByteArrayVec() {
1136        Vector vec = new Vector();
1137        vec.addElement(String JavaDoc.class);
1138        vec.addElement(byte[].class);
1139        vec.addElement(Byte JavaDoc[].class);
1140        vec.addElement(Character JavaDoc[].class);
1141        vec.addElement(char[].class);
1142        return vec;
1143    }
1144
1145    protected Vector buildFromClobVec() {
1146        Vector vec = new Vector();
1147        vec.addElement(String JavaDoc.class);
1148        vec.addElement(Character JavaDoc[].class);
1149        vec.addElement(char[].class);
1150        return vec;
1151    }
1152
1153    protected Vector buildFromBlobVec() {
1154        Vector vec = new Vector();
1155        vec.addElement(String JavaDoc.class);
1156        vec.addElement(Byte JavaDoc[].class);
1157        vec.addElement(byte[].class);
1158        vec.addElement(Character JavaDoc[].class);
1159        vec.addElement(char[].class);
1160        return vec;
1161    }
1162
1163    protected Vector buildFromUtilDateVec() {
1164        Vector vec = buildDateTimeVec();
1165        vec.addElement(String JavaDoc.class);
1166        vec.addElement(Long JavaDoc.class);
1167        vec.addElement(java.sql.Date JavaDoc.class);
1168        vec.addElement(Time.class);
1169        vec.addElement(long.class);
1170        vec.addElement(Character JavaDoc[].class);
1171        vec.addElement(char[].class);
1172        return vec;
1173    }
1174
1175    protected Vector buildFromTimestampVec() {
1176        return buildFromUtilDateVec();
1177    }
1178
1179    protected Vector buildFromCalendarVec() {
1180        return buildFromUtilDateVec();
1181    }
1182
1183    protected Vector buildFromDateVec() {
1184        Vector vec = buildDateTimeVec();
1185        vec.addElement(String JavaDoc.class);
1186        vec.addElement(Long JavaDoc.class);
1187        vec.addElement(java.sql.Date JavaDoc.class);
1188        vec.addElement(long.class);
1189        vec.addElement(Character JavaDoc[].class);
1190        vec.addElement(char[].class);
1191        return vec;
1192    }
1193
1194    protected Vector buildFromTimeVec() {
1195        Vector vec = buildDateTimeVec();
1196        vec.addElement(String JavaDoc.class);
1197        vec.addElement(Long JavaDoc.class);
1198        vec.addElement(Time.class);
1199        vec.addElement(long.class);
1200        vec.addElement(Character JavaDoc[].class);
1201        vec.addElement(char[].class);
1202        return vec;
1203    }
1204
1205    protected Vector buildFromByteObjectArraryVec() {
1206        Vector vec = new Vector();
1207        vec.addElement(Blob.class);
1208        vec.addElement(byte[].class);
1209        return vec;
1210    }
1211
1212    protected Vector buildFromCharArrayVec() {
1213        Vector vec = new Vector();
1214        vec.addElement(Clob.class);
1215        return vec;
1216    }
1217
1218    protected Vector buildFromCharacterArrayVec() {
1219        Vector vec = new Vector();
1220        vec.addElement(Clob.class);
1221        return vec;
1222    }
1223
1224    protected void buildDataTypesConvertedToAClass() {
1225        dataTypesConvertedToAClass.put(BigDecimal.class, buildToBigDecimalVec());
1226        dataTypesConvertedToAClass.put(BigInteger.class, buildToBigIntegerVec());
1227        dataTypesConvertedToAClass.put(Boolean JavaDoc.class, buildToBooleanVec());
1228        dataTypesConvertedToAClass.put(Byte JavaDoc.class, buildToByteVec());
1229        dataTypesConvertedToAClass.put(byte[].class, buildToByteArrayVec());
1230        dataTypesConvertedToAClass.put(Byte JavaDoc[].class, buildToByteObjectArrayVec());
1231        dataTypesConvertedToAClass.put(Calendar.class, buildToCalendarVec());
1232        dataTypesConvertedToAClass.put(Character JavaDoc.class, buildToCharacterVec());
1233        dataTypesConvertedToAClass.put(Character JavaDoc[].class, buildToCharacterArrayVec());
1234        dataTypesConvertedToAClass.put(char[].class, buildToCharArrayVec());
1235        dataTypesConvertedToAClass.put(java.sql.Date JavaDoc.class, buildToDateVec());
1236        dataTypesConvertedToAClass.put(Double JavaDoc.class, buildToDoubleVec());
1237        dataTypesConvertedToAClass.put(Float JavaDoc.class, buildToFloatVec());
1238        dataTypesConvertedToAClass.put(Integer JavaDoc.class, buildToIntegerVec());
1239        dataTypesConvertedToAClass.put(Long JavaDoc.class, buildToLongVec());
1240        dataTypesConvertedToAClass.put(Number JavaDoc.class, buildToNumberVec());
1241        dataTypesConvertedToAClass.put(Short JavaDoc.class, buildToShortVec());
1242        dataTypesConvertedToAClass.put(String JavaDoc.class, buildToStringVec());
1243        dataTypesConvertedToAClass.put(Timestamp.class, buildToTimestampVec());
1244        dataTypesConvertedToAClass.put(Time.class, buildToTimeVec());
1245        dataTypesConvertedToAClass.put(java.util.Date JavaDoc.class, buildToUtilDateVec());
1246        dataTypesConvertedToAClass.put(Clob.class, buildToClobVec());
1247        dataTypesConvertedToAClass.put(Blob.class, buildToBlobVec());
1248    }
1249
1250    protected Vector buildAllTypesToAClassVec() {
1251        Vector vec = new Vector();
1252        vec.addElement(String JavaDoc.class);
1253        vec.addElement(Integer JavaDoc.class);
1254        vec.addElement(java.util.Date JavaDoc.class);
1255        vec.addElement(java.sql.Date JavaDoc.class);
1256        vec.addElement(Time.class);
1257        vec.addElement(Timestamp.class);
1258        vec.addElement(Calendar.class);
1259        vec.addElement(Character JavaDoc.class);
1260        vec.addElement(Double JavaDoc.class);
1261        vec.addElement(Float JavaDoc.class);
1262        vec.addElement(Long JavaDoc.class);
1263        vec.addElement(Short JavaDoc.class);
1264        vec.addElement(Byte JavaDoc.class);
1265        vec.addElement(BigInteger.class);
1266        vec.addElement(BigDecimal.class);
1267        vec.addElement(Number JavaDoc.class);
1268        vec.addElement(Boolean JavaDoc.class);
1269        vec.addElement(Character JavaDoc[].class);
1270        vec.addElement(Blob.class);
1271        vec.addElement(Clob.class);
1272        return vec;
1273    }
1274
1275    protected Vector buildToBigDecimalVec() {
1276        Vector vec = buildNumberVec();
1277        vec.addElement(String JavaDoc.class);
1278        return vec;
1279    }
1280
1281    protected Vector buildToBigIntegerVec() {
1282        return buildToBigDecimalVec();
1283    }
1284
1285    protected Vector buildToBooleanVec() {
1286        Vector vec = buildToBigDecimalVec();
1287        vec.addElement(Character JavaDoc.class);
1288        vec.addElement(Boolean JavaDoc.class);
1289        return vec;
1290    }
1291
1292    protected Vector buildToByteVec() {
1293        return buildToBigDecimalVec();
1294    }
1295
1296    protected Vector buildToDoubleVec() {
1297        return buildToBigDecimalVec();
1298    }
1299
1300    protected Vector buildToFloatVec() {
1301        return buildToBigDecimalVec();
1302    }
1303
1304    protected Vector buildToIntegerVec() {
1305        Vector vec = buildToBigDecimalVec();
1306        vec.addElement(Boolean JavaDoc.class);
1307        return vec;
1308    }
1309
1310    protected Vector buildToLongVec() {
1311        Vector vec = buildToIntegerVec();
1312        vec.addElement(Calendar.class);
1313        vec.addElement(java.util.Date JavaDoc.class);
1314        return vec;
1315    }
1316
1317    protected Vector buildToNumberVec() {
1318        return buildToIntegerVec();
1319    }
1320
1321    protected Vector buildToShortVec() {
1322        return buildToIntegerVec();
1323    }
1324
1325    protected Vector buildToByteArrayVec() {
1326        Vector vec = new Vector();
1327        vec.addElement(String JavaDoc.class);
1328        vec.addElement(Blob.class);
1329        vec.addElement(byte[].class);
1330        vec.addElement(Byte JavaDoc[].class);
1331        return vec;
1332    }
1333
1334    protected Vector buildToByteObjectArrayVec() {
1335        Vector vec = buildToByteArrayVec();
1336        vec.addElement(Byte JavaDoc[].class);
1337        return vec;
1338    }
1339
1340    protected Vector buildToCharacterVec() {
1341        Vector vec = buildToBigDecimalVec();
1342        vec.addElement(Character JavaDoc.class);
1343        return vec;
1344    }
1345
1346    protected Vector buildToCharacterArrayVec() {
1347        return buildAllTypesToAClassVec();
1348    }
1349
1350    protected Vector buildToCharArrayVec() {
1351        return buildAllTypesToAClassVec();
1352    }
1353
1354    protected Vector buildToStringVec() {
1355        return buildAllTypesToAClassVec();
1356    }
1357
1358    protected Vector buildToCalendarVec() {
1359        Vector vec = buildDateTimeVec();
1360        vec.addElement(String JavaDoc.class);
1361        vec.addElement(Long JavaDoc.class);
1362        vec.addElement(java.sql.Date JavaDoc.class);
1363        vec.addElement(Time.class);
1364        return vec;
1365    }
1366
1367    protected Vector buildToTimestampVec() {
1368        return buildToCalendarVec();
1369    }
1370
1371    protected Vector buildToUtilDateVec() {
1372        return buildToCalendarVec();
1373    }
1374
1375    protected Vector buildToDateVec() {
1376        Vector vec = buildDateTimeVec();
1377        vec.addElement(String JavaDoc.class);
1378        vec.addElement(Long JavaDoc.class);
1379        vec.addElement(java.sql.Date JavaDoc.class);
1380        return vec;
1381    }
1382
1383    protected Vector buildToTimeVec() {
1384        Vector vec = buildDateTimeVec();
1385        vec.addElement(String JavaDoc.class);
1386        vec.addElement(Long JavaDoc.class);
1387        vec.addElement(Time.class);
1388        return vec;
1389    }
1390
1391    protected Vector buildToBlobVec() {
1392        Vector vec = new Vector();
1393        vec.addElement(Byte JavaDoc[].class);
1394        vec.addElement(byte[].class);
1395        return vec;
1396    }
1397
1398    protected Vector buildToClobVec() {
1399        Vector vec = new Vector();
1400        vec.addElement(String JavaDoc.class);
1401        vec.addElement(char[].class);
1402        vec.addElement(Character JavaDoc[].class);
1403        return vec;
1404    }
1405}
1406
Popular Tags