Revision 32880 branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/dbf/DBFStoreParameters.java

View differences:

DBFStoreParameters.java
2 2

  
3 3
import java.io.File;
4 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 5

  
10 6
import org.gvsig.fmap.dal.DataStoreParameters;
7
import org.gvsig.fmap.dal.FileHelper;
11 8
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
12 9
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
13
import org.gvsig.tools.ToolsLocator;
10
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
14 11
import org.gvsig.tools.dynobject.DelegatedDynObject;
15
import org.gvsig.tools.dynobject.DynClass;
16
import org.gvsig.tools.dynobject.DynField;
17
import org.gvsig.tools.dynobject.DynObjectManager;
18
import org.gvsig.tools.dynobject.DynObjectValueItem;
19 12

  
20 13

  
21 14
public class DBFStoreParameters extends AbstractDataParameters implements
22 15
		DataStoreParameters, FilesystemStoreParameters {
23 16

  
24
    public static final String DYNCLASS_NAME = "DBFStoreParameters";
17
    public static final String PARAMETERS_DEFINITION_NAME = "DBFStoreParameters";
25 18

  
26
    protected static final String FIELD_DBFFILENAME = "dbffilename";
19
	public static final String DBFFILE_PARAMTER_NAME = "dbfFile";
20
	public static final String ENCODING_PARAMTER_NAME = "encoding";
27 21

  
28
	public static final String FIELD_ENCODING = "encoding";
22
	private DelegatedDynObject parameters;
29 23

  
30
	protected static DynClass DYNCLASS = null;
24
	public DBFStoreParameters() {
25
		this(PARAMETERS_DEFINITION_NAME);
26
	}
31 27

  
32
	private DelegatedDynObject delegatedDynObject;
33

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

  
40
//			field = dynClass.addDynFieldSingle(FIELD_DBFFILENAME,
41
//					"DBF file name", DataTypes.STRING, null, true, true);
42
			
43
			dynClass.addDynFieldString(FIELD_DBFFILENAME)
44
					.setDescription("DBF file name")
45
					.setMandatory(true);
46

  
47
			Set charsetSet = new LinkedHashSet(160);
48

  
49
			charsetSet.add(new DynObjectValueItem(null, "{default}"));
50
			charsetSet.add(new DynObjectValueItem("US-ASCII"));
51
			charsetSet.add(new DynObjectValueItem("ISO-8859-1"));
52
			charsetSet.add(new DynObjectValueItem("ISO-8859-15"));
53
			charsetSet.add(new DynObjectValueItem("windows-1250"));
54
			charsetSet.add(new DynObjectValueItem("windows-1252"));
55
			charsetSet.add(new DynObjectValueItem("UTF-8"));
56
			charsetSet.add(new DynObjectValueItem("UTF-16"));
57
			charsetSet.add(new DynObjectValueItem("UTF-16BE"));
58
			charsetSet.add(new DynObjectValueItem("UTF-16LE"));
59
			Map charsets = Charset.availableCharsets();
60
			Iterator iter = charsets.keySet().iterator();
61
			while (iter.hasNext()){
62
				charsetSet.add(new DynObjectValueItem(iter.next()));
63
			}
64

  
65
			dynClass.addDynFieldString(FIELD_ENCODING)
66
					.setDescription("Encoding")
67
					.setTheTypeOfAvailableValues(DynField.CHOICE)
68
					.setAvailableValues((DynObjectValueItem[]) charsetSet
69
						.toArray(new DynObjectValueItem[0]));
70

  
71
			DYNCLASS = dynClass;
72

  
73
			// Register the DynClass in the PersistenceManager
74
			ToolsLocator.getPersistenceManager().registerClass(
75
					DBFStoreParameters.class, dynClass);
76
		}
77

  
28
	protected DBFStoreParameters(String parametersDefinitionName) {
29
		this(parametersDefinitionName, DBFStoreProvider.NAME);
78 30
	}
79 31

  
80
	public DBFStoreParameters() {
32
	public DBFStoreParameters(String parametersDefinitionName, String name) {
81 33
		super();
82
		initialize();
34
		this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
35
		this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);
83 36
	}
84 37

  
85
	protected void initialize() {
86
		this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
87
				.getDynObjectManager()
88
				.createDynObject(
89
						DBFStoreParameters.DYNCLASS);
38
	public String getDataStoreName() {
39
		return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
90 40
	}
91 41

  
92
	public String getDataStoreName() {
93
		return DBFStoreProvider.NAME;
42
	public String getDescription() {
43
		return this.getDynClass().getDescription();
94 44
	}
95 45

  
96 46
	public boolean isValid() {
......
98 48
	}
99 49

  
100 50
	public File getFile() {
101
		return new File(this.getDBFFileName());
51
		return (File) this.getDynValue(DBFFILE_PARAMTER_NAME);
102 52
	}
103 53

  
104
	public void setFile(File aFile) {
105
		this.setDBFFile(aFile);
54
	public void setFile(File file) {
55
		this.setDynValue(DBFFILE_PARAMTER_NAME, file);
106 56
	}
107 57

  
108
	public void setFile(String aFileName) {
109
		this.setDBFFileName(aFileName);
58
	public void setFile(String fileName) {
59
		this.setDynValue(DBFFILE_PARAMTER_NAME, fileName);
110 60
	}
111 61

  
112 62
	public String getDBFFileName() {
113
		return (String) this.getDynValue(FIELD_DBFFILENAME);
63
		if( this.getFile() == null ) {
64
			return null;
65
		}
66
		return this.getFile().getAbsolutePath();
114 67
	}
115 68

  
116 69
	public File getDBFFile() {
117
		return new File((String) this.getDynValue(FIELD_DBFFILENAME));
70
		return (File) this.getDynValue(DBFFILE_PARAMTER_NAME);
118 71
	}
119 72

  
120
	public void setDBFFile(File aFile) {
121
		this.setDynValue(FIELD_DBFFILENAME, aFile.getPath());
73
	public void setDBFFile(File file) {
74
		this.setDynValue(DBFFILE_PARAMTER_NAME, file);
122 75
	}
123 76

  
124
	public void setDBFFileName(String aFileName) {
125
		this.setDynValue(FIELD_DBFFILENAME, aFileName);
77
	public void setDBFFile(String fileName) {
78
		this.setDynValue(DBFFILE_PARAMTER_NAME, fileName);
126 79
	}
127 80

  
128
	public String getDescription() {
129
		return DBFStoreProvider.DESCRIPTION;
130
	}
131

  
132 81
	public String getEncodingName() {
133
		return (String) getDynValue(FIELD_ENCODING);
82
		return (String) getDynValue(ENCODING_PARAMTER_NAME);
134 83
	}
84
	
135 85
	public Charset getEncoding() {
136 86
		String name = getEncodingName();
137 87
		if (name == null) {
......
145 95
	}
146 96

  
147 97
	public void setEncoding(Charset charset) {
148
		this.setDynValue(FIELD_ENCODING, charset.name());
98
		this.setDynValue(ENCODING_PARAMTER_NAME, charset.name());
149 99
	}
150 100

  
151 101
	protected DelegatedDynObject getDelegatedDynObject() {
152
		return delegatedDynObject;
102
		return parameters;
153 103
	}
154 104
}

Also available in: Unified diff