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  
18  package org.orekit.files.ccsds.section;
19  
20  import java.util.regex.Matcher;
21  import java.util.regex.Pattern;
22  
23  import org.orekit.errors.OrekitException;
24  import org.orekit.errors.OrekitMessages;
25  import org.orekit.files.ccsds.definitions.TimeSystem;
26  
27  /** This class gathers the meta-data present in the Navigation Data Message (ADM, ODM and TDM).
28   * <p>
29   * Beware that the Orekit getters and setters all rely on SI units. The parsers
30   * and writers take care of converting these SI units into CCSDS mandatory units.
31   * The {@link org.orekit.utils.units.Unit Unit} class provides useful
32   * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
33   * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
34   * already use CCSDS units instead of the API SI units. The general-purpose
35   * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
36   * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
37   * (with an 's') also provide some predefined units. These predefined units and the
38   * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
39   * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
40   * what the parsers and writers use for the conversions.
41   * </p>
42   * @author Luc Maisonobe
43   * @since 11.0
44   */
45  public class Metadata extends CommentsContainer {
46  
47      /** Pattern for international designator. */
48      private static final Pattern INTERNATIONAL_DESIGNATOR = Pattern.compile("(\\p{Digit}{4})-(\\p{Digit}{3})(\\p{Upper}{1,3})");
49  
50      /** Time System: used for metadata, orbit state and covariance data. */
51      private TimeSystem timeSystem;
52  
53      /** Simple constructor.
54       * @param defaultTimeSystem default time system (may be null)
55       */
56      protected Metadata(final TimeSystem defaultTimeSystem) {
57          this.timeSystem = defaultTimeSystem;
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public void validate(final double version) {
63          super.validate(version);
64          checkNotNull(timeSystem, MetadataKey.TIME_SYSTEM.name());
65      }
66  
67      /** Get 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       * @return the time system
72       */
73      public TimeSystem getTimeSystem() {
74          return timeSystem;
75      }
76  
77      /** Set the Time System that: for OPM, is used for metadata, state vector,
78       * maneuver and covariance data, for OMM, is used for metadata, orbit state
79       * and covariance data, for OEM, is used for metadata, ephemeris and
80       * covariance data.
81       * @param timeSystem the time system to be set
82       */
83      public void setTimeSystem(final TimeSystem timeSystem) {
84          refuseFurtherComments();
85          this.timeSystem = timeSystem;
86      }
87  
88      /** Get the launch year.
89       * @param objectID object identifier
90       * @return launch year
91       */
92      protected int getLaunchYear(final String objectID) {
93          final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
94          if (matcher.matches()) {
95              return Integer.parseInt(matcher.group(1));
96          }
97          throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
98      }
99  
100     /** Get the launch number.
101      * @param objectID object identifier
102      * @return launch number
103      */
104     protected int getLaunchNumber(final String objectID) {
105         final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
106         if (matcher.matches()) {
107             return Integer.parseInt(matcher.group(2));
108         }
109         throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
110     }
111 
112     /** Get the piece of launch.
113      * @param objectID object identifier
114      * @return piece of launch
115      */
116     protected String getLaunchPiece(final String objectID) {
117         final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
118         if (matcher.matches()) {
119             return matcher.group(3);
120         }
121         throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
122     }
123 
124 }