Statistics
| Revision:

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

History | View | Annotate | Download (5.92 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 (File aFile){
57
                super(aFile);
58
        }
59

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

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

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

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

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

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

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

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

    
121

    
122

    
123

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

    
132

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

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

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

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

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

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

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

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

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

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