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);
}
}
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);
}
}
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);
}
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);
}
}
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);
}
Aggregations