1 package org.apache.velocity.exception; 2 3 import org.apache.commons.lang.StringUtils; 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 471254 2006-11-04 20:11:29Z henning $ 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 */ 106 public int getColumnNumber() 107 { 108 return columnNumber; 109 } 110 111 /** 112 * @see ExtendedParseException#getLineNumber() 113 */ 114 public int getLineNumber() 115 { 116 return lineNumber; 117 } 118 119 /** 120 * @see ExtendedParseException#getTemplateName() 121 */ 122 public String getTemplateName() 123 { 124 return templateName; 125 } 126 127 /** 128 * @see Exception#getMessage() 129 */ 130 public String getMessage() 131 { 132 StringBuffer message = new StringBuffer(); 133 message.append(super.getMessage()); 134 message.append(" @ "); 135 message.append(StringUtils.isNotEmpty(templateName) ? templateName : "<unknown template>"); 136 message.append("[").append(lineNumber).append(",").append(columnNumber).append("]"); 137 return message.toString(); 138 } 139 }