AbstractConstituentParser.java

  1. /* Copyright 2002-2022 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.files.ccsds.utils.parsing;

  18. import org.orekit.data.DataContext;
  19. import org.orekit.files.ccsds.ndm.NdmConstituent;
  20. import org.orekit.files.ccsds.ndm.ParsedUnitsBehavior;
  21. import org.orekit.files.ccsds.section.Header;
  22. import org.orekit.utils.IERSConventions;

  23. /** Parser for CCSDS messages.
  24.  * <p>
  25.  * Note than starting with Orekit 11.0, CCSDS message parsers are
  26.  * mutable objects that gather the data being parsed, until the
  27.  * message is complete and the {@link #parseMessage(org.orekit.data.DataSource)
  28.  * parseMessage} method has returned. This implies that parsers
  29.  * should <em>not</em> be used in a multi-thread context. The recommended
  30.  * way to use parsers is to either dedicate one parser for each message
  31.  * and drop it afterwards, or to use a single-thread loop.
  32.  * </p>
  33.  * @param <T> type of the file
  34.  * @param <P> type of the parser
  35.  * @author Luc Maisonobe
  36.  * @since 11.0
  37.  */
  38. public abstract class AbstractConstituentParser<T extends NdmConstituent<?, ?>, P extends AbstractConstituentParser<T, ?>>
  39.     extends AbstractMessageParser<T> {

  40.     /** IERS Conventions. */
  41.     private final  IERSConventions conventions;

  42.     /** Indicator for simple or accurate EOP interpolation. */
  43.     private final  boolean simpleEOP;

  44.     /** Data context used for obtain frames and time scales. */
  45.     private final DataContext dataContext;

  46.     /** Behavior adopted for units that have been parsed from a CCSDS message. */
  47.     private final ParsedUnitsBehavior parsedUnitsBehavior;

  48.     /** Complete constructor.
  49.      * @param root root element for XML files
  50.      * @param formatVersionKey key for format version
  51.      * @param conventions IERS Conventions
  52.      * @param simpleEOP if true, tidal effects are ignored when interpolating EOP
  53.      * @param dataContext used to retrieve frames and time scales
  54.      * @param parsedUnitsBehavior behavior to adopt for handling parsed units
  55.      */
  56.     protected AbstractConstituentParser(final String root,
  57.                                         final String formatVersionKey,
  58.                                         final IERSConventions conventions,
  59.                                         final boolean simpleEOP,
  60.                                         final DataContext dataContext,
  61.                                         final ParsedUnitsBehavior parsedUnitsBehavior) {
  62.         super(root, formatVersionKey);
  63.         this.conventions         = conventions;
  64.         this.simpleEOP           = simpleEOP;
  65.         this.dataContext         = dataContext;
  66.         this.parsedUnitsBehavior = parsedUnitsBehavior;
  67.     }

  68.     /** Get the behavior to adopt for handling parsed units.
  69.      * @return behavior to adopt for handling parsed units
  70.      */
  71.     public ParsedUnitsBehavior getParsedUnitsBehavior() {
  72.         return parsedUnitsBehavior;
  73.     }

  74.     /** Get IERS conventions.
  75.      * @return IERS conventions to use while parsing
  76.      */
  77.     public IERSConventions getConventions() {
  78.         return conventions;
  79.     }

  80.     /** Get EOP interpolation method.
  81.      * @return true if tidal effects are ignored when interpolating EOP
  82.      */
  83.     public boolean isSimpleEOP() {
  84.         return simpleEOP;
  85.     }

  86.     /** Get the data context used for getting frames, time scales, and celestial bodies.
  87.      * @return the data context.
  88.      */
  89.     public DataContext getDataContext() {
  90.         return dataContext;
  91.     }

  92.     /** Get file header to fill.
  93.      * @return file header to fill
  94.      */
  95.     public abstract Header getHeader();

  96.     /** Prepare header for parsing.
  97.      * @return true if parser was able to perform the action
  98.      */
  99.     public abstract boolean prepareHeader();

  100.     /** Acknowledge header parsing has started.
  101.      * @return true if parser was able to perform the action
  102.      */
  103.     public abstract boolean inHeader();

  104.     /** Finalize header after parsing.
  105.      * @return true if parser was able to perform the action
  106.      */
  107.     public abstract boolean finalizeHeader();

  108.     /** Prepare metadata for parsing.
  109.      * @return true if parser was able to perform the action
  110.      */
  111.     public abstract boolean prepareMetadata();

  112.     /** Acknowledge metada parsing has started.
  113.      * @return true if parser was able to perform the action
  114.      */
  115.     public abstract boolean inMetadata();

  116.     /** Finalize metadata after parsing.
  117.      * @return true if parser was able to perform the action
  118.      */
  119.     public abstract boolean finalizeMetadata();

  120.     /** Prepare data for parsing.
  121.      * @return true if parser was able to perform the action
  122.      */
  123.     public abstract boolean prepareData();

  124.     /** Acknowledge data parsing has started.
  125.      * @return true if parser was able to perform the action
  126.      */
  127.     public abstract boolean inData();

  128.     /** Finalize data after parsing.
  129.      * @return true if parser was able to perform the action
  130.      */
  131.     public abstract boolean finalizeData();

  132. }