Search in sources :

Example 6 with DataType

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

Example 7 with DataType

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();
    }
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) NoSuchElementException(java.util.NoSuchElementException)

Example 8 with DataType

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();
    }
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) FieldValueInvalidException(com.revolsys.record.FieldValueInvalidException) MapEx(com.revolsys.collection.map.MapEx) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) NoSuchElementException(java.util.NoSuchElementException)

Example 9 with DataType

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;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType)

Example 10 with DataType

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;
}
Also used : Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RecordDefinition(com.revolsys.record.schema.RecordDefinition) CollectionDataType(com.revolsys.datatype.CollectionDataType) EnumerationDataType(com.revolsys.datatype.EnumerationDataType) SimpleDataType(com.revolsys.datatype.SimpleDataType) DataType(com.revolsys.datatype.DataType)

Aggregations

DataType (com.revolsys.datatype.DataType)85 FieldDefinition (com.revolsys.record.schema.FieldDefinition)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 PathName (com.revolsys.io.PathName)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Geometry (com.revolsys.geometry.model.Geometry)10 Record (com.revolsys.record.Record)10 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)10 ArrayList (java.util.ArrayList)8 ArrayRecord (com.revolsys.record.ArrayRecord)6 PrintWriter (java.io.PrintWriter)6 EsriGeodatabaseXmlFieldType (com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)5 MapEx (com.revolsys.collection.map.MapEx)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 Point (com.revolsys.geometry.model.Point)4 IOException (java.io.IOException)4 Map (java.util.Map)4 CollectionDataType (com.revolsys.datatype.CollectionDataType)3 EnumerationDataType (com.revolsys.datatype.EnumerationDataType)3 CodeTable (com.revolsys.record.code.CodeTable)3