KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > spds > SyncRecordFunction


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 package sync4j.syncclient.spds;
20
21 import java.util.Vector JavaDoc;
22
23 import sync4j.syncclient.sps.common.*;
24
25
26 /**
27  * This class provide methods about
28  * control timestamp and modificationType
29  * $Id: SyncRecordFunction.java,v 1.2 2005/01/19 11:18:36 fabius Exp $
30  */

31 public class SyncRecordFunction {
32
33
34     /**
35      * set timestamp
36      * @param record
37      * @param timestamp
38      **/

39     public static void setTimestamp(Record record, String JavaDoc timestamp) {
40
41         Vector JavaDoc values = null;
42         values = new Vector JavaDoc();
43
44         values.addElement(timestamp);
45
46         record.setRecordField("timestamp", values);
47     }
48
49
50
51     /**
52      * set modificationType
53      * @param record
54      * @param modificationType
55      **/

56     public static void setModificationType(Record record, String JavaDoc modificationType) {
57
58         Vector JavaDoc values = null;
59         values = new Vector JavaDoc();
60
61         values.addElement(modificationType);
62
63         record.setRecordField("mtype", values);
64     }
65
66
67
68     /**
69      * @param record
70      * @return timestamp
71      **/

72     public static String JavaDoc getTimestamp(Record record) {
73
74         Vector JavaDoc values = null;
75
76         values = record.getRecordField("timestamp");
77
78         return (String JavaDoc) values.elementAt(0);
79     }
80     
81     /**
82      * @param record
83      * @return modificationType
84      **/

85     public static String JavaDoc getModificationType(Record record) {
86
87         Vector JavaDoc values = null;
88
89         values = record.getRecordField("mtype");
90
91         return (String JavaDoc) values.elementAt(0);
92
93     }
94
95
96
97     /**
98      * @param record
99      * @return timestamp field position, <p>-1</p> if timestamp field not present
100      **/

101     public static int getPositionTimestampField(Record record) {
102
103         Vector JavaDoc positions = null;
104
105         RecordMetadata recordMetadata = null;
106
107         recordMetadata = record.getDataStore().getRecordMetadata();
108
109         positions = recordMetadata.getRecordFieldPosition("timestamp");
110
111         if (positions.size() > 0) {
112             return Integer.parseInt(String.valueOf(positions.elementAt(0)));
113         } else {
114             return -1;
115         }
116
117     }
118
119
120
121     /**
122      * @param record
123      * @return modificationType field position, <p>-1</p> if timestamp field not present
124      **/

125     public static int getPositionModificationTypeField(Record record) {
126
127         Vector JavaDoc positions = null;
128
129         RecordMetadata recordMetadata = null;
130
131         recordMetadata = record.getDataStore().getRecordMetadata();
132
133         positions = recordMetadata.getRecordFieldPosition("mtype");
134
135         if (positions.size() > 0) {
136             return Integer.parseInt(String.valueOf(positions.elementAt(0)));
137         } else {
138             return -1;
139         }
140
141     }
142
143
144     /**
145      * @param record
146      * @return number of operation fields
147      **/

148     public static int getNumberOperationFields(Record record) {
149
150         int numberOperationFields = 0;
151
152         Vector JavaDoc positions = null;
153
154         RecordMetadata recordMetadata = null;
155
156         recordMetadata = record.getDataStore().getRecordMetadata();
157
158         positions = recordMetadata.getRecordFieldPosition("key");
159
160         if (positions.size()>0) {
161             numberOperationFields = positions.size();
162         }
163
164         positions = recordMetadata.getRecordFieldPosition("timestamp");
165
166         if (positions.size()>0) {
167             numberOperationFields = numberOperationFields + positions.size();
168         }
169
170         positions = recordMetadata.getRecordFieldPosition("mtype");
171
172         if (positions.size()>0) {
173             numberOperationFields = numberOperationFields + positions.size();
174         }
175
176         return numberOperationFields;
177
178     }
179     
180     /**
181      * @param recordMetadata
182      *
183      * @return the key field position
184      */

185     public static int getKeyFieldPosition(RecordMetadata recordMetadata) {
186         Vector JavaDoc positions = null;
187
188         positions = recordMetadata.getRecordFieldPosition("key");
189
190         if (positions.size() > 0) {
191             return Integer.parseInt(String.valueOf(positions.elementAt(0)));
192         } else {
193             return -1;
194         }
195     }
196     
197      /**
198      * @param recordMetadata
199      *
200      * @return the key field position
201      */

202     public static int getModificationTypeFieldPosition(RecordMetadata recordMetadata) {
203         Vector JavaDoc positions = null;
204
205         positions = recordMetadata.getRecordFieldPosition("mtype");
206
207         if (positions.size() > 0) {
208             return Integer.parseInt(String.valueOf(positions.elementAt(0)));
209         } else {
210             return -1;
211         }
212     }
213
214 }
Popular Tags