Revision 24143
branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/impl/FeatureTypeManager.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
|
|
42 |
package org.gvsig.fmap.data.feature.impl; |
|
43 |
|
|
44 |
import java.util.ArrayList; |
|
45 |
import java.util.HashMap; |
|
46 |
import java.util.Iterator; |
|
47 |
|
|
48 |
import org.gvsig.fmap.data.exceptions.DataException; |
|
49 |
import org.gvsig.fmap.data.feature.EditableFeature; |
|
50 |
import org.gvsig.fmap.data.feature.Feature; |
|
51 |
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor; |
|
52 |
import org.gvsig.fmap.data.feature.FeatureReference; |
|
53 |
import org.gvsig.fmap.data.feature.FeatureStore; |
|
54 |
import org.gvsig.fmap.data.feature.FeatureType; |
|
55 |
import org.gvsig.fmap.data.feature.impl.expansionadapter.ExpansionAdapter; |
|
56 |
|
|
57 |
|
|
58 |
/** |
|
59 |
* DOCUMENT ME! |
|
60 |
* |
|
61 |
* @author Vicente Caballero Navarro |
|
62 |
*/ |
|
63 |
public class FeatureTypeManager { |
|
64 |
private ExpansionAdapter expansionAdapter; |
|
65 |
private ArrayList deleted = new ArrayList();//<FeatureID> |
|
66 |
private int deltaSize=0; |
|
67 |
private HashMap added=new HashMap(); |
|
68 |
private HashMap modifiedFromOriginal=new HashMap(); |
|
69 |
public FeatureTypeManager(ExpansionAdapter expansionAdapter){ |
|
70 |
this.expansionAdapter=expansionAdapter; |
|
71 |
} |
|
72 |
|
|
73 |
|
|
74 |
public FeatureType delete(String id) { |
|
75 |
deleted.add(id); |
|
76 |
FeatureType type=(FeatureType)added.remove(id); |
|
77 |
if (type==null) |
|
78 |
type=(FeatureType)modifiedFromOriginal.remove(id); |
|
79 |
deltaSize--; |
|
80 |
return type; |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* DOCUMENT ME! |
|
85 |
* |
|
86 |
* @param feature DOCUMENT ME! |
|
87 |
*/ |
|
88 |
public void add(FeatureType type) { |
|
89 |
int pos = expansionAdapter.addObject(type); |
|
90 |
added.put(type.getId(),new Integer(pos)); |
|
91 |
deltaSize++; |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* DOCUMENT ME! |
|
96 |
* |
|
97 |
* @param id DOCUMENT ME! |
|
98 |
*/ |
|
99 |
public void deleteLastFeature() { |
|
100 |
expansionAdapter.deleteLastObject(); |
|
101 |
FeatureType type=(FeatureType)expansionAdapter.getObject(expansionAdapter.getSize()-1); |
|
102 |
added.remove(type.getId()); |
|
103 |
modifiedFromOriginal.remove(type.getId()); |
|
104 |
deltaSize--; |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* DOCUMENT ME! |
|
109 |
* |
|
110 |
* @param id DOCUMENT ME! |
|
111 |
* |
|
112 |
* @return DOCUMENT ME! |
|
113 |
* @throws IsNotFeatureSettingException |
|
114 |
*/ |
|
115 |
public FeatureType getType(String id) throws DataException { |
|
116 |
Integer intNum =((Integer) added.get(id)); |
|
117 |
if (intNum == null){ |
|
118 |
intNum =((Integer) modifiedFromOriginal.get(id)); |
|
119 |
if (intNum == null){ |
|
120 |
return null; |
|
121 |
} |
|
122 |
} |
|
123 |
int num = intNum.intValue(); |
|
124 |
|
|
125 |
FeatureType type=(FeatureType)expansionAdapter.getObject(num); |
|
126 |
return type; |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* DOCUMENT ME! |
|
131 |
* |
|
132 |
* @param feature DOCUMENT ME! |
|
133 |
* @param oldFeature DOCUMENT ME! |
|
134 |
*/ |
|
135 |
public int update(FeatureType type, FeatureType oldType) { |
|
136 |
// deleted.add(oldType.getId()); |
|
137 |
int oldNum=-1; |
|
138 |
int num = expansionAdapter.addObject(type); |
|
139 |
String id=type.getId(); |
|
140 |
|
|
141 |
if (added.containsKey(id)){ |
|
142 |
oldNum=((Integer)added.get(id)).intValue(); |
|
143 |
added.put(id,new Integer(num)); |
|
144 |
}else{ |
|
145 |
oldNum=((Integer)modifiedFromOriginal.get(id)).intValue(); |
|
146 |
modifiedFromOriginal.put(id,new Integer(num)); |
|
147 |
} |
|
148 |
return oldNum; |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* DOCUMENT ME! |
|
153 |
* |
|
154 |
* @param id DOCUMENT ME! |
|
155 |
*/ |
|
156 |
public void restore(String id) { |
|
157 |
deleted.remove(id); |
|
158 |
deltaSize++; |
|
159 |
} |
|
160 |
public void restore(String id,int num){ |
|
161 |
if (added.containsKey(id)){ |
|
162 |
added.put(id,new Integer(num)); |
|
163 |
}else{ |
|
164 |
modifiedFromOriginal.put(id,new Integer(num)); |
|
165 |
} |
|
166 |
} |
|
167 |
|
|
168 |
public boolean isDeleted(FeatureType type){ |
|
169 |
return deleted.contains(type.getId()); |
|
170 |
} |
|
171 |
|
|
172 |
public boolean isDeleted(String id) { |
|
173 |
return deleted.contains(id); |
|
174 |
} |
|
175 |
|
|
176 |
public void clear() { |
|
177 |
added.clear(); |
|
178 |
modifiedFromOriginal.clear(); |
|
179 |
expansionAdapter.close(); |
|
180 |
deleted.clear();//<FeatureID> |
|
181 |
deltaSize=0; |
|
182 |
} |
|
183 |
|
|
184 |
|
|
185 |
public boolean hasChanges() { |
|
186 |
return added.size()>0 || modifiedFromOriginal.size() > 0 || deleted.size() > 0; |
|
187 |
} |
|
188 |
|
|
189 |
public Iterator newsIterator() { |
|
190 |
return added.values().iterator(); |
|
191 |
} |
|
192 |
|
|
193 |
|
|
194 |
public boolean hasNews() { |
|
195 |
return !added.isEmpty(); |
|
196 |
} |
|
197 |
|
|
198 |
public long getDeltaSize() { |
|
199 |
return deltaSize; |
|
200 |
} |
|
201 |
} |
|
202 |
|
Also available in: Unified diff