1 /* Copyright 2002-2021 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.utils.parsing;
18
19 import org.orekit.data.DataContext;
20 import org.orekit.files.ccsds.ndm.NdmConstituent;
21 import org.orekit.files.ccsds.ndm.ParsedUnitsBehavior;
22 import org.orekit.files.ccsds.section.Header;
23 import org.orekit.utils.IERSConventions;
24
25 /** Parser for CCSDS messages.
26 * <p>
27 * Note than starting with Orekit 11.0, CCSDS message parsers are
28 * mutable objects that gather the data being parsed, until the
29 * message is complete and the {@link #parseMessage(org.orekit.data.DataSource)
30 * parseMessage} method has returned. This implies that parsers
31 * should <em>not</em> be used in a multi-thread context. The recommended
32 * way to use parsers is to either dedicate one parser for each message
33 * and drop it afterwards, or to use a single-thread loop.
34 * </p>
35 * @param <T> type of the file
36 * @param <P> type of the parser
37 * @author Luc Maisonobe
38 * @since 11.0
39 */
40 public abstract class AbstractConstituentParser<T extends NdmConstituent<?, ?>, P extends AbstractConstituentParser<T, ?>>
41 extends AbstractMessageParser<T> {
42
43 /** IERS Conventions. */
44 private final IERSConventions conventions;
45
46 /** Indicator for simple or accurate EOP interpolation. */
47 private final boolean simpleEOP;
48
49 /** Data context used for obtain frames and time scales. */
50 private final DataContext dataContext;
51
52 /** Behavior adopted for units that have been parsed from a CCSDS message. */
53 private final ParsedUnitsBehavior parsedUnitsBehavior;
54
55 /** Complete constructor.
56 * @param root root element for XML files
57 * @param formatVersionKey key for format version
58 * @param conventions IERS Conventions
59 * @param simpleEOP if true, tidal effects are ignored when interpolating EOP
60 * @param dataContext used to retrieve frames and time scales
61 * @param parsedUnitsBehavior behavior to adopt for handling parsed units
62 */
63 protected AbstractConstituentParser(final String root,
64 final String formatVersionKey,
65 final IERSConventions conventions,
66 final boolean simpleEOP,
67 final DataContext dataContext,
68 final ParsedUnitsBehavior parsedUnitsBehavior) {
69 super(root, formatVersionKey);
70 this.conventions = conventions;
71 this.simpleEOP = simpleEOP;
72 this.dataContext = dataContext;
73 this.parsedUnitsBehavior = parsedUnitsBehavior;
74 }
75
76 /** Get the behavior to adopt for handling parsed units.
77 * @return behavior to adopt for handling parsed units
78 */
79 public ParsedUnitsBehavior getParsedUnitsBehavior() {
80 return parsedUnitsBehavior;
81 }
82
83 /** Get IERS conventions.
84 * @return IERS conventions to use while parsing
85 */
86 public IERSConventions getConventions() {
87 return conventions;
88 }
89
90 /** Get EOP interpolation method.
91 * @return true if tidal effects are ignored when interpolating EOP
92 */
93 public boolean isSimpleEOP() {
94 return simpleEOP;
95 }
96
97 /** Get the data context used for getting frames, time scales, and celestial bodies.
98 * @return the data context.
99 */
100 public DataContext getDataContext() {
101 return dataContext;
102 }
103
104 /** Get file header to fill.
105 * @return file header to fill
106 */
107 public abstract Header getHeader();
108
109 /** Prepare header for parsing.
110 * @return true if parser was able to perform the action
111 */
112 public abstract boolean prepareHeader();
113
114 /** Acknowledge header parsing has started.
115 * @return true if parser was able to perform the action
116 */
117 public abstract boolean inHeader();
118
119 /** Finalize header after parsing.
120 * @return true if parser was able to perform the action
121 */
122 public abstract boolean finalizeHeader();
123
124 /** Prepare metadata for parsing.
125 * @return true if parser was able to perform the action
126 */
127 public abstract boolean prepareMetadata();
128
129 /** Acknowledge metada parsing has started.
130 * @return true if parser was able to perform the action
131 */
132 public abstract boolean inMetadata();
133
134 /** Finalize metadata after parsing.
135 * @return true if parser was able to perform the action
136 */
137 public abstract boolean finalizeMetadata();
138
139 /** Prepare data for parsing.
140 * @return true if parser was able to perform the action
141 */
142 public abstract boolean prepareData();
143
144 /** Acknowledge data parsing has started.
145 * @return true if parser was able to perform the action
146 */
147 public abstract boolean inData();
148
149 /** Finalize data after parsing.
150 * @return true if parser was able to perform the action
151 */
152 public abstract boolean finalizeData();
153
154 }