root / trunk / libraries / libDataSource / src / org / gvsig / data / vectorial / expansionadapter / AttributeManager.java @ 19488
History | View | Annotate | Download (4.58 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.data.vectorial.expansionadapter; |
44 |
|
45 |
import java.util.ArrayList; |
46 |
import java.util.HashMap; |
47 |
|
48 |
import org.gvsig.data.vectorial.DefaultFeatureType; |
49 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
50 |
import org.gvsig.data.vectorial.IFeatureType; |
51 |
|
52 |
|
53 |
/**
|
54 |
* DOCUMENT ME!
|
55 |
*
|
56 |
* @author Vicente Caballero Navarro
|
57 |
*/
|
58 |
public class AttributeManager { |
59 |
protected HashMap relations = new HashMap();//<String,Integer> |
60 |
protected IExpansionAdapter expansionAdapter;
|
61 |
protected ArrayList deletedAttributes = new ArrayList();//<String> |
62 |
|
63 |
public AttributeManager(IExpansionAdapter expansionAdapter){
|
64 |
this.expansionAdapter=expansionAdapter;
|
65 |
} |
66 |
|
67 |
public void deleteAttribute(String id) { |
68 |
deletedAttributes.add(id); |
69 |
} |
70 |
|
71 |
/**
|
72 |
* DOCUMENT ME!
|
73 |
*
|
74 |
* @param feature DOCUMENT ME!
|
75 |
*/
|
76 |
public void addAttribute(IFeatureAttributeDescriptor attributeDescriptor) { |
77 |
int pos = expansionAdapter.addObject(attributeDescriptor);
|
78 |
relations.put(attributeDescriptor.getName(), new Integer(pos)); |
79 |
} |
80 |
|
81 |
/**
|
82 |
* DOCUMENT ME!
|
83 |
*
|
84 |
* @param id DOCUMENT ME!
|
85 |
*/
|
86 |
public void deleteLastAttribute(String id) { |
87 |
expansionAdapter.deleteLastObject(); |
88 |
relations.remove(id); |
89 |
} |
90 |
|
91 |
/**
|
92 |
* DOCUMENT ME!
|
93 |
*
|
94 |
* @param id DOCUMENT ME!
|
95 |
*
|
96 |
* @return DOCUMENT ME!
|
97 |
*/
|
98 |
public boolean contains(String id) { |
99 |
return relations.containsKey(id);
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* DOCUMENT ME!
|
104 |
*
|
105 |
* @param id DOCUMENT ME!
|
106 |
*
|
107 |
* @return DOCUMENT ME!
|
108 |
*/
|
109 |
public IFeatureAttributeDescriptor getAttribute(String id) { |
110 |
int num = ((Integer) relations.get(id)).intValue(); |
111 |
|
112 |
return (IFeatureAttributeDescriptor)expansionAdapter.getObject(num);
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* DOCUMENT ME!
|
117 |
*
|
118 |
* @param feature DOCUMENT ME!
|
119 |
* @param oldFeature DOCUMENT ME!
|
120 |
*/
|
121 |
public void updateAttribute(IFeatureAttributeDescriptor attributeDescriptor, IFeatureAttributeDescriptor oldAttributeDescriptor) { |
122 |
deletedAttributes.add(oldAttributeDescriptor.getName()); |
123 |
|
124 |
int num = expansionAdapter.updateObject(attributeDescriptor);
|
125 |
|
126 |
/*
|
127 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
128 |
* fichero de expansi?n.
|
129 |
*/
|
130 |
relations.put(attributeDescriptor.getName(), new Integer(num)); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* DOCUMENT ME!
|
135 |
*
|
136 |
* @param id DOCUMENT ME!
|
137 |
*/
|
138 |
public void restoreAttribute(String id) { |
139 |
deletedAttributes.remove(id); |
140 |
} |
141 |
|
142 |
public IFeatureType getFeatureType(IFeatureType featureType) {
|
143 |
IFeatureType ft = new DefaultFeatureType();
|
144 |
ft.setGeometryTypes(featureType.getGeometryTypes()); |
145 |
for (int i=0;i<featureType.size();i++){ |
146 |
IFeatureAttributeDescriptor descriptor=(IFeatureAttributeDescriptor)featureType.get(i); |
147 |
if (!deletedAttributes.contains(descriptor)){
|
148 |
ft.add(descriptor); |
149 |
} |
150 |
} |
151 |
for (int i=0;i<relations.size();i++){ |
152 |
IFeatureAttributeDescriptor descriptor=(IFeatureAttributeDescriptor)expansionAdapter.getObject(i); |
153 |
if (!deletedAttributes.contains(descriptor)){
|
154 |
ft.add(descriptor); |
155 |
} |
156 |
} |
157 |
return ft;
|
158 |
} |
159 |
|
160 |
public void clear() { |
161 |
relations.clear();//<String,Integer>
|
162 |
expansionAdapter.close(); |
163 |
deletedAttributes.clear();//<String>
|
164 |
|
165 |
} |
166 |
} |