001    // Copyright 2006, 2008 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.services;
016    
017    import java.util.Collection;
018    
019    /**
020     * Defines how changes to fields (within components, within pages) may have their values persisted between requests.
021     * Different implementations store the field values {@linkplain org.apache.tapestry5.internal.services.SessionPersistentFieldStrategy
022     * in the session}, {@linkplain org.apache.tapestry5.internal.services.ClientPersistentFieldStrategy on the client}, or
023     * elsewhere.
024     */
025    public interface PersistentFieldStrategy
026    {
027        /**
028         * Posts a change of a persistent property.
029         *
030         * @param pageName    the name of the page containing the component
031         * @param componentId the nested id path of the component (or null for the page's root component)
032         * @param fieldName   the name of the field whose persistent value has changed
033         * @param newValue    the new value for the field, possibly null
034         */
035        void postChange(String pageName, String componentId, String fieldName, Object newValue);
036    
037        /**
038         * Finds all persistent changes previously stored for the named page (for the current active session or client).
039         */
040        Collection<PersistentFieldChange> gatherFieldChanges(String pageName);
041    
042        /**
043         * Discards any saved changes for the name page. There is no expectation that data already gathered from the
044         * strategy and persumably dumped into component instance fields will be affected, but future field access (within
045         * this request or a later one) will show no data for the indicated page.
046         *
047         * @param pageName logical name of page whose field persistent data should be discarded
048         */
049        void discardChanges(String pageName);
050    }