svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libFMap_data / src / org / gvsig / data / vectorial / AttributeDescriptor.java @ 21830
History | View | Annotate | Download (14 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; |
44 |
|
45 |
import java.lang.ref.WeakReference; |
46 |
|
47 |
|
48 |
|
49 |
/**
|
50 |
* DOCUMENT ME!
|
51 |
*
|
52 |
* @author Vicente Caballero Navarro
|
53 |
*/
|
54 |
public class AttributeDescriptor implements FeatureAttributeDescriptor { |
55 |
private String name = null; |
56 |
private String type = FeatureAttributeDescriptor.TYPE_STRING; |
57 |
private int size = 0; |
58 |
private int precision = 0; |
59 |
private int minimumOccurrences = 0; |
60 |
private int maximumOccurences = 0; |
61 |
private boolean isPrimaryKey = false; |
62 |
private int ordinal = 0; |
63 |
private Object defaultValue; |
64 |
private int geometryType; |
65 |
private String featureType; |
66 |
private String srs; |
67 |
private boolean allowNull; |
68 |
private ExpressionEvaluator evaluator;
|
69 |
protected boolean readOnly; |
70 |
protected boolean evaluated; |
71 |
protected String expression; |
72 |
|
73 |
protected boolean editing = false; |
74 |
protected AttributeDescriptor newAttributeDescriptor;
|
75 |
protected boolean loading = false; |
76 |
private int originalPosition=-1; |
77 |
private boolean isNew=false; |
78 |
private Class objectClass; |
79 |
private WeakReference wfFeatureType=null; |
80 |
|
81 |
protected AttributeDescriptor(FeatureType featureType) {
|
82 |
this.wfFeatureType = new WeakReference(featureType); |
83 |
this.isNew=false; |
84 |
} |
85 |
|
86 |
protected AttributeDescriptor(FeatureType featureType,boolean asNew) { |
87 |
this.wfFeatureType = new WeakReference(featureType); |
88 |
this.isNew=asNew;
|
89 |
} |
90 |
|
91 |
protected FeatureType getFeatureType(){
|
92 |
if (this.wfFeatureType == null){ |
93 |
return null; |
94 |
} |
95 |
return (FeatureType) this.wfFeatureType.get(); |
96 |
} |
97 |
|
98 |
public boolean isFromFeatureType(FeatureType featureType){ |
99 |
FeatureType myFtype= this.getFeatureType();
|
100 |
if (myFtype == null){ |
101 |
return false; |
102 |
} |
103 |
return myFtype == featureType;
|
104 |
} |
105 |
|
106 |
/* (non-Javadoc)
|
107 |
* @see org.gvsig.data.vectorial.FeatureAttributeDescriptor#getName()
|
108 |
*/
|
109 |
public String getName() { |
110 |
if (useNewAttributeValue()){
|
111 |
return this.newAttributeDescriptor.getName(); |
112 |
} |
113 |
return name;
|
114 |
} |
115 |
|
116 |
/* (non-Javadoc)
|
117 |
* @see org.gvsig.data.vectorial.FeatureAttributeDescriptor#getDataType()
|
118 |
*/
|
119 |
public String getDataType() { |
120 |
if (useNewAttributeValue()){
|
121 |
return this.newAttributeDescriptor.getDataType(); |
122 |
} |
123 |
return type;
|
124 |
} |
125 |
|
126 |
/* (non-Javadoc)
|
127 |
* @see org.gvsig.data.vectorial.FeatureAttributeDescriptor#getSize()
|
128 |
*/
|
129 |
public int getSize() { |
130 |
if (useNewAttributeValue()){
|
131 |
return this.newAttributeDescriptor.getSize(); |
132 |
} |
133 |
return size;
|
134 |
} |
135 |
|
136 |
/* (non-Javadoc)
|
137 |
* @see org.gvsig.data.vectorial.FeatureAttributeDescriptor#getPrecision()
|
138 |
*/
|
139 |
public int getPrecision() { |
140 |
if (useNewAttributeValue()){
|
141 |
return this.newAttributeDescriptor.getPrecision(); |
142 |
} |
143 |
return precision;
|
144 |
} |
145 |
|
146 |
/**
|
147 |
* DOCUMENT ME!
|
148 |
*
|
149 |
* @return DOCUMENT ME!
|
150 |
*/
|
151 |
public Class getObjectClass() { |
152 |
if (useNewAttributeValue()){
|
153 |
return this.newAttributeDescriptor.getObjectClass(); |
154 |
} |
155 |
return objectClass;
|
156 |
} |
157 |
|
158 |
/* (non-Javadoc)
|
159 |
* @see org.gvsig.data.vectorial.FeatureAttributeDescriptor#getMinimumOccurrences()
|
160 |
*/
|
161 |
public int getMinimumOccurrences() { |
162 |
if (useNewAttributeValue()){
|
163 |
return this.newAttributeDescriptor.getMinimumOccurrences(); |
164 |
} |
165 |
return minimumOccurrences;
|
166 |
} |
167 |
|
168 |
/* (non-Javadoc)
|
169 |
* @see org.gvsig.data.vectorial.FeatureAttributeDescriptor#getMaximumOccurrences()
|
170 |
*/
|
171 |
public int getMaximumOccurrences() { |
172 |
if (useNewAttributeValue()){
|
173 |
return this.newAttributeDescriptor.getMaximumOccurrences(); |
174 |
} |
175 |
return maximumOccurences;
|
176 |
|
177 |
} |
178 |
|
179 |
/* (non-Javadoc)
|
180 |
* @see org.gvsig.data.vectorial.FeatureAttributeDescriptor#isPrimaryKey()
|
181 |
*/
|
182 |
public boolean isPrimaryKey() { |
183 |
if (useNewAttributeValue()){
|
184 |
return this.newAttributeDescriptor.isPrimaryKey(); |
185 |
} |
186 |
return isPrimaryKey;
|
187 |
} |
188 |
|
189 |
/* (non-Javadoc)
|
190 |
* @see org.gvsig.data.vectorial.FeatureAttributeDescriptor#ordinal()
|
191 |
*/
|
192 |
public int ordinal() { |
193 |
if (useNewAttributeValue()){
|
194 |
return this.newAttributeDescriptor.ordinal(); |
195 |
} else {
|
196 |
return ordinal;
|
197 |
} |
198 |
} |
199 |
public void setPrimaryKey(boolean isPrimaryKey) throws IsNotAttributeSettingException { |
200 |
canSetValue(); |
201 |
if (useNewAttributeValue()){
|
202 |
this.newAttributeDescriptor.loading();
|
203 |
this.newAttributeDescriptor.setPrimaryKey(isPrimaryKey);
|
204 |
this.newAttributeDescriptor.stopLoading();
|
205 |
} else {
|
206 |
this.isPrimaryKey = isPrimaryKey;
|
207 |
} |
208 |
} |
209 |
public void setMaximumOccurences(int maximumOccurences) throws IsNotAttributeSettingException { |
210 |
canSetValue(); |
211 |
if (useNewAttributeValue()){
|
212 |
newAttributeDescriptor.loading(); |
213 |
this.newAttributeDescriptor.setMaximumOccurences(maximumOccurences);
|
214 |
newAttributeDescriptor.stopLoading(); |
215 |
} else {
|
216 |
this.maximumOccurences = maximumOccurences;
|
217 |
} |
218 |
} |
219 |
public void setMinimumOccurrences(int minimumOccurrences) throws IsNotAttributeSettingException { |
220 |
canSetValue(); |
221 |
if (useNewAttributeValue()){
|
222 |
newAttributeDescriptor.loading(); |
223 |
this.newAttributeDescriptor.setMinimumOccurrences(minimumOccurrences);
|
224 |
newAttributeDescriptor.stopLoading(); |
225 |
} else {
|
226 |
this.minimumOccurrences = minimumOccurrences;
|
227 |
} |
228 |
} |
229 |
public void setName(String name) throws IsNotAttributeSettingException { |
230 |
canSetValue(); |
231 |
if (useNewAttributeValue()){
|
232 |
newAttributeDescriptor.loading(); |
233 |
newAttributeDescriptor.setName(name); |
234 |
newAttributeDescriptor.stopLoading(); |
235 |
|
236 |
}else{
|
237 |
this.name = name;
|
238 |
} |
239 |
} |
240 |
|
241 |
/**
|
242 |
* M?todo ?nicamente utilizado desde esta librer?a en el DefaultFeatureType.add();
|
243 |
* @throws IsNotAttributeSettingException
|
244 |
*/
|
245 |
public void setOrdinal(int ordinal){ |
246 |
if (useNewAttributeValue()){
|
247 |
newAttributeDescriptor.loading(); |
248 |
newAttributeDescriptor.setOrdinal(ordinal); |
249 |
newAttributeDescriptor.stopLoading(); |
250 |
}else{
|
251 |
this.ordinal = ordinal;
|
252 |
} |
253 |
} |
254 |
|
255 |
public void setPrecision(int precision) throws IsNotAttributeSettingException { |
256 |
canSetValue(); |
257 |
if (useNewAttributeValue()){
|
258 |
newAttributeDescriptor.loading(); |
259 |
newAttributeDescriptor.setPrecision(precision); |
260 |
newAttributeDescriptor.stopLoading(); |
261 |
}else{
|
262 |
this.precision = precision;
|
263 |
|
264 |
} |
265 |
} |
266 |
|
267 |
public void setSize(int size) throws IsNotAttributeSettingException { |
268 |
canSetValue(); |
269 |
if (useNewAttributeValue()){
|
270 |
newAttributeDescriptor.loading(); |
271 |
newAttributeDescriptor.setSize(size); |
272 |
newAttributeDescriptor.stopLoading(); |
273 |
}else{
|
274 |
this.size = size;
|
275 |
} |
276 |
} |
277 |
public void setType(String type) throws IsNotAttributeSettingException { |
278 |
canSetValue(); |
279 |
if (useNewAttributeValue()){
|
280 |
newAttributeDescriptor.loading(); |
281 |
newAttributeDescriptor.setType(type); |
282 |
newAttributeDescriptor.stopLoading(); |
283 |
}else{
|
284 |
this.type = type;
|
285 |
} |
286 |
} |
287 |
|
288 |
public String getSRS() { |
289 |
if (useNewAttributeValue())
|
290 |
return newAttributeDescriptor.getSRS();
|
291 |
else
|
292 |
return srs;
|
293 |
} |
294 |
public void setSRS(String srs) throws IsNotAttributeSettingException { |
295 |
canSetValue(); |
296 |
if (useNewAttributeValue()){
|
297 |
newAttributeDescriptor.loading(); |
298 |
newAttributeDescriptor.setSRS(srs); |
299 |
newAttributeDescriptor.stopLoading(); |
300 |
}else{
|
301 |
this.srs=srs;
|
302 |
} |
303 |
} |
304 |
public int getGeometryType() { |
305 |
if (useNewAttributeValue())
|
306 |
return newAttributeDescriptor.getGeometryType();
|
307 |
else
|
308 |
return geometryType;
|
309 |
} |
310 |
|
311 |
public void setGeometryType(int type) throws IsNotAttributeSettingException{ |
312 |
canSetValue(); |
313 |
if (useNewAttributeValue()){
|
314 |
newAttributeDescriptor.loading(); |
315 |
newAttributeDescriptor.setGeometryType(type); |
316 |
newAttributeDescriptor.stopLoading(); |
317 |
}else{
|
318 |
this.geometryType=type;
|
319 |
} |
320 |
} |
321 |
public Object getDefaultValue() { |
322 |
if (useNewAttributeValue())
|
323 |
return newAttributeDescriptor.getDefaultValue();
|
324 |
else
|
325 |
return defaultValue;
|
326 |
} |
327 |
public void setDefaultValue(Object s) throws IsNotAttributeSettingException { |
328 |
canSetValue(); |
329 |
if (useNewAttributeValue()){
|
330 |
newAttributeDescriptor.loading(); |
331 |
newAttributeDescriptor.setDefaultValue(s); |
332 |
newAttributeDescriptor.stopLoading(); |
333 |
}else{
|
334 |
this.defaultValue=s;
|
335 |
} |
336 |
} |
337 |
|
338 |
public boolean isAllowNull() { |
339 |
if (useNewAttributeValue())
|
340 |
return newAttributeDescriptor.isAllowNull();
|
341 |
else
|
342 |
return allowNull;
|
343 |
} |
344 |
|
345 |
public void setAllowNull(boolean allowNull) throws IsNotAttributeSettingException { |
346 |
canSetValue(); |
347 |
if (useNewAttributeValue()){
|
348 |
newAttributeDescriptor.loading(); |
349 |
newAttributeDescriptor.setAllowNull(allowNull); |
350 |
newAttributeDescriptor.stopLoading(); |
351 |
}else{
|
352 |
this.allowNull = allowNull;
|
353 |
} |
354 |
} |
355 |
|
356 |
public FeatureAttributeDescriptor cloneAttribute() {
|
357 |
AttributeDescriptor newFD = (AttributeDescriptor)newAttribute(); |
358 |
newFD.name = this.name;
|
359 |
newFD.type = this.type;
|
360 |
newFD.size = this.size;
|
361 |
newFD.precision = this.precision;
|
362 |
newFD.minimumOccurrences = this.minimumOccurrences;
|
363 |
newFD.maximumOccurences = this.maximumOccurences;
|
364 |
newFD.isPrimaryKey = this.isPrimaryKey;
|
365 |
newFD.ordinal = this.ordinal;
|
366 |
newFD.defaultValue = this.defaultValue;
|
367 |
newFD.geometryType = this.geometryType;
|
368 |
newFD.featureType = this.featureType;
|
369 |
newFD.srs = this.srs;
|
370 |
newFD.allowNull = this.allowNull;
|
371 |
newFD.evaluator = this.evaluator;
|
372 |
|
373 |
return newFD;
|
374 |
} |
375 |
|
376 |
protected FeatureAttributeDescriptor newAttribute(){
|
377 |
return ((DefaultFeatureType)this.getFeatureType()).createAttributeDescriptor(); |
378 |
} |
379 |
|
380 |
public boolean isValid() { |
381 |
//TODO: Faltan mas comprobaciones
|
382 |
if (this.isEvaluated()){ |
383 |
if (this.evaluator == null){ |
384 |
return false; |
385 |
} |
386 |
} |
387 |
return true; |
388 |
} |
389 |
|
390 |
public ExpressionEvaluator getEvaluator() {
|
391 |
if (useNewAttributeValue())
|
392 |
return newAttributeDescriptor.getEvaluator();
|
393 |
else
|
394 |
return evaluator;
|
395 |
} |
396 |
public void setEvaluator(ExpressionEvaluator evaluator) throws IsNotAttributeSettingException { |
397 |
canSetValue(); |
398 |
if (useNewAttributeValue()){
|
399 |
newAttributeDescriptor.loading(); |
400 |
newAttributeDescriptor.setEvaluator(evaluator); |
401 |
newAttributeDescriptor.stopLoading(); |
402 |
}else{
|
403 |
this.evaluator = evaluator;
|
404 |
} |
405 |
} |
406 |
public boolean isReadOnly() { |
407 |
if (useNewAttributeValue())
|
408 |
return newAttributeDescriptor.isReadOnly();
|
409 |
else
|
410 |
return this.readOnly || this.isEvaluated(); |
411 |
} |
412 |
|
413 |
public void setReadOnly(boolean readOnly) throws IsNotAttributeSettingException { |
414 |
canSetValue(); |
415 |
if (useNewAttributeValue()){
|
416 |
newAttributeDescriptor.loading(); |
417 |
newAttributeDescriptor.setReadOnly(readOnly); |
418 |
newAttributeDescriptor.stopLoading(); |
419 |
}else{
|
420 |
this.readOnly = readOnly;
|
421 |
} |
422 |
} |
423 |
public String getExpression() { |
424 |
return expression;
|
425 |
} |
426 |
public void setExpression(String expression) throws IsNotAttributeSettingException { |
427 |
canSetValue(); |
428 |
if (useNewAttributeValue()){
|
429 |
newAttributeDescriptor.loading(); |
430 |
newAttributeDescriptor.setExpression(expression); |
431 |
newAttributeDescriptor.stopLoading(); |
432 |
}else{
|
433 |
this.expression = expression;
|
434 |
} |
435 |
} |
436 |
|
437 |
public void loading() { |
438 |
loading=true;
|
439 |
|
440 |
} |
441 |
public void stopLoading() { |
442 |
loading=false;
|
443 |
|
444 |
} |
445 |
public void editing() { |
446 |
editing=true;
|
447 |
newAttributeDescriptor=(AttributeDescriptor) this.cloneAttribute();
|
448 |
newAttributeDescriptor.setOriginalPosition(ordinal); |
449 |
} |
450 |
public void cancelEditing() { |
451 |
editing=false;
|
452 |
newAttributeDescriptor=null;
|
453 |
} |
454 |
public FeatureAttributeDescriptor getNewAttributeDescriptor() {
|
455 |
return newAttributeDescriptor;
|
456 |
} |
457 |
/* (non-Javadoc)
|
458 |
* @see org.gvsig.data.vectorial.FeatureAttributeDescriptor#isEvalued()
|
459 |
*/
|
460 |
public boolean isEvaluated() { |
461 |
if (useNewAttributeValue())
|
462 |
return this.newAttributeDescriptor.isEvaluated(); |
463 |
else
|
464 |
return this.evaluated; |
465 |
} |
466 |
|
467 |
public void setEvalued(boolean evalued) throws IsNotAttributeSettingException{ |
468 |
canSetValue(); |
469 |
if (useNewAttributeValue()){
|
470 |
newAttributeDescriptor.loading(); |
471 |
newAttributeDescriptor.setEvalued(evalued); |
472 |
newAttributeDescriptor.stopLoading(); |
473 |
}else{
|
474 |
this.evaluated = evalued;
|
475 |
} |
476 |
} |
477 |
protected void stopEditing() { |
478 |
editing=false;
|
479 |
if (this.isNew){ |
480 |
this.isNew =false; |
481 |
} |
482 |
} |
483 |
protected void canSetValue() throws IsNotAttributeSettingException { |
484 |
if (!editing && !loading){
|
485 |
throw new IsNotAttributeSettingException("set"); |
486 |
} |
487 |
if (!loading && isReadOnly()){
|
488 |
//TODO Construir la clase adecuada para esta excepci?n
|
489 |
throw new IsNotAttributeSettingException(" Read only field: " +getName()); |
490 |
} |
491 |
} |
492 |
|
493 |
protected boolean useNewAttributeValue(){ |
494 |
return this.editing && !this.isNew; |
495 |
|
496 |
} |
497 |
|
498 |
public int originalPosition() { |
499 |
if (originalPosition!=-1){ |
500 |
return originalPosition;
|
501 |
} |
502 |
return ordinal;
|
503 |
} |
504 |
private void setOriginalPosition(int i){ |
505 |
originalPosition=i; |
506 |
} |
507 |
|
508 |
/**
|
509 |
* @return
|
510 |
*/
|
511 |
public boolean isNew() { |
512 |
return this.isNew; |
513 |
} |
514 |
} |