001 // Copyright 2008, 2009, 2010, 2011 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry5.ioc; 016 017 import java.lang.annotation.Annotation; 018 019 import org.apache.tapestry5.plastic.MethodInvocation; 020 021 /** 022 * A method invocation passed to a {@link org.apache.tapestry5.ioc.MethodAdvice}. 023 * 024 * @deprecated Deprecated in 5.3, to be removed in 5.4. Replaced with {@link MethodInvocation}. 025 */ 026 public interface Invocation 027 { 028 /** 029 * Returns the name of the method being invoked. 030 */ 031 String getMethodName(); 032 033 /** 034 * Returns the type of the method result, which may be a primitive type (i.e., int.class) or even void 035 * (void.class). 036 */ 037 Class getResultType(); 038 039 /** 040 * Returns the number of parameters passed to the method. 041 */ 042 int getParameterCount(); 043 044 /** 045 * Returns the type of the parameter at the index. 046 */ 047 Class getParameterType(int index); 048 049 /** 050 * Returns the indicated parameter (may return null if the parameter is null). 051 */ 052 Object getParameter(int index); 053 054 /** 055 * Replaces a parameter in the invocation. 056 * 057 * @param index 058 * of parameter to update 059 * @param newParameter 060 * new parameter value (may be null) 061 */ 062 void override(int index, Object newParameter); 063 064 /** 065 * Proceed with the invocation of the advised method. If the invocation results in a <em>runtime</em> exception, 066 * that is thrown. A checked exception is detected by invoking {@link #isFail()}. 067 */ 068 void proceed(); 069 070 /** 071 * If true, then the proceeded invocation threw a checked exception. 072 */ 073 boolean isFail(); 074 075 /** 076 * If the invocation failed (with a checked exception), then rethrow the exception wrapped in a 077 * RuntimeException. 078 * 079 * @since 5.2.0 080 */ 081 void rethrow(); 082 083 /** 084 * After invoking {@link #proceed()}, used to obtain the thrown (checked) exception, if assignable to the provided 085 * type. 086 * 087 * @param throwableClass 088 * the type of exception to match 089 * @return the exception, if the proceeded invocation threw a checked exception, and the exception is assignable to 090 * the provided type. In other cases, null is returned. 091 */ 092 <T extends Throwable> T getThrown(Class<T> throwableClass); 093 094 /** 095 * Overrides the thrown exception. The passed exception should be a checked exception of the method. Note that for 096 * runtime exceptions, or even {@link Error}s, those can just be thrown. Sets the fail flag. 097 * 098 * @param thrown 099 * @throws IllegalArgumentException 100 * if thrown is null, or not a declared exception of the method 101 */ 102 void overrideThrown(Exception thrown); 103 104 /** 105 * The return value after {@link #proceed()}, which may be null. 106 */ 107 Object getResult(); 108 109 /** 110 * Overrides the result. Clears the thrown exception (if any). 111 */ 112 void overrideResult(Object newResult); 113 114 /** 115 * Returns the annotation, placed on the method being invoked, for the specified type. If 116 * such an annotation is present, else null. 117 * 118 * @param annotationClass 119 * the Class object corresponding to the 120 * annotation type 121 * @return method's annotation for the specified annotation type if 122 * present on this element, else null 123 * @since 5.3 124 */ 125 <T extends Annotation> T getMethodAnnotation(Class<T> annotationClass); 126 }