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 used for setting values that appear to be properties.
024 * Ex.
025 * <code>
026 * ${foo.bar = "hello"}
027 * </code>
028 *
029 * @since 1.0
030 */
031public interface JexlPropertySet {
032
033    /**
034     * Method used to set the property value of an object.
035     *
036     * @param obj Object on which the property setter will be called with the value
037     * @param arg value to be set
038     * @return the value returned from the set operation (impl specific)
039     * @throws Exception on any error.
040     */
041    Object invoke(Object obj, Object arg) throws Exception;
042
043    /**
044     * Specifies if this JexlPropertySet is cacheable and able to be reused for
045     * this class of object it was returned for.
046     *
047     * @return true if can be reused for this class, false if not
048     */
049    boolean isCacheable();
050
051    /**
052     * Checks whether a tryInvoke failed or not.
053     *
054     * @param rval the value returned by tryInvoke
055     * @return true if tryInvoke failed, false otherwise
056     */
057    boolean tryFailed(Object rval);
058
059    /**
060     * Attempts to reuse this JexlPropertySet, checking that it is compatible with
061     * the actual set of arguments.
062     *
063     * @param obj the object to invoke the get upon
064     * @param key the property key to get
065     * @param value the property value to set
066     * @return the result of the method invocation that should be checked by tryFailed to determine if it succeeded
067     * or failed.
068     * @throws JexlException.TryFailed if the underlying method was invoked but threw an exception
069     * ({@link java.lang.reflect.InvocationTargetException})
070     */
071    Object tryInvoke(Object obj, Object key, Object value) throws JexlException.TryFailed;
072}