    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.services;
    014
    015import org.apache.tapestry5.Binding;
    016import org.apache.tapestry5.ComponentResources;
    017import org.apache.tapestry5.commons.Location;
    018import org.apache.tapestry5.ioc.annotations.UsesMappedConfiguration;
    019
    020/**
    021 * Used to acquire bindings for component parameters. The BindingSource service strips off the binding prefix to locate
    022 * a {@link org.apache.tapestry5.services.BindingFactory}.
    023 */
    024@UsesMappedConfiguration(BindingFactory.class)
    025public interface BindingSource
    026{
    027    /**
    028     * Examines the expression and strips off the leading prefix. The prefix is used to choose the appropriate {@link
    029     * BindingFactory}, which receives the description, the expression (after the prefix), and the location. If the
    030     * prefix doesn't exist, or if there's no prefix, then the factory for the default prefix (often "literal") is used
    031     * (and passed the full prefix).
    032     *
    033     * The binding represents a connection between the container and the component (the component is usually the child
    034     * of the container, though in a few cases, it is the component itself). In most cases, the expression is evaluated
    035     * in terms of the resources of the <em>container</em> and the component is ignored.
    036     *
    037     * @param description   description of the binding, such as "parameter foo"
    038     * @param container     typically, the parent of the component
    039     * @param component     the component whose parameter is to be bound
    040     * @param defaultPrefix the default prefix used when the expression itself does not have a prefix
    041     * @param expression    the binding
    042     * @param location      location assigned to the binding (or null if not known)
    043     * @return a binding
    044     */
    045    Binding newBinding(String description, ComponentResources container, ComponentResources component,
    046                       String defaultPrefix, String expression, Location location);
    047
    048    /**
    049     * A simpler version of {@link #newBinding(String, ComponentResources, ComponentResources, String, String,
    050     * Location)} that defaults the values for several parameters. This is used in most cases. The default binding
    051     * prefix will be "prop". Most often, this is used to create a new default binding.
    052     *
    053     * @param description   description of the binding, such as "parameter foo"
    054     * @param container     typically, the parent of the component. This value will be used as the container
    055     *                      <em>and</em> the component, so whatever type of expression is evaluated, will be evaulated
    056     *                      in terms of this component
    057     * @param defaultPrefix the default prefix used when the expression itself does not have a prefix
    058     * @param expression    the binding
    059     * @return a binding
    060     */
    061    Binding newBinding(String description, ComponentResources container, String defaultPrefix, String expression);
    062}