Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.dbf / src / main / java / org / gvsig / fmap / dal / store / dbf / DBFStoreParameters.java @ 40559

History | View | Annotate | Download (3.75 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.dbf;
25

    
26
import java.io.File;
27
import java.nio.charset.Charset;
28

    
29
import org.gvsig.fmap.dal.DataStoreParameters;
30
import org.gvsig.fmap.dal.FileHelper;
31
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
32
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
33
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
34
import org.gvsig.tools.dynobject.DelegatedDynObject;
35

    
36

    
37
public class DBFStoreParameters extends AbstractDataParameters implements
38
                DataStoreParameters, FilesystemStoreParameters {
39

    
40
    public static final String PARAMETERS_DEFINITION_NAME = "DBFStoreParameters";
41

    
42
        public static final String DBFFILE_PARAMTER_NAME = "dbfFile";
43
        public static final String ENCODING_PARAMTER_NAME = "encoding";
44

    
45
        private DelegatedDynObject parameters;
46

    
47
        public DBFStoreParameters() {
48
                this(PARAMETERS_DEFINITION_NAME);
49
        }
50

    
51
        protected DBFStoreParameters(String parametersDefinitionName) {
52
                this(parametersDefinitionName, DBFStoreProvider.NAME);
53
        }
54

    
55
        public DBFStoreParameters(String parametersDefinitionName, String name) {
56
                super();
57
                this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
58
                this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);
59
        }
60

    
61
        public String getDataStoreName() {
62
                return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
63
        }
64

    
65
        public String getDescription() {
66
                return this.getDynClass().getDescription();
67
        }
68

    
69
        public boolean isValid() {
70
                return (this.getDBFFileName() != null);
71
        }
72

    
73
        public File getFile() {
74
                return (File) this.getDynValue(DBFFILE_PARAMTER_NAME);
75
        }
76

    
77
        public void setFile(File file) {
78
                this.setDynValue(DBFFILE_PARAMTER_NAME, file);
79
        }
80

    
81
        public void setFile(String fileName) {
82
                this.setDynValue(DBFFILE_PARAMTER_NAME, fileName);
83
        }
84

    
85
        public String getDBFFileName() {
86
                if( this.getDBFFile() == null ) {
87
                        return null;
88
                }
89
                return this.getDBFFile().getAbsolutePath();
90
        }
91

    
92
        public File getDBFFile() {
93
                return (File) this.getDynValue(DBFFILE_PARAMTER_NAME);
94
        }
95

    
96
        public void setDBFFile(File file) {
97
                this.setDynValue(DBFFILE_PARAMTER_NAME, file);
98
        }
99

    
100
        public void setDBFFile(String fileName) {
101
                this.setDynValue(DBFFILE_PARAMTER_NAME, fileName);
102
        }
103

    
104
        public String getEncodingName() {
105
                return (String) getDynValue(ENCODING_PARAMTER_NAME);
106
        }
107
        
108
        public Charset getEncoding() {
109
                String name = getEncodingName();
110
                if (name == null) {
111
                        return null;
112
                }
113
                return Charset.forName(name);
114
        }
115

    
116
        public void setEncoding(String encoding) {
117
                this.setEncoding(Charset.forName(encoding));
118
        }
119

    
120
        public void setEncoding(Charset charset) {
121
                this.setDynValue(ENCODING_PARAMTER_NAME, charset.name());
122
        }
123

    
124
        protected DelegatedDynObject getDelegatedDynObject() {
125
                return parameters;
126
        }
127
}