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     * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
029     * @version $Id: JexlMethod.java 889760 2009-12-11 18:42:49Z sebb $
030     */
031    public interface JexlMethod {
032        /**
033         * Invocation method, called when the method invocation should be performed
034         * and a value returned.
035    
036         * @param obj the object
037         * @param params method parameters.
038         * @return the result
039         * @throws Exception on any error.
040         */
041        Object invoke(Object obj, Object[] params) throws Exception;
042    
043        /**
044         * Attempts to reuse this JexlMethod, checking that it is compatible with
045         * the actual set of arguments.
046         * Related to isCacheable since this method is often used with cached JexlMethod instances.
047         * @param obj the object to invoke the method upon
048         * @param name the method name
049         * @param params the method arguments
050         * @return the result of the method invocation that should be checked by tryFailed to determine if it succeeded
051         * or failed.
052         */
053        Object tryInvoke(String name, Object obj, Object[] params);
054    
055        /**
056         * Checks whether a tryInvoke failed or not.
057         * @param rval the value returned by tryInvoke
058         * @return true if tryInvoke failed, false otherwise
059         */
060        boolean tryFailed(Object rval);
061    
062        /**
063         * Specifies if this JexlMethod is cacheable and able to be reused for this
064         * class of object it was returned for.
065         * 
066         * @return true if can be reused for this class, false if not
067         */
068        boolean isCacheable();
069    
070        /**
071         * returns the return type of the method invoked.
072         * @return return type
073         */
074        Class<?> getReturnType();
075    }