001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.jexl2.introspection; 019 020 /** 021 * Interface used for regular method invocation. 022 * Ex. 023 * <code> 024 * ${foo.bar()} 025 * </code> 026 * 027 * @since 1.0 028 */ 029 public interface JexlMethod { 030 /** 031 * Invocation method, called when the method invocation should be performed 032 * and a value returned. 033 034 * @param obj the object 035 * @param params method parameters. 036 * @return the result 037 * @throws Exception on any error. 038 */ 039 Object invoke(Object obj, Object[] params) throws Exception; 040 041 /** 042 * Attempts to reuse this JexlMethod, checking that it is compatible with 043 * the actual set of arguments. 044 * Related to isCacheable since this method is often used with cached JexlMethod instances. 045 * @param obj the object to invoke the method upon 046 * @param name the method name 047 * @param params the method arguments 048 * @return the result of the method invocation that should be checked by tryFailed to determine if it succeeded 049 * or failed. 050 */ 051 Object tryInvoke(String name, Object obj, Object[] params); 052 053 /** 054 * Checks whether a tryInvoke failed or not. 055 * @param rval the value returned by tryInvoke 056 * @return true if tryInvoke failed, false otherwise 057 */ 058 boolean tryFailed(Object rval); 059 060 /** 061 * Specifies if this JexlMethod is cacheable and able to be reused for this 062 * class of object it was returned for. 063 * 064 * @return true if can be reused for this class, false if not 065 */ 066 boolean isCacheable(); 067 068 /** 069 * returns the return type of the method invoked. 070 * @return return type 071 */ 072 Class<?> getReturnType(); 073 }