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