1 /*******************************************************************************
2 * Copyright (c) 2007, 2014 Massimiliano Ziccardi
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 package it.jnrpe.utils.thresholds;
17
18 import java.text.MessageFormat;
19
20 /**
21 * Exception thrown when the parse string is not complete.
22 *
23 * @author Massimiliano Ziccardi
24 */
25 public class PrematureEndOfRangeException extends RangeException {
26 /**
27 *
28 */
29 private static final long serialVersionUID = 2036144202685590610L;
30
31 /**
32 * Message pattern.
33 */
34 private static final String MESSAGE_PATTERN =
35 "Premature end of range parsing ''{0}''. "
36 + "Stage ''{1}'' expected one of ''{2}''";
37
38 /**
39 * Builds the exception specifying the stage and the range string.
40 *
41 * @param stage
42 * The stage that caused the error.
43 * @param wholeString
44 * The received range string.
45 */
46 PrematureEndOfRangeException(final Stage stage, final String wholeString) {
47 super(stage, null, wholeString);
48 }
49
50 /**
51 * @return the exception message
52 */
53 @Override
54 public final String getMessage() {
55 return MessageFormat.format(MESSAGE_PATTERN, getWholeRangeString(),
56 getFailedStage().getName(), getExpectedTokens());
57 }
58 }