001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005// http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.plastic;
014
015/**
016 * A {@link FieldConduit} is an object that effectively <em>replaces</em> the field in the instantiated object.
017 * All reads and writes of the field are replaced with invocations on the conduit. Once a field's access is replaced
018 * with a conduit, the field itself is no longer used. The conduit will even see initializations of the field.
019 *
020 * In Aspect Oriented Programming terms, a FieldConduit allows you to advise read and write access to the field.
021 *
022 * If a field has both a FieldConduit and a {@link FieldHandle}, then the methods of the FieldHandle will be connected
023 * to the methods of the FieldConduit.
024 */
025public interface FieldConduit<T>
026{
027    /**
028     * Invoked when the field is read.
029     * 
030     * @param instance
031     *            the instance containing the field
032     * @param context
033     *            (see {@link ClassInstantiator#with(Class, Object)})
034     */
035    T get(Object instance, InstanceContext context);
036
037    /**
038     * Invoked when the field's value is updated.
039     * 
040     * @param instance
041     *            the instance containing the field
042     * @param context
043     *            (see {@link ClassInstantiator#with(Class, Object)})
044     * @param newValue
045     *            value assigned to the field
046     */
047    void set(Object instance, InstanceContext context, T newValue);
048}