KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > sps > common > Record


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.sps.common;
20
21 import java.util.Vector JavaDoc;
22
23 /**
24  * This interface define Record method
25  *
26  * @author Fabio Maggi @ Funambol
27  * $Id: Record.java,v 1.4 2005/01/19 11:18:36 fabius Exp $
28  */

29 public class Record {
30
31     //-------------------------------------------------------------- Private data
32

33     private Object JavaDoc[] data;
34     private DataStore dataStore;
35     private int positionKeyField;
36
37
38     //------------------------------------------------------------- Constructors
39
public Record(DataStore dataStore, String JavaDoc key) {
40
41         String JavaDoc function = null;
42         Vector JavaDoc positions = null;
43
44         RecordMetadata recordMetadata = null;
45
46         this.data = new Object JavaDoc[dataStore.getRecordMetadata().getFieldMetadata().length];
47
48         this.dataStore = dataStore;
49
50         recordMetadata = this.dataStore.getRecordMetadata();
51
52         positions = recordMetadata.getRecordFieldPosition("key");
53
54         positionKeyField = ((Integer JavaDoc) positions.elementAt(0)).intValue();
55
56         this.setField(positionKeyField, key);
57
58     }
59
60
61     //----------------------------------------------------------- Public methods
62

63     /**
64      * set record field
65      *
66      * @param i position [1...n]
67      * @param dataField
68      **/

69     public void setField(int i, String JavaDoc dataField) {
70         this.data[i - 1] = dataField;
71     }
72
73     /**
74      * set key
75      *
76      * @param key
77      **/

78     public void setKey(String JavaDoc key) {
79         this.data[positionKeyField] = (Object JavaDoc) key;
80     }
81
82     /**
83      * set dataStore
84      *
85      * @param dataStore
86      **/

87     public void setDataStore(DataStore dataStore) {
88         this.dataStore = dataStore;
89     }
90
91     /**
92      * return key
93      *
94      **/

95     public String JavaDoc getKey() {
96         return (String JavaDoc) this.getString(positionKeyField);
97     }
98
99     /**
100      * return dataStore
101      *
102      **/

103     public DataStore getDataStore() {
104         return this.dataStore;
105     }
106
107     /**
108      * read String field
109      *
110      * @param i position [1...n]
111      * @return field
112      **/

113     public String JavaDoc getString(int i) {
114         return (String JavaDoc) this.data[i - 1];
115     }
116
117     /**
118      * read int field
119      *
120      * @param i position [1...n]
121      * @return field
122      **/

123     public int getInt(int i) {
124         return ((Integer JavaDoc) this.data[i - 1]).intValue();
125     }
126
127     /**
128      * @return record length
129      **/

130     public int getLength() {
131         return this.data.length;
132     }
133
134     /**
135      * @return position key field
136      **/

137     public int getPositionKeyField() {
138         return this.positionKeyField;
139     }
140
141     /**
142      * @param function
143      * @return values of fields about setting function
144      **/

145     public Vector JavaDoc getRecordField(String JavaDoc function) {
146
147         Vector JavaDoc positions = null;
148         Vector JavaDoc values = new Vector JavaDoc();
149
150         positions = this.dataStore.getRecordMetadata().getRecordFieldPosition(function);
151
152         Integer JavaDoc pos = null;
153
154         int l = positions.size();
155
156         for (int i=0; i < l; i++) {
157             values.addElement(this.getString(((Integer JavaDoc) positions.elementAt(i)).intValue()));
158         }
159
160         return values;
161
162     }
163
164     /**
165      * @param function
166      * @param values values to set fields about setting function
167      **/

168     public void setRecordField(String JavaDoc function, Vector JavaDoc values) {
169
170         Vector JavaDoc positions = null;
171
172         positions = this.dataStore.getRecordMetadata().getRecordFieldPosition(function);
173
174         int l = positions.size();
175
176         for (int i=0; i < l; i++) {
177             this.setField(((Integer JavaDoc) positions.elementAt(i)).intValue(), (String JavaDoc) values.elementAt(i));
178         }
179
180        return;
181
182     }
183
184 }
Popular Tags