Metadata.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.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.  * @author Luc Maisonobe
  25.  * @since 11.0
  26.  */
  27. public class Metadata extends CommentsContainer {

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

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

  32.     /** Simple constructor.
  33.      * @param defaultTimeSystem default time system (may be null)
  34.      */
  35.     protected Metadata(final TimeSystem defaultTimeSystem) {
  36.         this.timeSystem = defaultTimeSystem;
  37.     }

  38.     /** {@inheritDoc} */
  39.     @Override
  40.     public void validate(final double version) {
  41.         super.validate(version);
  42.         checkNotNull(timeSystem, MetadataKey.TIME_SYSTEM.name());
  43.     }

  44.     /** Get the Time System that: for OPM, is used for metadata, state vector,
  45.      * maneuver and covariance data, for OMM, is used for metadata, orbit state
  46.      * and covariance data, for OEM, is used for metadata, ephemeris and
  47.      * covariance data.
  48.      * @return the time system
  49.      */
  50.     public TimeSystem getTimeSystem() {
  51.         return timeSystem;
  52.     }

  53.     /** Set the Time System that: for OPM, is used for metadata, state vector,
  54.      * maneuver and covariance data, for OMM, is used for metadata, orbit state
  55.      * and covariance data, for OEM, is used for metadata, ephemeris and
  56.      * covariance data.
  57.      * @param timeSystem the time system to be set
  58.      */
  59.     public void setTimeSystem(final TimeSystem timeSystem) {
  60.         refuseFurtherComments();
  61.         this.timeSystem = timeSystem;
  62.     }

  63.     /** Get the launch year.
  64.      * @param objectID object identifier
  65.      * @return launch year
  66.      */
  67.     protected int getLaunchYear(final String objectID) {
  68.         final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
  69.         if (matcher.matches()) {
  70.             return Integer.parseInt(matcher.group(1));
  71.         }
  72.         throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
  73.     }

  74.     /** Get the launch number.
  75.      * @param objectID object identifier
  76.      * @return launch number
  77.      */
  78.     protected int getLaunchNumber(final String objectID) {
  79.         final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
  80.         if (matcher.matches()) {
  81.             return Integer.parseInt(matcher.group(2));
  82.         }
  83.         throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
  84.     }

  85.     /** Get the piece of launch.
  86.      * @param objectID object identifier
  87.      * @return piece of launch
  88.      */
  89.     protected String getLaunchPiece(final String objectID) {
  90.         final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
  91.         if (matcher.matches()) {
  92.             return matcher.group(3);
  93.         }
  94.         throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
  95.     }

  96. }