*/
protected List<AttributeDescriptor> readAttributes() throws IOException {
ShapefileSetManager shpManager = getDataStore().shpManager;
PrjFileReader prj = null;
ShapefileReader shp = null;
DbaseFileReader dbf = null;
CoordinateReferenceSystem crs = null;
AttributeTypeBuilder build = new AttributeTypeBuilder();
List<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>();
try {
shp = shpManager.openShapeReader(new GeometryFactory(), false);
dbf = shpManager.openDbfReader(false);
try {
prj = shpManager.openPrjReader();
if (prj != null) {
crs = prj.getCoordinateReferenceSystem();
}
} catch (FactoryException fe) {
crs = null;
}
Class<?> geometryClass = JTSUtilities.findBestGeometryClass(shp.getHeader()
.getShapeType());
build.setName(Classes.getShortName(geometryClass));
build.setNillable(true);
build.setCRS(crs);
build.setBinding(geometryClass);
GeometryType geometryType = build.buildGeometryType();
attributes.add(build.buildDescriptor(BasicFeatureTypes.GEOMETRY_ATTRIBUTE_NAME,
geometryType));
Set<String> usedNames = new HashSet<String>(); // record names in
// case of
// duplicates
usedNames.add(BasicFeatureTypes.GEOMETRY_ATTRIBUTE_NAME);
// take care of the case where no dbf and query wants all =>
// geometry only
if (dbf != null) {
DbaseFileHeader header = dbf.getHeader();
for (int i = 0, ii = header.getNumFields(); i < ii; i++) {
Class attributeClass = header.getFieldClass(i);
String name = header.getFieldName(i);
if (usedNames.contains(name)) {
String origional = name;
int count = 1;
name = name + count;
while (usedNames.contains(name)) {
count++;
name = origional + count;
}
build.addUserData(ShapefileDataStore.ORIGINAL_FIELD_NAME, origional);
build.addUserData(ShapefileDataStore.ORIGINAL_FIELD_DUPLICITY_COUNT, count);
}
usedNames.add(name);
int length = header.getFieldLength(i);
build.setNillable(true);
build.setLength(length);
build.setBinding(attributeClass);
attributes.add(build.buildDescriptor(name));
}
}
return attributes;
} finally {
try {
if (prj != null) {
prj.close();
}
} catch (IOException ioe) {
// do nothing
}
try {
if (dbf != null) {
dbf.close();
}
} catch (IOException ioe) {
// do nothing
}
try {