Revision 43610 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultFeatureType.java
DefaultFeatureType.java | ||
---|---|---|
29 | 29 |
import java.util.Collections; |
30 | 30 |
import java.util.Iterator; |
31 | 31 |
import java.util.List; |
32 |
import java.util.zip.CRC32; |
|
32 | 33 |
import org.apache.commons.lang3.ArrayUtils; |
33 | 34 |
import org.apache.commons.lang3.StringUtils; |
34 | 35 |
|
... | ... | |
777 | 778 |
return (FeatureAttributeDescriptor) super |
778 | 779 |
.get(this.defaultTimeAttributeIndex); |
779 | 780 |
} |
781 |
|
|
782 |
public void setDefaultTimeAttributeName(String name) { |
|
783 |
if (name == null || name.length() == 0) { |
|
784 |
this.defaultTimeAttributeIndex = -1; |
|
785 |
return; |
|
786 |
} |
|
787 |
DefaultFeatureAttributeDescriptor attr = (DefaultFeatureAttributeDescriptor) this.get(name); |
|
788 |
if (attr == null) { |
|
789 |
throw new IllegalArgumentException("Attribute '" + name + "' not found."); |
|
790 |
} |
|
791 |
if( attr.getIndex()<0 ) { |
|
792 |
fixAll(); |
|
793 |
} |
|
794 |
this.defaultTimeAttributeIndex = attr.getIndex(); |
|
795 |
} |
|
796 |
|
|
797 |
protected void fixAll() { |
|
798 |
int i = 0; |
|
799 |
Iterator iter = super.iterator(); |
|
800 |
DefaultFeatureAttributeDescriptor attr; |
|
801 |
|
|
802 |
while (iter.hasNext()) { |
|
803 |
attr = (DefaultFeatureAttributeDescriptor) iter.next(); |
|
804 |
attr.setIndex(i++); |
|
805 |
if (attr instanceof DefaultEditableFeatureAttributeDescriptor) { |
|
806 |
((DefaultEditableFeatureAttributeDescriptor) attr).fixAll(); |
|
807 |
} |
|
808 |
if (attr.getEvaluator() != null) { |
|
809 |
this.hasEvaluators = true; |
|
810 |
} |
|
811 |
if (attr.getFeatureAttributeEmulator() != null) { |
|
812 |
this.hasEmulators = true; |
|
813 |
} |
|
814 |
if (this.defaultGeometryAttributeName == null && attr.getType() == DataTypes.GEOMETRY) { |
|
815 |
this.defaultGeometryAttributeName = attr.getName(); |
|
816 |
} |
|
817 |
} |
|
818 |
if (this.defaultGeometryAttributeName != null) { |
|
819 |
this.defaultGeometryAttributeIndex = this.getIndex(this.defaultGeometryAttributeName); |
|
820 |
} |
|
821 |
this.internalID = Long.toHexString(this.getCRC()); |
|
822 |
|
|
823 |
} |
|
824 |
|
|
825 |
protected long getCRC() { |
|
826 |
StringBuffer buffer = new StringBuffer(); |
|
827 |
for (int i = 0; i < this.size(); i++) { |
|
828 |
FeatureAttributeDescriptor x = this.getAttributeDescriptor(i); |
|
829 |
buffer.append(x.getName()); |
|
830 |
buffer.append(x.getDataTypeName()); |
|
831 |
buffer.append(x.getSize()); |
|
832 |
} |
|
833 |
CRC32 crc = new CRC32(); |
|
834 |
byte[] data = buffer.toString().getBytes(); |
|
835 |
crc.update(data); |
|
836 |
return crc.getValue(); |
|
837 |
} |
|
780 | 838 |
} |
Also available in: Unified diff