RotationXmlTokenBuilder.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.adm;

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

  20. import org.orekit.files.ccsds.utils.lexical.ParseToken;
  21. import org.orekit.files.ccsds.utils.lexical.TokenType;
  22. import org.orekit.files.ccsds.utils.lexical.XmlTokenBuilder;
  23. import org.orekit.utils.units.Unit;
  24. import org.orekit.utils.units.UnitsCache;
  25. import org.xml.sax.Attributes;

  26. /** Builder for rotation angles and rates.
  27.  * <p>
  28.  * Instances of this class are immutable.
  29.  * </p>
  30.  * @author Luc Maisonobe
  31.  * @since 11.0
  32.  */
  33. public class RotationXmlTokenBuilder implements XmlTokenBuilder {

  34.     /** Attribute defining rotation angle. */
  35.     private static final String ANGLE = "angle";

  36.     /** Attribute defining rotation rate. */
  37.     private static final String RATE = "rate";

  38.     /** Attribute name for units. */
  39.     private static final String UNITS = "units";

  40.     /** Cache for parsed units. */
  41.     private final UnitsCache cache;

  42.     /** Simple constructor.
  43.      */
  44.     public RotationXmlTokenBuilder() {
  45.         this.cache = new UnitsCache();
  46.     }

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     public List<ParseToken> buildTokens(final boolean startTag, final String qName,
  50.                                         final String content, final Attributes attributes,
  51.                                         final int lineNumber, final String fileName) {

  52.         // get the token name from the first attribute found
  53.         String name = attributes.getValue(ANGLE);
  54.         if (name == null) {
  55.             name = attributes.getValue(RATE);
  56.         }

  57.         // elaborate the token type
  58.         final TokenType type = (content == null) ? (startTag ? TokenType.START : TokenType.STOP) : TokenType.ENTRY;

  59.         // get units
  60.         final Unit units = cache.getUnits(attributes.getValue(UNITS));

  61.         // final build
  62.         final ParseToken token = new ParseToken(type, name, content, units, lineNumber, fileName);

  63.         return Collections.singletonList(token);

  64.     }

  65. }