root / branches / v2_0_0_prep / libraries / libFMap_dataDB / src / org / gvsig / fmap / data / feature / db / DBExplorerParameters.java @ 23540
History | View | Annotate | Download (5.35 KB)
1 |
package org.gvsig.fmap.data.feature.db; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.Map; |
5 |
|
6 |
import org.gvsig.fmap.data.AbstractDataExplorerParameters; |
7 |
import org.gvsig.fmap.data.InitializeException; |
8 |
|
9 |
import com.iver.utiles.NotExistInXMLEntity; |
10 |
import com.iver.utiles.XMLEntity; |
11 |
|
12 |
|
13 |
public abstract class DBExplorerParameters extends |
14 |
AbstractDataExplorerParameters implements DBParameters {
|
15 |
|
16 |
protected Map internalMap; |
17 |
|
18 |
private String user = null; |
19 |
private String passw = null; |
20 |
private String schema = null; |
21 |
private String catalog = null; |
22 |
private String host; |
23 |
private String port; |
24 |
private String db; |
25 |
|
26 |
public void clear() { |
27 |
user = null;
|
28 |
passw = null;
|
29 |
schema = null;
|
30 |
catalog = null;
|
31 |
host = null;
|
32 |
port = null;
|
33 |
db = null;
|
34 |
this.clearInternalMap();
|
35 |
} |
36 |
|
37 |
protected void clearInternalMap() { |
38 |
if (this.internalMap != null) { |
39 |
this.internalMap.clear();
|
40 |
} |
41 |
} |
42 |
|
43 |
protected Map getInternalMap() { |
44 |
if (this.internalMap == null) { |
45 |
this.internalMap = new HashMap(18); |
46 |
} |
47 |
if (this.internalMap.size() == 0) { |
48 |
this.internalMap.put("user", user); |
49 |
this.internalMap.put("passw", passw); |
50 |
this.internalMap.put("schema", schema); |
51 |
this.internalMap.put("catalog", catalog); |
52 |
this.internalMap.put("host", host); |
53 |
this.internalMap.put("port", port); |
54 |
this.internalMap.put("db", db); |
55 |
} |
56 |
return this.internalMap; |
57 |
} |
58 |
|
59 |
|
60 |
public void fillStoreParameters(DBStoreParameters dbParameters){ |
61 |
dbParameters.setUser(this.user);
|
62 |
dbParameters.setPassw(this.passw);
|
63 |
dbParameters.setSchema(this.schema);
|
64 |
dbParameters.setCatalog(this.catalog);
|
65 |
dbParameters.setHost(this.host);
|
66 |
dbParameters.setPort(this.port);
|
67 |
dbParameters.setDb(this.db);
|
68 |
} |
69 |
|
70 |
public void loadFromStoreParameters(DBStoreParameters dbParameters){ |
71 |
this.user = dbParameters.getUser();
|
72 |
this.passw = dbParameters.getPassw();
|
73 |
this.schema = dbParameters.getSchema();
|
74 |
this.passw= dbParameters.getPassw();
|
75 |
this.catalog = dbParameters.getCatalog();
|
76 |
this.host = dbParameters.getHost();
|
77 |
this.port = dbParameters.getPort();
|
78 |
this.db = dbParameters.getDb();
|
79 |
} |
80 |
|
81 |
public String getDb() { |
82 |
return db;
|
83 |
} |
84 |
public void setDb(String db) { |
85 |
this.db = db;
|
86 |
} |
87 |
public String getHost() { |
88 |
return host;
|
89 |
} |
90 |
public void setHost(String host) { |
91 |
this.host = host;
|
92 |
} |
93 |
public String getPort() { |
94 |
return port;
|
95 |
} |
96 |
public void setPort(String port) { |
97 |
this.port = port;
|
98 |
} |
99 |
public String getSchema() { |
100 |
return schema;
|
101 |
} |
102 |
public void setSchema(String schema) { |
103 |
this.schema = schema;
|
104 |
} |
105 |
public String getPassw() { |
106 |
return passw;
|
107 |
} |
108 |
public void setPassw(String passw) { |
109 |
this.passw = passw;
|
110 |
} |
111 |
|
112 |
public String getUser() { |
113 |
return user;
|
114 |
} |
115 |
public void setUser(String user) { |
116 |
this.user = user;
|
117 |
} |
118 |
public String getCatalog() { |
119 |
return catalog;
|
120 |
} |
121 |
public void setCatalog(String catalog) { |
122 |
this.catalog = catalog;
|
123 |
} |
124 |
|
125 |
public XMLEntity getXMLEntity() {
|
126 |
XMLEntity xmlEntity = super.getXMLEntity();
|
127 |
|
128 |
xmlEntity.putProperty("user", this.user); |
129 |
//xmlEntity.putProperty("passw", this.passw);
|
130 |
xmlEntity.putProperty("schema", this.schema); |
131 |
xmlEntity.putProperty("catalog", this.catalog); |
132 |
xmlEntity.putProperty("host", this.host); |
133 |
xmlEntity.putProperty("port", this.port); |
134 |
xmlEntity.putProperty("db", this.db); |
135 |
|
136 |
return xmlEntity;
|
137 |
} |
138 |
|
139 |
public void loadFromXMLEntity(XMLEntity xmlEntity) |
140 |
throws InitializeException {
|
141 |
try {
|
142 |
this.user = xmlEntity.getStringProperty("user"); |
143 |
} catch (NotExistInXMLEntity e) {
|
144 |
this.user = null; |
145 |
} |
146 |
|
147 |
try {
|
148 |
this.passw = xmlEntity.getStringProperty("passw"); |
149 |
} catch (NotExistInXMLEntity e) {
|
150 |
this.passw = null; |
151 |
} |
152 |
|
153 |
try {
|
154 |
this.schema = xmlEntity.getStringProperty("schema"); |
155 |
} catch (NotExistInXMLEntity e) {
|
156 |
this.schema = null; |
157 |
} |
158 |
|
159 |
try {
|
160 |
this.catalog = xmlEntity.getStringProperty("catalog"); |
161 |
} catch (NotExistInXMLEntity e) {
|
162 |
this.catalog = null; |
163 |
} |
164 |
|
165 |
try {
|
166 |
this.host = xmlEntity.getStringProperty("host"); |
167 |
} catch (NotExistInXMLEntity e) {
|
168 |
throw new InitializeException("host property not set", this |
169 |
.getDataExplorerName()); |
170 |
} |
171 |
try {
|
172 |
this.port = xmlEntity.getStringProperty("port"); |
173 |
} catch (NotExistInXMLEntity e) {
|
174 |
throw new InitializeException("port property not set", this |
175 |
.getDataExplorerName()); |
176 |
} |
177 |
try {
|
178 |
this.db = xmlEntity.getStringProperty("db"); |
179 |
} catch (NotExistInXMLEntity e) {
|
180 |
throw new InitializeException("db property not set", this |
181 |
.getDataExplorerName()); |
182 |
} |
183 |
} |
184 |
|
185 |
public Object put(Object key, Object value) { |
186 |
if (!(key instanceof String)) { |
187 |
throw new ClassCastException("key must be String"); |
188 |
|
189 |
} |
190 |
String sKey = (String) key; |
191 |
Object rValue = null; |
192 |
|
193 |
if (sKey.equalsIgnoreCase("user")) { |
194 |
rValue = this.user;
|
195 |
this.user = (String) value; |
196 |
} else if (sKey.equalsIgnoreCase("passw")) { |
197 |
rValue = this.passw;
|
198 |
this.passw = (String) value; |
199 |
} else if (sKey.equalsIgnoreCase("schema")) { |
200 |
rValue = this.schema;
|
201 |
this.schema = (String) value; |
202 |
} else if (sKey.equalsIgnoreCase("catalog")) { |
203 |
rValue = this.catalog;
|
204 |
this.catalog = (String) value; |
205 |
} else if (sKey.equalsIgnoreCase("host")) { |
206 |
rValue = this.host;
|
207 |
this.host = (String) value; |
208 |
} else if (sKey.equalsIgnoreCase("port")) { |
209 |
rValue = this.port;
|
210 |
this.port = (String) value; |
211 |
} else if (sKey.equalsIgnoreCase("db")) { |
212 |
rValue = this.db;
|
213 |
this.db = (String) value; |
214 |
} else {
|
215 |
throw new IllegalArgumentException("key:" + sKey); |
216 |
} |
217 |
this.clearInternalMap();
|
218 |
return rValue;
|
219 |
} |
220 |
} |