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   * @version $Id$
29   */
30  public class InterpolationException
31      extends Exception
32  {
33  
34      private static final long serialVersionUID = 1L;
35      
36      private final String expression;
37  
38      /**
39       * @param message The general description of the problem
40       * @param expression The expression that triggered the problem
41       * @param cause The wrapped exception
42       */
43      public InterpolationException( String message,
44                                        String expression,
45                                        Throwable cause )
46      {
47          super( buildMessage( message, expression ), cause );
48          this.expression = expression;
49      }
50  
51      /**
52       * @param message The general description of the problem
53       * @param expression The expression that triggered the problem
54       */
55      public InterpolationException( String message, String expression )
56      {
57          super( buildMessage( message, expression ) );
58          this.expression = expression;
59      }
60  
61      private static String buildMessage( String message,
62                                          String expression )
63      {
64          return "Resolving expression: '" + expression + "': " + message;
65      }
66  
67      /**
68       * @return The expression that triggered this exception.
69       */
70      public String getExpression()
71      {
72          return expression;
73      }
74  
75  }