01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.mail.pop3;
19:
20: import java.util.Date;
21:
22: import org.columba.mail.folder.headercache.CachedHeaderfields;
23: import org.columba.mail.message.ColumbaHeader;
24: import org.columba.mail.message.IColumbaHeader;
25:
26: import com.sleepycat.bind.tuple.TupleBinding;
27: import com.sleepycat.bind.tuple.TupleInput;
28: import com.sleepycat.bind.tuple.TupleOutput;
29:
30: public class POP3HeaderBinding extends TupleBinding {
31:
32: public Object entryToObject(TupleInput in) {
33: ColumbaHeader header = new ColumbaHeader();
34:
35: String[] columnNames = CachedHeaderfields.POP3_HEADERFIELDS;
36: Class[] columnTypes = CachedHeaderfields.POP3_HEADERFIELDS_TYPE;
37:
38: for (int j = 0; j < columnNames.length; j++) {
39: Object value = null;
40:
41: if (columnTypes[j] == Integer.class) {
42: value = new Integer(in.readInt());
43: } else if (columnTypes[j] == Date.class) {
44: value = new Date(in.readLong());
45: } else if (columnTypes[j] == String.class) {
46: value = in.readString();
47: } else if (columnTypes[j] == Boolean.class) {
48: value = new Boolean(in.readBoolean());
49: }
50:
51: if (value != null) {
52: header.set(columnNames[j], value);
53: }
54: }
55:
56: return header;
57: }
58:
59: public void objectToEntry(Object arg0, TupleOutput out) {
60: IColumbaHeader header = (IColumbaHeader) arg0;
61:
62: String[] columnNames = CachedHeaderfields.POP3_HEADERFIELDS;
63: Class[] columnTypes = CachedHeaderfields.POP3_HEADERFIELDS_TYPE;
64: Object o;
65:
66: for (int j = 0; j < columnNames.length; j++) {
67: o = header.get(columnNames[j]);
68:
69: if (columnTypes[j] == Integer.class) {
70: if (o == null) {
71: out.writeInt(0);
72: } else {
73: out.writeInt(((Integer) o).intValue());
74: }
75: } else if (columnTypes[j] == Date.class) {
76: if (o == null) {
77: out.writeLong(System.currentTimeMillis());
78: } else {
79: out.writeLong(((Date) o).getTime());
80: }
81: } else if (columnTypes[j] == String.class) {
82: if (o == null) {
83: out.writeString("");
84: } else {
85: out.writeString((String) o);
86: }
87: } else if (columnTypes[j] == Boolean.class) {
88: if (o == null) {
89: out.writeBoolean(false);
90: } else {
91: out.writeBoolean(((Boolean) o).booleanValue());
92: }
93: }
94: }
95: }
96:
97: }
|