View Javadoc
1   package org.codehaus.plexus.interpolation;
2   
3   /*
4    * Copyright 2001-2008 Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  /**
20   * Signals an unrecoverable error in the process of interpolating a string, such
21   * as the detection of an expression cycle. Errors resolving individual values
22   * from expressions, such as those that happen when an object wrapped in an
23   * {@link ObjectBasedValueSource} doesn't have the property represented by a
24   * particular expression part, should <b>NOT</b> result in InterpolationExceptions
25   * being thrown. Instead, they should be reported in the feedback from the {@link ValueSource},
26   * which is propagated out through {@link Interpolator#getFeedback()}.
27   *
28   */
29  public class InterpolationException extends Exception {
30  
31      private static final long serialVersionUID = 1L;
32  
33      private final String expression;
34  
35      /**
36       * @param message The general description of the problem
37       * @param expression The expression that triggered the problem
38       * @param cause The wrapped exception
39       */
40      public InterpolationException(String message, String expression, Throwable cause) {
41          super(buildMessage(message, expression), cause);
42          this.expression = expression;
43      }
44  
45      /**
46       * @param message The general description of the problem
47       * @param expression The expression that triggered the problem
48       */
49      public InterpolationException(String message, String expression) {
50          super(buildMessage(message, expression));
51          this.expression = expression;
52      }
53  
54      private static String buildMessage(String message, String expression) {
55          return "Resolving expression: '" + expression + "': " + message;
56      }
57  
58      /**
59       * @return The expression that triggered this exception.
60       */
61      public String getExpression() {
62          return expression;
63      }
64  }