KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > sps > palm > PalmRecord


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19  /* Portions copyright © 2001 Palm, Inc. or its subsidiaries. All rights reserved. */
20
21
22 package sync4j.syncclient.sps.palm;
23
24 import java.io.*;
25 import java.util.Vector JavaDoc;
26
27 import palm.conduit.*;
28
29
30 /**
31  * Extends GenericRecord to implement the Palm Record. This object can be
32  * used to store and translate hand-held device records used by the Sync4j Client
33  * application.
34  *
35  * @author Fabio Maggi @ Funambol
36  * $Id: PalmRecord.java,v 1.2 2005/01/19 11:18:37 fabius Exp $
37  */

38 public class PalmRecord extends AbstractRecord {
39
40     //---------------------------------------------------------------- Private data
41

42     private int recordSize = 0;
43
44     private String JavaDoc key = null;
45     private Vector JavaDoc store = new Vector JavaDoc();
46
47     //---------------------------------------------------------------- Public methods
48

49     public String JavaDoc getKey() {
50         return this.key;
51     }
52
53     public String JavaDoc getStoreField(int i) {
54         return (String JavaDoc) store.elementAt(i);
55     }
56
57     public int getSize() {
58         return this.store.size();
59     }
60
61     public String JavaDoc getField(int position) {
62         return (String JavaDoc) this.store.elementAt(position);
63     }
64
65     public int getRecordSize() {
66         return this.recordSize;
67     }
68
69     public void setKey(String JavaDoc key) {
70         this.key = key;
71     }
72
73     public void setField(int position, String JavaDoc value) {
74         this.store.setElementAt((Object JavaDoc) value, position);
75     }
76
77     public void addStoreField(String JavaDoc field) {
78         this.store.addElement(field);
79     }
80
81     public void setRecordSize(int recordSize) {
82         this.recordSize = recordSize;
83     }
84
85     public void writeData(DataOutputStream out) throws IOException {
86         String JavaDoc fieldValue = null;
87
88         if (this.key != null) {
89             out.write(key.getBytes());
90             out.write(0);
91         }
92
93         int l = store.size();
94
95         for (int i=0; i < l; i++) {
96              fieldValue = (String JavaDoc) store.elementAt(i);
97
98              if (fieldValue == null) {
99                 fieldValue = "";
100              }
101
102              out.write(fieldValue.getBytes());
103              out.write(0);
104         }
105     }
106
107     /** Converts a DataInputStream representing the body of the hand-held device's
108      * Sync4j client record into PalmRecord object members.
109      * @param in The DataInputStream containing record body information from
110      * the hand-held device's Sync4j client application record.
111      */

112     public void readData(DataInputStream in) throws IOException {
113         Vector JavaDoc tmpStore = new Vector JavaDoc();
114
115         this.key = readCString(in);
116
117         int l = this.recordSize;
118
119         for(int i=0; i < l; i++) {
120             tmpStore.addElement(readCString(in));
121         }
122
123         this.store = tmpStore;
124     }
125 }
Popular Tags