Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap_dataFile / src / org / gvsig / data / datastores / vectorial / file / dbf / DBFResource.java @ 20692

History | View | Annotate | Download (6.27 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I   {{Task}}
26
*/
27

    
28
/**
29
 *
30
 */
31
package org.gvsig.data.datastores.vectorial.file.dbf;
32

    
33
import java.io.File;
34
import java.nio.channels.FileChannel;
35
import java.util.Date;
36

    
37
import org.gvsig.data.Resource;
38
import org.gvsig.data.datastores.vectorial.file.FileResource;
39
import org.gvsig.data.datastores.vectorial.file.IFileResource;
40
import org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile;
41
import org.gvsig.data.exception.CloseException;
42
import org.gvsig.data.exception.DataException;
43
import org.gvsig.data.exception.OpenException;
44
import org.gvsig.data.exception.ReadException;
45
import org.gvsig.data.exception.UnsupportedEncodingException;
46
import org.gvsig.data.exception.WriteException;
47

    
48

    
49
/**
50
 * @author jmvivo
51
 *
52
 */
53
public class DBFResource extends FileResource{
54

    
55
        protected DbaseFile dbfFile;
56
        DBFResource (DBFStoreParameters params){
57
                super(params);
58
                this.file = params.getDBFFile();
59
        }
60

    
61
        DbaseFile getDbf(){
62
                return this.dbfFile;
63
        }
64

    
65
        /* (non-Javadoc)
66
         * @see org.gvsig.data.datastores.vectorial.file.IFileResource#getTotalFiles()
67
         */
68
        public int getTotalFiles() {
69
                return 1;
70
        }
71

    
72
        /* (non-Javadoc)
73
         * @see org.gvsig.data.Resource#getKey()
74
         */
75
        public String getKey() {
76
                return "DBF:"+this.file.getAbsolutePath();
77
        }
78

    
79
        /* (non-Javadoc)
80
         * @see org.gvsig.data.Resource#description()
81
         */
82

    
83
        public String description() {
84
                if (this.getFile()!= null){
85
                        return "DBF File resource: " + this.getFile().getAbsolutePath();
86
                } else{
87
                        return "DBF File resource: {No file}";
88
                }
89
        }
90

    
91
        /* (non-Javadoc)
92
         * @see org.gvsig.data.Resource#doClose()
93
         */
94
        protected boolean doClose() throws CloseException{
95
                dbfFile.close();
96
                return super.doClose();
97
        }
98

    
99
        /* (non-Javadoc)
100
         * @see org.gvsig.data.Resource#doDispose()
101
         */
102
        protected void doDispose() throws DataException{
103
                super.doDispose();
104
                this.dbfFile = null;
105
        }
106

    
107
        /* (non-Javadoc)
108
         * @see org.gvsig.data.Resource#doOpen()
109
         */
110
        protected synchronized boolean doOpen() throws OpenException{
111
                if (this.dbfFile == null){
112
                        this.dbfFile = new DbaseFile(this.file);
113
                        this.updateLastModified();
114
                } else{
115
                        this.checkChanged();
116
                }
117
                this.dbfFile.open();
118
                this.setOpened();
119
                return true;
120
        }
121

    
122

    
123

    
124

    
125
        /********************************
126
         * ******************************
127
         *
128
         * Deletated methos of DbaseFile
129
         *
130
         * ******************************
131
         ********************************/
132

    
133

    
134
        /**
135
         * @param rowIndex
136
         * @param fieldId
137
         * @return
138
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getBooleanFieldValue(int, int)
139
         */
140
        public boolean getBooleanFieldValue(int rowIndex, int fieldId)  throws ReadException{
141
                this.checkOpen();
142
                return dbfFile.getBooleanFieldValue(rowIndex, fieldId);
143
        }
144

    
145
        /**
146
         * @return
147
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldCount()
148
         */
149
        public int getFieldCount() throws ReadException {
150
                this.checkOpen();
151
                return dbfFile.getFieldCount();
152
        }
153

    
154
        /**
155
         * @param inIndex
156
         * @return
157
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldDecimalLength(int)
158
         */
159
        public int getFieldDecimalLength(int inIndex) throws ReadException {
160
                this.checkOpen();
161
                return dbfFile.getFieldDecimalLength(inIndex);
162
        }
163

    
164
        /**
165
         * @param inIndex
166
         * @return
167
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldLength(int)
168
         */
169
        public int getFieldLength(int inIndex)  throws ReadException{
170
                this.checkOpen();
171
                return dbfFile.getFieldLength(inIndex);
172
        }
173

    
174
        /**
175
         * @param inIndex
176
         * @return
177
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldName(int)
178
         */
179
        public String getFieldName(int inIndex)  throws ReadException{
180
                this.checkOpen();
181
                return dbfFile.getFieldName(inIndex);
182
        }
183

    
184
        /**
185
         * @param inIndex
186
         * @return
187
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getFieldType(int)
188
         */
189
        public char getFieldType(int inIndex)  throws ReadException{
190
                this.checkOpen();
191
                return dbfFile.getFieldType(inIndex);
192
        }
193

    
194
        /**
195
         * @return
196
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getRecordCount()
197
         */
198
        public int getRecordCount()  throws ReadException{
199
                this.checkOpen();
200
                return dbfFile.getRecordCount();
201
        }
202

    
203
        /**
204
         * @param rowIndex
205
         * @param fieldId
206
         * @return
207
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getStringFieldValue(int, int)
208
         */
209
        public String getStringFieldValue(int rowIndex, int fieldId)  throws ReadException{
210
                this.checkOpen();
211
                return dbfFile.getStringFieldValue(rowIndex, fieldId);
212
        }
213

    
214
        /**
215
         * @return
216
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#getWriteChannel()
217
         */
218
        public FileChannel getWriteChannel()  throws DataException{
219
                this.checkOpen();
220
                return dbfFile.getWriteChannel();
221
        }
222

    
223
        /**
224
         * @param rowIndex
225
         * @param fieldId
226
         * @param obj
227
         * @throws UnsupportedEncodingException
228
         * @throws WriteException
229
         * @see org.gvsig.data.datastores.vectorial.file.dbf.utils.DbaseFile#setFieldValue(int, int, java.lang.Object)
230
         */
231
        public void setFieldValue(int rowIndex, int fieldId, Object obj) throws UnsupportedEncodingException, WriteException{
232
//                FIXME: this.checkOpen();?????
233
                dbfFile.setFieldValue(rowIndex, fieldId, obj);
234
        }
235

    
236
        /* (non-Javadoc)
237
         * @see org.gvsig.data.datastores.vectorial.file.FileResource#editing()
238
         */
239
        protected void editing() {
240
                super.editing();
241
        }
242

    
243
        /* (non-Javadoc)
244
         * @see org.gvsig.data.datastores.vectorial.file.FileResource#stopEditing()
245
         */
246
        protected void stopEditing() {
247
                super.stopEditing();
248
        }
249
}
250