CdmMetadataKey.java

  1. /* Copyright 2002-2022 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.ndm.cdm;

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

  20. import org.orekit.files.ccsds.definitions.YesNoUnknown;
  21. import org.orekit.files.ccsds.ndm.odm.ocm.ObjectType;
  22. import org.orekit.files.ccsds.utils.ContextBinding;
  23. import org.orekit.files.ccsds.utils.lexical.ParseToken;
  24. import org.orekit.files.ccsds.utils.lexical.TokenType;

  25. /** Keys for {@link CdmMetadata CDM container} entries.
  26.  * @author Melina Vanel
  27.  * @since 11.2
  28.  */
  29. public enum CdmMetadataKey {

  30.     /** Object to which data apply. */
  31.     OBJECT((token, context, container) -> token.processAsNormalizedString(container::setObject)),

  32.     /** Satellite catalog designator for object. */
  33.     OBJECT_DESIGNATOR((token, context, container) -> token.processAsNormalizedString(container::setObjectDesignator)),

  34.     /** Satellite catalog used for the object. */
  35.     CATALOG_NAME((token, context, container) -> token.processAsNormalizedString(container::setCatalogName)),

  36.     /** Spacecraft name for the object. */
  37.     OBJECT_NAME((token, context, container) -> token.processAsNormalizedString(container::setObjectName)),

  38.     /** Full international designator name for the object. */
  39.     INTERNATIONAL_DESIGNATOR((token, context, container) -> token.processAsNormalizedString(container::setInternationalDes)),

  40.     /** Object Type. */
  41.     OBJECT_TYPE((token, context, container) -> token.processAsEnum(ObjectType.class, container::setObjectType)),

  42.     /** Contact position of the owner/operator of the object. */
  43.     OPERATOR_CONTACT_POSITION((token, context, container) -> token.processAsNormalizedString(container::setOperatorContactPosition)),

  44.     /** Contact organization of the object. */
  45.     OPERATOR_ORGANIZATION((token, context, container) -> token.processAsNormalizedString(container::setOperatorOrganization)),

  46.     /** Phone number of the contact position for the object. */
  47.     OPERATOR_PHONE((token, context, container) -> token.processAsNormalizedString(container::setOperatorPhone)),

  48.     /** Email address of the contact position for the object. */
  49.     OPERATOR_EMAIL((token, context, container) -> token.processAsNormalizedString(container::setOperatorEmail)),

  50.     /** Unique identifier of Orbit Data Message(s) that are linked (relevant) to this Conjunction Data Message. */
  51.     ODM_MSG_LINK((token, context, container) -> token.processAsFreeTextString(container::setOdmMsgLink)),

  52.     /** Unique identifier of Attitude Data Message(s) that are linked (relevant) to this Conjunction Data Message. */
  53.     ADM_MSG_LINK((token, context, container) -> token.processAsFreeTextString(container::setAdmMsgLink)),

  54.     /** Unique name of the external ephemeris file used for the object or NONE. */
  55.     EPHEMERIS_NAME((token, context, container) -> token.processAsNormalizedString(container::setEphemName)),

  56.     /** Flag indicating whether new tracking observations are anticipated prior to the issue of the next CDM associated with the event
  57.      * specified by CONJUNCTION_ID. */
  58.     OBS_BEFORE_NEXT_MESSAGE((token, context, container) -> token.processAsEnum(YesNoUnknown.class, container::setObsBeforeNextMessage)),

  59.     /** Method used to calculate the covariance. */
  60.     COVARIANCE_METHOD((token, context, container) -> token.processAsEnum(CovarianceMethod.class, container::setCovarianceMethod)),

  61.     /** The source from which the covariance data used in the report for both Object 1 and Object 2 originates. */
  62.     COVARIANCE_SOURCE((token, context, container) -> token.processAsNormalizedString(container::setCovarianceSource)),

  63.     /** Manoeuver capacity. */
  64.     MANEUVERABLE((token, context, container) -> token.processAsManeuvrableEnum(container::setManeuverable)),

  65.     /** Central body for Object 1 and 2. */
  66.     ORBIT_CENTER((token, context, container) -> token.processAsCenter(container::setOrbitCenter,
  67.                                                                     context.getDataContext().getCelestialBodies())),

  68.     /** Name of the reference frame, in which state vector data are given. */
  69.     REF_FRAME((token, context, container) -> token.processAsFrame(container::setRefFrame, context, true, true, true)),

  70.     /** Flag indicating the type of alternate covariance information provided. */
  71.     ALT_COV_TYPE((token, context, container) -> token.processAsEnum(AltCovarianceType.class, container::setAltCovType)),

  72.     /** Name of the reference frame in which the alternate covariance data are given. */
  73.     ALT_COV_REF_FRAME((token, context, container) -> token.processAsFrame(container::setAltCovRefFrame, context, true, false, false)),

  74.     /** Gravity model. */
  75.     GRAVITY_MODEL(new GravityProcessor()),

  76.     /** Name of atmospheric model. */
  77.     ATMOSPHERIC_MODEL((token, context, container) -> token.processAsNormalizedString(container::setAtmosphericModel)),

  78.     /** N-body perturbation bodies. */
  79.     N_BODY_PERTURBATIONS((token, context, container) -> token.processAsCenterList(container::setNBodyPerturbations,
  80.                                                                                   context.getDataContext().getCelestialBodies())),

  81.     /** Is solar radiation pressure used for the OD of the object ? */
  82.     SOLAR_RAD_PRESSURE((token, context, container) -> token.processAsBoolean(container::setSolarRadiationPressure)),

  83.     /** Is solid Earth and ocean tides used for the OD of the object ? */
  84.     EARTH_TIDES((token, context, container) -> token.processAsBoolean(container::setEarthTides)),

  85.     /** Indication of whether in-track thrust modeling used for the object. */
  86.     INTRACK_THRUST((token, context, container) -> token.processAsBoolean(container::setIntrackThrust));

  87.     /** Processing method. */
  88.     private final TokenProcessor processor;

  89.     /** Simple constructor.
  90.      * @param processor processing method
  91.      */
  92.     CdmMetadataKey(final TokenProcessor processor) {
  93.         this.processor = processor;
  94.     }

  95.     /** Process an token.
  96.      * @param token token to process
  97.      * @param context context binding
  98.      * @param container container to fill
  99.      * @return true of token was accepted
  100.      */
  101.     public boolean process(final ParseToken token, final ContextBinding context, final CdmMetadata container) {
  102.         return processor.process(token, context, container);
  103.     }

  104.     /** Interface for processing one token. */
  105.     interface TokenProcessor {
  106.         /** Process one token.
  107.          * @param token token to process
  108.          * @param context context binding
  109.          * @param container container to fill
  110.          * @return true of token was accepted
  111.          */
  112.         boolean process(ParseToken token, ContextBinding context, CdmMetadata container);
  113.     }

  114.     /** Dedicated processor for gravity field. */
  115.     private static class GravityProcessor implements TokenProcessor {

  116.         /** Pattern for splitting gravity specification. */
  117.         private static final Pattern GRAVITY_PATTERN =
  118.                         Pattern.compile("^\\p{Blank}*([-_A-Za-z0-9]+)\\p{Blank}*:" +
  119.                                         "\\p{Blank}*([0-9]+)D" +
  120.                                         "\\p{Blank}*([0-9]+)O" +
  121.                                         "\\p{Blank}*$");

  122.         /** {@inheritDoc} */
  123.         @Override
  124.         public boolean process(final ParseToken token, final ContextBinding context, final CdmMetadata container) {
  125.             if (token.getType() == TokenType.ENTRY) {
  126.                 final Matcher matcher = GRAVITY_PATTERN.matcher(token.getContentAsNormalizedString());
  127.                 if (!matcher.matches()) {
  128.                     throw token.generateException(null);
  129.                 }
  130.                 container.setGravityModel(matcher.group(1),
  131.                                           Integer.parseInt(matcher.group(2)),
  132.                                           Integer.parseInt(matcher.group(3)));
  133.             }
  134.             return true;
  135.         }
  136.     }

  137. }