Author: henning Date: Sat Nov 4 12:11:29 2006 New Revision: 471254 URL: http://svn.apache.org/viewvc?view=rev&rev=471254 Log: Reorganize the Throwable wrapping a bit (shuffle it up into VelocityException). Add Template Name, Line Number and Column Number recording to MethodInvocationException by implementing the ExtendedParseException interface thus allowing Velocity integrators to retrieve the location and the template exactly and in the same way as with the other parse exceptions. Resolves VELOCITY-414.
Modified: jakarta/velocity/engine/trunk/CONTRIBUTORS jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java Modified: jakarta/velocity/engine/trunk/CONTRIBUTORS URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/CONTRIBUTORS?view=diff&rev=471254&r1=471253&r2=471254 ============================================================================== --- jakarta/velocity/engine/trunk/CONTRIBUTORS (original) +++ jakarta/velocity/engine/trunk/CONTRIBUTORS Sat Nov 4 12:11:29 2006 @@ -25,6 +25,7 @@ Leon Messerschmidt Llewellyn Falco Matt Raible +Matthijs Lambooy Nathan Bubna Paulo Gaspar Peter Romianowski Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java?view=diff&rev=471254&r1=471253&r2=471254 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/MethodInvocationException.java Sat Nov 4 12:11:29 2006 @@ -1,5 +1,7 @@ package org.apache.velocity.exception; +import org.apache.commons.lang.StringUtils; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -16,10 +18,9 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations - * under the License. + * under the License. */ -import org.apache.velocity.util.ExceptionUtils; /** @@ -33,16 +34,20 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a> * @version $Id$ */ -public class MethodInvocationException extends VelocityException +public class MethodInvocationException extends VelocityException implements ExtendedParseException { /** * Version Id for serializable */ - private static final long serialVersionUID = 7305685093478106341L; + private static final long serialVersionUID = 7305685093478106342L; - private String methodName = ""; private String referenceName = ""; - private Throwable wrapped = null; + + private final String methodName; + + private final int lineNumber; + private final int columnNumber; + private final String templateName; /** * CTOR - wraps the passed in exception for @@ -51,18 +56,21 @@ * @param message * @param e Throwable that we are wrapping * @param methodName name of method that threw the exception + * @param templateName The name of the template where the exception occured. */ - public MethodInvocationException( String message, Throwable e, String methodName ) + public MethodInvocationException(final String message, final Throwable e, final String methodName, final String templateName, final int lineNumber, final int columnNumber) { - super(message); - this.wrapped = e; - ExceptionUtils.setCause(this, e); + super(message, e); + this.methodName = methodName; + this.templateName = templateName; + this.lineNumber = lineNumber; + this.columnNumber = columnNumber; } /** * Returns the name of the method that threw the - * exception + * exception. * * @return String name of method */ @@ -72,34 +80,60 @@ } /** - * returns the wrapped Throwable that caused this - * MethodInvocationException to be thrown - * - * @return Throwable thrown by method invocation - */ - public Throwable getWrappedThrowable() - { - return wrapped; - } - - /** - * Sets the reference name that threw this exception + * Sets the reference name that threw this exception. * * @param ref name of reference */ - public void setReferenceName( String ref ) + public void setReferenceName(String ref) { referenceName = ref; } /** * Retrieves the name of the reference that caused the - * exception + * exception. * - * @return name of reference + * @return name of reference. */ public String getReferenceName() { return referenceName; + } + + /** + * @see ExtendedParseException#getColumnNumber() + */ + public int getColumnNumber() + { + return columnNumber; + } + + /** + * @see ExtendedParseException#getLineNumber() + */ + public int getLineNumber() + { + return lineNumber; + } + + /** + * @see ExtendedParseException#getTemplateName() + */ + public String getTemplateName() + { + return templateName; + } + + /** + * @see Exception#getMessage() + */ + public String getMessage() + { + StringBuffer message = new StringBuffer(); + message.append(super.getMessage()); + message.append(" @ "); + message.append(StringUtils.isNotEmpty(templateName) ? templateName : "<unknown template>"); + message.append("[").append(lineNumber).append(",").append(columnNumber).append("]"); + return message.toString(); } } Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java?view=diff&rev=471254&r1=471253&r2=471254 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/exception/VelocityException.java Sat Nov 4 12:11:29 2006 @@ -1,5 +1,7 @@ package org.apache.velocity.exception; +import org.apache.velocity.util.ExceptionUtils; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -26,18 +28,43 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Kyle F. Downey</a> * @version $Id$ */ -public class VelocityException extends RuntimeException +public class VelocityException + extends RuntimeException { /** * Version Id for serializable */ - private static final long serialVersionUID = 1251243065134956044L; + private static final long serialVersionUID = 1251243065134956045L; + + private final Throwable wrapped; /** - * @param exceptionMessage + * @param exceptionMessage The message to register. */ - public VelocityException(String exceptionMessage ) + public VelocityException(String exceptionMessage) { super(exceptionMessage); + wrapped = null; + } + + /** + * @param exceptionMessage The message to register. + */ + public VelocityException(final String exceptionMessage, final Throwable wrapped) + { + super(exceptionMessage); + this.wrapped = wrapped; + ExceptionUtils.setCause(this, wrapped); + } + + /** + * returns the wrapped Throwable that caused this + * MethodInvocationException to be thrown + * + * @return Throwable thrown by method invocation + */ + public Throwable getWrappedThrowable() + { + return wrapped; } } Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java?view=diff&rev=471254&r1=471253&r2=471254 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java Sat Nov 4 12:11:29 2006 @@ -205,9 +205,8 @@ "Invocation of method '" + vg.getMethodName() + "'" + " in " + o.getClass() + " threw exception " - + ite.getTargetException().getClass() + " : " - + ite.getTargetException().getMessage(), - ite.getTargetException(), vg.getMethodName()); + + ite.getTargetException().toString(), + ite.getTargetException(), vg.getMethodName(), context.getCurrentTemplateName(), this.getLine(), this.getColumn()); } } else @@ -220,9 +219,8 @@ "Invocation of method '" + vg.getMethodName() + "'" + " in " + o.getClass() + " threw exception " - + ite.getTargetException().getClass() + " : " - + ite.getTargetException().getMessage(), - ite.getTargetException(), vg.getMethodName()); + + ite.getTargetException().toString(), + ite.getTargetException(), vg.getMethodName(), context.getCurrentTemplateName(), this.getLine(), this.getColumn()); } Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java?view=diff&rev=471254&r1=471253&r2=471254 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTMethod.java Sat Nov 4 12:11:29 2006 @@ -288,11 +288,9 @@ throw new MethodInvocationException( "Invocation of method '" + methodName + "' in " + o.getClass() - + " in template " + context.getCurrentTemplateName() - + " at line=" + this.getLine() + " column=" + this.getColumn() + " threw exception " - + e.getClass() + " : " + e.getMessage(), - e, methodName ); + + e.toString(), + e, methodName, context.getCurrentTemplateName(), this.getLine(), this.getColumn()); } } else @@ -304,12 +302,9 @@ throw new MethodInvocationException( "Invocation of method '" + methodName + "' in " + o.getClass() - + " in template " + context.getCurrentTemplateName() - + " at line=" + this.getLine() + " column=" + this.getColumn() + " threw exception " - + ite.getTargetException().getClass() + " : " - + ite.getTargetException().getMessage(), - ite.getTargetException(), methodName ); + + ite.getTargetException().toString(), + ite.getTargetException(), methodName, context.getCurrentTemplateName(), this.getLine(), this.getColumn()); } } /** Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java?view=diff&rev=471254&r1=471253&r2=471254 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTReference.java Sat Nov 4 12:11:29 2006 @@ -497,8 +497,8 @@ "ASTReference : Invocation of method '" + identifier + "' in " + result.getClass() + " threw exception " - + ite.getTargetException().getClass(), - ite.getTargetException(), identifier ); + + ite.getTargetException().toString(), + ite.getTargetException(), identifier, context.getCurrentTemplateName(), this.getLine(), this.getColumn()); } /** * pass through application level runtime exceptions --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]