use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class EsriXmlRecordDefinitionUtil method getRecordDefinition.
public static RecordDefinition getRecordDefinition(final String schemaName, final Domain domain, final boolean appendIdToName) {
final String tableName;
if (appendIdToName) {
tableName = domain.getName() + "_ID";
} else {
tableName = domain.getName();
}
final PathName typePath = PathName.newPathName(PathUtil.toPath(schemaName, tableName));
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(typePath);
final FieldType fieldType = domain.getFieldType();
final DataType dataType = EsriGeodatabaseXmlFieldTypeRegistry.INSTANCE.getDataType(fieldType);
int length = 0;
for (final CodedValue codedValue : domain.getCodedValues()) {
length = Math.max(length, codedValue.getCode().toString().length());
}
recordDefinition.addField(tableName, dataType, length, true);
recordDefinition.addField("DESCRIPTION", DataTypes.STRING, 255, true);
recordDefinition.setIdFieldIndex(0);
return recordDefinition;
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class RecordDefinitionConvertRecordReader method next.
@Override
public Record next() {
if (hasNext()) {
final Record source = this.iterator.next();
final Record target = new ArrayRecord(this.recordDefinition);
for (final FieldDefinition attribute : this.recordDefinition.getFields()) {
final String name = attribute.getName();
final Object value = source.getValue(name);
if (value != null) {
final DataType dataType = this.recordDefinition.getFieldType(name);
final Object convertedValue = dataType.toObject(value);
target.setValue(name, convertedValue);
}
}
return target;
} else {
throw new NoSuchElementException();
}
}
use of com.revolsys.datatype.DataType 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.datatype.DataType in project com.revolsys.open by revolsys.
the class ShapefileGeometryHandler method getShapeType.
public int getShapeType(final Geometry geometry) {
if (geometry != null) {
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
final DataType dataType = geometry.getDataType();
return getShapeType(geometryFactory, dataType);
}
return ShapefileConstants.NULL_SHAPE;
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class SaifSchemaReader method getDefinition.
private Object getDefinition(final CsnIterator iterator) throws IOException {
while (iterator.next() != CsnIterator.END_DEFINITION) {
switch(iterator.getEventType()) {
case CsnIterator.CLASS_NAME:
final String superClassName = iterator.getPathValue();
if (superClassName.equals("/Enumeration")) {
final DataType enumeration = processEnumeration(iterator);
nameTypeMap.put(enumeration.getName(), enumeration);
return enumeration;
}
final RecordDefinition superClass = this.schema.getRecordDefinition(superClassName);
if (superClass == null) {
throw new IllegalStateException("Cannot find super class '" + superClassName + "'");
}
this.currentSuperClasses.add(superClass);
break;
case CsnIterator.COMPONENT_NAME:
final String componentName = iterator.getStringValue();
try {
final Method method = getClass().getMethod(componentName, new Class[] { RecordDefinition.class, CsnIterator.class });
method.invoke(this, new Object[] { this.currentClass, iterator });
} catch (final SecurityException e) {
throw new IllegalStateException("Unknown component '" + componentName + "'");
} catch (final NoSuchMethodException e) {
throw new IllegalStateException("Unknown component '" + componentName + "'");
} catch (final IllegalAccessException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (final InvocationTargetException e) {
final Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else if (cause instanceof Error) {
throw (Error) cause;
} else if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new RuntimeException(cause.getMessage(), cause);
}
}
default:
break;
}
}
return this.currentClass;
}
Aggregations