    001    // Copyright 2006, 2008, 2009 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.internal.bindings;
    016
    017    import org.apache.tapestry5.ioc.Location;
    018
    019    /**
    020     * Binding type for literal, immutable values. Literal bindings are {@linkplain org.apache.tapestry5.Binding#isInvariant()
    021     * invariant}; any value provided by a LiteralBinding, even if {@linkplain org.apache.tapestry5.ioc.services.TypeCoercer#coerce(Object,
    022     * Class) coerced}, will be cached aggresively by Tapestry cmponent.
    023     * <p/>
    024     * <p>LiteralBindings are often used for literal string values supplied in-line in the component template, but is used
    025     * for many other things as well, any kind of fixed, read-only value.
    026     */
    027    public class LiteralBinding extends AbstractBinding
    028    {
    029        private final String description;
    030
    031        private final Object value;
    032
    033        public LiteralBinding(Location location, String description, Object value)
    034        {
    035            super(location);
    036            this.description = description;
    037            this.value = value;
    038        }
    039
    040        public Object get()
    041        {
    042            return value;
    043        }
    044
    045        @Override
    046        public String toString()
    047        {
    048            return String.format("LiteralBinding[%s: %s]", description, value);
    049        }
    050    }