1 /* Copyright 2002-2019 CS Systèmes d'Information
2 * Licensed to CS Systèmes d'Information (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
19 import java.text.MessageFormat;
20 import java.util.Locale;
21
22 import org.hipparchus.exception.Localizable;
23
24 /** Extension of {@link java.lang.Runtime} with localized message for internal errors only.
25 * @since 7.1
26 */
27 public class OrekitInternalError extends IllegalStateException implements LocalizedException {
28
29 /** Serializable UID. */
30 private static final long serialVersionUID = 20150611L;
31
32 /** Format specifier (to be translated). */
33 private final Localizable specifier = OrekitMessages.INTERNAL_ERROR;
34
35 /** Parts to insert in the format (no translation). */
36 private final String[] parts = new String[] {
37 "https://gitlab.orekit.org/orekit/orekit/issues"
38 };
39
40 /** Create an exception with localized message.
41 * @param cause underlying cause
42 */
43 public OrekitInternalError(final Throwable cause) {
44 super(cause);
45 }
46
47 /** {@inheritDoc} */
48 @Override
49 public String getMessage(final Locale locale) {
50 return buildMessage(locale);
51 }
52
53 /** {@inheritDoc} */
54 @Override
55 public String getMessage() {
56 return buildMessage(Locale.US);
57 }
58
59 /** {@inheritDoc} */
60 @Override
61 public String getLocalizedMessage() {
62 return buildMessage(Locale.getDefault());
63 }
64
65 /** {@inheritDoc} */
66 @Override
67 public Localizable getSpecifier() {
68 return specifier;
69 }
70
71 /** {@inheritDoc} */
72 @Override
73 public Object[] getParts() {
74 return parts.clone();
75 }
76
77 /**
78 * Builds a message string by from a pattern and its arguments.
79 * @param locale Locale in which the message should be translated
80 * @return a message string
81 */
82 private String buildMessage(final Locale locale) {
83 return new MessageFormat(specifier.getLocalizedString(locale), locale).format(parts);
84 }
85
86 }