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