Revision 1305 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/impl/DefaultDynField.java
DefaultDynField.java | ||
---|---|---|
79 | 79 |
|
80 | 80 |
private boolean validateElements; |
81 | 81 |
private boolean isReadOnly; |
82 |
private Tags tags = new DefaultTags(); |
|
82 |
private final Tags tags = new DefaultTags();
|
|
83 | 83 |
|
84 | 84 |
private ValueType itemsType; |
85 | 85 |
private boolean validateItems; |
... | ... | |
87 | 87 |
// Para implementacion futura, como minimo para implementar |
88 | 88 |
// un copy entre dynobject y saber cuando parar. |
89 | 89 |
// Los valores deberan ser algo asi como: |
90 |
// - Composicion, 1:1 o 1:N y se copian. |
|
91 |
// - Agregacion, 1:N, no se copian |
|
92 |
// - Colaboracion, 1:1, no se copian |
|
90 |
// - Identidad/Identity, 1:1 y se copian. |
|
91 |
// - Composicion/Composition, 1:N y se copian. |
|
92 |
// - Agregacion/Aggregate, 1:N, no se copian |
|
93 |
// - Colaboracion/Collaboration, 1:1, no se copian |
|
93 | 94 |
// Y solo tendra efecto/sentido cuando el field sea de tipo |
94 | 95 |
// DynObject, y tal vez lista de DynObject |
95 | 96 |
private int relationType; |
... | ... | |
134 | 135 |
public void check() throws ListBaseException { |
135 | 136 |
} |
136 | 137 |
|
138 |
@Override |
|
137 | 139 |
public String toString() { |
138 |
StringBuffer buffer = new StringBuffer();
|
|
140 |
StringBuilder buffer = new StringBuilder();
|
|
139 | 141 |
|
140 | 142 |
buffer.append("DynField").append("[").append(this.hashCode()) |
141 | 143 |
.append("]").append("( ").append("name='").append(this.name) |
... | ... | |
152 | 154 |
return buffer.toString(); |
153 | 155 |
} |
154 | 156 |
|
157 |
@Override |
|
155 | 158 |
public String getName() { |
156 | 159 |
return name; |
157 | 160 |
} |
... | ... | |
164 | 167 |
return this; |
165 | 168 |
} |
166 | 169 |
|
170 |
@Override |
|
167 | 171 |
public DynField setDescription(String description) { |
168 | 172 |
this.description = description; |
169 | 173 |
return this; |
170 | 174 |
} |
171 | 175 |
|
176 |
@Override |
|
172 | 177 |
public String getDescription() { |
173 | 178 |
return (description == null) ? getLabel() : description; |
174 | 179 |
} |
175 | 180 |
|
181 |
@Override |
|
176 | 182 |
public DynField setLabel(String label) { |
177 | 183 |
this.label = label; |
178 | 184 |
return this; |
179 | 185 |
} |
180 | 186 |
|
187 |
@Override |
|
181 | 188 |
public String getLabel() { |
182 | 189 |
return (label == null) ? getName() : label; |
183 | 190 |
} |
184 | 191 |
|
192 |
@Override |
|
185 | 193 |
public DynField setType(int dataType) { |
186 | 194 |
this.type.setType(dataType); |
187 | 195 |
return this; |
188 | 196 |
} |
189 | 197 |
|
198 |
@Override |
|
190 | 199 |
public DynField setType(DataType dataType) { |
191 | 200 |
this.type.setType(dataType); |
192 | 201 |
return this; |
193 | 202 |
} |
194 | 203 |
|
204 |
@Override |
|
195 | 205 |
public int getType() { |
196 | 206 |
return this.type.getType(); |
197 | 207 |
} |
198 | 208 |
|
209 |
@Override |
|
199 | 210 |
public DataType getDataType() { |
200 | 211 |
return this.type.getDataType(); |
201 | 212 |
} |
202 | 213 |
|
214 |
@Override |
|
203 | 215 |
public DynField setSubtype(String subtype) { |
204 | 216 |
this.subtype = subtype; |
205 | 217 |
return this; |
206 | 218 |
} |
207 | 219 |
|
220 |
@Override |
|
208 | 221 |
public String getSubtype() { |
209 | 222 |
return subtype; |
210 | 223 |
} |
211 | 224 |
|
225 |
@Override |
|
212 | 226 |
public DynField setDefaultDynValue(Object defaultValue) { |
213 | 227 |
this.defaultValue = defaultValue; |
214 | 228 |
return this; |
215 | 229 |
} |
216 | 230 |
|
231 |
@Override |
|
217 | 232 |
public Object getDefaultValue() { |
218 | 233 |
return defaultValue; |
219 | 234 |
} |
220 | 235 |
|
236 |
@Override |
|
221 | 237 |
public DynField setAvailableValues(DynObjectValueItem[] availableValues) { |
222 | 238 |
if ( availableValues == null || availableValues.length == 0 ) { |
223 | 239 |
this.availableValues = null; |
... | ... | |
227 | 243 |
return this; |
228 | 244 |
} |
229 | 245 |
|
246 |
@Override |
|
230 | 247 |
public DynField setAvailableValues(List availableValues) { |
231 | 248 |
if ( availableValues == null ) { |
232 | 249 |
this.availableValues = null; |
... | ... | |
239 | 256 |
return this; |
240 | 257 |
} |
241 | 258 |
|
259 |
@Override |
|
242 | 260 |
public DynObjectValueItem[] getAvailableValues() { |
243 | 261 |
return availableValues; |
244 | 262 |
} |
245 | 263 |
|
264 |
@Override |
|
246 | 265 |
public DynField setMinValue(Object minValue) { |
247 | 266 |
try { |
248 | 267 |
this.minValue = this.coerce(minValue); |
249 | 268 |
} catch (CoercionException e) { |
250 |
IllegalArgumentException ex = new IllegalArgumentException(e.getLocalizedMessage()); |
|
251 |
ex.initCause(e); |
|
252 |
throw ex; |
|
269 |
throw new IllegalArgumentException(); |
|
253 | 270 |
} |
254 | 271 |
return this; |
255 | 272 |
} |
256 | 273 |
|
274 |
@Override |
|
257 | 275 |
public Object getMinValue() { |
258 | 276 |
return minValue; |
259 | 277 |
} |
260 | 278 |
|
279 |
@Override |
|
261 | 280 |
public DynField setMaxValue(Object maxValue) { |
262 | 281 |
try { |
263 | 282 |
this.maxValue = this.coerce(maxValue); |
264 | 283 |
} catch (CoercionException e) { |
265 |
IllegalArgumentException ex = new IllegalArgumentException(e.getLocalizedMessage()); |
|
266 |
ex.initCause(e); |
|
267 |
throw ex; |
|
284 |
throw new IllegalArgumentException(e); |
|
268 | 285 |
} |
269 | 286 |
return this; |
270 | 287 |
} |
271 | 288 |
|
289 |
@Override |
|
272 | 290 |
public Object getMaxValue() { |
273 | 291 |
return maxValue; |
274 | 292 |
} |
275 | 293 |
|
294 |
@Override |
|
276 | 295 |
public boolean isMandatory() { |
277 | 296 |
return this.mandatory; |
278 | 297 |
} |
279 | 298 |
|
299 |
@Override |
|
280 | 300 |
public boolean isPersistent() { |
281 | 301 |
return this.persistent; |
282 | 302 |
} |
283 | 303 |
|
304 |
@Override |
|
284 | 305 |
public DynField setMandatory(boolean mandatory) { |
285 | 306 |
this.mandatory = mandatory; |
286 | 307 |
return this; |
287 | 308 |
} |
288 | 309 |
|
310 |
@Override |
|
289 | 311 |
public DynField setPersistent(boolean persistent) { |
290 | 312 |
this.persistent = persistent; |
291 | 313 |
return this; |
292 | 314 |
} |
293 | 315 |
|
316 |
@Override |
|
294 | 317 |
public DynField setTheTypeOfAvailableValues(int type) { |
295 | 318 |
return this; // FIXME: this method is @deprecated |
296 | 319 |
} |
297 | 320 |
|
321 |
@Override |
|
298 | 322 |
public int getTheTypeOfAvailableValues() { |
299 | 323 |
return 1; // FIXME: this method is @deprecated |
300 | 324 |
} |
301 | 325 |
|
326 |
@Override |
|
302 | 327 |
public boolean equals(Object obj) { |
303 | 328 |
if ( this == obj ) { |
304 | 329 |
return true; |
... | ... | |
310 | 335 |
return false; |
311 | 336 |
} |
312 | 337 |
|
338 |
@Override |
|
313 | 339 |
public Class getClassOfValue() { |
314 | 340 |
return this.type.getClassOfValue(); |
315 | 341 |
} |
316 | 342 |
|
343 |
@Override |
|
317 | 344 |
public DynField setClassOfValue(Class theClass) { |
318 | 345 |
this.type.setClassOfValue(theClass); |
319 | 346 |
return this; |
320 | 347 |
} |
321 | 348 |
|
349 |
@Override |
|
322 | 350 |
public DynField setClassOfValue(String theClassName) { |
323 | 351 |
this.type.setClassOfValue(theClassName); |
324 | 352 |
return this; |
325 | 353 |
} |
326 | 354 |
|
355 |
@Override |
|
327 | 356 |
public boolean isContainer() { |
328 | 357 |
if ( type.getDataType() == null ) { |
329 | 358 |
return false; |
... | ... | |
331 | 360 |
return type.getDataType().isContainer(); |
332 | 361 |
} |
333 | 362 |
|
363 |
@Override |
|
334 | 364 |
public void validate(Object value) throws DynFieldValidateException { |
335 | 365 |
Comparable v; |
336 | 366 |
if ( value == null ) { |
... | ... | |
494 | 524 |
} |
495 | 525 |
v = (Comparable) value; |
496 | 526 |
boolean ok = false; |
497 |
for ( int i = 0; i < this.availableValues.length; i++ ) {
|
|
498 |
if ( v.compareTo(this.availableValues[i].getValue()) == 0 ) {
|
|
527 |
for (DynObjectValueItem availableValue : this.availableValues) {
|
|
528 |
if (v.compareTo(availableValue.getValue()) == 0) {
|
|
499 | 529 |
ok = true; |
500 | 530 |
break; |
501 | 531 |
} |
... | ... | |
549 | 579 |
} |
550 | 580 |
} |
551 | 581 |
|
582 |
@Override |
|
552 | 583 |
public Object coerce(Object value) throws CoercionException { |
553 | 584 |
if ( value == null ) { |
554 | 585 |
return value; // O debe devolver this.defaultValue |
... | ... | |
560 | 591 |
} |
561 | 592 |
} |
562 | 593 |
|
594 |
@Override |
|
563 | 595 |
public String getGroup() { |
564 | 596 |
return this.groupName; |
565 | 597 |
} |
566 | 598 |
|
599 |
@Override |
|
567 | 600 |
public DynField setGroup(String groupName) { |
568 | 601 |
this.groupName = groupName; |
569 | 602 |
return this; |
570 | 603 |
} |
571 | 604 |
|
605 |
@Override |
|
572 | 606 |
public int getOder() { |
573 | 607 |
return this.order; |
574 | 608 |
} |
575 | 609 |
|
610 |
@Override |
|
576 | 611 |
public DynField setOrder(int order) { |
577 | 612 |
this.order = order; |
578 | 613 |
return this; |
579 | 614 |
} |
580 | 615 |
|
616 |
@Override |
|
581 | 617 |
public boolean isHidden() { |
582 | 618 |
return this.hidden; |
583 | 619 |
} |
584 | 620 |
|
621 |
@Override |
|
585 | 622 |
public DynField setHidden(boolean hidden) { |
586 | 623 |
this.hidden = hidden; |
587 | 624 |
return this; |
588 | 625 |
} |
589 | 626 |
|
627 |
@Override |
|
590 | 628 |
public boolean isReadOnly() { |
591 | 629 |
return this.isReadOnly; |
592 | 630 |
} |
593 | 631 |
|
632 |
@Override |
|
594 | 633 |
public DynField setReadOnly(boolean isReadOnly) { |
595 | 634 |
this.isReadOnly = isReadOnly; |
596 | 635 |
return this; |
597 | 636 |
} |
598 | 637 |
|
638 |
@Override |
|
599 | 639 |
public DynField setDefaultFieldValue(Object defaultValue) { |
600 | 640 |
try { |
601 | 641 |
this.defaultValue = this.coerce(defaultValue); |
602 | 642 |
} catch (CoercionException e) { |
603 |
IllegalArgumentException ex = new IllegalArgumentException(e.getLocalizedMessage()); |
|
604 |
ex.initCause(e); |
|
605 |
throw ex; |
|
643 |
throw new IllegalArgumentException(e); |
|
606 | 644 |
} |
607 | 645 |
return this; |
608 | 646 |
} |
609 | 647 |
|
648 |
@Override |
|
610 | 649 |
public Tags getTags() { |
611 | 650 |
return tags; |
612 | 651 |
} |
613 | 652 |
|
653 |
@Override |
|
614 | 654 |
public String getClassNameOfValue() { |
615 | 655 |
return this.type.getClassNameOfValue(); |
616 | 656 |
} |
617 | 657 |
|
658 |
@Override |
|
618 | 659 |
public DynField setClassOfValue(DynStruct dynStruct) { |
619 | 660 |
this.type.setClassOfValue(dynStruct); |
620 | 661 |
return this; |
621 | 662 |
} |
622 | 663 |
|
664 |
@Override |
|
623 | 665 |
public DynStruct getDynClassOfValue() { |
624 | 666 |
return this.type.getDynClassOfValue(); |
625 | 667 |
} |
626 | 668 |
|
669 |
@Override |
|
627 | 670 |
public int getRelationType() { |
628 | 671 |
return this.relationType; |
629 | 672 |
} |
630 | 673 |
|
674 |
@Override |
|
631 | 675 |
public DynField setRelationType(int relationType) { |
632 | 676 |
this.relationType = relationType; |
633 | 677 |
return this; |
634 | 678 |
} |
635 | 679 |
|
680 |
@Override |
|
636 | 681 |
public DynField setElementsType(int type) { |
637 | 682 |
this.setTypeOfItems(type); |
638 | 683 |
return this; |
639 | 684 |
} |
640 | 685 |
|
686 |
@Override |
|
641 | 687 |
public DynField setElementsType(DynStruct type) { |
642 | 688 |
this.setClassOfItems(type); |
643 | 689 |
return this; |
644 | 690 |
} |
645 | 691 |
|
692 |
@Override |
|
646 | 693 |
public DynField getElementsType() { |
647 | 694 |
throw new UnsupportedOperationException("This operation is not suported nevermore."); |
648 | 695 |
} |
649 | 696 |
|
697 |
@Override |
|
650 | 698 |
public DynField setClassOfItems(DynStruct dynStrct) { |
651 | 699 |
if ( !this.isContainer() ) { |
652 | 700 |
throw new IllegalStateException("Can't assign validateElements in non container."); |
... | ... | |
655 | 703 |
return this; |
656 | 704 |
} |
657 | 705 |
|
706 |
@Override |
|
658 | 707 |
public DynField setClassOfItems(String theClassNameOfValue) { |
659 | 708 |
if ( !this.isContainer() ) { |
660 | 709 |
throw new IllegalStateException("Can't assign validateElements in non container."); |
... | ... | |
663 | 712 |
return this; |
664 | 713 |
} |
665 | 714 |
|
715 |
@Override |
|
666 | 716 |
public String getClassNameOfItems() { |
667 | 717 |
if ( !this.isContainer() ) { |
668 | 718 |
throw new IllegalStateException("Can't assign validateElements in non container."); |
... | ... | |
670 | 720 |
return this.itemsType.getClassNameOfValue(); |
671 | 721 |
} |
672 | 722 |
|
723 |
@Override |
|
673 | 724 |
public DynStruct getDynClassOfItems() { |
674 | 725 |
if ( !this.isContainer() ) { |
675 | 726 |
throw new IllegalStateException("Can't assign validateElements in non container."); |
... | ... | |
677 | 728 |
return this.itemsType.getDynClassOfValue(); |
678 | 729 |
} |
679 | 730 |
|
731 |
@Override |
|
680 | 732 |
public DynField setClassOfItems(Class theClass) |
681 | 733 |
throws DynFieldIsNotAContainerException { |
682 | 734 |
if ( !this.isContainer() ) { |
... | ... | |
686 | 738 |
return this; |
687 | 739 |
} |
688 | 740 |
|
741 |
@Override |
|
689 | 742 |
public Class getClassOfItems() { |
690 | 743 |
if ( !this.isContainer() ) { |
691 | 744 |
throw new IllegalStateException("Can't assign validateElements in non container."); |
... | ... | |
693 | 746 |
return this.itemsType.getClassOfValue(); |
694 | 747 |
} |
695 | 748 |
|
749 |
@Override |
|
696 | 750 |
public DynField setTypeOfItems(int type) { |
697 | 751 |
if ( !this.isContainer() ) { |
698 | 752 |
throw new IllegalStateException("Can't assign validateElements in non container."); |
... | ... | |
701 | 755 |
return this; |
702 | 756 |
} |
703 | 757 |
|
758 |
@Override |
|
704 | 759 |
public int getTypeOfItems() { |
705 | 760 |
if ( !this.isContainer() ) { |
706 | 761 |
throw new IllegalStateException("Can't assign validateElements in non container."); |
Also available in: Unified diff