Revision 45990
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/CSVStoreProvider.java | ||
---|---|---|
574 | 574 |
private Coercion coercion[]; |
575 | 575 |
private CoercionContext coercionContext[]; |
576 | 576 |
private int sizes[]; |
577 |
private String[] names; |
|
577 | 578 |
private final boolean ignore_errors; |
578 | 579 |
private long count_errors; |
579 | 580 |
private FeatureType csvFeatureType; |
... | ... | |
590 | 591 |
public void initialize(FeatureType ftype) { |
591 | 592 |
this.csvFeatureType = ftype; |
592 | 593 |
int columns = this.csvFeatureType.size(); |
594 |
this.names = new String[columns]; |
|
593 | 595 |
this.coercion = new Coercion[columns]; |
594 | 596 |
this.coercionContext = new CoercionContext[columns]; |
595 | 597 |
this.sizes = new int[columns]; |
598 |
int index = 0; |
|
596 | 599 |
for (int i = 0; i < this.csvFeatureType.size(); i++) { |
597 | 600 |
FeatureAttributeDescriptor ad = this.csvFeatureType.getAttributeDescriptor(i); |
598 |
coercion[i] = ad.getCoercion(); |
|
599 |
coercionContext[i] = ad.getCoercionContext(); |
|
600 |
sizes[i] = ad.getSize(); |
|
601 |
// sizes[i] = -1; |
|
602 |
// switch (ad.getDataType().getType()) { |
|
603 |
// case DataTypes.INT: |
|
604 |
// sizes[i] = 0; |
|
605 |
// break; |
|
606 |
// case DataTypes.LONG: |
|
607 |
// sizes[i] = 0; |
|
608 |
// break; |
|
609 |
// case DataTypes.STRING: |
|
610 |
// if (ad.getSize() == 0) { |
|
611 |
// // Es un string y no tiene un size asignado. |
|
612 |
// // Lo ponemos a cero para calcularlo. |
|
613 |
// sizes[i] = 0; |
|
614 |
// } |
|
615 |
// break; |
|
616 |
// case DataTypes.URL: |
|
617 |
// case DataTypes.URI: |
|
618 |
// case DataTypes.FILE: |
|
619 |
// sizes[i] = 0; |
|
620 |
// } |
|
601 |
names[i] = null; |
|
602 |
if( ad.isComputed() ) { |
|
603 |
continue; |
|
604 |
} |
|
605 |
names[index] = ad.getName(); |
|
606 |
coercion[index] = ad.getCoercion(); |
|
607 |
coercionContext[index] = ad.getCoercionContext(); |
|
608 |
sizes[index] = ad.getSize(); |
|
609 |
index++; |
|
621 | 610 |
} |
622 | 611 |
} |
623 | 612 |
|
624 | 613 |
public void translate(long rowindex, List<String> row, FeatureProvider feature) throws Exception { |
625 | 614 |
|
626 | 615 |
feature.setOID(rowindex); |
627 |
FeatureType featureType = feature.getType();
|
|
628 |
|
|
629 |
for (FeatureAttributeDescriptor attr : featureType) {
|
|
630 |
int featureAttrIndex = attr.getIndex();
|
|
631 |
int csvAttrIndex = csvFeatureType.getAttributeDescriptor(attr.getName()).getIndex();
|
|
632 |
Object rawvalue = row.get(csvAttrIndex);
|
|
616 |
for (int i = 0; i < names.length; i++) {
|
|
617 |
String name = names[i]; |
|
618 |
if( name == null ) {
|
|
619 |
break;
|
|
620 |
}
|
|
621 |
Object rawvalue = row.get(i);
|
|
633 | 622 |
try { |
634 | 623 |
Object value = null; |
635 |
if (coercion[csvAttrIndex] != null) {
|
|
636 |
value = coercion[csvAttrIndex].coerce(rawvalue, coercionContext[csvAttrIndex]);
|
|
624 |
if (coercion[i] != null) {
|
|
625 |
value = coercion[i].coerce(rawvalue, coercionContext[i]);
|
|
637 | 626 |
} |
638 |
feature.set(featureAttrIndex, value);
|
|
639 |
if (sizes[csvAttrIndex] >= 0
|
|
627 |
feature.set(name, value);
|
|
628 |
if (sizes[i] >= 0
|
|
640 | 629 |
&& (value instanceof String || value instanceof URL |
641 | 630 |
|| value instanceof URI || value instanceof File)) { |
642 | 631 |
int x = value.toString().length(); |
643 |
if (sizes[csvAttrIndex] < x) {
|
|
644 |
sizes[csvAttrIndex] = x;
|
|
632 |
if (sizes[i] < x) {
|
|
633 |
sizes[i] = x;
|
|
645 | 634 |
} |
646 | 635 |
} |
647 | 636 |
} catch (Exception ex) { |
... | ... | |
649 | 638 |
throw ex; |
650 | 639 |
} |
651 | 640 |
if (count_errors++ < 10) { |
652 |
LOGGER.warn("Can't load value of attribute " + featureAttrIndex + " in row " + rowindex + ".", ex);
|
|
641 |
LOGGER.warn("Can't load value of attribute " + name +"/" +i+" in row " + rowindex + ".", ex);
|
|
653 | 642 |
} |
654 | 643 |
if (count_errors == 10) { |
655 | 644 |
LOGGER.info("Too many errors, suppress messages."); |
Also available in: Unified diff