View Javadoc

1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
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  
17  package com.fatwire.gst.foundation.facade.runtag;
18  
19  import COM.FutureTense.Interfaces.FTValList;
20  import COM.FutureTense.Util.ftErrors;
21  
22  import com.fatwire.gst.foundation.CSRuntimeException;
23  
24  /**
25   * Exception that is thrown when a TagRunner is invoked and the
26   * 
27   * @author Dolf.Dijkstra
28   */
29  public class TagRunnerRuntimeException extends CSRuntimeException {
30      private final String pageName;
31      private final String elementName;
32      private final FTValList arguments;
33      private static final long serialVersionUID = 5392042951880858120L;
34  
35      /**
36       * @param msg
37       * @param errno
38       */
39      public TagRunnerRuntimeException(String msg, int errno, final FTValList arguments) {
40          this(msg, errno, arguments, null, null, null);
41      }
42  
43      public TagRunnerRuntimeException(String msg, int errno, final FTValList arguments, ftErrors complexError,
44              String pagename, String elementname) {
45          super(msg, complexError, errno);
46          this.arguments = arguments;
47          this.pageName = pagename;
48          this.elementName = elementname;
49      }
50  
51      /**
52       * @return the pagename that generated this exception or null if this was
53       *         not provided
54       */
55      public String getPageName() {
56          return pageName;
57      }
58  
59      /**
60       * @return the name of the element that generated this exception or null if
61       *         this was not provided
62       */
63      public String getElementName() {
64          return elementName;
65      }
66  
67      public FTValList getArguments() {
68          return arguments;
69      }
70  
71      @Override
72      public String getMessage() {
73          StringBuilder builder = new StringBuilder();
74          builder.append(super.getMessage());
75          builder.append("|");
76          builder.append(arguments);
77          builder.append("|");
78          builder.append(getPageName());
79          builder.append("|");
80          builder.append(getElementName());
81          if (getComplexError() != null) {
82              builder.append("|");
83              builder.append("reason: ").append(getComplexError().getReason());
84              builder.append("|message: ");
85              builder.append(getComplexError().getMessage());
86  
87              int details = getComplexError().details();
88              if (details > 0) {
89                  builder.append("|");
90              }
91              for (int i = 0; i < details; i++) {
92                  builder.append(" ");
93                  builder.append(getComplexError().detail(i));
94              }
95          }
96          return builder.toString();
97      }
98  }