Search in sources :

Example 41 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class XhtmlRecordWriter method write.

@Override
public void write(final Record record) {
    if (!this.opened) {
        writeHeader();
    }
    if (this.singleObject) {
        for (final FieldDefinition fieldDefinition : this.recordDefinition.getFields()) {
            final String fieldName = fieldDefinition.getName();
            final Object value = record.getValue(fieldName);
            if (isValueWritable(value)) {
                this.out.startTag(HtmlElem.TR);
                this.out.element(HtmlElem.TH, CaseConverter.toCapitalizedWords(fieldName));
                this.out.startTag(HtmlElem.TD);
                if (value == null) {
                    this.out.text("-");
                } else if (value instanceof URI) {
                    HtmlUtil.serializeA(this.out, null, value, value);
                } else {
                    writeValue(fieldDefinition, value);
                }
                this.out.endTag(HtmlElem.TD);
                this.out.endTag(HtmlElem.TR);
            }
        }
    } else {
        this.out.startTag(HtmlElem.TR);
        for (final FieldDefinition fieldDefinition : this.recordDefinition.getFields()) {
            final String fieldName = fieldDefinition.getName();
            final Object value;
            if (isWriteCodeValues()) {
                value = record.getCodeValue(fieldName);
            } else {
                value = record.getValue(fieldName);
            }
            this.out.startTag(HtmlElem.TD);
            if (value == null) {
                this.out.text("-");
            }
            if (value instanceof URI) {
                HtmlUtil.serializeA(this.out, null, value, value);
            } else {
                writeValue(fieldDefinition, value);
            }
            this.out.endTag(HtmlElem.TD);
        }
        this.out.endTag(HtmlElem.TR);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) URI(java.net.URI)

Example 42 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class JsonRecordWriter method write.

@Override
public void write(final Record record) {
    try {
        final Writer out = this.out;
        if (this.written) {
            out.write(",\n");
        } else {
            writeHeader();
        }
        startObject();
        boolean hasValue = false;
        for (final FieldDefinition field : this.recordDefinition.getFields()) {
            final int fieldIndex = field.getIndex();
            final Object value;
            if (isWriteCodeValues()) {
                value = record.getCodeValue(fieldIndex);
            } else {
                value = record.getValue(fieldIndex);
            }
            if (isValueWritable(value)) {
                if (hasValue) {
                    this.out.write(",\n");
                } else {
                    hasValue = true;
                }
                final String name = field.getName();
                label(name);
                final DataType dataType = field.getDataType();
                value(dataType, value);
            }
        }
        endObject();
    } catch (final IOException e) {
        throw Exceptions.wrap(e);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) IOException(java.io.IOException) AbstractRecordWriter(com.revolsys.io.AbstractRecordWriter) Writer(java.io.Writer)

Example 43 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class JsonSchemaWriter method write.

public void write(final RecordDefinition recordDefinition) {
    final Map<String, Object> recordDefinitionMap = new LinkedHashMap<>();
    recordDefinitionMap.put("name", recordDefinition.getPath());
    final List<Map<String, Object>> fields = new ArrayList<>();
    recordDefinitionMap.put("fields", fields);
    for (final FieldDefinition attribute : recordDefinition.getFields()) {
        final Map<String, Object> field = new LinkedHashMap<>();
        final String name = attribute.getName();
        field.put("name", name);
        final DataType dataType = attribute.getDataType();
        final String dataTypeName = dataType.getName();
        field.put("type", dataTypeName);
        final int length = attribute.getLength();
        if (length > 0) {
            field.put("length", length);
        }
        final int scale = attribute.getScale();
        if (scale > 0) {
            field.put("scale", scale);
        }
        final boolean required = attribute.isRequired();
        field.put("required", required);
        final Map<String, ?> attributeProperties = attribute.getProperties();
        final Map<String, Object> fieldProperties = toJsonMap(attributeProperties);
        if (!fieldProperties.isEmpty()) {
            field.put("properties", fieldProperties);
        }
        fields.add(field);
    }
    this.writer.write(recordDefinitionMap);
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) ArrayList(java.util.ArrayList) DataType(com.revolsys.datatype.DataType) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 44 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition 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);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) FieldType(com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType)

Example 45 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition 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);
}
Also used : GmlFieldType(com.revolsys.record.io.format.gml.type.GmlFieldType) QName(javax.xml.namespace.QName) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

FieldDefinition (com.revolsys.record.schema.FieldDefinition)133 RecordDefinition (com.revolsys.record.schema.RecordDefinition)38 DataType (com.revolsys.datatype.DataType)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 JdbcFieldDefinition (com.revolsys.jdbc.field.JdbcFieldDefinition)19 PathName (com.revolsys.io.PathName)15 Record (com.revolsys.record.Record)15 ArrayList (java.util.ArrayList)15 Geometry (com.revolsys.geometry.model.Geometry)13 CodeTable (com.revolsys.record.code.CodeTable)9 Query (com.revolsys.record.query.Query)8 LineString (com.revolsys.geometry.model.LineString)7 ArrayRecord (com.revolsys.record.ArrayRecord)7 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)7 SQLException (java.sql.SQLException)7 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 BadLocationException (javax.swing.text.BadLocationException)4