Metadata.java

  1. /* Copyright 2002-2025 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.section;

  18. import java.util.regex.Matcher;
  19. import java.util.regex.Pattern;

  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.errors.OrekitMessages;
  22. import org.orekit.files.ccsds.definitions.TimeSystem;

  23. /** This class gathers the meta-data present in the Navigation Data Message (ADM, ODM and TDM).
  24.  * <p>
  25.  * Beware that the Orekit getters and setters all rely on SI units. The parsers
  26.  * and writers take care of converting these SI units into CCSDS mandatory units.
  27.  * The {@link org.orekit.utils.units.Unit Unit} class provides useful
  28.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  29.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
  30.  * already use CCSDS units instead of the API SI units. The general-purpose
  31.  * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
  32.  * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
  33.  * (with an 's') also provide some predefined units. These predefined units and the
  34.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  35.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
  36.  * what the parsers and writers use for the conversions.
  37.  * </p>
  38.  * @author Luc Maisonobe
  39.  * @since 11.0
  40.  */
  41. public class Metadata extends CommentsContainer {

  42.     /** Pattern for international designator. */
  43.     private static final Pattern INTERNATIONAL_DESIGNATOR = Pattern.compile("(\\p{Digit}{4})-(\\p{Digit}{3})(\\p{Upper}{1,3})");

  44.     /** Time System: used for metadata, orbit state and covariance data. */
  45.     private TimeSystem timeSystem;

  46.     /** Simple constructor.
  47.      * @param defaultTimeSystem default time system (may be null)
  48.      */
  49.     protected Metadata(final TimeSystem defaultTimeSystem) {
  50.         this.timeSystem = defaultTimeSystem;
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public void validate(final double version) {
  55.         super.validate(version);
  56.         checkNotNull(timeSystem, MetadataKey.TIME_SYSTEM.name());
  57.     }

  58.     /** Get the Time System that: for OPM, is used for metadata, state vector,
  59.      * maneuver and covariance data, for OMM, is used for metadata, orbit state
  60.      * and covariance data, for OEM, is used for metadata, ephemeris and
  61.      * covariance data.
  62.      * @return the time system
  63.      */
  64.     public TimeSystem getTimeSystem() {
  65.         return timeSystem;
  66.     }

  67.     /** Set the Time System that: for OPM, is used for metadata, state vector,
  68.      * maneuver and covariance data, for OMM, is used for metadata, orbit state
  69.      * and covariance data, for OEM, is used for metadata, ephemeris and
  70.      * covariance data.
  71.      * @param timeSystem the time system to be set
  72.      */
  73.     public void setTimeSystem(final TimeSystem timeSystem) {
  74.         refuseFurtherComments();
  75.         this.timeSystem = timeSystem;
  76.     }

  77.     /** Get the launch year.
  78.      * @param objectID object identifier
  79.      * @return launch year
  80.      */
  81.     protected int getLaunchYear(final String objectID) {
  82.         final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
  83.         if (matcher.matches()) {
  84.             return Integer.parseInt(matcher.group(1));
  85.         }
  86.         throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
  87.     }

  88.     /** Get the launch number.
  89.      * @param objectID object identifier
  90.      * @return launch number
  91.      */
  92.     protected int getLaunchNumber(final String objectID) {
  93.         final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
  94.         if (matcher.matches()) {
  95.             return Integer.parseInt(matcher.group(2));
  96.         }
  97.         throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
  98.     }

  99.     /** Get the piece of launch.
  100.      * @param objectID object identifier
  101.      * @return piece of launch
  102.      */
  103.     protected String getLaunchPiece(final String objectID) {
  104.         final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
  105.         if (matcher.matches()) {
  106.             return matcher.group(3);
  107.         }
  108.         throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
  109.     }

  110. }