svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / featureset / FastEditedIterator.java @ 40435
History | View | Annotate | Download (3.85 KB)
1 | 40435 | jjdelcerro | /* 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 | package org.gvsig.fmap.dal.feature.impl.featureset; |
||
23 | |||
24 | import org.gvsig.fmap.dal.exception.DataException; |
||
25 | import org.gvsig.fmap.dal.feature.FeatureReference; |
||
26 | import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
||
27 | import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReference; |
||
28 | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
||
29 | import org.gvsig.tools.exception.BaseException; |
||
30 | |||
31 | /**
|
||
32 | * Iterator implementation which shares the returned Feature object instance.
|
||
33 | *
|
||
34 | * @author gvSIG Team
|
||
35 | * @version $Id$
|
||
36 | */
|
||
37 | public class FastEditedIterator extends EditedIterator { |
||
38 | |||
39 | DefaultFeature myFeature; |
||
40 | |||
41 | public FastEditedIterator(DefaultFeatureSet featureSet, long index) |
||
42 | throws DataException {
|
||
43 | super(featureSet);
|
||
44 | this.initializeFeature();
|
||
45 | if (index > 0) { |
||
46 | if (featureSet.provider.canIterateFromIndex()) {
|
||
47 | try {
|
||
48 | this.iterator = featureSet.provider.fastIterator(index);
|
||
49 | } catch (IllegalArgumentException e) { |
||
50 | this.iterator = featureSet.provider.fastIterator();
|
||
51 | setNewsFeatures(null);
|
||
52 | skypto(index); |
||
53 | } catch (UnsupportedOperationException e) { |
||
54 | this.iterator = featureSet.provider.fastIterator();
|
||
55 | setNewsFeatures(null);
|
||
56 | skypto(index); |
||
57 | } |
||
58 | } else {
|
||
59 | this.iterator = featureSet.provider.fastIterator();
|
||
60 | setNewsFeatures(null);
|
||
61 | skypto(index); |
||
62 | } |
||
63 | } else {
|
||
64 | this.iterator = featureSet.provider.fastIterator();
|
||
65 | setNewsFeatures(featureManager.getInserted()); |
||
66 | } |
||
67 | |||
68 | } |
||
69 | |||
70 | protected void initializeFeature() { |
||
71 | myFeature = new DefaultFeature(fset.store);
|
||
72 | } |
||
73 | |||
74 | protected DefaultFeature createFeature(FeatureProvider data) throws DataException { |
||
75 | |||
76 | DefaultFeature f = null;
|
||
77 | try {
|
||
78 | data.setNew(isFeatureIsNew()); |
||
79 | FeatureReference ref = |
||
80 | new DefaultFeatureReference(fset.store, data);
|
||
81 | f = |
||
82 | (DefaultFeature) featureManager.get(ref, fset.store, |
||
83 | data.getType()); |
||
84 | } catch (DataException e) {
|
||
85 | RuntimeException ex = new RuntimeException(); |
||
86 | e.initCause(e); |
||
87 | throw ex;
|
||
88 | } |
||
89 | if (f == null) { |
||
90 | this.myFeature.setData(data);
|
||
91 | } else {
|
||
92 | // TODO Sacamos una copia del data o no???
|
||
93 | this.myFeature.setData(f.getData().getCopy());
|
||
94 | } |
||
95 | if (this.fset.transform.isEmpty()) { |
||
96 | return myFeature;
|
||
97 | } else {
|
||
98 | return (DefaultFeature) this.fset.transform.applyTransform( |
||
99 | myFeature, fset.getDefaultFeatureType()); |
||
100 | } |
||
101 | |||
102 | } |
||
103 | |||
104 | public void remove() { |
||
105 | super.remove();
|
||
106 | this.initializeFeature();
|
||
107 | } |
||
108 | |||
109 | protected void doDispose() throws BaseException { |
||
110 | super.doDispose();
|
||
111 | myFeature = null;
|
||
112 | } |
||
113 | |||
114 | } |