Search in sources :

Example 1 with OsnSerializer

use of com.revolsys.record.io.format.saif.util.OsnSerializer in project com.revolsys.open by revolsys.

the class SaifWriter method writeExports.

private void writeExports() throws IOException {
    final File exportsFile = new File(this.tempDirectory, "exports.dir");
    final OsnSerializer exportsSerializer = newSerializer("/ExportedObject", exportsFile, Long.MAX_VALUE);
    exportsSerializer.startObject("/ExportedObjects");
    exportsSerializer.fieldName("handles");
    exportsSerializer.startCollection("Set");
    writeExport(exportsSerializer, "GlobalMetadata", "GlobalMetadata", "globmeta.osn");
    for (final Map<String, Object> export : this.exports.values()) {
        final String compositeType = (String) export.get("compositeType");
        final String referenceId = (String) export.get("referenceId");
        final String objectSubset = (String) export.get("objectSubset");
        String compositeTypeName = PathUtil.getName(compositeType);
        final String compositeNamespace = PathUtil.getPath(compositeType).replaceAll("/", "");
        if (Property.hasValue(compositeNamespace)) {
            compositeTypeName += "::" + compositeNamespace;
        }
        writeExport(exportsSerializer, referenceId, compositeTypeName, objectSubset);
    }
    exportsSerializer.close();
}
Also used : OsnSerializer(com.revolsys.record.io.format.saif.util.OsnSerializer) File(java.io.File)

Example 2 with OsnSerializer

use of com.revolsys.record.io.format.saif.util.OsnSerializer in project com.revolsys.open by revolsys.

the class SaifWriter method write.

