AbstractConstituentParser.java

  1. /* Copyright 2002-2024 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 java.util.List;
  19. import java.util.function.Function;

  20. import org.orekit.data.DataContext;
  21. import org.orekit.files.ccsds.ndm.NdmConstituent;
  22. import org.orekit.files.ccsds.ndm.ParsedUnitsBehavior;
  23. import org.orekit.files.ccsds.section.Header;
  24. import org.orekit.files.ccsds.utils.lexical.ParseToken;
  25. import org.orekit.utils.IERSConventions;

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

  44.     /** IERS Conventions. */
  45.     private final  IERSConventions conventions;

  46.     /** Indicator for simple or accurate EOP interpolation. */
  47.     private final  boolean simpleEOP;

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

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

  52.     /** Complete constructor.
  53.      * @param root root element for XML files
  54.      * @param formatVersionKey key for format version
  55.      * @param conventions IERS Conventions
  56.      * @param simpleEOP if true, tidal effects are ignored when interpolating EOP
  57.      * @param dataContext used to retrieve frames and time scales
  58.      * @param parsedUnitsBehavior behavior to adopt for handling parsed units
  59.      * @param filters filters to apply to parse tokens
  60.      * @since 12.0
  61.      */
  62.     protected AbstractConstituentParser(final String root,
  63.                                         final String formatVersionKey,
  64.                                         final IERSConventions conventions,
  65.                                         final boolean simpleEOP,
  66.                                         final DataContext dataContext,
  67.                                         final ParsedUnitsBehavior parsedUnitsBehavior,
  68.                                         final Function<ParseToken, List<ParseToken>>[] filters) {
  69.         super(root, formatVersionKey, filters);
  70.         this.conventions         = conventions;
  71.         this.simpleEOP           = simpleEOP;
  72.         this.dataContext         = dataContext;
  73.         this.parsedUnitsBehavior = parsedUnitsBehavior;
  74.     }

  75.     /** Get the behavior to adopt for handling parsed units.
  76.      * @return behavior to adopt for handling parsed units
  77.      */
  78.     public ParsedUnitsBehavior getParsedUnitsBehavior() {
  79.         return parsedUnitsBehavior;
  80.     }

  81.     /** Get IERS conventions.
  82.      * @return IERS conventions to use while parsing
  83.      */
  84.     public IERSConventions getConventions() {
  85.         return conventions;
  86.     }

  87.     /** Get EOP interpolation method.
  88.      * @return true if tidal effects are ignored when interpolating EOP
  89.      */
  90.     public boolean isSimpleEOP() {
  91.         return simpleEOP;
  92.     }

  93.     /** Get the data context used for getting frames, time scales, and celestial bodies.
  94.      * @return the data context.
  95.      */
  96.     public DataContext getDataContext() {
  97.         return dataContext;
  98.     }

  99.     /** Get file header to fill.
  100.      * @return file header to fill
  101.      */
  102.     public abstract H getHeader();

  103.     /** Prepare header for parsing.
  104.      * @return true if parser was able to perform the action
  105.      */
  106.     public abstract boolean prepareHeader();

  107.     /** Acknowledge header parsing has started.
  108.      * @return true if parser was able to perform the action
  109.      */
  110.     public abstract boolean inHeader();

  111.     /** Finalize header after parsing.
  112.      * @return true if parser was able to perform the action
  113.      */
  114.     public abstract boolean finalizeHeader();

  115.     /** Prepare metadata for parsing.
  116.      * @return true if parser was able to perform the action
  117.      */
  118.     public abstract boolean prepareMetadata();

  119.     /** Acknowledge metada parsing has started.
  120.      * @return true if parser was able to perform the action
  121.      */
  122.     public abstract boolean inMetadata();

  123.     /** Finalize metadata after parsing.
  124.      * @return true if parser was able to perform the action
  125.      */
  126.     public abstract boolean finalizeMetadata();

  127.     /** Prepare data for parsing.
  128.      * @return true if parser was able to perform the action
  129.      */
  130.     public abstract boolean prepareData();

  131.     /** Acknowledge data parsing has started.
  132.      * @return true if parser was able to perform the action
  133.      */
  134.     public abstract boolean inData();

  135.     /** Finalize data after parsing.
  136.      * @return true if parser was able to perform the action
  137.      */
  138.     public abstract boolean finalizeData();

  139. }