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  
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   * @author Luc Maisonobe
29   * @since 11.0
30   */
31  public class Metadata extends CommentsContainer {
32  
33      /** Pattern for international designator. */
34      private static final Pattern INTERNATIONAL_DESIGNATOR = Pattern.compile("(\\p{Digit}{4})-(\\p{Digit}{3})(\\p{Upper}{1,3})");
35  
36      /** Time System: used for metadata, orbit state and covariance data. */
37      private TimeSystem timeSystem;
38  
39      /** Simple constructor.
40       * @param defaultTimeSystem default time system (may be null)
41       */
42      protected Metadata(final TimeSystem defaultTimeSystem) {
43          this.timeSystem = defaultTimeSystem;
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      public void validate(final double version) {
49          super.validate(version);
50          checkNotNull(timeSystem, MetadataKey.TIME_SYSTEM.name());
51      }
52  
53      /** Get 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       * @return the time system
58       */
59      public TimeSystem getTimeSystem() {
60          return timeSystem;
61      }
62  
63      /** Set the Time System that: for OPM, is used for metadata, state vector,
64       * maneuver and covariance data, for OMM, is used for metadata, orbit state
65       * and covariance data, for OEM, is used for metadata, ephemeris and
66       * covariance data.
67       * @param timeSystem the time system to be set
68       */
69      public void setTimeSystem(final TimeSystem timeSystem) {
70          refuseFurtherComments();
71          this.timeSystem = timeSystem;
72      }
73  
74      /** Get the launch year.
75       * @param objectID object identifier
76       * @return launch year
77       */
78      protected int getLaunchYear(final String objectID) {
79          final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
80          if (matcher.matches()) {
81              return Integer.parseInt(matcher.group(1));
82          }
83          throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
84      }
85  
86      /** Get the launch number.
87       * @param objectID object identifier
88       * @return launch number
89       */
90      protected int getLaunchNumber(final String objectID) {
91          final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
92          if (matcher.matches()) {
93              return Integer.parseInt(matcher.group(2));
94          }
95          throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
96      }
97  
98      /** Get the piece of launch.
99       * @param objectID object identifier
100      * @return piece of launch
101      */
102     protected String getLaunchPiece(final String objectID) {
103         final Matcher matcher = INTERNATIONAL_DESIGNATOR.matcher(objectID);
104         if (matcher.matches()) {
105             return matcher.group(3);
106         }
107         throw new OrekitException(OrekitMessages.NOT_VALID_INTERNATIONAL_DESIGNATOR, objectID);
108     }
109 
110 }