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.ndm.adm;
18
19 import java.util.Collections;
20 import java.util.List;
21
22 import org.orekit.files.ccsds.utils.lexical.ParseToken;
23 import org.orekit.files.ccsds.utils.lexical.TokenType;
24 import org.orekit.files.ccsds.utils.lexical.XmlTokenBuilder;
25 import org.orekit.utils.units.Unit;
26 import org.orekit.utils.units.UnitsCache;
27 import org.xml.sax.Attributes;
28
29 /** Builder for rotation angles and rates.
30 * <p>
31 * Instances of this class are immutable.
32 * </p>
33 * @author Luc Maisonobe
34 * @since 11.0
35 */
36 public class RotationXmlTokenBuilder implements XmlTokenBuilder {
37
38 /** Attribute defining rotation angle. */
39 private static final String ANGLE = "angle";
40
41 /** Attribute defining rotation rate. */
42 private static final String RATE = "rate";
43
44 /** Attribute name for units. */
45 private static final String UNITS = "units";
46
47 /** Cache for parsed units. */
48 private final UnitsCache cache;
49
50 /** Simple constructor.
51 */
52 public RotationXmlTokenBuilder() {
53 this.cache = new UnitsCache();
54 }
55
56 /** {@inheritDoc} */
57 @Override
58 public List<ParseToken> buildTokens(final boolean startTag, final String qName,
59 final String content, final Attributes attributes,
60 final int lineNumber, final String fileName) {
61
62 // get the token name from the first attribute found
63 String name = attributes.getValue(ANGLE);
64 if (name == null) {
65 name = attributes.getValue(RATE);
66 }
67
68 // elaborate the token type
69 final TokenType type = (content == null) ? (startTag ? TokenType.START : TokenType.STOP) : TokenType.ENTRY;
70
71 // get units
72 final Unit units = cache.getUnits(attributes.getValue(UNITS));
73
74 // final build
75 final ParseToken token = new ParseToken(type, name, content, units, lineNumber, fileName);
76
77 return Collections.singletonList(token);
78
79 }
80
81 }