NdmConstituent.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;

  18. import java.util.Collections;
  19. import java.util.List;

  20. import org.orekit.data.DataContext;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.files.ccsds.section.Header;
  24. import org.orekit.files.ccsds.section.Segment;
  25. import org.orekit.utils.IERSConventions;

  26. /**
  27.  * Constituents of a CCSDS Navigation Data Message.
  28.  * Constituents may be Attitude Data Message (ADM), Orbit Data Message (ODM),
  29.  * Tracking Data Message (TDM)…
  30.  * Each constituent has its own header and a list of segments.
  31.  * @param <H> type of the header
  32.  * @param <S> type of the segments
  33.  * @author Bryan Cazabonne
  34.  * @since 10.2
  35.  */
  36. public abstract class NdmConstituent<H extends Header, S extends Segment<?, ?>> {

  37.     /** Header. */
  38.     private final H header;

  39.     /** segments list. */
  40.     private final List<S> segments;

  41.     /** IERS conventions used. */
  42.     private final IERSConventions conventions;

  43.     /** Data context. */
  44.     private final DataContext dataContext;

  45.     /**
  46.      * Constructor.
  47.      * @param header file header
  48.      * @param segments file segments
  49.      * @param conventions IERS conventions
  50.      * @param dataContext used for creating frames, time scales, etc.
  51.      */
  52.     protected NdmConstituent(final H header, final List<S> segments,
  53.                              final IERSConventions conventions, final DataContext dataContext) {
  54.         this.header      = header;
  55.         this.segments    = segments;
  56.         this.conventions = conventions;
  57.         this.dataContext = dataContext;
  58.     }

  59.     /**
  60.      * Get the header.
  61.      * @return header
  62.      * @since 11.0
  63.      */
  64.     public H getHeader() {
  65.         return header;
  66.     }

  67.     /**
  68.      * Get the segments.
  69.      * @return segments
  70.      * @since 11.0
  71.      */
  72.     public List<S> getSegments() {
  73.         return Collections.unmodifiableList(segments);
  74.     }

  75.     /**
  76.      * Get IERS conventions.
  77.      * @return IERS conventions
  78.      */
  79.     public IERSConventions getConventions() {
  80.         if (conventions != null) {
  81.             return conventions;
  82.         } else {
  83.             throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
  84.         }
  85.     }

  86.     /**
  87.      * Get the data context.
  88.      * @return the data context used for creating frames, time scales, etc.
  89.      */
  90.     public DataContext getDataContext() {
  91.         return dataContext;
  92.     }

  93.     /**
  94.      * Validate the file message for required and forbidden entries.
  95.      * <p>
  96.      * This method throws an exception if file does not meet format requirements.
  97.      * The requirements may depend on format version, which is found in header.
  98.      * </p>
  99.      */
  100.     public void validate() {
  101.         header.validate(header.getFormatVersion());
  102.         for (final S segment : segments) {
  103.             segment.getMetadata().validate(header.getFormatVersion());
  104.             segment.getData().validate(header.getFormatVersion());
  105.         }
  106.     }
  107. }