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