01: //$Id: $
02: package org.hibernate.type;
03:
04: import org.hibernate.HibernateException;
05:
06: /**
07: * Bridge Character[] and VARCHAR
08: * @author Emmanuel Bernard
09: */
10: public class CharacterArrayType extends AbstractCharArrayType {
11: protected Object toExternalFormat(char[] chars) {
12: if (chars == null)
13: return null;
14: Character[] characters = new Character[chars.length];
15: for (int i = 0; i < chars.length; i++) {
16: characters[i] = new Character(chars[i]);
17: }
18: return characters;
19: }
20:
21: protected char[] toInternalFormat(Object value) {
22: if (value == null)
23: return null;
24: Character[] characters = (Character[]) value;
25: char[] chars = new char[characters.length];
26: for (int i = 0; i < characters.length; i++) {
27: if (characters[i] == null)
28: throw new HibernateException(
29: "Unable to store an Character[] when one of its element is null");
30: chars[i] = characters[i].charValue();
31: }
32: return chars;
33: }
34:
35: public Class getReturnedClass() {
36: return Character[].class;
37: }
38:
39: public String getName() {
40: return "wrapper-characters";
41: }
42: }
|