Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / dbf / DBFStoreParameters.java @ 30754

History | View | Annotate | Download (4.4 KB)

1
package org.gvsig.fmap.dal.store.dbf;
2

    
3
import java.io.File;
4
import java.nio.charset.Charset;
5
import java.util.Iterator;
6
import java.util.LinkedHashSet;
7
import java.util.Map;
8
import java.util.Set;
9

    
10
import org.gvsig.fmap.dal.DataStoreParameters;
11
import org.gvsig.fmap.dal.DataTypes;
12
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
13
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
14
import org.gvsig.tools.ToolsLocator;
15
import org.gvsig.tools.dynobject.DelegatedDynObject;
16
import org.gvsig.tools.dynobject.DynClass;
17
import org.gvsig.tools.dynobject.DynField;
18
import org.gvsig.tools.dynobject.DynObjectManager;
19
import org.gvsig.tools.dynobject.DynObjectValueItem;
20

    
21

    
22
public class DBFStoreParameters extends AbstractDataParameters implements
23
                DataStoreParameters, FilesystemStoreParameters {
24

    
25
    public static final String DYNCLASS_NAME = "DBFStoreParameters";
26

    
27
    protected static final String FIELD_DBFFILENAME = "dbffilename";
28

    
29
        public static final String FIELD_ENCODING = "encoding";
30

    
31
        protected static DynClass DYNCLASS = null;
32

    
33
    protected static void registerDynClass() {
34
                DynObjectManager dynman = ToolsLocator.getDynObjectManager();
35
                DynClass dynClass;
36
                DynField field;
37
                if (DYNCLASS == null) {
38
                        dynClass = dynman.add(DYNCLASS_NAME);
39

    
40
                        field = dynClass.addDynField(FIELD_DBFFILENAME);
41
                        field.setTheTypeOfAvailableValues(DynField.SINGLE);
42
                        field.setDescription("DBF file name");
43
                        field.setType(DataTypes.STRING);
44
                        field.setMandatory(true);
45
                        DYNCLASS = dynClass;
46

    
47

    
48
                        field = dynClass.addDynField(FIELD_ENCODING);
49
                        field.setTheTypeOfAvailableValues(DynField.CHOICE);
50
                        field.setDescription("Encoding");
51
                        field.setType(DataTypes.STRING);
52
                        field.setMandatory(false);
53
                        field.setDefaultDynValue(null);
54

    
55

    
56
                        Set charsetSet = new LinkedHashSet(160);
57

    
58
                        charsetSet.add(new DynObjectValueItem(null, "{default}"));
59
                        charsetSet.add(new DynObjectValueItem("US-ASCII"));
60
                        charsetSet.add(new DynObjectValueItem("ISO-8859-1"));
61
                        charsetSet.add(new DynObjectValueItem("ISO-8859-15"));
62
                        charsetSet.add(new DynObjectValueItem("windows-1250"));
63
                        charsetSet.add(new DynObjectValueItem("windows-1252"));
64
                        charsetSet.add(new DynObjectValueItem("UTF-8"));
65
                        charsetSet.add(new DynObjectValueItem("UTF-16"));
66
                        charsetSet.add(new DynObjectValueItem("UTF-16BE"));
67
                        charsetSet.add(new DynObjectValueItem("UTF-16LE"));
68
                        Map charsets = Charset.availableCharsets();
69
                        Iterator iter = charsets.keySet().iterator();
70
                        while (iter.hasNext()){
71
                                charsetSet.add(new DynObjectValueItem(iter.next()));
72
                        }
73
                        field.setAvailableValues((DynObjectValueItem[]) charsetSet
74
                                        .toArray(new DynObjectValueItem[0]));
75

    
76
                        DYNCLASS = dynClass;
77

    
78
                        // Register the DynClass in the PersistenceManager
79
                        ToolsLocator.getPersistenceManager().registerClass(
80
                                        DBFStoreParameters.class, dynClass);
81
                }
82

    
83
        }
84

    
85
        public DBFStoreParameters() {
86
                super();
87
                initialize();
88
        }
89

    
90
        protected void initialize() {
91
                this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
92
                                .getDynObjectManager()
93
                                .createDynObject(
94
                                                DBFStoreParameters.DYNCLASS);
95
        }
96

    
97
        public String getDataStoreName() {
98
                return DBFStoreProvider.NAME;
99
        }
100

    
101
        public boolean isValid() {
102
                return (this.getDBFFileName() != null);
103
        }
104

    
105
        public File getFile() {
106
                return new File(this.getDBFFileName());
107
        }
108

    
109
        public void setFile(File aFile) {
110
                this.setDBFFile(aFile);
111
        }
112

    
113
        public void setFile(String aFileName) {
114
                this.setDBFFileName(aFileName);
115
        }
116

    
117
        public String getDBFFileName() {
118
                return (String) this.getDynValue(FIELD_DBFFILENAME);
119
        }
120

    
121
        public File getDBFFile() {
122
                return new File((String) this.getDynValue(FIELD_DBFFILENAME));
123
        }
124

    
125
        public void setDBFFile(File aFile) {
126
                this.setDynValue(FIELD_DBFFILENAME, aFile.getPath());
127
        }
128

    
129
        public void setDBFFileName(String aFileName) {
130
                this.setDynValue(FIELD_DBFFILENAME, aFileName);
131
        }
132

    
133
        public String getDescription() {
134
                return DBFStoreProvider.DESCRIPTION;
135
        }
136

    
137
        public String getEncodingName() {
138
                return (String) getDynValue(FIELD_ENCODING);
139
        }
140
        public Charset getEncoding() {
141
                String name = getEncodingName();
142
                if (name == null) {
143
                        return null;
144
                }
145
                return Charset.forName(name);
146
        }
147

    
148
        public void setEncoding(String encoding) {
149
                this.setEncoding(Charset.forName(encoding));
150
        }
151

    
152
        public void setEncoding(Charset charset) {
153
                this.setDynValue(FIELD_ENCODING, charset.name());
154
        }
155
}