svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataFile / src / org / gvsig / fmap / data / feature / file / FileExplorerParameters.java @ 23543
History | View | Annotate | Download (2.15 KB)
1 |
package org.gvsig.fmap.data.feature.file; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.HashMap; |
5 |
import java.util.Map; |
6 |
|
7 |
import org.gvsig.fmap.data.AbstractDataExplorerParameters; |
8 |
import org.gvsig.fmap.data.DataManager; |
9 |
import org.gvsig.fmap.data.DataStoreParameters; |
10 |
import org.gvsig.fmap.data.InitializeException; |
11 |
|
12 |
import com.iver.utiles.NotExistInXMLEntity; |
13 |
import com.iver.utiles.XMLEntity; |
14 |
|
15 |
public abstract class FileExplorerParameters extends |
16 |
AbstractDataExplorerParameters { |
17 |
private Map internalMap; |
18 |
|
19 |
protected File source; |
20 |
|
21 |
public void setSource(File source){ |
22 |
this.source = source;
|
23 |
this.clearInternalMap();
|
24 |
} |
25 |
|
26 |
public File getSource(){ |
27 |
return this.source; |
28 |
} |
29 |
|
30 |
public XMLEntity getXMLEntity() {
|
31 |
XMLEntity entity = super.getXMLEntity();
|
32 |
entity.putProperty("source", source.getPath());
|
33 |
return entity;
|
34 |
} |
35 |
|
36 |
public void loadFromXMLEntity(XMLEntity xmlEntity) |
37 |
throws InitializeException {
|
38 |
try {
|
39 |
this.source = new File(xmlEntity.getStringProperty("source")); |
40 |
} catch (NotExistInXMLEntity e) {
|
41 |
throw new InitializeException("source property not set", this |
42 |
.getDataExplorerName()); |
43 |
} |
44 |
|
45 |
} |
46 |
|
47 |
public DataStoreParameters newStoreParameters() throws InitializeException { |
48 |
return DataManager.getManager().createDataStoreParameters(
|
49 |
this.getXMLEntity());
|
50 |
} |
51 |
|
52 |
public void clear() { |
53 |
this.source = null; |
54 |
this.clearInternalMap();
|
55 |
} |
56 |
|
57 |
protected Map getInternalMap() { |
58 |
if (this.internalMap == null) { |
59 |
this.internalMap = new HashMap(1); |
60 |
} |
61 |
if (this.internalMap.size() == 0) { |
62 |
this.internalMap.put("source", this.source); |
63 |
} |
64 |
return this.internalMap; |
65 |
} |
66 |
|
67 |
public Object put(Object key, Object value) { |
68 |
if (!(key instanceof String)) { |
69 |
throw new ClassCastException("key must be String"); |
70 |
|
71 |
} |
72 |
String sKey = (String) key; |
73 |
Object rValue = null; |
74 |
if (sKey.equalsIgnoreCase("source")) { |
75 |
rValue = this.source;
|
76 |
this.source = (File) value; |
77 |
} else {
|
78 |
throw new IllegalArgumentException("key:" + sKey); |
79 |
} |
80 |
this.clearInternalMap();
|
81 |
return rValue;
|
82 |
} |
83 |
|
84 |
protected void clearInternalMap() { |
85 |
if (this.internalMap != null) { |
86 |
this.internalMap.clear();
|
87 |
} |
88 |
|
89 |
} |
90 |
|
91 |
} |