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