Revision 25751

View differences:

branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/spi/DefaultLongList.java
49 49
	}
50 50

  
51 51
	public Iterator iterator() {
52
		return new LongIterator(list.iterator());
52
		return list.iterator();
53 53
	}
54 54

  
55 55
	public Iterator iterator(long index) {
......
58 58
		}		
59 59
		return list.listIterator((int) index);
60 60
	}
61
	class LongIterator implements Iterator{
62
		private Iterator iterator;
63
		public LongIterator(Iterator iterator) {
64
			this.iterator=iterator;
65
		}
66
		public boolean hasNext() {
67
			return iterator.hasNext();
68
		}
69

  
70
		public Object next() {
71
			Object obj=iterator.next();
72
			if (obj instanceof Integer){
73
				return new Long(((Integer)obj).longValue());
74
			}
75
			return obj;
76
		}
77

  
78
		public void remove() {
79
			iterator.remove();
80
		}
81

  
82
	}
83

  
84 61
}
85 62

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/spi/index/AbstractFeatureIndexProvider.java
2 2
*
3 3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4 4
* of the Valencian Government (CIT)
5
* 
5
*
6 6
* This program is free software; you can redistribute it and/or
7 7
* modify it under the terms of the GNU General Public License
8 8
* as published by the Free Software Foundation; either version 2
9 9
* of the License, or (at your option) any later version.
10
* 
10
*
11 11
* This program is distributed in the hope that it will be useful,
12 12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
* GNU General Public License for more details.
15
* 
15
*
16 16
* You should have received a copy of the GNU General Public License
17 17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19
* MA  02110-1301, USA.
20
* 
20
*
21 21
*/
22 22

  
23 23
/*
24 24
* AUTHORS (In addition to CIT):
25 25
* 2008 {{Company}}   {{Task}}
26 26
*/
27
 
28 27

  
28

  
29 29
package org.gvsig.fmap.dal.feature.spi.index;
30 30

  
31
import java.util.ArrayList;
32
import java.util.Collection;
33
import java.util.Iterator;
34
import java.util.List;
35
import java.util.ListIterator;
36

  
31 37
import org.gvsig.fmap.dal.exception.InitializeException;
32 38

  
33 39

  
34 40
public abstract class AbstractFeatureIndexProvider implements FeatureIndexProvider {
35 41

  
36 42
	private FeatureIndexProviderServices services = null;
37
	
43

  
38 44
	public void initialize() throws InitializeException {
39 45
	}
40 46

  
......
42 48
			FeatureIndexProviderServices services) {
43 49
		this.services = services;
44 50
	}
45
	
51

  
46 52
	public FeatureIndexProviderServices getFeatureIndexProviderServices() {
47 53
		return services;
48 54
	}
