01: //$Id: $
02: package org.hibernate.type;
03:
04: import org.hibernate.HibernateException;
05:
06: /**
07: * @author Emmanuel Bernard
08: */
09: public class WrapperBinaryType extends AbstractBynaryType {
10: protected Object toExternalFormat(byte[] bytes) {
11: if (bytes == null)
12: return null;
13: int length = bytes.length;
14: Byte[] result = new Byte[length];
15: for (int index = 0; index < length; index++) {
16: result[index] = new Byte(bytes[index]);
17: }
18: return result;
19: }
20:
21: protected byte[] toInternalFormat(Object val) {
22: if (val == null)
23: return null;
24: Byte[] bytes = (Byte[]) val;
25: int length = bytes.length;
26: byte[] result = new byte[length];
27: for (int i = 0; i < length; i++) {
28: if (bytes[i] == null)
29: throw new HibernateException(
30: "Unable to store an Byte[] when one of its element is null");
31: result[i] = bytes[i].byteValue();
32: }
33: return result;
34: }
35:
36: public Class getReturnedClass() {
37: return Byte[].class;
38: }
39:
40: public String getName() {
41: //TODO find a decent name before documenting
42: return "wrapper-binary";
43: }
44: }
|