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