001    // Copyright 2005 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.tapestry.enhance;
016    
017    import org.apache.hivemind.Location;
018    import org.apache.tapestry.IBinding;
019    import org.apache.tapestry.IComponent;
020    import org.apache.tapestry.binding.BindingConstants;
021    import org.apache.tapestry.binding.BindingSource;
022    
023    /**
024     * Encapsulates information needed to construct an initial value binding for a
025     * specified property (with an initial value).
026     * 
027     * @author Howard M. Lewis Ship
028     * @since 4.0
029     */
030    public class InitialValueBindingCreator
031    {
032        private BindingSource _bindingSource;
033    
034        private String _description;
035    
036        private String _initialValue;
037    
038        private Location _location;
039    
040        public InitialValueBindingCreator(BindingSource bindingSource,
041                String description, String initialValue, Location location)
042        {
043            _bindingSource = bindingSource;
044            _description = description;
045            _initialValue = initialValue;
046            _location = location;
047        }
048        
049        /**
050         * This method is just implemented for testing purposes.
051         */
052    
053        public boolean equals(Object obj)
054        {
055            InitialValueBindingCreator c = (InitialValueBindingCreator) obj;
056    
057            return _bindingSource == c._bindingSource
058                    && _description.equals(c._description)
059                    && _initialValue.equals(c._initialValue)
060                    && _location.equals(c._location);
061        }
062    
063        public IBinding createBinding(IComponent component)
064        {
065            return _bindingSource.createBinding(component, _description, _initialValue, BindingConstants.OGNL_PREFIX, _location);
066        }
067    }