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 @ 40559
History | View | Annotate | Download (3.9 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40559 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40559 | jjdelcerro | *
|
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.fmap.dal.feature.impl.featureset; |
||
25 | |||
26 | import org.gvsig.fmap.dal.exception.DataException; |
||
27 | import org.gvsig.fmap.dal.feature.FeatureReference; |
||
28 | import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
||
29 | import org.gvsig.fmap.dal.feature.impl.DefaultFeatureReference; |
||
30 | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
||
31 | import org.gvsig.tools.exception.BaseException; |
||
32 | |||
33 | /**
|
||
34 | * Iterator implementation which shares the returned Feature object instance.
|
||
35 | *
|
||
36 | * @author gvSIG Team
|
||
37 | * @version $Id$
|
||
38 | */
|
||
39 | public class FastEditedIterator extends EditedIterator { |
||
40 | |||
41 | DefaultFeature myFeature; |
||
42 | |||
43 | public FastEditedIterator(DefaultFeatureSet featureSet, long index) |
||
44 | throws DataException {
|
||
45 | super(featureSet);
|
||
46 | this.initializeFeature();
|
||
47 | if (index > 0) { |
||
48 | if (featureSet.provider.canIterateFromIndex()) {
|
||
49 | try {
|
||
50 | this.iterator = featureSet.provider.fastIterator(index);
|
||
51 | } catch (IllegalArgumentException e) { |
||
52 | this.iterator = featureSet.provider.fastIterator();
|
||
53 | setNewsFeatures(null);
|
||
54 | skypto(index); |
||
55 | } catch (UnsupportedOperationException e) { |
||
56 | this.iterator = featureSet.provider.fastIterator();
|
||
57 | setNewsFeatures(null);
|
||
58 | skypto(index); |
||
59 | } |
||
60 | } else {
|
||
61 | this.iterator = featureSet.provider.fastIterator();
|
||
62 | setNewsFeatures(null);
|
||
63 | skypto(index); |
||
64 | } |
||
65 | } else {
|
||
66 | this.iterator = featureSet.provider.fastIterator();
|
||
67 | setNewsFeatures(featureManager.getInserted()); |
||
68 | } |
||
69 | |||
70 | } |
||
71 | |||
72 | protected void initializeFeature() { |
||
73 | myFeature = new DefaultFeature(fset.store);
|
||
74 | } |
||
75 | |||
76 | protected DefaultFeature createFeature(FeatureProvider data) throws DataException { |
||
77 | |||
78 | DefaultFeature f = null;
|
||
79 | try {
|
||
80 | data.setNew(isFeatureIsNew()); |
||
81 | FeatureReference ref = |
||
82 | new DefaultFeatureReference(fset.store, data);
|
||
83 | f = |
||
84 | (DefaultFeature) featureManager.get(ref, fset.store, |
||
85 | data.getType()); |
||
86 | } catch (DataException e) {
|
||
87 | RuntimeException ex = new RuntimeException(); |
||
88 | e.initCause(e); |
||
89 | throw ex;
|
||
90 | } |
||
91 | if (f == null) { |
||
92 | this.myFeature.setData(data);
|
||
93 | } else {
|
||
94 | // TODO Sacamos una copia del data o no???
|
||
95 | this.myFeature.setData(f.getData().getCopy());
|
||
96 | } |
||
97 | if (this.fset.transform.isEmpty()) { |
||
98 | return myFeature;
|
||
99 | } else {
|
||
100 | return (DefaultFeature) this.fset.transform.applyTransform( |
||
101 | myFeature, fset.getDefaultFeatureType()); |
||
102 | } |
||
103 | |||
104 | } |
||
105 | |||
106 | public void remove() { |
||
107 | super.remove();
|
||
108 | this.initializeFeature();
|
||
109 | } |
||
110 | |||
111 | protected void doDispose() throws BaseException { |
||
112 | super.doDispose();
|
||
113 | myFeature = null;
|
||
114 | } |
||
115 | |||
116 | } |