1 package org.apache.velocity.exception;
2
3 import org.apache.velocity.runtime.log.Log;
4
5 /*
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 */
23
24
25
26 /**
27 * Application-level exception thrown when a reference method is
28 * invoked and an exception is thrown.
29 * <br>
30 * When this exception is thrown, a best effort will be made to have
31 * useful information in the exception's message. For complete
32 * information, consult the runtime log.
33 *
34 * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
35 * @version $Id: MethodInvocationException.java 898045 2010-01-11 20:11:02Z nbubna $
36 */
37 public class MethodInvocationException extends VelocityException implements ExtendedParseException
38 {
39 /**
40 * Version Id for serializable
41 */
42 private static final long serialVersionUID = 7305685093478106342L;
43
44 private String referenceName = "";
45
46 private final String methodName;
47
48 private final int lineNumber;
49 private final int columnNumber;
50 private final String templateName;
51
52 /**
53 * CTOR - wraps the passed in exception for
54 * examination later
55 *
56 * @param message
57 * @param e Throwable that we are wrapping
58 * @param methodName name of method that threw the exception
59 * @param templateName The name of the template where the exception occured.
60 */
61 public MethodInvocationException(final String message, final Throwable e, final String methodName, final String templateName, final int lineNumber, final int columnNumber)
62 {
63 super(message, e);
64
65 this.methodName = methodName;
66 this.templateName = templateName;
67 this.lineNumber = lineNumber;
68 this.columnNumber = columnNumber;
69 }
70
71 /**
72 * Returns the name of the method that threw the
73 * exception.
74 *
75 * @return String name of method
76 */
77 public String getMethodName()
78 {
79 return methodName;
80 }
81
82 /**
83 * Sets the reference name that threw this exception.
84 *
85 * @param ref name of reference
86 */
87 public void setReferenceName(String ref)
88 {
89 referenceName = ref;
90 }
91
92 /**
93 * Retrieves the name of the reference that caused the
94 * exception.
95 *
96 * @return name of reference.
97 */
98 public String getReferenceName()
99 {
100 return referenceName;
101 }
102
103 /**
104 * @see ExtendedParseException#getColumnNumber()
105 * @since 1.5
106 */
107 public int getColumnNumber()
108 {
109 return columnNumber;
110 }
111
112 /**
113 * @see ExtendedParseException#getLineNumber()
114 * @since 1.5
115 */
116 public int getLineNumber()
117 {
118 return lineNumber;
119 }
120
121 /**
122 * @see ExtendedParseException#getTemplateName()
123 * @since 1.5
124 */
125 public String getTemplateName()
126 {
127 return templateName;
128 }
129
130 /**
131 * @see Exception#getMessage()
132 * @since 1.5
133 */
134 public String getMessage()
135 {
136 StringBuffer message = new StringBuffer();
137 message.append(super.getMessage());
138 message.append(" at ");
139 message.append(Log.formatFileString(templateName, lineNumber, columnNumber));
140 return message.toString();
141 }
142 }