root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / FeatureTypeManager.java @ 24496
History | View | Annotate | Download (5.11 KB)
1 | 24143 | vcaballero | /* 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 | 24496 | jmvivo | package org.gvsig.fmap.dal.feature.impl; |
43 | 24143 | vcaballero | |
44 | import java.util.ArrayList; |
||
45 | import java.util.HashMap; |
||
46 | import java.util.Iterator; |
||
47 | |||
48 | 24496 | jmvivo | import org.gvsig.fmap.dal.exceptions.DataException; |
49 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
50 | import org.gvsig.fmap.dal.feature.impl.expansionadapter.ExpansionAdapter; |
||
51 | 24143 | vcaballero | |
52 | |||
53 | /**
|
||
54 | * DOCUMENT ME!
|
||
55 | *
|
||
56 | * @author Vicente Caballero Navarro
|
||
57 | */
|
||
58 | public class FeatureTypeManager { |
||
59 | private ExpansionAdapter expansionAdapter;
|
||
60 | private ArrayList deleted = new ArrayList();//<FeatureID> |
||
61 | private int deltaSize=0; |
||
62 | private HashMap added=new HashMap(); |
||
63 | private HashMap modifiedFromOriginal=new HashMap(); |
||
64 | public FeatureTypeManager(ExpansionAdapter expansionAdapter){
|
||
65 | this.expansionAdapter=expansionAdapter;
|
||
66 | } |
||
67 | |||
68 | |||
69 | public FeatureType delete(String id) { |
||
70 | deleted.add(id); |
||
71 | FeatureType type=(FeatureType)added.remove(id); |
||
72 | 24181 | jjdelcerro | if (type==null) { |
73 | type=(FeatureType)modifiedFromOriginal.remove(id); |
||
74 | } |
||
75 | 24143 | vcaballero | deltaSize--; |
76 | return type;
|
||
77 | } |
||
78 | |||
79 | /**
|
||
80 | * DOCUMENT ME!
|
||
81 | *
|
||
82 | * @param feature DOCUMENT ME!
|
||
83 | */
|
||
84 | public void add(FeatureType type) { |
||
85 | int pos = expansionAdapter.addObject(type);
|
||
86 | added.put(type.getId(),new Integer(pos)); |
||
87 | deltaSize++; |
||
88 | } |
||
89 | |||
90 | /**
|
||
91 | * DOCUMENT ME!
|
||
92 | *
|
||
93 | * @param id DOCUMENT ME!
|
||
94 | */
|
||
95 | public void deleteLastFeature() { |
||
96 | expansionAdapter.deleteLastObject(); |
||
97 | FeatureType type=(FeatureType)expansionAdapter.getObject(expansionAdapter.getSize()-1);
|
||
98 | added.remove(type.getId()); |
||
99 | modifiedFromOriginal.remove(type.getId()); |
||
100 | deltaSize--; |
||
101 | } |
||
102 | |||
103 | /**
|
||
104 | * DOCUMENT ME!
|
||
105 | *
|
||
106 | * @param id DOCUMENT ME!
|
||
107 | *
|
||
108 | * @return DOCUMENT ME!
|
||
109 | * @throws IsNotFeatureSettingException
|
||
110 | */
|
||
111 | public FeatureType getType(String id) throws DataException { |
||
112 | Integer intNum =((Integer) added.get(id)); |
||
113 | if (intNum == null){ |
||
114 | intNum =((Integer) modifiedFromOriginal.get(id));
|
||
115 | if (intNum == null){ |
||
116 | return null; |
||
117 | } |
||
118 | } |
||
119 | int num = intNum.intValue();
|
||
120 | |||
121 | FeatureType type=(FeatureType)expansionAdapter.getObject(num); |
||
122 | return type;
|
||
123 | } |
||
124 | |||
125 | /**
|
||
126 | * DOCUMENT ME!
|
||
127 | *
|
||
128 | * @param feature DOCUMENT ME!
|
||
129 | * @param oldFeature DOCUMENT ME!
|
||
130 | */
|
||
131 | public int update(FeatureType type, FeatureType oldType) { |
||
132 | // deleted.add(oldType.getId());
|
||
133 | int oldNum=-1; |
||
134 | int num = expansionAdapter.addObject(type);
|
||
135 | String id=type.getId();
|
||
136 | |||
137 | if (added.containsKey(id)){
|
||
138 | oldNum=((Integer)added.get(id)).intValue();
|
||
139 | added.put(id,new Integer(num)); |
||
140 | }else{
|
||
141 | oldNum=((Integer)modifiedFromOriginal.get(id)).intValue();
|
||
142 | modifiedFromOriginal.put(id,new Integer(num)); |
||
143 | } |
||
144 | return oldNum;
|
||
145 | } |
||
146 | |||
147 | /**
|
||
148 | * DOCUMENT ME!
|
||
149 | *
|
||
150 | * @param id DOCUMENT ME!
|
||
151 | */
|
||
152 | public void restore(String id) { |
||
153 | deleted.remove(id); |
||
154 | deltaSize++; |
||
155 | } |
||
156 | public void restore(String id,int num){ |
||
157 | if (added.containsKey(id)){
|
||
158 | added.put(id,new Integer(num)); |
||
159 | }else{
|
||
160 | modifiedFromOriginal.put(id,new Integer(num)); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | public boolean isDeleted(FeatureType type){ |
||
165 | return deleted.contains(type.getId());
|
||
166 | } |
||
167 | |||
168 | public boolean isDeleted(String id) { |
||
169 | return deleted.contains(id);
|
||
170 | } |
||
171 | |||
172 | public void clear() { |
||
173 | added.clear(); |
||
174 | modifiedFromOriginal.clear(); |
||
175 | expansionAdapter.close(); |
||
176 | deleted.clear();//<FeatureID>
|
||
177 | deltaSize=0;
|
||
178 | } |
||
179 | |||
180 | |||
181 | public boolean hasChanges() { |
||
182 | return added.size()>0 || modifiedFromOriginal.size() > 0 || deleted.size() > 0; |
||
183 | } |
||
184 | |||
185 | public Iterator newsIterator() { |
||
186 | return added.values().iterator();
|
||
187 | } |
||
188 | |||
189 | |||
190 | public boolean hasNews() { |
||
191 | return !added.isEmpty();
|
||
192 | } |
||
193 | |||
194 | public long getDeltaSize() { |
||
195 | return deltaSize;
|
||
196 | } |
||
197 | } |