55

  
56
	protected class LongList implements java.util.List{
57
		private ArrayList list;
58
		public LongList(java.util.List list) {
59
			this.list=(ArrayList)list;
60
		}
61
		public void add(int arg0, Object arg1) {
62
			list.add(arg0, arg1);
63
		}
64

  
65
		public boolean add(Object arg0) {
66
			return list.add(arg0);
67
		}
68

  
69
		public Object set(int arg0, Object arg1) {
70
			return list.set(arg0, arg1);
71
		}
72
		public boolean addAll(Collection arg0) {
73
			return list.addAll(arg0);
74
		}
75
		public boolean addAll(int arg0, Collection arg1) {
76
			return list.addAll(arg0, arg1);
77
		}
78
		public void clear() {
79
			list.clear();
80
		}
81
		public boolean contains(Object o) {
82
			return list.contains(o);
83
		}
84
		public boolean containsAll(Collection arg0) {
85
			return list.containsAll(arg0);
86
		}
87
		public Object get(int index) {
88
			Object obj=list.get(index);
89
			if (obj instanceof Integer){
90
				return new Long(((Integer)obj).longValue());
91
			}
92
			return obj;
93
		}
94
		public int indexOf(Object o) {
95
			return list.indexOf(o);
96
		}
97
		public boolean isEmpty() {
98
			return list.isEmpty();
99
		}
100
		public Iterator iterator() {
101
			return new LongIterator(list.iterator());
102
		}
103
		public int lastIndexOf(Object o) {
104
			return list.lastIndexOf(o);
105
		}
106
		public ListIterator listIterator() {
107
			return list.listIterator();
108
		}
109
		public ListIterator listIterator(int index) {
110
			return list.listIterator(index);
111
		}
112
		public boolean remove(Object o) {
113
			return list.remove(o);
114
		}
115
		public Object remove(int index) {
116
			return list.remove(index);
117
		}
118
		public boolean removeAll(Collection arg0) {
119
			return list.removeAll(arg0);
120
		}
121
		public boolean retainAll(Collection arg0) {
122
			return list.retainAll(arg0);
123
		}
124
		public int size() {
125
			return list.size();
126
		}
127
		public List subList(int fromIndex, int toIndex) {
128
			return list.subList(fromIndex, toIndex);
129
		}
130
		public Object[] toArray() {
131
			return list.toArray();
132
		}
133
		public Object[] toArray(Object[] arg0) {
134
			return list.toArray(arg0);
135
		}
136
		class LongIterator implements Iterator{
137
			private Iterator iterator;
138
			public LongIterator(Iterator it) {
139
				iterator=it;
140
			}
141
			public boolean hasNext() {
142
				return iterator.hasNext();
143
			}
144

  
145
			public Object next() {
146
				Object obj=iterator.next();
147
				if (obj instanceof Integer){
148
					return new Long(((Integer)obj).longValue());
149
				}
150
				return obj;
151
			}
152

  
153
			public void remove() {
154
				iterator.remove();
155
			}
156
		}
157
	}
49 158
}
50 159

  
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/DefaultFeatureStore.java
872 872
			throw new NotYetImplemented(
873 873
					"export whith more than one type not yet implemented");
874 874
		}
875
		FeatureSelection featureSelection=(FeatureSelection)getSelection();
