Source code
Description: source: package: org.apache.commons.jexl3.introspection, interface: JexlPropertyGet

    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 *      https://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
    018package org.apache.commons.jexl3.introspection;
    019
    020import org.apache.commons.jexl3.JexlException;
    021
    022/**
    023 * Interface for getting values that appear to be properties.
    024 * Ex.
    025 * <code>
    026 * ${foo.bar}
    027 * </code>
    028 *
    029 * @since 1.0
    030 */
    031public interface JexlPropertyGet {
    032
    033    /**
    034     * Method used to get the property value of an object.
    035     *
    036     * @param obj the object to get the property value from.
    037     * @return the property value.
    038     * @throws Exception on any error.
    039     */
    040    Object invoke(Object obj) throws Exception;
    041
    042    /**
    043     * Specifies if this JexlPropertyGet is cacheable and able to be reused for
    044     * this class of object it was returned for.
    045     *
    046     * @return true if can be reused for this class, false if not
    047     */
    048    boolean isCacheable();
    049
    050    /**
    051     * Checks whether this JexlPropertyGet returns a constant.
    052     *
    053     * @return true if invoking this getter will always return the same value, false otherwise
    054     */
    055    default boolean isConstant() {
    056        return false;
    057    }
    058
    059    /**
    060     * Checks whether a tryInvoke failed or not.
    061     *
    062     * @param rval the value returned by tryInvoke
    063     * @return true if tryInvoke failed, false otherwise
    064     */
    065    boolean tryFailed(Object rval);
    066
    067    /**
    068     * Attempts to reuse this JexlPropertyGet, checking that it is compatible with
    069     * the actual set of arguments.
    070     *
    071     * @param obj the object to invoke the property get upon
    072     * @param key the property key to get
    073     * @return the result of the method invocation that should be checked by tryFailed to determine if it succeeded
    074     * or failed.
    075     * @throws JexlException.TryFailed if the underlying method was invoked but threw an exception
    076     * ({@link java.lang.reflect.InvocationTargetException})
    077     */
    078    Object tryInvoke(Object obj, Object key) throws JexlException.TryFailed;
    079}