use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class MapReaderRecordReader method next.
@Override
public Record next() {
if (hasNext()) {
final MapEx source = this.mapIterator.next();
final Record target = new ArrayRecord(this.recordDefinition);
for (final FieldDefinition field : this.recordDefinition.getFields()) {
final String name = field.getName();
final Object value = source.get(name);
if (value != null) {
final DataType dataType = this.recordDefinition.getFieldType(name);
final Object convertedValue;
try {
convertedValue = dataType.toObject(value);
} catch (final Throwable e) {
throw new FieldValueInvalidException(name, value, e);
}
target.setValue(name, convertedValue);
}
}
return target;
} else {
throw new NoSuchElementException();
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class SaifReader method open.
/**
* Open a SAIF archive, extracting compressed archives to a temporary
* directory.
*/
@Override
public void open() {
if (!this.opened) {
this.opened = true;
try {
if (log.isDebugEnabled()) {
log.debug("Opening SAIF archive '" + this.file.getCanonicalPath() + "'");
}
if (this.file.isDirectory()) {
this.saifArchiveDirectory = this.file;
} else if (!this.file.exists()) {
throw new IllegalArgumentException("SAIF file " + this.file + " does not exist");
} else {
this.zipFile = new ZipFile(this.file);
}
if (log.isDebugEnabled()) {
log.debug(" Finished opening archive");
}
loadSchema();
loadExportedObjects();
loadSrid();
final GeometryFactory geometryFactory = GeometryFactory.fixed3d(this.srid, 1.0, 1.0, 1.0);
for (final RecordDefinition recordDefinition : ((RecordDefinitionFactoryImpl) this.recordDefinitionFactory).getRecordDefinitions()) {
final FieldDefinition geometryField = recordDefinition.getGeometryField();
if (geometryField != null) {
geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
}
}
} catch (final IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class SaifSchemaReader method restricted.
public void restricted(final RecordDefinition type, final CsnIterator iterator) throws IOException {
while (iterator.getNextEventType() == CsnIterator.ATTRIBUTE_PATH) {
iterator.next();
String fieldName = iterator.getStringValue();
boolean hasMore = true;
final List<String> typePaths = new ArrayList<>();
final List<Object> values = new ArrayList<>();
while (hasMore) {
switch(iterator.getNextEventType()) {
case CsnIterator.CLASS_NAME:
iterator.next();
final String typePath = iterator.getPathValue();
typePaths.add(typePath);
break;
case CsnIterator.FORCE_TYPE:
iterator.next();
if (iterator.next() == CsnIterator.CLASS_NAME) {
typePaths.add(iterator.getPathValue());
} else {
throw new IllegalStateException("Expecting a class name");
}
break;
case CsnIterator.EXCLUDE_TYPE:
iterator.next();
if (iterator.next() == CsnIterator.CLASS_NAME) {
typePaths.add(iterator.getPathValue());
} else {
throw new IllegalStateException("Expecting a class name");
}
break;
case CsnIterator.VALUE:
iterator.next();
values.add(iterator.getValue());
break;
default:
hasMore = false;
break;
}
}
fieldName = fieldName.replaceFirst("position.geometry", "position");
final int dotIndex = fieldName.indexOf('.');
if (dotIndex == -1) {
final FieldDefinition attribute = type.getField(fieldName);
if (attribute != null) {
if (!typePaths.isEmpty()) {
attribute.setProperty(FieldProperties.ALLOWED_TYPE_NAMES, typePaths);
}
if (!values.isEmpty()) {
attribute.setProperty(FieldProperties.ALLOWED_VALUES, values);
}
}
} else {
final String key = fieldName.substring(0, dotIndex);
final String subKey = fieldName.substring(dotIndex + 1);
final FieldDefinition attribute = type.getField(key);
if (attribute != null) {
if (!typePaths.isEmpty()) {
Map<String, List<String>> allowedValues = attribute.getProperty(FieldProperties.FIELD_ALLOWED_TYPE_NAMES);
if (allowedValues == null) {
allowedValues = new HashMap<>();
attribute.setProperty(FieldProperties.FIELD_ALLOWED_TYPE_NAMES, allowedValues);
}
allowedValues.put(subKey, typePaths);
}
if (!values.isEmpty()) {
Map<String, List<Object>> allowedValues = attribute.getProperty(FieldProperties.FIELD_ALLOWED_VALUES);
if (allowedValues == null) {
allowedValues = new HashMap<>();
attribute.setProperty(FieldProperties.FIELD_ALLOWED_VALUES, allowedValues);
}
allowedValues.put(subKey, values);
}
}
}
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class SaifSchemaReader method addSuperClass.
public void addSuperClass(final RecordDefinitionImpl currentClass, final RecordDefinition superClass) {
currentClass.addSuperClass(superClass);
for (final String name : superClass.getFieldNames()) {
final FieldDefinition attribute = superClass.getField(name);
currentClass.addField(attribute.clone());
}
for (final Entry<String, Object> defaultValue : superClass.getDefaultValues().entrySet()) {
final String name = defaultValue.getKey();
final Object value = defaultValue.getValue();
if (!currentClass.hasField(name)) {
currentClass.addDefaultValue(name, value);
}
}
final String idFieldName = superClass.getIdFieldName();
if (idFieldName != null) {
currentClass.setIdFieldName(idFieldName);
}
String geometryFieldName = superClass.getGeometryFieldName();
final String path = currentClass.getPath();
if (path.equals("/TRIM/TrimText")) {
geometryFieldName = "textOrSymbol";
}
if (geometryFieldName != null) {
currentClass.setGeometryFieldName(geometryFieldName);
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class Value method setRecordDefinition.
@Override
public void setRecordDefinition(final RecordDefinition recordDefinition) {
final String fieldName = this.fieldDefinition.getName();
if (Property.hasValue(fieldName)) {
final FieldDefinition field = recordDefinition.getField(fieldName);
setFieldDefinition(field);
}
}
Aggregations