Revision 31196
branches/v2_0_0_prep/extensions/extDalTransformJoin/src/org/gvsig/app/join/JoinTransformExtension.java | ||
---|---|---|
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 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.app.join; |
|
29 |
|
|
30 |
import org.gvsig.andami.plugins.Extension; |
|
31 |
import org.gvsig.app.daltransform.DataTransformLocator; |
|
32 |
import org.gvsig.app.daltransform.DataTransformManager; |
|
33 |
import org.gvsig.app.join.daltransform.JoinTransformGui; |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
38 |
*/ |
|
39 |
public class JoinTransformExtension extends Extension{ |
|
40 |
|
|
41 |
/* (non-Javadoc) |
|
42 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String) |
|
43 |
*/ |
|
44 |
public void execute(String actionCommand) { |
|
45 |
// TODO Auto-generated method stub |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
/* (non-Javadoc) |
|
50 |
* @see com.iver.andami.plugins.IExtension#initialize() |
|
51 |
*/ |
|
52 |
public void initialize() { |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public void postInitialize() { |
|
57 |
super.postInitialize(); |
|
58 |
DataTransformManager dataTransformManager = DataTransformLocator.getDataTransformManager(); |
|
59 |
dataTransformManager.registerDataTransform("join", JoinTransformGui.class); |
|
60 |
} |
|
61 |
|
|
62 |
/* (non-Javadoc) |
|
63 |
* @see com.iver.andami.plugins.IExtension#isEnabled() |
|
64 |
*/ |
|
65 |
public boolean isEnabled() { |
|
66 |
// TODO Auto-generated method stub |
|
67 |
return false; |
|
68 |
} |
|
69 |
|
|
70 |
/* (non-Javadoc) |
|
71 |
* @see com.iver.andami.plugins.IExtension#isVisible() |
|
72 |
*/ |
|
73 |
public boolean isVisible() { |
|
74 |
// TODO Auto-generated method stub |
|
75 |
return false; |
|
76 |
} |
|
77 |
|
|
78 |
} |
|
79 |
|
branches/v2_0_0_prep/extensions/extDalTransformJoin/src/org/gvsig/app/join/JoinTransformLibrary.java | ||
---|---|---|
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 |
* 2009 {Iver T.I.} {Task} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.app.join; |
|
29 |
|
|
30 |
import org.gvsig.app.daltransform.DataTransformLocator; |
|
31 |
import org.gvsig.app.daltransform.DataTransformManager; |
|
32 |
import org.gvsig.app.join.dal.feature.JoinTransform; |
|
33 |
import org.gvsig.app.join.daltransform.JoinTransformGui; |
|
34 |
import org.gvsig.tools.library.AbstractLibrary; |
|
35 |
import org.gvsig.tools.library.LibraryException; |
|
36 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
|
37 |
|
|
38 |
/** |
|
39 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a> |
|
40 |
*/ |
|
41 |
public class JoinTransformLibrary extends AbstractLibrary { |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void doInitialize() throws LibraryException { |
|
45 |
// TODO Auto-generated method stub |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
protected void doPostInitialize() throws LibraryException { |
|
51 |
// Validate there is any implementation registered. |
|
52 |
DataTransformManager dataTransformManager = DataTransformLocator.getDataTransformManager(); |
|
53 |
if (dataTransformManager == null) { |
|
54 |
throw new ReferenceNotRegisteredException( |
|
55 |
DataTransformLocator.DATA_TRANSFORM_MANAGER_NAME, DataTransformLocator.getInstance()); |
|
56 |
} |
|
57 |
dataTransformManager.registerDataTransform("join", JoinTransformGui.class); |
|
58 |
|
|
59 |
JoinTransform.registerPersistent(); |
|
60 |
} |
|
61 |
|
|
62 |
} |
|
63 |
|
|
0 | 64 |
branches/v2_0_0_prep/extensions/extDalTransformJoin/src/org/gvsig/app/join/dal/feature/JoinTransform.java | ||
---|---|---|
4 | 4 |
import java.util.Arrays; |
5 | 5 |
import java.util.HashMap; |
6 | 6 |
import java.util.Iterator; |
7 |
import java.util.List; |
|
7 | 8 |
import java.util.Map; |
8 | 9 |
import java.util.Map.Entry; |
9 | 10 |
|
11 |
import org.gvsig.fmap.dal.DataTypes; |
|
10 | 12 |
import org.gvsig.fmap.dal.exception.DataException; |
11 | 13 |
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform; |
12 | 14 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
... | ... | |
18 | 20 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
19 | 21 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
20 | 22 |
import org.gvsig.fmap.dal.feature.FeatureType; |
23 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeatureQuery; |
|
24 |
import org.gvsig.tools.ToolsLocator; |
|
25 |
import org.gvsig.tools.dynobject.DynClass; |
|
26 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
21 | 27 |
import org.gvsig.tools.evaluator.Evaluator; |
22 | 28 |
import org.gvsig.tools.evaluator.EvaluatorData; |
23 | 29 |
import org.gvsig.tools.evaluator.EvaluatorException; |
... | ... | |
99 | 105 |
public void initialize(FeatureStore store1, FeatureStore store2, |
100 | 106 |
String keyAttr1, String keyAttr2, String prefix1, String prefix2, |
101 | 107 |
String[] attrs) |
102 |
throws DataException {
|
|
108 |
throws DataException { |
|
103 | 109 |
|
104 | 110 |
if (store1 == store2) { |
105 | 111 |
throw new IllegalArgumentException("store1 == store2"); |
... | ... | |
119 | 125 |
// feature type |
120 | 126 |
// FIXME for more than one FTypes ?? |
121 | 127 |
this.originalFeatureType = this.getFeatureStore() |
122 |
.getDefaultFeatureType();
|
|
128 |
.getDefaultFeatureType(); |
|
123 | 129 |
|
124 | 130 |
// TODO tener en cuenta prefix1 |
125 | 131 |
EditableFeatureType type = this.getFeatureStore().getDefaultFeatureType().getEditable(); |
... | ... | |
167 | 173 |
* @throws DataException |
168 | 174 |
*/ |
169 | 175 |
public void applyTransform(Feature source, EditableFeature target) |
170 |
throws DataException {
|
|
176 |
throws DataException { |
|
171 | 177 |
|
172 | 178 |
// copy the data from store1 into the resulting feature |
173 | 179 |
this.copySourceToTarget(source, target); |
... | ... | |
186 | 192 |
|
187 | 193 |
try { |
188 | 194 |
|
189 |
set = store2.getFeatureSet(query); |
|
190 |
// In this join implementation, we will take only the first matching |
|
191 |
// feature found in store2 |
|
195 |
set = store2.getFeatureSet(query);
|
|
196 |
// In this join implementation, we will take only the first matching
|
|
197 |
// feature found in store2
|
|
192 | 198 |
|
193 |
Feature feat; |
|
199 |
Feature feat;
|
|
194 | 200 |
|
195 | 201 |
|
196 |
itFeat = set.iterator(); |
|
197 |
if (itFeat.hasNext()) { |
|
198 |
feat = (Feature) itFeat.next(); |
|
202 |
itFeat = set.iterator();
|
|
203 |
if (itFeat.hasNext()) {
|
|
204 |
feat = (Feature) itFeat.next();
|
|
199 | 205 |
|
200 |
// copy all attributes from joined feature to target |
|
201 |
this.copyJoinToTarget(feat, target); |
|
202 |
} |
|
206 |
// copy all attributes from joined feature to target
|
|
207 |
this.copyJoinToTarget(feat, target);
|
|
208 |
}
|
|
203 | 209 |
} finally { |
204 | 210 |
if (itFeat != null) { |
205 | 211 |
itFeat.dispose(); |
... | ... | |
216 | 222 |
*/ |
217 | 223 |
private void copyJoinToTarget(Feature join, EditableFeature target) { |
218 | 224 |
Iterator iter = targetNamesMap.entrySet() |
219 |
.iterator();
|
|
225 |
.iterator(); |
|
220 | 226 |
Entry entry; |
221 | 227 |
FeatureType trgType = target.getType(); |
222 | 228 |
FeatureAttributeDescriptor attr; |
... | ... | |
313 | 319 |
return this.info; |
314 | 320 |
} |
315 | 321 |
|
316 |
} |
|
322 |
}
|
|
317 | 323 |
|
318 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
319 |
// TODO Auto-generated method stub |
|
320 |
|
|
321 |
} |
|
322 |
|
|
323 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
324 |
// TODO Auto-generated method stub |
|
325 |
|
|
326 |
} |
|
327 |
|
|
328 | 324 |
public FeatureType getSourceFeatureTypeFrom(FeatureType arg0) { |
329 | 325 |
EditableFeatureType orgType = originalFeatureType.getEditable(); |
330 | 326 |
Iterator iter = arg0.iterator(); |
... | ... | |
358 | 354 |
return false; |
359 | 355 |
} |
360 | 356 |
|
357 |
public static void registerPersistent() { |
|
358 |
DynObjectManager dynMan = ToolsLocator.getDynObjectManager(); |
|
359 |
|
|
360 |
DynClass dynClass = dynMan.add( |
|
361 |
"JoinTransform_Persistent", |
|
362 |
"JoinTransform Persistent definition"); |
|
363 |
|
|
364 |
dynClass.extend(ABSTRACT_FEATURESTORE_DYNCLASS_NAME); |
|
365 |
|
|
366 |
dynClass.addDynField("store2").setType(DataTypes.OBJECT); |
|
367 |
dynClass.addDynField("keyAttr1").setType(DataTypes.STRING); |
|
368 |
dynClass.addDynField("keyAttr2").setType(DataTypes.STRING); |
|
369 |
dynClass.addDynField("prefix1").setType(DataTypes.STRING); |
|
370 |
dynClass.addDynField("prefix2").setType(DataTypes.STRING); |
|
371 |
dynClass.addDynField("attrs").setType(DataTypes.LIST); |
|
372 |
|
|
373 |
ToolsLocator.getPersistenceManager().registerClass( |
|
374 |
JoinTransform.class, dynClass); |
|
375 |
} |
|
376 |
|
|
377 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
378 |
super.saveToState(state); |
|
379 |
state.set("store2", this.store2); |
|
380 |
state.set("keyAttr1", this.keyAttr1); |
|
381 |
state.set("keyAttr2", this.keyAttr2); |
|
382 |
state.set("prefix1", this.prefix1); |
|
383 |
state.set("prefix2", this.prefix2); |
|
384 |
state.set("attrs", Arrays.asList(this.attrs)); |
|
385 |
} |
|
386 |
|
|
387 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
388 |
super.loadFromState(state); |
|
389 |
FeatureStore store2 = (FeatureStore) state.get("store2"); |
|
390 |
String keyAttr1 = state.getString("keyAttr1"); |
|
391 |
String keyAttr2 = state.getString("keyAttr2"); |
|
392 |
String prefix1 = state.getString("prefix1"); |
|
393 |
String prefix2 = state.getString("prefix2"); |
|
394 |
List attrList = (List) state.get("attrs"); |
|
395 |
String[] attrs = null; |
|
396 |
if (attrList == null) { |
|
397 |
attrs = null; |
|
398 |
} else { |
|
399 |
attrs = (String[]) attrList |
|
400 |
.toArray(new String[attrList.size()]); |
|
401 |
} |
|
402 |
try { |
|
403 |
initialize(getFeatureStore(), store2, keyAttr1, keyAttr2, prefix1, prefix2, attrs); |
|
404 |
} catch (DataException e) { |
|
405 |
throw new PersistenceException("Impossible to create the transform", e); |
|
406 |
} |
|
407 |
} |
|
408 |
|
|
361 | 409 |
} |
Also available in: Unified diff