Commit 66efcf85 authored by Luc Maisonobe's avatar Luc Maisonobe

Fixed structure of XML files.

parent 41bf72cd
......@@ -41,6 +41,9 @@ import org.orekit.utils.TimeStampedAngularCoordinates;
public class AemFile extends NdmFile<Header, AemSegment>
implements AttitudeEphemerisFile<TimeStampedAngularCoordinates, AemSegment> {
/** Root element for XML files. */
public static final String ROOT = "aem";
/** Key for format version. */
public static final String FORMAT_VERSION_KEY = "CCSDS_AEM_VERS";
......
......@@ -56,9 +56,6 @@ import org.orekit.utils.IERSConventions;
*/
public class AemParser extends AdmParser<AemFile, AemParser> implements AttitudeEphemerisFileParser<AemFile> {
/** Root element for XML files. */
private static final String ROOT = "aem";
/** Pattern for splitting strings at blanks. */
private static final Pattern SPLIT_AT_BLANKS = Pattern.compile("\\s+");
......@@ -102,7 +99,7 @@ public class AemParser extends AdmParser<AemFile, AemParser> implements Attitude
public AemParser(final IERSConventions conventions, final boolean simpleEOP,
final DataContext dataContext,
final AbsoluteDate missionReferenceDate, final int defaultInterpolationDegree) {
super(ROOT, AemFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, missionReferenceDate);
super(AemFile.ROOT, AemFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, missionReferenceDate);
this.defaultInterpolationDegree = defaultInterpolationDegree;
}
......@@ -126,7 +123,7 @@ public class AemParser extends AdmParser<AemFile, AemParser> implements Attitude
metadata = null;
context = null;
if (fileFormat == FileFormat.XML) {
structureProcessor = new XmlStructureProcessingState(ROOT, this);
structureProcessor = new XmlStructureProcessingState(AemFile.ROOT, this);
reset(fileFormat, structureProcessor);
} else {
structureProcessor = new KvnStructureProcessingState(this);
......
......@@ -257,7 +257,7 @@ public class AemWriter extends AbstractMessageWriter<Header, AemSegment, AemFile
*/
public AemWriter(final IERSConventions conventions, final DataContext dataContext,
final AbsoluteDate missionReferenceDate) {
super(AemFile.FORMAT_VERSION_KEY, CCSDS_AEM_VERS,
super(AemFile.ROOT, AemFile.FORMAT_VERSION_KEY, CCSDS_AEM_VERS,
new ContextBinding(
() -> conventions, () -> true, () -> dataContext,
() -> missionReferenceDate, () -> TimeSystem.UTC,
......@@ -266,7 +266,7 @@ public class AemWriter extends AbstractMessageWriter<Header, AemSegment, AemFile
/** {@inheritDoc} */
@Override
public void writeSegment(final Generator generator, final AemSegment segment) throws IOException {
public void writeSegmentContent(final Generator generator, final AemSegment segment) throws IOException {
final AemMetadata metadata = segment.getMetadata();
writeMetadata(generator, metadata);
......
......@@ -138,12 +138,16 @@ public class AttitudeWriter implements AttitudeEphemerisFileWriter {
try (Generator generator = fileFormat == FileFormat.KVN ?
new KvnGenerator(appendable, AemWriter.KVN_PADDING_WIDTH, outputName) :
new XmlGenerator(appendable, XmlGenerator.DEFAULT_INDENT, outputName)) {
writer.writeHeader(generator, header);
// Loop on segments
for (final S segment : segments) {
writeSegment(generator, segment);
}
writer.writeFooter(generator);
}
}
......
......@@ -41,6 +41,9 @@ import org.orekit.utils.TimeStampedAngularCoordinates;
*/
public class ApmFile extends NdmFile<Header, Segment<AdmMetadata, ApmData>> {
/** Root element for XML files. */
public static final String ROOT = "apm";
/** Key for format version. */
public static final String FORMAT_VERSION_KEY = "CCSDS_APM_VERS";
......
......@@ -54,9 +54,6 @@ import org.orekit.utils.IERSConventions;
*/
public class ApmParser extends AdmParser<ApmFile, ApmParser> {
/** Root element for XML files. */
private static final String ROOT = "apm";
/** File header. */
private Header header;
......@@ -108,7 +105,7 @@ public class ApmParser extends AdmParser<ApmFile, ApmParser> {
public ApmParser(final IERSConventions conventions, final boolean simpleEOP,
final DataContext dataContext,
final AbsoluteDate missionReferenceDate) {
super(ROOT, ApmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, missionReferenceDate);
super(ApmFile.ROOT, ApmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, missionReferenceDate);
}
/** {@inheritDoc} */
......@@ -131,7 +128,7 @@ public class ApmParser extends AdmParser<ApmFile, ApmParser> {
currentManeuver = null;
maneuvers = new ArrayList<>();
if (fileFormat == FileFormat.XML) {
structureProcessor = new XmlStructureProcessingState(ROOT, this);
structureProcessor = new XmlStructureProcessingState(ApmFile.ROOT, this);
reset(fileFormat, structureProcessor);
} else {
structureProcessor = new ErrorState(); // should never be called
......
......@@ -59,7 +59,7 @@ public class ApmWriter extends AbstractMessageWriter<Header, Segment<AdmMetadata
*/
public ApmWriter(final IERSConventions conventions, final DataContext dataContext,
final AbsoluteDate missionReferenceDate) {
super(ApmFile.FORMAT_VERSION_KEY, CCSDS_APM_VERS,
super(ApmFile.ROOT, ApmFile.FORMAT_VERSION_KEY, CCSDS_APM_VERS,
new ContextBinding(
() -> conventions, () -> false, () -> dataContext,
() -> missionReferenceDate, () -> TimeSystem.UTC,
......@@ -68,7 +68,7 @@ public class ApmWriter extends AbstractMessageWriter<Header, Segment<AdmMetadata
/** {@inheritDoc} */
@Override
public void writeSegment(final Generator generator, final Segment<AdmMetadata, ApmData> segment)
public void writeSegmentContent(final Generator generator, final Segment<AdmMetadata, ApmData> segment)
throws IOException {
// write the metadata
......
......@@ -36,6 +36,9 @@ import org.orekit.utils.TimeStampedPVCoordinates;
public class OcmFile extends NdmFile<Header, Segment<OcmMetadata, OcmData>>
implements EphemerisFile<TimeStampedPVCoordinates, OrbitStateHistory> {
/** Root element for XML messages. */
public static final String ROOT = "ocm";
/** Key for format version. */
public static final String FORMAT_VERSION_KEY = "CCSDS_OCM_VERS";
......
......@@ -63,9 +63,6 @@ import org.orekit.utils.units.Unit;
*/
public class OcmParser extends CommonParser<OcmFile, OcmParser> implements EphemerisFileParser<OcmFile> {
/** Root element for XML messages. */
private static final String ROOT = "ocm";
/** Orbit line element for XML messages. */
private static final String ORB_LINE = "orbLine";
......@@ -140,7 +137,7 @@ public class OcmParser extends CommonParser<OcmFile, OcmParser> implements Ephem
*/
public OcmParser(final IERSConventions conventions, final boolean simpleEOP,
final DataContext dataContext, final double mu) {
super(ROOT, OcmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, null, mu);
super(OcmFile.ROOT, OcmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, null, mu);
}
/** {@inheritDoc} */
......@@ -182,7 +179,7 @@ public class OcmParser extends CommonParser<OcmFile, OcmParser> implements Ephem
orbitDeterminationBlock = null;
userDefinedBlock = null;
if (fileFormat == FileFormat.XML) {
structureProcessor = new XmlStructureProcessingState(ROOT, this);
structureProcessor = new XmlStructureProcessingState(OcmFile.ROOT, this);
reset(fileFormat, structureProcessor);
} else {
structureProcessor = new KvnStructureProcessingState(this);
......
......@@ -55,7 +55,7 @@ public class OcmWriter extends AbstractMessageWriter<Header, Segment<OcmMetadata
* @param dataContext used to retrieve frames, time scales, etc.
*/
public OcmWriter(final IERSConventions conventions, final DataContext dataContext) {
super(OcmFile.FORMAT_VERSION_KEY, CCSDS_OCM_VERS,
super(OcmFile.ROOT, OcmFile.FORMAT_VERSION_KEY, CCSDS_OCM_VERS,
new ContextBinding(
() -> conventions, () -> false, () -> dataContext,
() -> null, () -> TimeSystem.UTC,
......@@ -67,7 +67,7 @@ public class OcmWriter extends AbstractMessageWriter<Header, Segment<OcmMetadata
* @param segment segment to write
* @throws IOException if any buffer writing operations fails
*/
public void writeSegment(final Generator generator, final Segment<OcmMetadata, OcmData> segment)
public void writeSegmentContent(final Generator generator, final Segment<OcmMetadata, OcmData> segment)
throws IOException {
// write the metadata
......
......@@ -141,12 +141,16 @@ public class EphemerisWriter implements EphemerisFileWriter {
try (Generator generator = fileFormat == FileFormat.KVN ?
new KvnGenerator(appendable, OemWriter.KVN_PADDING_WIDTH, outputName) :
new XmlGenerator(appendable, XmlGenerator.DEFAULT_INDENT, outputName)) {
writer.writeHeader(generator, header);
// Loop on segments
for (final S segment : segments) {
writeSegment(generator, segment);
}
writer.writeFooter(generator);
}
}
......
......@@ -45,6 +45,9 @@ import org.orekit.utils.TimeStampedPVCoordinates;
public class OemFile extends NdmFile<Header, OemSegment>
implements EphemerisFile<TimeStampedPVCoordinates, OemSegment> {
/** Root element for XML files. */
public static final String ROOT = "oem";
/** Key for format version. */
public static final String FORMAT_VERSION_KEY = "CCSDS_OEM_VERS";
......
......@@ -63,9 +63,6 @@ import org.orekit.utils.units.Unit;
*/
public class OemParser extends CommonParser<OemFile, OemParser> implements EphemerisFileParser<OemFile> {
/** Root element for XML files. */
private static final String ROOT = "oem";
/** Comment marker. */
private static final String COMMENT = "COMMENT";
......@@ -124,7 +121,7 @@ public class OemParser extends CommonParser<OemFile, OemParser> implements Ephem
final DataContext dataContext,
final AbsoluteDate missionReferenceDate, final double mu,
final int defaultInterpolationDegree) {
super(ROOT, OemFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext,
super(OemFile.ROOT, OemFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext,
missionReferenceDate, mu);
this.defaultInterpolationDegree = defaultInterpolationDegree;
}
......@@ -153,7 +150,7 @@ public class OemParser extends CommonParser<OemFile, OemParser> implements Ephem
currentCovariance = null;
currentRow = -1;
if (fileFormat == FileFormat.XML) {
structureProcessor = new XmlStructureProcessingState(ROOT, this);
structureProcessor = new XmlStructureProcessingState(OemFile.ROOT, this);
reset(fileFormat, structureProcessor);
} else {
structureProcessor = new KvnStructureProcessingState(this);
......
......@@ -235,7 +235,7 @@ public class OemWriter extends AbstractMessageWriter<Header, OemSegment, OemFile
*/
public OemWriter(final IERSConventions conventions, final DataContext dataContext,
final AbsoluteDate missionReferenceDate) {
super(OemFile.FORMAT_VERSION_KEY, CCSDS_OEM_VERS,
super(OemFile.ROOT, OemFile.FORMAT_VERSION_KEY, CCSDS_OEM_VERS,
new ContextBinding(
() -> conventions, () -> true, () -> dataContext,
() -> missionReferenceDate, () -> TimeSystem.UTC, () -> 0.0, () -> 1.0));
......@@ -243,7 +243,7 @@ public class OemWriter extends AbstractMessageWriter<Header, OemSegment, OemFile
/** {@inheritDoc} */
@Override
public void writeSegment(final Generator generator, final OemSegment segment) throws IOException {
public void writeSegmentContent(final Generator generator, final OemSegment segment) throws IOException {
final OemMetadata metadata = segment.getMetadata();
writeMetadata(generator, metadata);
......
......@@ -40,6 +40,9 @@ import org.orekit.utils.IERSConventions;
*/
public class OmmFile extends NdmFile<Header, Segment<OmmMetadata, OmmData>> implements TimeStamped {
/** Root element for XML files. */
public static final String ROOT = "omm";
/** Key for format version. */
public static final String FORMAT_VERSION_KEY = "CCSDS_OMM_VERS";
......
......@@ -66,9 +66,6 @@ import org.orekit.utils.IERSConventions;
*/
public class OmmParser extends CommonParser<OmmFile, OmmParser> {
/** Root element for XML files. */
private static final String ROOT = "omm";
/** User-defined element. */
private static final String USER_DEFINED = "USER_DEFINED";
......@@ -121,7 +118,7 @@ public class OmmParser extends CommonParser<OmmFile, OmmParser> {
public OmmParser(final IERSConventions conventions, final boolean simpleEOP,
final DataContext dataContext, final AbsoluteDate missionReferenceDate,
final double mu, final double defaultMass) {
super(ROOT, OmmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, missionReferenceDate, mu);
super(OmmFile.ROOT, OmmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, missionReferenceDate, mu);
this.defaultMass = defaultMass;
}
......@@ -157,7 +154,7 @@ public class OmmParser extends CommonParser<OmmFile, OmmParser> {
covarianceBlock = null;
userDefinedBlock = null;
if (fileFormat == FileFormat.XML) {
structureProcessor = new XmlStructureProcessingState(ROOT, this);
structureProcessor = new XmlStructureProcessingState(OmmFile.ROOT, this);
reset(fileFormat, structureProcessor);
} else {
structureProcessor = new ErrorState(); // should never be called
......
......@@ -60,7 +60,7 @@ public class OmmWriter extends AbstractMessageWriter<Header, Segment<OmmMetadata
*/
public OmmWriter(final IERSConventions conventions, final DataContext dataContext,
final AbsoluteDate missionReferenceDate) {
super(OmmFile.FORMAT_VERSION_KEY, CCSDS_OMM_VERS,
super(OmmFile.ROOT, OmmFile.FORMAT_VERSION_KEY, CCSDS_OMM_VERS,
new ContextBinding(
() -> conventions, () -> false, () -> dataContext,
() -> missionReferenceDate, () -> TimeSystem.UTC,
......@@ -72,7 +72,7 @@ public class OmmWriter extends AbstractMessageWriter<Header, Segment<OmmMetadata
* @param segment segment to write
* @throws IOException if any buffer writing operations fails
*/
public void writeSegment(final Generator generator, final Segment<OmmMetadata, OmmData> segment)
public void writeSegmentContent(final Generator generator, final Segment<OmmMetadata, OmmData> segment)
throws IOException {
// write the metadata
......
......@@ -39,6 +39,9 @@ import org.orekit.utils.TimeStampedPVCoordinates;
*/
public class OpmFile extends NdmFile<Header, Segment<CommonMetadata, OpmData>> implements TimeStamped {
/** Root element for XML files. */
public static final String ROOT = "opm";
/** Key for format version. */
public static final String FORMAT_VERSION_KEY = "CCSDS_OPM_VERS";
......
......@@ -67,9 +67,6 @@ import org.orekit.utils.IERSConventions;
*/
public class OpmParser extends CommonParser<OpmFile, OpmParser> {
/** Root element for XML files. */
private static final String ROOT = "opm";
/** User-defined element. */
private static final String USER_DEFINED = "USER_DEFINED";
......@@ -129,7 +126,7 @@ public class OpmParser extends CommonParser<OpmFile, OpmParser> {
final DataContext dataContext,
final AbsoluteDate missionReferenceDate, final double mu,
final double defaultMass) {
super(ROOT, OpmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, missionReferenceDate, mu);
super(OpmFile.ROOT, OpmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext, missionReferenceDate, mu);
this.defaultMass = defaultMass;
}
......@@ -167,7 +164,7 @@ public class OpmParser extends CommonParser<OpmFile, OpmParser> {
maneuverBlocks = new ArrayList<>();
userDefinedBlock = null;
if (fileFormat == FileFormat.XML) {
structureProcessor = new XmlStructureProcessingState(ROOT, this);
structureProcessor = new XmlStructureProcessingState(OpmFile.ROOT, this);
reset(fileFormat, structureProcessor);
} else {
structureProcessor = new ErrorState(); // should never be called
......
......@@ -63,7 +63,7 @@ public class OpmWriter extends AbstractMessageWriter<Header, Segment<CommonMetad
*/
public OpmWriter(final IERSConventions conventions, final DataContext dataContext,
final AbsoluteDate missionReferenceDate) {
super(OpmFile.FORMAT_VERSION_KEY, CCSDS_OPM_VERS,
super(OpmFile.ROOT, OpmFile.FORMAT_VERSION_KEY, CCSDS_OPM_VERS,
new ContextBinding(
() -> conventions, () -> false, () -> dataContext,
() -> missionReferenceDate, () -> TimeSystem.UTC,
......@@ -75,7 +75,7 @@ public class OpmWriter extends AbstractMessageWriter<Header, Segment<CommonMetad
* @param segment segment to write
* @throws IOException if any buffer writing operations fails
*/
public void writeSegment(final Generator generator, final Segment<CommonMetadata, OpmData> segment)
public void writeSegmentContent(final Generator generator, final Segment<CommonMetadata, OpmData> segment)
throws IOException {
// write the metadata
......
......@@ -18,7 +18,6 @@ package org.orekit.files.ccsds.ndm.tdm;
import java.io.IOException;
import org.orekit.errors.OrekitInternalError;
import org.orekit.files.ccsds.definitions.TimeConverter;
import org.orekit.files.ccsds.section.AbstractWriter;
import org.orekit.files.ccsds.section.KvnStructureKey;
......@@ -74,17 +73,19 @@ class ObservationsBlockWriter extends AbstractWriter {
for (final Observation observation : observationsBlock.getObservations()) {
final Observationtype type = observation.getType();
final AbsoluteDate date = observation.getEpoch();
final double rawValue = observation.getMeasurement();
final double siValue = type.siToRaw(converter, metadata, date, rawValue);
final double siValue = observation.getMeasurement();
final double rawValue = type.siToRaw(converter, metadata, date, siValue);
if (generator.getFormat() == FileFormat.KVN) {
final StringBuilder builder = new StringBuilder();
builder.append(generator.dateToString(timeConverter, date));
builder.append(' ');
builder.append(generator.doubleToString(siValue));
builder.append(generator.doubleToString(rawValue));
generator.writeEntry(observation.getType().name(), builder.toString(), false);
} else {
// TODO
throw new OrekitInternalError(null);
generator.enterSection(TdmDataKey.observation.name());
generator.writeEntry(TdmDataKey.EPOCH.name(), timeConverter, date, true);
generator.writeEntry(type.name(), rawValue, true);
generator.exitSection();
}
}
......
......@@ -38,6 +38,9 @@ import org.orekit.utils.IERSConventions;
*/
public class TdmFile extends NdmFile<Header, Segment<TdmMetadata, ObservationsBlock>> {
/** Root element for XML files. */
public static final String ROOT = "tdm";
/** Key for format version. */
public static final String FORMAT_VERSION_KEY = "CCSDS_TDM_VERS";
......
......@@ -55,9 +55,6 @@ import org.orekit.utils.IERSConventions;
*/
public class TdmParser extends AbstractMessageParser<TdmFile, TdmParser> {
/** Root element for XML files. */
private static final String ROOT = "tdm";
/** Converter for {@link RangeUnits#RU Range Units} (may be null). */
private final RangeUnitsConverter converter;
......@@ -93,7 +90,7 @@ public class TdmParser extends AbstractMessageParser<TdmFile, TdmParser> {
*/
public TdmParser(final IERSConventions conventions, final boolean simpleEOP,
final DataContext dataContext, final RangeUnitsConverter converter) {
super(ROOT, TdmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext);
super(TdmFile.ROOT, TdmFile.FORMAT_VERSION_KEY, conventions, simpleEOP, dataContext);
this.converter = converter;
}
......@@ -112,7 +109,7 @@ public class TdmParser extends AbstractMessageParser<TdmFile, TdmParser> {
context = null;
observationsBlock = null;
if (fileFormat == FileFormat.XML) {
structureProcessor = new XmlStructureProcessingState(ROOT, this);
structureProcessor = new XmlStructureProcessingState(TdmFile.ROOT, this);
reset(fileFormat, structureProcessor);
} else {
structureProcessor = new KvnStructureProcessingState(this);
......
......@@ -57,7 +57,7 @@ public class TdmWriter extends AbstractMessageWriter<Header, Segment<TdmMetadata
*/
public TdmWriter(final IERSConventions conventions, final DataContext dataContext,
final RangeUnitsConverter converter) {
super(TdmFile.FORMAT_VERSION_KEY, CCSDS_TDM_VERS,
super(TdmFile.ROOT, TdmFile.FORMAT_VERSION_KEY, CCSDS_TDM_VERS,
new ContextBinding(
() -> conventions, () -> false, () -> dataContext,
() -> null, () -> TimeSystem.UTC,
......@@ -70,7 +70,7 @@ public class TdmWriter extends AbstractMessageWriter<Header, Segment<TdmMetadata
* @param segment segment to write
* @throws IOException if any buffer writing operations fails
*/
public void writeSegment(final Generator generator, final Segment<TdmMetadata, ObservationsBlock> segment)
public void writeSegmentContent(final Generator generator, final Segment<TdmMetadata, ObservationsBlock> segment)
throws IOException {
// write the metadata
......
......@@ -25,7 +25,9 @@ import org.orekit.files.ccsds.ndm.NdmFile;
import org.orekit.files.ccsds.section.Header;
import org.orekit.files.ccsds.section.HeaderKey;
import org.orekit.files.ccsds.section.Segment;
import org.orekit.files.ccsds.section.XmlStructureKey;
import org.orekit.files.ccsds.utils.ContextBinding;
import org.orekit.files.ccsds.utils.FileFormat;
import org.orekit.time.DateComponents;
import org.orekit.time.DateTimeComponents;
import org.orekit.time.TimeComponents;
......@@ -43,6 +45,9 @@ public abstract class AbstractMessageWriter<H extends Header, S extends Segment<
/** Default value for {@link HeaderKey#ORIGINATOR}. */
public static final String DEFAULT_ORIGINATOR = "OREKIT";
/** Root element for XML files. */
private final String root;
/** Key for format version. */
private final String formatVersionKey;
......@@ -61,13 +66,15 @@ public abstract class AbstractMessageWriter<H extends Header, S extends Segment<
* <p>
* If creation date and originator are not present in header, built-in defaults will be used
* </p>
* @param root root element for XML files
* @param formatVersionKey key for format version
* @param defaultVersion default format version
* @param context context binding (may be reset for each segment)
*/
public AbstractMessageWriter(final String formatVersionKey, final double defaultVersion,
final ContextBinding context) {
public AbstractMessageWriter(final String root, final String formatVersionKey,
final double defaultVersion, final ContextBinding context) {
this.root = root;
this.defaultVersion = defaultVersion;
this.formatVersionKey = formatVersionKey;
......@@ -103,7 +110,11 @@ public abstract class AbstractMessageWriter<H extends Header, S extends Segment<
final double version = (header == null || Double.isNaN(header.getFormatVersion())) ?
defaultVersion : header.getFormatVersion();
generator.startMessage(formatVersionKey, version);
generator.startMessage(root, formatVersionKey, version);
if (generator.getFormat() == FileFormat.XML) {
generator.enterSection(XmlStructureKey.header.name());
}
// comments are optional
if (header != null) {
......@@ -137,9 +148,45 @@ public abstract class AbstractMessageWriter<H extends Header, S extends Segment<
generator.writeEntry(HeaderKey.MESSAGE_ID.name(), header.getMessageId(), false);
}
if (generator.getFormat() == FileFormat.XML) {
generator.exitSection();
}
// add an empty line for presentation
generator.newLine();
if (generator.getFormat() == FileFormat.XML) {
generator.enterSection(XmlStructureKey.body.name());
}
}
/** {@inheritDoc} */
@Override
public void writeSegment(final Generator generator, final S segment) throws IOException {
if (generator.getFormat() == FileFormat.XML) {
generator.enterSection(XmlStructureKey.segment.name());
}
writeSegmentContent(generator, segment);
if (generator.getFormat() == FileFormat.XML) {
generator.exitSection();
}
}
/** Write one segment content (without XML wrapping).
* @param generator generator to use for producing output
* @param segment segment to write
* @throws IOException if any buffer writing operations fails
*/
public abstract void writeSegmentContent(Generator generator, S segment) throws IOException;
/** {@inheritDoc} */
@Override
public void writeFooter(final Generator generator) throws IOException {
if (generator.getFormat() == FileFormat.XML) {
generator.exitSection();
}
generator.endMessage(root);
}
}
......@@ -41,16 +41,17 @@ public interface Generator extends AutoCloseable {
/** Start CCSDS message.
* @param messageTypeKey key for message type