001    package org.apache.commons.ognl;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.util.Map;
023    
024    /**
025     * This interface defines methods for setting and getting a property from a target object. A "property" in this case is
026     * a named data value that takes the generic form of an Object---the same definition as is used by beans. But the
027     * operational semantics of the term will vary by implementation of this interface: a bean-style implementation will get
028     * and set properties as beans do, by reflection on the target object's class, but other implementations are possible,
029     * such as one that uses the property name as a key into a map.
030     * <p>
031     * An implementation of this interface will often require that its target objects all be of some particular type. For
032     * example, the MapPropertyAccessor class requires that its targets all implement the java.util.Map interface.
033     * <p>
034     * Note that the "name" of a property is represented by a generic Object. Some implementations may require properties'
035     * names to be Strings, while others may allow them to be other types---for example, ArrayPropertyAccessor treats Number
036     * names as indexes into the target object, which must be an array.
037     * 
038     * @author Luke Blanshard (blanshlu@netscape.net)
039     * @author Drew Davidson (drew@ognl.org)
040     */
041    public interface PropertyAccessor
042    {
043    
044        /**
045         * Extracts and returns the property of the given name from the given target object.
046         * 
047         * @param context The current execution context.
048         * @param target the object to get the property from
049         * @param name the name of the property to get.
050         * @return the current value of the given property in the given object
051         * @exception OgnlException if there is an error locating the property in the given object
052         */
053        Object getProperty( Map<String, Object> context, Object target, Object name )
054            throws OgnlException;
055    
056        /**
057         * Sets the value of the property of the given name in the given target object.
058         * 
059         * @param context The current execution context.
060         * @param target the object to set the property in
061         * @param name the name of the property to set
062         * @param value the new value for the property.
063         * @exception OgnlException if there is an error setting the property in the given object
064         */
065        void setProperty( Map<String, Object> context, Object target, Object name, Object value )
066            throws OgnlException;
067    
068        /**
069         * Returns a java string representing the textual method that should be called to access a particular element. (ie
070         * "get")
071         * 
072         * @param context The current execution context.
073         * @param target The current object target on the expression tree being evaluated.
074         * @param index The index object that will be placed inside the string to access the value.
075         * @return The source accessor method to call.
076         */
077        String getSourceAccessor( OgnlContext context, Object target, Object index );
078    
079        /**
080         * Returns a java string representing the textual method that should be called to set a particular element. (ie
081         * "set")
082         * 
083         * @param context The current execution context.
084         * @param target The current object target on the expression tree being evaluated.
085         * @param index The index object that will be placed inside the string to set the value.
086         * @return The source setter method to call.
087         */
088        String getSourceSetter( OgnlContext context, Object target, Object index );
089    }