875 876
		try {
876 877
			FeatureType type = this.getDefaultFeatureType();
877 878
			if (params.getDefaultFeatureType() == null) {
......
883 884
			FeatureStore target = (FeatureStore) manager
884 885
					.createStore(params);
885 886
			target.edit(MODE_APPEND);
886

  
887
			FeatureSet features = this.getFeatureSet();
887
			FeatureSet features=null;
888
			if (featureSelection.getSize()>0){
889
				features = this.getFeatureSelection();
890
			}else{
891
				features = this.getFeatureSet();
892
			}
888 893
			Iterator it1 = features.iterator();
889 894
			while (it1.hasNext()) {
890 895
				Feature feature = (Feature) it1.next();
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/join/JoinTransform.java
1
package org.gvsig.fmap.dal.feature.impl.join;
2

  
3
import java.util.HashMap;
4
import java.util.Iterator;
5
import java.util.Map;
6

  
7
import org.gvsig.fmap.dal.DALLocator;
8
import org.gvsig.fmap.dal.exception.DataException;
9
import org.gvsig.fmap.dal.feature.AbstractFeatureStoreTransform;
10
import org.gvsig.fmap.dal.feature.EditableFeature;
11
import org.gvsig.fmap.dal.feature.EditableFeatureType;
12
import org.gvsig.fmap.dal.feature.Feature;
13
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
14
import org.gvsig.fmap.dal.feature.FeatureQuery;
15
import org.gvsig.fmap.dal.feature.FeatureSet;
16
import org.gvsig.fmap.dal.feature.FeatureStore;
17
import org.gvsig.tools.evaluator.Evaluator;
18
import org.gvsig.tools.persistence.PersistenceException;
19
import org.gvsig.tools.persistence.PersistentState;
20

  
21
public class JoinTransform extends AbstractFeatureStoreTransform {
22

  
23
	/**
24
	 * Store from which the join transform will get the additional attributes
25
	 */
26
	private FeatureStore store2;
27

  
28
	/**
29
	 * name of the key attr in store1 that will be used to match features in
30
	 * store2
31
	 */
32
	private String keyAttr1;
33

  
34
	/**
35
	 * name of the key attr in store2 that will be used to match features in
36
	 * store1
37
	 */
38
	private String keyAttr2;
39

  
40
	/**
41
	 * names of the attributes to join from store2 to store1
42
	 */
43
	private String[] attrs;
44

  
45
	/**
46
	 * Attribute names may change after transformation if they are repeated in
47
	 * both stores. This map keeps correspondence between store2 original names
48
	 * and their transformed counterparts.
49
	 */
50
	private Map targetNamesMap;
51

  
52
	/**
53
	 * A default constructor
54
	 */
55
	public JoinTransform() {
56
		targetNamesMap = new HashMap();
57
	}
58

  
59
	/**
60
	 * Initializes all the necessary data for this transform
61
	 * 
62
	 * @param store1
63
	 *            store whose default feature type is the target of this
64
	 *            transform
65
	 * 
66
	 * @param store2
67
	 *            store whose default feature type will provide the new
68
	 *            attributes to join
69
	 * 
70
	 * @param keyAttr1
71
	 *            key attribute in store1 that matches keyAttr2 in store2
72
	 *            (foreign key), used for joining both stores.
73
	 * 
74
	 * @param keyAttr2
75
	 *            key attribute in store2 that matches keyAttr1 in store2
76
	 *            (foreign key), used for joining both stores.
77
	 * 
78
	 * @param attrs
79
	 *            names of the attributes in store2 that will be joined to
80
	 *            store1.
81
	 */
82
	public void initialize(FeatureStore store1, FeatureStore store2,
83
			String keyAttr1, String keyAttr2, String[] attrs)
84
			throws DataException {
85

  
86
		// Initialize needed data
87
		this.setFeatureStore(store1);
88
		this.store2 = store2;
89
		this.keyAttr1 = keyAttr1;
90
		this.keyAttr2 = keyAttr2;
91
		this.attrs = attrs;
92

  
93
		// calculate this transform resulting feature type
94
		// by adding all specified attrs from store2 to store1's default
95
		// feature type
96
		EditableFeatureType type = this.getFeatureStore().getDefaultFeatureType().getEditable();
97

  
98
		for (int i = 0; i < attrs.length; i++) {
99
			String name = attrs[i];
100

  
101
			// If an attribute already exists with the same name in store1's
102
			// default feature type,
103
			// calculate an alternate name and add it to our type
104
			int j = 0;
105
			while (type.get(name) != null) {
106
				name = attrs[i] + "_" + ++j;
107
			}
108
			type.add(name, store2.getDefaultFeatureType()
109
					.getAttributeDescriptor(attrs[i]).getDataType());
110

  
111
			// keep correspondence between original name and transformed name
112
			this.targetNamesMap.put(attrs[i], name);
113
		}
114

  
115
		// assign calculated feature type as this transform's feature type
116
		setDefaultFeatureType(type.getNotEditableCopy());
117
	}
118

  
119
	/**
120
	 * 
121
	 * 
122
	 * @param source
123
	 * 
124
	 * @param target
125
	 * 
126
	 * @throws DataException
127
	 */
128
	public void applyTransform(Feature source, EditableFeature target)
129
			throws DataException {
130

  
131
		// copy the data from store1 into the resulting feature
132
		target.copyFrom(source);
133

  
134
		// ask store2 for the specified attributes, filtering by the key
135
		// attribute value
136
		// from the source feature
137
		Evaluator eval = DALLocator.getDataManager().createExpresion(
138
				keyAttr2 + "=" + source.get(keyAttr1));
139
		FeatureQuery query = new FeatureQuery(attrs, eval);
140
		FeatureSet set = store2.getFeatureSet(query);
141

  
142
		// In this join implementation, we will take only the first matching
143
		// feature found in store2
144
		Iterator it = set.iterator();
145
		if (it.hasNext()) {
146
			Feature feat = (Feature) it.next();
147

  
148
			// copy all attributes from joined feature to target
149
			Iterator it2 = feat.getType().iterator();
150
			while (it2.hasNext()) {
151
				FeatureAttributeDescriptor attr = (FeatureAttributeDescriptor) it2
152
						.next();
153
				// find original attribute name
154
				String targetName = (String) this.targetNamesMap.get(attr
155
						.getName());
156
				// copy its value to target feature attribute
157
				target.set(targetName, feat.get(attr.getName()));
158
			}
159
		}
160
		set.dispose();
161
	}
162

  
163
	public void loadState(PersistentState state) throws PersistenceException {
164
		// TODO Auto-generated method stub
165

  
166
	}
167

  
168
	public void setState(PersistentState state) throws PersistenceException {
169
		// TODO Auto-generated method stub
170

  
171
	}
172

  
173
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/FeatureManager.java
54 54
import org.gvsig.fmap.dal.feature.FeatureStore;
55 55
import org.gvsig.fmap.dal.feature.FeatureType;
56 56
import org.gvsig.fmap.dal.feature.impl.expansionadapter.ExpansionAdapter;
57
import org.gvsig.fmap.dal.feature.spi.FeatureData;
58 57
import org.gvsig.fmap.geom.Geometry;
59 58

  
60 59

  
......
90 89
     * @param feature DOCUMENT ME!
91 90
     */
92 91
    public void add(Feature feature) {
93
        int pos = expansionAdapter.addObject(((DefaultFeature)feature).getData());
92
        int pos = expansionAdapter.addObject(feature);
94 93
        added.put(feature.getReference(),new Integer(pos));
95 94
        deltaSize++;
96 95
    }
......
155 154
    	}
156 155
        int num = intNum.intValue();
157 156

  
158
        FeatureData featureData=(FeatureData)expansionAdapter.getObject(num);
157
        Feature feature=(Feature)expansionAdapter.getObject(num);
159 158
        if (featureType== null){
160 159
        	featureType = store.getDefaultFeatureType();
161 160
        }
162
       	return getCorrectFeature(featureData, store,featureType);
161
       	return getCorrectFeature(feature, store,featureType);
163 162
    }
164 163

  
165
    private Feature getCorrectFeature(FeatureData featureData, FeatureStore store,
164
    private Feature getCorrectFeature(Feature feature, FeatureStore store,
166 165
			FeatureType featureType) throws DataException {
167 166
    	 Iterator iterator=featureType.iterator();
168
         EditableFeature newFeature=store.createNewFeature(featureType, false);
169
         FeatureType orgType = featureData.getType();
167
         EditableFeature newFeature=feature.getEditable();//store.createNewFeature(featureType, false);
168
         FeatureType orgType = feature.getType();
170 169
         int orgIndex;
171 170
         while (iterator.hasNext()) {
172 171
 			FeatureAttributeDescriptor fad = (FeatureAttributeDescriptor) iterator.next();
......
176 175
 			}
177 176
 			if (featureType.getDefaultGeometryAttributeName().equals(
178 177
									fad.getName())){
179
 				newFeature.setGeometry(fad.getIndex(), (Geometry)featureData.get(orgIndex));
178
 				newFeature.setGeometry(fad.getIndex(), (Geometry)feature.get(orgIndex));
180 179
 			} else{
181
 				newFeature.set(fad.getIndex(), featureData.get(orgIndex));
180
 				newFeature.set(fad.getIndex(), feature.get(orgIndex));
182 181
 			}
183 182
 		}
184 183
         return newFeature.getNotEditableCopy();
......
267 266
		hasnext=true;
268 267
		if (size > pos){
269 268
			pos++;
270
			if (deleted.contains(expansionAdapter.getObject(pos))){
269
			DefaultFeature obj=(DefaultFeature)expansionAdapter.getObject(pos);
270
			if (deleted.contains(obj.getReference())){
271 271
				return true;
272 272
			}else{
273 273
				return hasNext();
......
283 283
			hasnext=false;
284 284
		}
285 285
		if (size > pos){
286
			if (deleted.contains(expansionAdapter.getObject(pos))){
287
				Object obj=expansionAdapter.getObject(pos);
288
				return obj;
286
			DefaultFeature obj=(DefaultFeature)expansionAdapter.getObject(pos);
287
			if (deleted.contains(obj.getReference())){
288

  
289
				return obj.getData();
289 290
			}else{
290 291
				if (hasNext()){
291 292
					return next();
......
312 313
			hasnext=true;
313 314
			pos++;
314 315
			if (size > pos){
315
				if (deleted.contains(expansionAdapter.getObject(pos))){
316
				DefaultFeature obj=(DefaultFeature)expansionAdapter.getObject(pos);
317
				if (deleted.contains(obj.getReference())){
316 318
					return hasNext();
317 319
				}else if (!added.containsValue(new Integer(pos))){
318 320
					return hasNext();
......
329 331
				hasnext=false;
330 332
			}
331 333
			if (size > pos){
332
				if (deleted.contains(expansionAdapter.getObject(pos))){
334
				DefaultFeature obj=(DefaultFeature)expansionAdapter.getObject(pos);
335
				if (deleted.contains(obj.getReference())){
333 336
					if (hasNext()){
334 337
						return next();
335 338
					}
......
338 341
						return next();
339 342
					}
340 343
				}else {
341
					Object obj=expansionAdapter.getObject(pos);
342
					return obj;
344
					return obj.getData();
343 345
				}
344 346
			}
345 347
			return null;
......
362 364
			hasnext=true;
363 365
			if (size > pos){
364 366
				pos++;
365
				if (deleted.contains(expansionAdapter.getObject(pos))){
367
				DefaultFeature obj=(DefaultFeature)expansionAdapter.getObject(pos);
368
				if (deleted.contains(obj.getReference())){
366 369
					return hasNext();
367 370
				}else if (!modifiedFromOriginal.containsValue(new Integer(pos))){
368 371
					return hasNext();
......
379 382
				hasnext=false;
380 383
			}
381 384
			if (size > pos){
382
				if (deleted.contains(expansionAdapter.getObject(pos))){
385
				DefaultFeature obj=(DefaultFeature)expansionAdapter.getObject(pos);
386
				if (deleted.contains(obj.getReference())){
383 387
					if (hasNext()){
384 388
						return next();
385 389
					}
......
388 392
						return next();
389 393
					}
390 394
				}else {
391
					Object obj=expansionAdapter.getObject(pos);
392
					return obj;
395
					return obj.getData();
393 396
				}
394 397
			}
395 398
			return null;
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/featureset/FilteredIterator.java
5 5

  
6 6
import org.gvsig.fmap.dal.exception.DataEvaluatorException;
7 7
import org.gvsig.fmap.dal.exception.DataException;
8
import org.gvsig.fmap.dal.feature.Feature;
8 9
import org.gvsig.fmap.dal.feature.impl.DefaultFeature;
9 10
import org.gvsig.fmap.dal.feature.spi.FeatureData;
10 11
import org.gvsig.tools.evaluator.Evaluator;
......
48 49
		DefaultFeature feature;
49 50
		FeatureData data;
50 51
		while (this.getIterator().hasNext()) {
51
			data = (FeatureData) this.getIterator().next();
52
			data = (FeatureData)this.getIterator().next();
52 53
			if (isDeleted(data)) {
53 54
				continue;
54 55
			}
......
82 83

  
83 84
	public boolean match(DefaultFeature feature) throws DataException {
84 85
		try {
86
			if (filter==null)
87
				return true;
85 88
			return ((Boolean) this.filter.evaluate(feature)).booleanValue();
86 89
		} catch (EvaluatorException e) {
87 90
			throw new DataEvaluatorException(e);

Also available in: Unified diff