    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.MarkupWriter;
    016import org.apache.tapestry5.internal.structure.PageResetListener;
    017import org.apache.tapestry5.plastic.MethodDescription;
    018import org.apache.tapestry5.plastic.PlasticUtils;
    019import org.apache.tapestry5.runtime.Component;
    020import org.apache.tapestry5.runtime.ComponentEvent;
    021import org.apache.tapestry5.runtime.Event;
    022import org.apache.tapestry5.runtime.PageLifecycleListener;
    023import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
    024
    025import java.lang.reflect.Modifier;
    026
    027/**
    028 * Constants used by implementations {@link ComponentClassTransformWorker2}.
    029 *
    030 * Note: render phase methods on transformed components will not be invoked <em>unless</em>
    031 * {@linkplain org.apache.tapestry5.model.MutableComponentModel#addRenderPhase(Class) the component model is updated to
    032 * identify the use of the corresponding render phase}. This represents an optimization introduced in Tapestry 5.1.
    033 */
    034public final class TransformConstants
    035{
    036    // Shared parameters of a whole bunch of lifecycle methods, representing the different
    037    // component render states.
    038    private static final String[] RENDER_PHASE_METHOD_PARAMETERS =
    039            {MarkupWriter.class.getName(), Event.class.getName()};
    040
    041
    042    /**
    043     * Description for
    044     * {@link org.apache.tapestry5.runtime.Component#dispatchComponentEvent(org.apache.tapestry5.runtime.ComponentEvent)}
    045     * .
    046     *
    047     * @see org.apache.tapestry5.annotations.OnEvent
    048     * @since 5.3
    049     */
    050    public static final MethodDescription DISPATCH_COMPONENT_EVENT_DESCRIPTION = PlasticUtils.getMethodDescription(
    051            Component.class, "dispatchComponentEvent", ComponentEvent.class);
    052
    053
    054    /**
    055     * Description for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidLoad()}.
    056     *
    057     * @since 5.3
    058     */
    059    public static final MethodDescription CONTAINING_PAGE_DID_LOAD_DESCRIPTION = PlasticUtils.getMethodDescription(
    060            PageLifecycleListener.class, "containingPageDidLoad");
    061
    062    /**
    063     * Description for {@link org.apache.tapestry5.internal.structure.PageResetListener#containingPageDidReset()}. Note that the {@link PageResetListener}
    064     * interface is not automatically implemented by components. ]
    065     *
    066     * @see org.apache.tapestry5.annotations.PageReset
    067     * @see org.apache.tapestry5.internal.transform.PageResetAnnotationWorker
    068     * @since 5.3
    069     */
    070    public static final MethodDescription CONTAINING_PAGE_DID_RESET_DESCRIPTION = PlasticUtils.getMethodDescription(PageResetListener.class, "containingPageDidReset");
    071
    072
    073    /**
    074     * Description for {@link org.apache.tapestry5.runtime.Component#postRenderCleanup()}.
    075     *
    076     * @since 5.3
    077     */
    078    public static final MethodDescription POST_RENDER_CLEANUP_DESCRIPTION = PlasticUtils.getMethodDescription(Component.class, "postRenderCleanup");
    079
    080
    081    /**
    082     * Description for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidDetach()}.
    083     *
    084     * @since 5.3
    085     */
    086    public static final MethodDescription CONTAINING_PAGE_DID_DETACH_DESCRIPTION = PlasticUtils.getMethodDescription(PageLifecycleListener.class, "containingPageDidDetach");
    087
    088
    089    /**
    090     * Description for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidAttach()}.
    091     *
    092     * @since 5.3
    093     */
    094    public static final MethodDescription CONTAINING_PAGE_DID_ATTACH_DESCRIPTION = PlasticUtils.getMethodDescription(PageLifecycleListener.class, "containingPageDidAttach");
    095
    096
    097    /**
    098     * Description for {@link org.apache.tapestry5.runtime.Component#setupRender(MarkupWriter, Event)}.
    099     *
    100     * @see org.apache.tapestry5.annotations.SetupRender
    101     * @since 5.3
    102     */
    103    public static final MethodDescription SETUP_RENDER_DESCRIPTION = renderPhaseDescription("setupRender");
    104
    105
    106    /**
    107     * Description for {@link org.apache.tapestry5.runtime.Component#beginRender(MarkupWriter, Event)}.
    108     *
    109     * @see org.apache.tapestry5.annotations.BeginRender
    110     * @since 5.3
    111     */
    112    public static final MethodDescription BEGIN_RENDER_DESCRIPTION = renderPhaseDescription("beginRender");
    113
    114
    115    /**
    116     * Description for {@link org.apache.tapestry5.runtime.Component#beforeRenderTemplate(MarkupWriter, Event)}.
    117     *
    118     * @see org.apache.tapestry5.annotations.BeforeRenderTemplate
    119     * @since 5.3
    120     */
    121    public static final MethodDescription BEFORE_RENDER_TEMPLATE_DESCRIPTION = renderPhaseDescription("beforeRenderTemplate");
    122
    123
    124    /**
    125     * Description for {@link org.apache.tapestry5.runtime.Component#afterRenderTemplate(MarkupWriter, Event)}.
    126     *
    127     * @see org.apache.tapestry5.annotations.BeforeRenderTemplate
    128     * @since 5.3
    129     */
    130    public static final MethodDescription AFTER_RENDER_TEMPLATE_DESCRIPTION = renderPhaseDescription("afterRenderTemplate");
    131
    132
    133    /**
    134     * Description for {@link org.apache.tapestry5.runtime.Component#beforeRenderBody(MarkupWriter, Event)}.
    135     *
    136     * @see org.apache.tapestry5.annotations.BeforeRenderBody
    137     * @since 5.3
    138     */
    139    public static final MethodDescription BEFORE_RENDER_BODY_DESCRIPTION = renderPhaseDescription("beforeRenderBody");
    140
    141
    142    /**
    143     * Description for {@link org.apache.tapestry5.runtime.Component#afterRenderBody(MarkupWriter, Event)}.
    144     *
    145     * @see org.apache.tapestry5.annotations.AfterRenderBody
    146     * @since 5.3
    147     */
    148    public static final MethodDescription AFTER_RENDER_BODY_DESCRIPTION = renderPhaseDescription("afterRenderBody");
    149
    150
    151    /**
    152     * Description for {@link org.apache.tapestry5.runtime.Component#afterRender(MarkupWriter, Event)}
    153     *
    154     * @see org.apache.tapestry5.annotations.AfterRender
    155     * @since 5.3
    156     */
    157    public static final MethodDescription AFTER_RENDER_DESCRIPTION = renderPhaseDescription("afterRender");
    158
    159
    160    /**
    161     * Description for {@link org.apache.tapestry5.runtime.Component#cleanupRender(MarkupWriter, Event)}.
    162     *
    163     * @see org.apache.tapestry5.annotations.CleanupRender
    164     * @since 5.3
    165     */
    166    public static final MethodDescription CLEANUP_RENDER_DESCRIPTION = renderPhaseDescription("cleanupRender");
    167
    168
    169    private static MethodDescription renderPhaseDescription(String name)
    170    {
    171        return new MethodDescription(Modifier.PUBLIC, "void", name, RENDER_PHASE_METHOD_PARAMETERS, null, null);
    172    }
    173
    174}