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 @ 45989
History | View | Annotate | Download (4.51 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 | 41183 | jldominguez | import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
28 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
29 | import org.gvsig.fmap.dal.feature.impl.DefaultEditableFeature; |
||
30 | 40435 | jjdelcerro | import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
31 | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
||
32 | import org.gvsig.tools.exception.BaseException; |
||
33 | |||
34 | /**
|
||
35 | * Iterator implementation which shares the returned Feature object instance.
|
||
36 | *
|
||
37 | * @author gvSIG Team
|
||
38 | * @version $Id$
|
||
39 | */
|
||
40 | public class FastEditedIterator extends EditedIterator { |
||
41 | |||
42 | 45738 | fdiaz | private DefaultFeature myFeature;
|
43 | 40435 | jjdelcerro | |
44 | 45989 | fdiaz | public FastEditedIterator(DefaultFeatureSet featureSet, long index, long elements) |
45 | 40435 | jjdelcerro | throws DataException {
|
46 | 45989 | fdiaz | super(featureSet, index, elements);
|
47 | 40435 | jjdelcerro | } |
48 | |||
49 | 45522 | fdiaz | @Override
|
50 | 40435 | jjdelcerro | protected DefaultFeature createFeature(FeatureProvider data) throws DataException { |
51 | 45738 | fdiaz | if(myFeature == null){ |
52 | myFeature = new DefaultFeature(fset.store);
|
||
53 | } |
||
54 | 40435 | jjdelcerro | |
55 | 45647 | fdiaz | DefaultFeature f = this.featureManager.get(data);
|
56 | // DefaultFeature f = null;
|
||
57 | // try {
|
||
58 | // FeatureReference ref = new DefaultFeatureReference(fset.store, data);
|
||
59 | // f = (DefaultFeature) featureManager.get(ref, fset.store);
|
||
60 | // } catch (DataException e) {
|
||
61 | // RuntimeException ex = new RuntimeException();
|
||
62 | // e.initCause(e);
|
||
63 | // throw ex;
|
||
64 | // }
|
||
65 | 40435 | jjdelcerro | if (f == null) { |
66 | this.myFeature.setData(data);
|
||
67 | } else {
|
||
68 | // TODO Sacamos una copia del data o no???
|
||
69 | this.myFeature.setData(f.getData().getCopy());
|
||
70 | } |
||
71 | if (this.fset.transform.isEmpty()) { |
||
72 | return myFeature;
|
||
73 | } else {
|
||
74 | 41183 | jldominguez | |
75 | if (f == null) { |
||
76 | myFeature = (DefaultFeature) |
||
77 | this.fset.transform.applyTransform(myFeature,
|
||
78 | fset.getDefaultFeatureType()); |
||
79 | } else {
|
||
80 | /*
|
||
81 | * In this case "f != null" the data comes from the featureManager,
|
||
82 | * so it is data inserted/updated by the user, so we must
|
||
83 | * overwrite the data after applying the transformations
|
||
84 | * because the transformations can be "Adding field"
|
||
85 | * and are necessary in some cases:
|
||
86 | */
|
||
87 | DefaultFeature saved_feat = (DefaultFeature) myFeature.getCopy(); |
||
88 | myFeature = (DefaultFeature) |
||
89 | this.fset.transform.applyTransform(myFeature,
|
||
90 | fset.getDefaultFeatureType()); |
||
91 | myFeature = overwrite(myFeature, saved_feat); |
||
92 | } |
||
93 | return myFeature;
|
||
94 | 40435 | jjdelcerro | } |
95 | |||
96 | } |
||
97 | |||
98 | 41183 | jldominguez | private DefaultFeature overwrite(
|
99 | DefaultFeature old_feat, |
||
100 | DefaultFeature new_feat) { |
||
101 | |||
102 | DefaultEditableFeature resp = (DefaultEditableFeature) old_feat.getEditable(); |
||
103 | |||
104 | FeatureType fty = new_feat.getData().getType(); |
||
105 | FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
|
||
106 | for (int i=0; i<atts.length; i++) { |
||
107 | try {
|
||
108 | resp.set(atts[i].getName(), new_feat.get(atts[i].getName())); |
||
109 | } catch (Exception exc) { |
||
110 | // Field not found
|
||
111 | } |
||
112 | } |
||
113 | return (DefaultFeature) resp.getNotEditableCopy();
|
||
114 | } |
||
115 | |||
116 | 45522 | fdiaz | @Override
|
117 | 40435 | jjdelcerro | public void remove() { |
118 | super.remove();
|
||
119 | 45522 | fdiaz | myFeature = new DefaultFeature(fset.store);
|
120 | 40435 | jjdelcerro | } |
121 | |||
122 | 45522 | fdiaz | @Override
|
123 | 40435 | jjdelcerro | protected void doDispose() throws BaseException { |
124 | super.doDispose();
|
||
125 | myFeature = null;
|
||
126 | } |
||
127 | |||
128 | } |