root / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / feature / joinstore / JoinFeatureStoreParameters.java @ 24250
History | View | Annotate | Download (8.58 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 IVER T.I {{Task}}
|
26 |
*/
|
27 |
|
28 |
/**
|
29 |
*
|
30 |
*/
|
31 |
package org.gvsig.fmap.data.feature.joinstore; |
32 |
|
33 |
import java.util.HashMap; |
34 |
import java.util.Map; |
35 |
|
36 |
import org.gvsig.fmap.data.DataManager; |
37 |
import org.gvsig.fmap.data.DataStoreParameters; |
38 |
import org.gvsig.fmap.data.exceptions.InitializeException; |
39 |
import org.gvsig.fmap.data.impl.DefaultDataManager; |
40 |
|
41 |
import com.iver.utiles.NotExistInXMLEntity; |
42 |
import com.iver.utiles.XMLEntity; |
43 |
|
44 |
/**
|
45 |
* Class for {@link JoinFeatureStore} parameters. <br>
|
46 |
* <br>
|
47 |
* For create a new JoinFeatureStore you need to fill the follow parameters:<br>
|
48 |
* <b>storePrimary</b>: Principal Store of the <code>join</code> operation<br>
|
49 |
* <b>storeSecondary</b>: Subordinate Store of the <code>join</code> operation<br>
|
50 |
* <b>linkFieldPrimary</b>: Field of the Principal Store to use for the join
|
51 |
* operation<br>
|
52 |
* <b>linkFieldSecondary</b>: Field of the Principal Store to use for the join
|
53 |
* operation<br>
|
54 |
* <br>
|
55 |
* <!--Optionally you can define a limited number of fields for each stores
|
56 |
* using the <b>featureTypePrimary</b> and <b>featureTypeSecondary</b>
|
57 |
* parameters. -->
|
58 |
*
|
59 |
* You can set in <b>defautlGeomerty</b> the name of the field to use as the
|
60 |
* Store defaultGeometry.
|
61 |
*
|
62 |
* @author jmvivo
|
63 |
*
|
64 |
*/
|
65 |
public class JoinFeatureStoreParameters extends DataStoreParameters { |
66 |
private Map internalMap; |
67 |
|
68 |
private static String defaultFieldNamePrefix = "join_"; |
69 |
|
70 |
protected Map createDefaultValuesMap() { |
71 |
Map defaultValues = new HashMap(7); |
72 |
defaultValues.put("storePrimary", null); |
73 |
defaultValues.put("storeSecondary", null); |
74 |
defaultValues.put("linkFieldPrimary", null); |
75 |
defaultValues.put("linkFieldSecondary", null); |
76 |
defaultValues.put("defaultGeometry", null); |
77 |
defaultValues.put("fieldNamePrefix", defaultFieldNamePrefix);
|
78 |
defaultValues.put("fieldsStorePrimary", null); |
79 |
defaultValues.put("fieldsStoreSecondary", null); |
80 |
return defaultValues;
|
81 |
} |
82 |
|
83 |
|
84 |
|
85 |
public String[] getFieldsStorePrimary() { |
86 |
return (String[]) this.getAttribute("fieldsStorePrimary"); |
87 |
} |
88 |
|
89 |
public void setFieldsStorePrimary(String[] fieldsStorePrimary) { |
90 |
this.put("fieldsStorePrimary", fieldsStorePrimary); |
91 |
} |
92 |
|
93 |
public String[] getFieldsStoreSecondary() { |
94 |
return (String[]) this.getAttribute("fieldsStoreSecondary"); |
95 |
} |
96 |
|
97 |
public void setFieldsStoreSecondary(String[] fieldsStoreSecondary) { |
98 |
this.put("fieldsStoreSecondary", fieldsStoreSecondary); |
99 |
} |
100 |
|
101 |
/* (non-Javadoc)
|
102 |
* @see org.gvsig.fmap.data.DataStoreParameters#getDataStoreName()
|
103 |
*/
|
104 |
public String getDataStoreName() { |
105 |
return JoinFeatureStore.DATASTORE_NAME;
|
106 |
} |
107 |
|
108 |
/* (non-Javadoc)
|
109 |
* @see org.gvsig.fmap.data.DataStoreParameters#isValid()
|
110 |
*/
|
111 |
public boolean isValid() { |
112 |
if (this.getStorePrimary() == null || this.getStoreSecondary() == null) { |
113 |
return false; |
114 |
} |
115 |
if (this.getLinkFieldPrimary() == null |
116 |
|| this.getLinkFieldSecondary() == null) { |
117 |
return false; |
118 |
} |
119 |
if (this.getLinkFieldPrimary().length() < 1 |
120 |
|| this.getLinkFieldSecondary().length() < 1) { |
121 |
return false; |
122 |
} |
123 |
if (this.getFieldNamePrefix() == null |
124 |
|| this.getFieldNamePrefix().length() < 1) { |
125 |
return false; |
126 |
} |
127 |
return true; |
128 |
} |
129 |
|
130 |
public String getDefaultGeometry() { |
131 |
return (String) this.getAttribute("defaultGeometry"); |
132 |
} |
133 |
|
134 |
public void setDefaultGeometry(String defaultGeometry) { |
135 |
this.put("defaultGeometry", defaultGeometry); |
136 |
} |
137 |
|
138 |
public String getLinkFieldPrimary() { |
139 |
return (String) this.getAttribute("linkFieldPrimary"); |
140 |
} |
141 |
|
142 |
public void setLinkFieldPrimary(String linkFieldPrimary) { |
143 |
this.put("linkFieldPrimary", linkFieldPrimary); |
144 |
} |
145 |
|
146 |
public String getLinkFieldSecondary() { |
147 |
return (String) this.getAttribute("linkFieldSecondary"); |
148 |
} |
149 |
|
150 |
public void setLinkFieldSecondary(String linkFieldSecondary) { |
151 |
this.put("linkFieldSecondary", linkFieldSecondary); |
152 |
} |
153 |
|
154 |
public DataStoreParameters getStorePrimary() {
|
155 |
return (DataStoreParameters) this.getAttribute("storePrimary"); |
156 |
} |
157 |
|
158 |
public void setStorePrimary(DataStoreParameters storePrimary) { |
159 |
this.put("storePrimary", storePrimary); |
160 |
} |
161 |
|
162 |
public DataStoreParameters getStoreSecondary() {
|
163 |
return (DataStoreParameters) this.getAttribute("storeSecondary"); |
164 |
} |
165 |
|
166 |
public void setStoreSecondary(DataStoreParameters storeSecondary) { |
167 |
this.put("storeSecondary", storeSecondary); |
168 |
} |
169 |
|
170 |
public String getFieldNamePrefix() { |
171 |
return (String) this.getAttribute("fieldNamePrefix"); |
172 |
} |
173 |
|
174 |
public void setFieldNamePrefix(String fieldNamePrefix) { |
175 |
this.put("fieldNamePrefix", fieldNamePrefix); |
176 |
} |
177 |
|
178 |
public String getDescription() { |
179 |
return "Join of two Stores"; |
180 |
} |
181 |
|
182 |
public XMLEntity getXMLEntity() {
|
183 |
XMLEntity xmlEntity = super.getXMLEntity();
|
184 |
|
185 |
XMLEntity params = this.getStorePrimary().getXMLEntity();
|
186 |
params.putProperty("store", "primary"); |
187 |
xmlEntity.addChild(params); |
188 |
|
189 |
params = this.getStoreSecondary().getXMLEntity();
|
190 |
params.putProperty("store", "secondary"); |
191 |
xmlEntity.addChild(params); |
192 |
|
193 |
xmlEntity.putProperty("linkFieldPrimary", this.getLinkFieldPrimary()); |
194 |
xmlEntity.putProperty("linkFieldSecondary", this |
195 |
.getLinkFieldSecondary()); |
196 |
xmlEntity.putProperty("defaultGeometry", this.getDefaultGeometry()); |
197 |
|
198 |
xmlEntity.putProperty("fieldNamePrefix", this.getFieldNamePrefix()); |
199 |
|
200 |
if (this.getFieldsStorePrimary() != null |
201 |
&& this.getFieldsStorePrimary().length > 0) { |
202 |
|
203 |
xmlEntity.putProperty("fieldsStorePrimary",
|
204 |
arrayToString(this
|
205 |
.getFieldsStorePrimary())); |
206 |
|
207 |
} |
208 |
|
209 |
if (this.getFieldsStoreSecondary() != null |
210 |
&& this.getFieldsStoreSecondary().length > 0) { |
211 |
|
212 |
xmlEntity.putProperty("fieldsStoreSecondary",
|
213 |
arrayToString(this
|
214 |
.getFieldsStoreSecondary())); |
215 |
} |
216 |
|
217 |
return xmlEntity;
|
218 |
} |
219 |
|
220 |
public void loadFromXMLEntity(XMLEntity xmlEntity) |
221 |
throws InitializeException {
|
222 |
DataManager manager = DefaultDataManager.getManager(); |
223 |
|
224 |
XMLEntity params; |
225 |
params = xmlEntity.firstChild("store", "primary"); |
226 |
|
227 |
if (params == null) { |
228 |
throw new InitializeException("store params(primary) not found", |
229 |
this.getDataStoreName());
|
230 |
|
231 |
} |
232 |
try {
|
233 |
this.setStorePrimary(manager.createStoreParameters(params));
|
234 |
} catch (InitializeException e) {
|
235 |
new InitializeException("store params(primary) error", this |
236 |
.getDataStoreName(), e); |
237 |
} |
238 |
|
239 |
params = xmlEntity.firstChild("store", "secondary"); |
240 |
|
241 |
if (params == null) { |
242 |
throw new InitializeException("store params(secondary) not found", |
243 |
this.getDataStoreName());
|
244 |
|
245 |
} |
246 |
try {
|
247 |
this.setStoreSecondary(manager.createStoreParameters(params));
|
248 |
} catch (InitializeException e) {
|
249 |
new InitializeException("store params(secondary) error", this |
250 |
.getDataStoreName(), e); |
251 |
} |
252 |
|
253 |
|
254 |
|
255 |
try {
|
256 |
this.setLinkFieldPrimary(xmlEntity
|
257 |
.getStringProperty("linkFieldPrimary"));
|
258 |
} catch (NotExistInXMLEntity e) {
|
259 |
throw new InitializeException("linkFieldPrimary property not found", this |
260 |
.getDataStoreName()); |
261 |
} |
262 |
|
263 |
try {
|
264 |
this.setLinkFieldSecondary(xmlEntity
|
265 |
.getStringProperty("linkFieldSecondary"));
|
266 |
} catch (NotExistInXMLEntity e) {
|
267 |
throw new InitializeException( |
268 |
"linkFieldSecondary property not found", this |
269 |
.getDataStoreName()); |
270 |
} |
271 |
|
272 |
|
273 |
try {
|
274 |
this.setDefaultGeometry(xmlEntity
|
275 |
.getStringProperty("defaultGeometry"));
|
276 |
} catch (NotExistInXMLEntity e) {
|
277 |
this.remove("defaultGeometry"); |
278 |
} |
279 |
|
280 |
try {
|
281 |
this.setFieldNamePrefix(xmlEntity
|
282 |
.getStringProperty("fieldNamePrefix"));
|
283 |
} catch (NotExistInXMLEntity e) {
|
284 |
this.remove("fieldNamePrefix"); |
285 |
} |
286 |
|
287 |
String tmp = null; |
288 |
|
289 |
try {
|
290 |
tmp = xmlEntity.getStringProperty("fieldsStoreSecondary");
|
291 |
this.setFieldsStoreSecondary(tmp.split(",")); |
292 |
} catch (NotExistInXMLEntity e) {
|
293 |
this.remove("fieldsStoreSecondary"); |
294 |
} |
295 |
|
296 |
} |
297 |
|
298 |
|
299 |
private String arrayToString(Object[] array) { |
300 |
StringBuffer buff = new StringBuffer(); |
301 |
if (array.length < 1) { |
302 |
return ""; |
303 |
} |
304 |
for (int i = 0; i < array.length; i++) { |
305 |
buff.append(array[i] + ",");
|
306 |
} |
307 |
|
308 |
String r = buff.toString();
|
309 |
return r.substring(0, r.length() - 1); |
310 |
} |
311 |
|
312 |
} |
313 |
|