001: package org.apache.velocity.exception;
002:
003: import org.apache.commons.lang.StringUtils;
004:
005: /*
006: * Licensed to the Apache Software Foundation (ASF) under one
007: * or more contributor license agreements. See the NOTICE file
008: * distributed with this work for additional information
009: * regarding copyright ownership. The ASF licenses this file
010: * to you under the Apache License, Version 2.0 (the
011: * "License"); you may not use this file except in compliance
012: * with the License. You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing,
017: * software distributed under the License is distributed on an
018: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
019: * KIND, either express or implied. See the License for the
020: * specific language governing permissions and limitations
021: * under the License.
022: */
023:
024: /**
025: * Application-level exception thrown when a reference method is
026: * invoked and an exception is thrown.
027: * <br>
028: * When this exception is thrown, a best effort will be made to have
029: * useful information in the exception's message. For complete
030: * information, consult the runtime log.
031: *
032: * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
033: * @version $Id: MethodInvocationException.java 471254 2006-11-04 20:11:29Z henning $
034: */
035: public class MethodInvocationException extends VelocityException
036: implements ExtendedParseException {
037: /**
038: * Version Id for serializable
039: */
040: private static final long serialVersionUID = 7305685093478106342L;
041:
042: private String referenceName = "";
043:
044: private final String methodName;
045:
046: private final int lineNumber;
047: private final int columnNumber;
048: private final String templateName;
049:
050: /**
051: * CTOR - wraps the passed in exception for
052: * examination later
053: *
054: * @param message
055: * @param e Throwable that we are wrapping
056: * @param methodName name of method that threw the exception
057: * @param templateName The name of the template where the exception occured.
058: */
059: public MethodInvocationException(final String message,
060: final Throwable e, final String methodName,
061: final String templateName, final int lineNumber,
062: final int columnNumber) {
063: super (message, e);
064:
065: this .methodName = methodName;
066: this .templateName = templateName;
067: this .lineNumber = lineNumber;
068: this .columnNumber = columnNumber;
069: }
070:
071: /**
072: * Returns the name of the method that threw the
073: * exception.
074: *
075: * @return String name of method
076: */
077: public String getMethodName() {
078: return methodName;
079: }
080:
081: /**
082: * Sets the reference name that threw this exception.
083: *
084: * @param ref name of reference
085: */
086: public void setReferenceName(String ref) {
087: referenceName = ref;
088: }
089:
090: /**
091: * Retrieves the name of the reference that caused the
092: * exception.
093: *
094: * @return name of reference.
095: */
096: public String getReferenceName() {
097: return referenceName;
098: }
099:
100: /**
101: * @see ExtendedParseException#getColumnNumber()
102: */
103: public int getColumnNumber() {
104: return columnNumber;
105: }
106:
107: /**
108: * @see ExtendedParseException#getLineNumber()
109: */
110: public int getLineNumber() {
111: return lineNumber;
112: }
113:
114: /**
115: * @see ExtendedParseException#getTemplateName()
116: */
117: public String getTemplateName() {
118: return templateName;
119: }
120:
121: /**
122: * @see Exception#getMessage()
123: */
124: public String getMessage() {
125: StringBuffer message = new StringBuffer();
126: message.append(super .getMessage());
127: message.append(" @ ");
128: message
129: .append(StringUtils.isNotEmpty(templateName) ? templateName
130: : "<unknown template>");
131: message.append("[").append(lineNumber).append(",").append(
132: columnNumber).append("]");
133: return message.toString();
134: }
135: }
|