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