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      private final String message;
34      private Throwable cause;
35      private final String path;
36  
37      public ObjectInterpolationWarning(String path, String message) {
38          this.path = path;
39          this.message = message;
40      }
41  
42      public ObjectInterpolationWarning(String path, String message, Throwable cause) {
43          this.path = path;
44          this.message = message;
45          this.cause = cause;
46      }
47  
48      public String getPath() {
49          return path;
50      }
51  
52      public String getMessage() {
53          return message;
54      }
55  
56      public Throwable getCause() {
57          return cause;
58      }
59  
60      public String toString() {
61          if (cause == null) {
62              return path + ": " + message;
63          } else {
64              StringWriter w = new StringWriter();
65              PrintWriter pw = new PrintWriter(w);
66  
67              pw.print(path);
68              pw.print(": ");
69              pw.println(message);
70              pw.println("Cause: ");
71              cause.printStackTrace(pw);
72  
73              return w.toString();
74          }
75      }
76  }