KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > pop3 > POP3HeaderBinding


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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 JavaDoc;
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 JavaDoc entryToObject(TupleInput in) {
33         ColumbaHeader header = new ColumbaHeader();
34         
35         String JavaDoc[] columnNames = CachedHeaderfields.POP3_HEADERFIELDS;
36         Class JavaDoc[] columnTypes = CachedHeaderfields.POP3_HEADERFIELDS_TYPE;
37
38         for (int j = 0; j < columnNames.length; j++) {
39                 Object JavaDoc value = null;
40
41                 if (columnTypes[j] == Integer JavaDoc.class) {
42                     value = new Integer JavaDoc(in.readInt());
43                 } else if (columnTypes[j] == Date JavaDoc.class) {
44                     value = new Date JavaDoc(in.readLong());
45                 } else if (columnTypes[j] == String JavaDoc.class) {
46                     value = in.readString();
47                 } else if ( columnTypes[j] == Boolean JavaDoc.class){
48                     value = new Boolean JavaDoc(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 JavaDoc arg0, TupleOutput out) {
60         IColumbaHeader header = (IColumbaHeader) arg0;
61         
62         String JavaDoc[] columnNames = CachedHeaderfields.POP3_HEADERFIELDS;
63         Class JavaDoc[] columnTypes = CachedHeaderfields.POP3_HEADERFIELDS_TYPE;
64         Object JavaDoc o;
65
66         for (int j = 0; j < columnNames.length; j++) {
67             o = header.get(columnNames[j]);
68
69             if (columnTypes[j] == Integer JavaDoc.class) {
70                 if (o == null) {
71                     out.writeInt(0);
72                 } else {
73                     out.writeInt(((Integer JavaDoc) o).intValue());
74                 }
75             } else if (columnTypes[j] == Date JavaDoc.class) {
76                 if (o == null) {
77                     out.writeLong(System.currentTimeMillis());
78                 } else {
79                     out.writeLong(((Date JavaDoc) o).getTime());
80                 }
81             } else if (columnTypes[j] == String JavaDoc.class) {
82                 if (o == null) {
83                     out.writeString("");
84                 } else {
85                     out.writeString((String JavaDoc) o);
86                 }
87             } else if (columnTypes[j] == Boolean JavaDoc.class) {
88                 if( o == null) {
89                     out.writeBoolean(false);
90                 } else {
91                     out.writeBoolean(((Boolean JavaDoc) o).booleanValue());
92                 }
93             }
94         }
95     }
96
97 }
98
Popular Tags