@Override
public void write(final Record object) {
    try {
        final RecordDefinition type = object.getRecordDefinition();
        final OsnSerializer serializer = getSerializer(type.getPath());
        if (serializer != null) {
            serializer.serializeRecord(object);
            if (this.indentEnabled) {
                serializer.endLine();
            }
        } else {
            log.error("No serializer for type '" + type.getPath() + "'");
        }
    } catch (final IOException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : OsnSerializer(com.revolsys.record.io.format.saif.util.OsnSerializer) IOException(java.io.IOException) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 3 with OsnSerializer

use of com.revolsys.record.io.format.saif.util.OsnSerializer in project com.revolsys.open by revolsys.

the class SaifWriter method newSerializer.

protected OsnSerializer newSerializer(final String typePath, final File file, final long maxSize) throws IOException {
    final OsnSerializer serializer = new OsnSerializer(typePath, file, maxSize, this.converters);
    serializer.setIndentEnabled(this.indentEnabled);
    return serializer;
}
Also used : OsnSerializer(com.revolsys.record.io.format.saif.util.OsnSerializer)

Example 4 with OsnSerializer

use of com.revolsys.record.io.format.saif.util.OsnSerializer in project com.revolsys.open by revolsys.

the class SaifWriter method writeMissingGlobalMetadata.

private void writeMissingGlobalMetadata() {
    if (!this.exports.containsKey(GLOBAL_METADATA)) {
        try {
            addExport(GLOBAL_METADATA, GLOBAL_METADATA, "globmeta.osn");
            final File metaFile = new File(this.tempDirectory, "globmeta.osn");
            final OsnSerializer serializer = newSerializer(GLOBAL_METADATA, metaFile, Long.MAX_VALUE);
            serializer.startObject("/GlobalMetadata");
            serializer.attribute("objectIdentifier", "GlobalMetadata", true);
            serializer.fieldName("creationTime");
            serializer.startObject("/TimeStamp");
            final Date creationTimestamp = new Date(System.currentTimeMillis());
            serializer.attribute("year", new BigDecimal(creationTimestamp.getYear() + 1900), true);
            serializer.attribute("month", new BigDecimal(creationTimestamp.getMonth() + 1), true);
            serializer.attribute("day", new BigDecimal(creationTimestamp.getDate()), true);
            serializer.attribute("hour", new BigDecimal(creationTimestamp.getHours()), true);
            serializer.attribute("minute", new BigDecimal(creationTimestamp.getMinutes()), true);
            serializer.attribute("second", new BigDecimal(creationTimestamp.getSeconds()), true);
            serializer.endObject();
            serializer.fieldName("saifProfile");
            serializer.startObject("/Profile");
            serializer.attribute("authority", "Government of British Columbia", true);
            serializer.attribute("idName", "SAIFLite", true);
            serializer.attribute("version", "Release 1.1", true);
            serializer.endObject();
            serializer.attribute("saifRelease", "SAIF 3.2", true);
            serializer.attribute("toolkitVersion", "SAIF Toolkit Version 1.4.0 (May 05, 1997)", true);
            serializer.fieldName("userProfile");
            serializer.startObject("/UserProfile");
            serializer.fieldName("coordDefs");
            serializer.startObject("/LocationalDefinitions");
            serializer.attributeEnum("c1", "real32", true);
            serializer.attributeEnum("c2", "real32", true);
            serializer.attributeEnum("c3", "real32", true);
            serializer.endObject();
            serializer.attribute("organization", new BigDecimal("4"), true);
            serializer.endObject();
            serializer.endObject();
            serializer.close();
        } catch (final IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
Also used : OsnSerializer(com.revolsys.record.io.format.saif.util.OsnSerializer) IOException(java.io.IOException) File(java.io.File) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 5 with OsnSerializer

use of com.revolsys.record.io.format.saif.util.OsnSerializer in project com.revolsys.open by revolsys.

the class SaifWriter method getSerializer.

private OsnSerializer getSerializer(final String typePath) throws IOException {
    OsnSerializer serializer = this.serializers.get(typePath);
    if (serializer == null) {
        initialize();
        try {
            final RecordDefinition compositeType = getCompositeType(typePath);
            if (compositeType != null) {
                final String objectSubsetName = getObjectSubsetName(typePath);
                if (this.maxSubsetSize != Long.MAX_VALUE) {
                    FileUtil.deleteFiles(this.tempDirectory, ObjectSetUtil.getObjectSubsetPrefix(objectSubsetName) + "...osn");
                    serializer = newSerializer(typePath, new File(this.tempDirectory, objectSubsetName), this.maxSubsetSize);
                } else {
                    serializer = newSerializer(typePath, new File(this.tempDirectory, objectSubsetName), Long.MAX_VALUE);
                }
                if (compositeType.isInstanceOf(this.annotatedSpatialDataSetType)) {
                    serializer.startObject(compositeType.getPath());
                    serializer.fieldName("objectIdentifier");
                    final String objectIdentifier = getObjectIdentifier(typePath);
                    serializer.attributeValue(objectIdentifier);
                    serializer.endLine();
                    serializer.serializeIndent();
                    serializer.fieldName("annotationComponents");
                    serializer.startCollection("Set");
                } else if (compositeType.isInstanceOf(this.spatialDataSetType)) {
                    serializer.startObject(compositeType.getPath());
                    serializer.fieldName("objectIdentifier");
                    final String objectIdentifier = getObjectIdentifier(typePath);
                    serializer.attributeValue(objectIdentifier);
                    serializer.endLine();
                    serializer.serializeIndent();
                    serializer.fieldName("geoComponents");
                    serializer.startCollection("Set");
                }
                addExport(typePath, compositeType.getPath(), objectSubsetName);
                this.serializers.put(typePath, serializer);
            } else if (typePath.equals("/ImportedObjects")) {
                serializer = newSerializer("/ImportedObject", new File(this.tempDirectory, "imports.dir"), Long.MAX_VALUE);
                this.serializers.put(typePath, serializer);
            } else if (PathUtil.getName(typePath).endsWith("InternallyReferencedObjects")) {
                serializer = newSerializer("/InternallyReferencedObject", new File(this.tempDirectory, "internal.dir"), Long.MAX_VALUE);
                this.serializers.put(typePath, serializer);
            } else if (PathUtil.getName(typePath).endsWith("GlobalMetadata")) {
                serializer = newSerializer(GLOBAL_METADATA, new File(this.tempDirectory, "globmeta.osn"), Long.MAX_VALUE);
                addExport(typePath, typePath, "globmeta.osn");
                this.serializers.put(typePath, serializer);
            }
        } catch (final IOException e) {
            log.error("Unable to create serializer: " + e.getMessage(), e);
        }
    }
    return serializer;
}
Also used : OsnSerializer(com.revolsys.record.io.format.saif.util.OsnSerializer) IOException(java.io.IOException) File(java.io.File) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

OsnSerializer (com.revolsys.record.io.format.saif.util.OsnSerializer)6 IOException (java.io.IOException)4 File (java.io.File)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1