root / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / feature / AttributeManager.java @ 23303
History | View | Annotate | Download (5.47 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
|
43 |
package org.gvsig.fmap.data.feature; |
44 |
|
45 |
import java.util.ArrayList; |
46 |
import java.util.HashMap; |
47 |
import java.util.Iterator; |
48 |
|
49 |
import org.gvsig.fmap.data.feature.expansionadapter.ExpansionAdapter; |
50 |
|
51 |
|
52 |
/**
|
53 |
* DOCUMENT ME!
|
54 |
*
|
55 |
* @author Vicente Caballero Navarro
|
56 |
*/
|
57 |
public class AttributeManager { |
58 |
protected HashMap relations = new HashMap();//<String,Integer> |
59 |
protected ExpansionAdapter expansionAdapter;
|
60 |
protected ArrayList deletedAttributes = new ArrayList();//<String> |
61 |
protected int size=0; |
62 |
protected int count=0; |
63 |
private FeatureType featureType;
|
64 |
private FeatureType currentFeatureType;
|
65 |
|
66 |
public AttributeManager(ExpansionAdapter expansionAdapter,FeatureType featureType){
|
67 |
this.expansionAdapter=expansionAdapter;
|
68 |
this.featureType=featureType;
|
69 |
this.currentFeatureType=null; |
70 |
} |
71 |
|
72 |
public void deleteAttribute(Integer id) { |
73 |
deletedAttributes.add(id); |
74 |
size--; |
75 |
this.currentFeatureType=null; |
76 |
} |
77 |
|
78 |
/**
|
79 |
* DOCUMENT ME!
|
80 |
*
|
81 |
* @param feature DOCUMENT ME!
|
82 |
*/
|
83 |
public void addAttribute(FeatureAttributeDescriptor attributeDescriptor) { |
84 |
((AttributeDescriptor)attributeDescriptor).setOrdinal(count+((DefaultFeatureType)featureType).getCount()); |
85 |
count++; |
86 |
int pos = expansionAdapter.addObject(attributeDescriptor);
|
87 |
relations.put(new Integer(attributeDescriptor.ordinal()), new Integer(pos)); |
88 |
size++; |
89 |
this.currentFeatureType=null; |
90 |
} |
91 |
|
92 |
/**
|
93 |
* DOCUMENT ME!
|
94 |
*
|
95 |
* @param id DOCUMENT ME!
|
96 |
*/
|
97 |
public void deleteLastAttribute(Integer id) { |
98 |
expansionAdapter.deleteLastObject(); |
99 |
relations.remove(id); |
100 |
size--; |
101 |
this.currentFeatureType=null; |
102 |
} |
103 |
|
104 |
/**
|
105 |
* DOCUMENT ME!
|
106 |
*
|
107 |
* @param id DOCUMENT ME!
|
108 |
*
|
109 |
* @return DOCUMENT ME!
|
110 |
*/
|
111 |
public boolean contains(Integer id) { |
112 |
return relations.containsKey(id);
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* DOCUMENT ME!
|
117 |
*
|
118 |
* @param id DOCUMENT ME!
|
119 |
*
|
120 |
* @return DOCUMENT ME!
|
121 |
*/
|
122 |
public FeatureAttributeDescriptor getAttribute(Integer id) { |
123 |
int num = ((Integer) relations.get(id)).intValue(); |
124 |
|
125 |
return (FeatureAttributeDescriptor)expansionAdapter.getObject(num);
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* DOCUMENT ME!
|
130 |
*
|
131 |
* @param feature DOCUMENT ME!
|
132 |
* @param oldFeature DOCUMENT ME!
|
133 |
*/
|
134 |
public void updateAttribute(FeatureAttributeDescriptor attributeDescriptor) { |
135 |
deletedAttributes.add(new Integer(attributeDescriptor.ordinal())); |
136 |
|
137 |
int num = expansionAdapter.updateObject(attributeDescriptor);
|
138 |
|
139 |
/*
|
140 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
141 |
* fichero de expansi?n.
|
142 |
*/
|
143 |
((AttributeDescriptor)attributeDescriptor).setOrdinal(num); |
144 |
relations.put(new Integer(attributeDescriptor.ordinal()), new Integer(num)); |
145 |
this.currentFeatureType=null; |
146 |
} |
147 |
|
148 |
/**
|
149 |
* DOCUMENT ME!
|
150 |
*
|
151 |
* @param id DOCUMENT ME!
|
152 |
*/
|
153 |
public void restoreAttribute(Integer id) { |
154 |
deletedAttributes.remove(id); |
155 |
size++; |
156 |
this.currentFeatureType=null; |
157 |
} |
158 |
public int getNum(){ |
159 |
return size;
|
160 |
} |
161 |
public FeatureType getFeatureType() {
|
162 |
if (this.currentFeatureType == null){ |
163 |
DefaultFeatureType dft=(DefaultFeatureType)featureType.cloneFeatureType(); |
164 |
dft.clear(); |
165 |
Iterator iter=featureType.iterator();
|
166 |
while (iter.hasNext()) {
|
167 |
FeatureAttributeDescriptor descriptor= (FeatureAttributeDescriptor) iter.next(); |
168 |
if (!deletedAttributes.contains(new Integer(descriptor.ordinal()))){ |
169 |
dft.addWithoutOrdinal(descriptor.cloneAttribute()); |
170 |
} |
171 |
} |
172 |
for (int i=0;i<relations.size();i++){ |
173 |
FeatureAttributeDescriptor descriptor=(FeatureAttributeDescriptor)expansionAdapter.getObject(i); |
174 |
if (!deletedAttributes.contains(new Integer(descriptor.ordinal()))){ |
175 |
dft.addWithoutOrdinal(descriptor.cloneAttribute()); |
176 |
} |
177 |
} |
178 |
this.currentFeatureType=dft;
|
179 |
} |
180 |
return this.currentFeatureType; |
181 |
} |
182 |
|
183 |
public void clear() { |
184 |
relations.clear();//<String,Integer>
|
185 |
expansionAdapter.close(); |
186 |
deletedAttributes.clear();//<String>
|
187 |
size=0;
|
188 |
this.currentFeatureType=null; |
189 |
} |
190 |
} |