    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.annotations;
    014
    015import org.apache.tapestry5.internal.transform.BindParameterWorker;
    016import org.apache.tapestry5.ioc.annotations.UseWith;
    017
    018import java.lang.annotation.ElementType;
    019import java.lang.annotation.Retention;
    020import java.lang.annotation.RetentionPolicy;
    021import java.lang.annotation.Target;
    022
    023import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.MIXIN;
    024
    025/**
    026 * Designates a field in a mixin which is bound to the parameter of the containing
    027 * component corresponding to the value of the annotation. If no value is specified,
    028 * the bound parameter name is assumed to match the field name of the mixin.
    029 * For example, a mixin intended to work with form fields would define a field named
    030 * "value", marked by this annotation. The user-variable bound to the component's value
    031 * parameter would ultimately be bound in a chain:
    032 * user-variable {@code <=>} mixin.value {@code <=>} component.value.
    033 * Changes to any one value in the chain will be propagated accordingly.
    034 *
    035 * @since 5.2.0
    036 * @see BindParameterWorker
    037 */
    038@Target(ElementType.FIELD)
    039@Retention(RetentionPolicy.RUNTIME)
    040@UseWith(MIXIN)
    041public @interface BindParameter
    042{
    043
    044    /**
    045     * @return the name of the mixin bound-parameter, exactly as for the Parameter annotation.
    046     */
    047    String name() default "";
    048
    049    /**
    050     * @return the name(s) of the parent parameter to bind. Defaults to the name of the mixin field.
    051     *         If more than one
    052     *         name is specified, the first name matching a declared parameter of the core component
    053     *         will be used.
    054     */
    055    String[] value() default
    056    { "" };
    057}