View Javadoc
1   package org.codehaus.plexus.interpolation.object;
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  import java.io.PrintWriter;
20  import java.io.StringWriter;
21  
22  /**
23   * Represents a warning that occurred while interpolating an object graph. These
24   * warnings may not have a serious effect, so they don't cause an exception to be
25   * thrown. Each warning contains the path through the object graph from the point
26   * of entry to the place where the warning occurred, along with a message containing
27   * the actual warning and possibly a {@link Throwable} cause.
28   * 
29   * @author jdcasey
30   */
31  public class ObjectInterpolationWarning
32  {
33      
34      private final String message;
35      private Throwable cause;
36      private final String path;
37  
38      public ObjectInterpolationWarning( String path, String message )
39      {
40          this.path = path;
41          this.message = message;
42      }
43  
44      public ObjectInterpolationWarning( String path, String message, Throwable cause )
45      {
46          this.path = path;
47          this.message = message;
48          this.cause = cause;
49      }
50      
51      public String getPath()
52      {
53          return path;
54      }
55  
56      public String getMessage()
57      {
58          return message;
59      }
60  
61      public Throwable getCause()
62      {
63          return cause;
64      }
65      
66      public String toString()
67      {
68          if ( cause == null )
69          {
70              return path + ": " + message;
71          }
72          else
73          {
74              StringWriter w = new StringWriter();
75              PrintWriter pw = new PrintWriter( w );
76              
77              pw.print( path );
78              pw.print( ": " );
79              pw.println( message );
80              pw.println( "Cause: " );
81              cause.printStackTrace( pw );
82              
83              return w.toString();
84          }
85      }
86  
87  }