use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class FeatureLayer method addField.
private void addField(final RecordDefinitionImpl recordDefinition, final String geometryType, final MapEx field) {
final String fieldName = field.getString("name");
final String fieldTitle = field.getString("string");
final String fieldType = field.getString("type");
final FieldType esriFieldType = FieldType.valueOf(fieldType);
final DataType dataType;
if (esriFieldType == FieldType.esriFieldTypeGeometry) {
final DataType geometryDataType = getGeometryDataType(geometryType);
if (geometryDataType == null) {
throw new IllegalArgumentException("No geometryType specified for " + getServiceUrl());
}
dataType = geometryDataType;
} else {
dataType = esriFieldType.getDataType();
}
if (dataType == null) {
throw new IllegalArgumentException("Unsupported field=" + fieldName + " type=" + dataType + " for " + getServiceUrl());
}
final int length = field.getInteger("length", 0);
final FieldDefinition fieldDefinition = recordDefinition.addField(fieldName, dataType, length, false);
fieldDefinition.setTitle(fieldTitle);
setCodeTable(fieldDefinition, field);
if (esriFieldType == FieldType.esriFieldTypeOID) {
recordDefinition.setIdFieldName(fieldName);
fieldDefinition.setRequired(true);
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class GmlRecordWriter method write.
@Override
public void write(final Record record) {
if (!this.opened) {
writeHeader();
}
this.out.startTag(Gml.FEATURE_MEMBER);
final RecordDefinition recordDefinition = record.getRecordDefinition();
QName qualifiedName = recordDefinition.getProperty(RecordProperties.QUALIFIED_NAME);
if (qualifiedName == null) {
final String typeName = recordDefinition.getPath();
final String path = PathUtil.getPath(typeName);
final String name = PathUtil.getName(typeName);
qualifiedName = new QName(path, name);
recordDefinition.setProperty(RecordProperties.QUALIFIED_NAME, qualifiedName);
}
this.out.startTag(qualifiedName);
for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
final String fieldName = fieldDefinition.getName();
final Object value;
if (isWriteCodeValues()) {
value = record.getCodeValue(fieldName);
} else {
value = record.getValue(fieldName);
}
if (isValueWritable(value)) {
this.out.startTag(this.namespaceUri, fieldName);
final DataType dataType = fieldDefinition.getDataType();
final GmlFieldType fieldType = this.fieldTypes.getFieldType(dataType);
if (fieldType != null) {
fieldType.writeValue(this.out, value);
}
this.out.endTag();
}
}
this.out.endTag(qualifiedName);
this.out.endTag(Gml.FEATURE_MEMBER);
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class FeatureSource method newLayer.
private FeatureLayer newLayer(final String name, final MapEx element, final MapEx complexType) {
if (!"true".equals(getString(complexType, "@abstract"))) {
final PathName pathName = getPathName();
final PathName layerPathName = pathName.newChild(name);
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(layerPathName);
GeometryFactory geometryFactory = GeometryFactory.DEFAULT_3D;
final MapEx complexContent = getValue(complexType, "xs:complexContent");
final MapEx extension = getValue(complexContent, "xs:extension");
if ("gml:AbstractFeatureType".equals(getString(extension, "@base"))) {
final MapEx sequence = getValue(extension, "xs:sequence");
final List<MapEx> elements = sequence.getValue("xs:element");
for (final MapEx fieldElement : elements) {
final String fieldName = getString(fieldElement, "@name");
final boolean required = !"0".equals(getString(fieldElement, "@minOccurs"));
DataType dataType = DataTypes.STRING;
final MapEx simpleFieldType = getValue(fieldElement, "xs:simpleType");
if (simpleFieldType == null) {
final String fieldType = getString(fieldElement, "@type");
if ("gml:AbstractGeometryType".equals(fieldType)) {
final String geometryTypes = getString(fieldElement, "@fdo:geometryTypes");
for (final String geometryType : geometryTypes.split(" ")) {
final DataType geometryDataType = DataTypes.getDataType(geometryType);
if (geometryDataType != DataTypes.OBJECT) {
if (dataType == DataTypes.STRING) {
dataType = geometryDataType;
} else if (dataType == DataTypes.GEOMETRY) {
} else if (geometryDataType == DataTypes.GEOMETRY) {
dataType = DataTypes.GEOMETRY;
} else if (geometryDataType == DataTypes.GEOMETRY_COLLECTION) {
dataType = DataTypes.GEOMETRY;
} else if (dataType.equals(DataTypes.POINT)) {
if (geometryDataType.equals(DataTypes.POINT)) {
} else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
dataType = DataTypes.MULTI_POINT;
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.MULTI_POINT)) {
if (geometryDataType.equals(DataTypes.POINT)) {
} else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.LINE_STRING)) {
if (geometryDataType.equals(DataTypes.LINE_STRING)) {
} else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
dataType = DataTypes.MULTI_LINE_STRING;
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.MULTI_LINE_STRING)) {
if (geometryDataType.equals(DataTypes.LINE_STRING)) {
} else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.POLYGON)) {
if (geometryDataType.equals(DataTypes.POLYGON)) {
} else if (geometryDataType.equals(DataTypes.MULTI_POLYGON)) {
dataType = DataTypes.MULTI_POLYGON;
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.MULTI_POLYGON)) {
if (geometryDataType.equals(DataTypes.POLYGON)) {
} else if (geometryDataType.equals(DataTypes.MULTI_POLYGON)) {
} else {
dataType = DataTypes.GEOMETRY;
}
}
}
}
if (dataType == DataTypes.STRING) {
dataType = DataTypes.GEOMETRY;
}
int axisCount = 2;
if ("true".equals(getString(fieldElement, "@fdo:hasMeasure"))) {
axisCount = 4;
} else if ("true".equals(getString(fieldElement, "@fdo:hasElevation"))) {
axisCount = 3;
}
final String srsName = getString(fieldElement, "@fdo:srsName");
if (Property.hasValue(srsName)) {
final Integer coordinateSystemId = Maps.getInteger(this.coordinateSystemIdBySrsName, srsName);
if (coordinateSystemId == null) {
try {
final Map<String, Object> csParameters = Collections.singletonMap("CSCODE", srsName);
final MapGuideWebService webService = getWebService();
final Resource wktResource = webService.getResource("CS.CONVERTCOORDINATESYSTEMCODETOWKT", null, csParameters);
final String wkt = wktResource.contentsAsString();
geometryFactory = GeometryFactory.floating(wkt, axisCount);
} catch (final Throwable e) {
}
} else {
geometryFactory = GeometryFactory.floating(coordinateSystemId, axisCount);
}
}
}
} else {
final MapEx restriction = getValue(simpleFieldType, "xs:restriction");
if (restriction != null) {
final String fieldBase = getString(restriction, "@base");
dataType = DataTypes.getDataType(fieldBase.replace("xs:", ""));
}
}
if (dataType != null) {
recordDefinition.addField(fieldName, dataType, required);
}
}
recordDefinition.setGeometryFactory(geometryFactory);
final FeatureLayer layer = new FeatureLayer(this, recordDefinition);
return layer;
}
}
return null;
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class XbaseIterator method loadRecord.
protected Record loadRecord() throws IOException {
if (this.in.read(this.recordBuffer) != this.recordBuffer.length) {
throw new IllegalStateException("Unexpected end of mappedFile");
}
final Record object = this.recordFactory.newRecord(this.recordDefinition);
int startIndex = 0;
for (int i = 0; i < this.recordDefinition.getFieldCount(); i++) {
int len = this.recordDefinition.getFieldLength(i);
final DataType type = this.recordDefinition.getFieldType(i);
Object value = null;
if (type == DataTypes.STRING) {
if (len < 255) {
value = getString(startIndex, len);
} else {
value = getMemo(startIndex, len);
len = 10;
}
} else if (type == DataTypes.DECIMAL || type == DataTypes.FLOAT) {
value = getNumber(startIndex, len);
} else if (type == DataTypes.BOOLEAN) {
value = getBoolean(startIndex);
} else if (type == DataTypes.DATE_TIME) {
value = getDate(startIndex, len);
}
startIndex += len;
object.setValue(i, value);
}
return object;
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class XbaseIterator method readRecordDefinition.
private void readRecordDefinition() throws IOException {
this.recordDefinition = new RecordDefinitionImpl(this.typeName);
int b = this.in.read();
while (b != 0x0D) {
final StringBuilder fieldName = new StringBuilder();
boolean endOfName = false;
for (int i = 0; i < 11; i++) {
if (!endOfName && b != 0) {
fieldName.append((char) b);
} else {
endOfName = true;
}
if (i != 10) {
b = this.in.read();
}
}
final char fieldType = (char) this.in.read();
this.in.skipBytes(4);
int length = this.in.read();
final int decimalCount = this.in.read();
this.in.skipBytes(14);
b = this.in.read();
final DataType dataType = DATA_TYPES.get(fieldType);
if (fieldType == MEMO_TYPE) {
length = Integer.MAX_VALUE;
}
this.recordDefinition.addField(fieldName.toString(), dataType, length, decimalCount, false);
}
if (this.mappedFile) {
final EndianMappedByteBuffer file = (EndianMappedByteBuffer) this.in;
this.firstIndex = file.getFilePointer();
}
}
Aggregations