TimeStampedCacheException.java

  1. /* Copyright 2002-2025 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.errors;

  18. import org.hipparchus.exception.Localizable;
  19. import org.hipparchus.exception.MathRuntimeException;

  20. /** This class is the base class for all specific exceptions thrown by
  21.  * during the {@link org.orekit.utils.GenericTimeStampedCache}.
  22.  *
  23.  * @author Luc Maisonobe
  24.  */
  25. public class TimeStampedCacheException extends OrekitException {

  26.     /** Serializable UID. */
  27.     private static final long serialVersionUID = 9015424948577907926L;

  28.     /** Simple constructor.
  29.      * Build an exception with a translated and formatted message
  30.      * @param specifier format specifier (to be translated)
  31.      * @param parts parts to insert in the format (no translation)
  32.      */
  33.     public TimeStampedCacheException(final Localizable specifier, final Object... parts) {
  34.         super(specifier, parts);
  35.     }

  36.     /** Simple constructor.
  37.      * Build an exception from a cause and with a specified message
  38.      * @param cause underlying cause
  39.      * @param specifier format specifier (to be translated)
  40.      * @param parts parts to insert in the format (no translation)
  41.      */
  42.     public TimeStampedCacheException(final Throwable cause, final Localizable specifier,
  43.                                      final Object... parts) {
  44.         super(cause, specifier, parts);
  45.     }

  46.     /** Simple constructor.
  47.      * Build an exception wrapping an {@link OrekitException} instance
  48.      * @param exception underlying cause
  49.      */
  50.     public TimeStampedCacheException(final OrekitException exception) {
  51.         super(exception);
  52.     }

  53.     /** Simple constructor.
  54.      * Build an exception from an Hipparchus exception
  55.      * @param exception underlying Hipparchus exception
  56.      */
  57.     public TimeStampedCacheException(final MathRuntimeException exception) {
  58.         super(exception);
  59.     }

  60.     /** Recover a TimeStampedCacheException, possibly embedded in a {@link OrekitException}.
  61.      * <p>
  62.      * If the {@code OrekitException} does not embed a TimeStampedCacheException, a
  63.      * new one will be created.
  64.      * </p>
  65.      * @param oe OrekitException to analyze
  66.      * @return a (possibly embedded) TimeStampedCacheException
  67.      */
  68.     public static TimeStampedCacheException unwrap(final OrekitException oe) {

  69.         for (Throwable t = oe; t != null; t = t.getCause()) {
  70.             if (t instanceof TimeStampedCacheException) {
  71.                 return (TimeStampedCacheException) t;
  72.             }
  73.         }

  74.         return new TimeStampedCacheException(oe);

  75.     }

  76.     /** Recover a TimeStampedCacheException, possibly embedded in a {@link MathRuntimeException}.
  77.      * <p>
  78.      * If the {@code MathRuntimeException} does not embed a TimeStampedCacheException, a
  79.      * new one will be created.
  80.      * </p>
  81.      * @param exception MathRuntimeException to analyze
  82.      * @return a (possibly embedded) TimeStampedCacheException
  83.      */
  84.     public static TimeStampedCacheException unwrap(final MathRuntimeException exception) {

  85.         for (Throwable t = exception; t != null; t = t.getCause()) {
  86.             if (t instanceof OrekitException) {
  87.                 if (t instanceof TimeStampedCacheException) {
  88.                     return (TimeStampedCacheException) t;
  89.                 } else {
  90.                     return new TimeStampedCacheException((OrekitException) t);
  91.                 }
  92.             }
  93.         }

  94.         return new TimeStampedCacheException(exception);

  95.     }

  96. }