001// Copyright 2006, 2007, 2008, 2009, 2011 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.MarkupWriter;
018import org.apache.tapestry5.internal.structure.PageResetListener;
019import org.apache.tapestry5.plastic.MethodDescription;
020import org.apache.tapestry5.plastic.PlasticUtils;
021import org.apache.tapestry5.runtime.Component;
022import org.apache.tapestry5.runtime.ComponentEvent;
023import org.apache.tapestry5.runtime.Event;
024import org.apache.tapestry5.runtime.PageLifecycleListener;
025import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
026
027import java.lang.reflect.Modifier;
028
029/**
030 * Constants used by implementations of {@link org.apache.tapestry5.services.ComponentClassTransformWorker} and
031 * {@link ComponentClassTransformWorker2}.
032 * <p/>
033 * Note: methods on transformed components will not be invoked <em>unless</em>
034 * {@linkplain org.apache.tapestry5.model.MutableComponentModel#addRenderPhase(Class) the component model is updated to
035 * identify the use of the corresponding render phase}.
036 */
037public final class TransformConstants
038{
039    // Shared parameters of a whole bunch of lifecycle methods, representing the different
040    // component render states.
041    private static final String[] RENDER_PHASE_METHOD_PARAMETERS =
042            {MarkupWriter.class.getName(), Event.class.getName()};
043
044    /**
045     * Signature for
046     * {@link org.apache.tapestry5.runtime.Component#dispatchComponentEvent(org.apache.tapestry5.runtime.ComponentEvent)}
047     * .
048     *
049     * @see org.apache.tapestry5.annotations.OnEvent
050     * @deprecated Deprecated in Tapestry 5.3, use {@link #DISPATCH_COMPONENT_EVENT_DESCRIPTION}.
051     */
052    public static final TransformMethodSignature DISPATCH_COMPONENT_EVENT = new TransformMethodSignature(
053            Modifier.PUBLIC, "boolean", "dispatchComponentEvent", new String[]
054            {ComponentEvent.class.getName()}, null);
055
056    /**
057     * Description for
058     * {@link org.apache.tapestry5.runtime.Component#dispatchComponentEvent(org.apache.tapestry5.runtime.ComponentEvent)}
059     * .
060     *
061     * @see org.apache.tapestry5.annotations.OnEvent
062     * @since 5.3
063     */
064    public static final MethodDescription DISPATCH_COMPONENT_EVENT_DESCRIPTION = PlasticUtils.getMethodDescription(
065            Component.class, "dispatchComponentEvent", ComponentEvent.class);
066
067    /**
068     * Signature for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidLoad()}.
069     *
070     * @deprecated Deprecated in 5.3, use {@link #CONTAINING_PAGE_DID_LOAD_DESCRIPTION}.
071     */
072    public static final TransformMethodSignature CONTAINING_PAGE_DID_LOAD_SIGNATURE = new TransformMethodSignature(
073            "containingPageDidLoad");
074
075    /**
076     * Description for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidLoad()}.
077     *
078     * @since 5.3
079     */
080    public static final MethodDescription CONTAINING_PAGE_DID_LOAD_DESCRIPTION = PlasticUtils.getMethodDescription(
081            PageLifecycleListener.class, "containingPageDidLoad");
082
083    /**
084     * Description for {@link org.apache.tapestry5.internal.structure.PageResetListener#containingPageDidReset()}. Note that the {@link PageResetListener}
085     * interface is not automatically implemented by components. ]
086     *
087     * @see org.apache.tapestry5.annotations.PageReset
088     * @see org.apache.tapestry5.internal.transform.PageResetAnnotationWorker
089     * @since 5.3
090     */
091    public static final MethodDescription CONTAINING_PAGE_DID_RESET_DESCRIPTION = PlasticUtils.getMethodDescription(PageResetListener.class, "containingPageDidReset");
092
093    /**
094     * Signature for {@link org.apache.tapestry5.runtime.Component#postRenderCleanup()}.
095     */
096    public static final TransformMethodSignature POST_RENDER_CLEANUP_SIGNATURE = new TransformMethodSignature(
097            "postRenderCleanup");
098
099
100    /**
101     * Description for {@link org.apache.tapestry5.runtime.Component#postRenderCleanup()}.
102     *
103     * @since 5.3
104     */
105    public static final MethodDescription POST_RENDER_CLEANUP_DESCRIPTION = PlasticUtils.getMethodDescription(Component.class, "postRenderCleanup");
106
107    /**
108     * Signature for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidDetach()}.
109     *
110     * @deprecated Deprecated in Tapestry 5.3, use {@link #CONTAINING_PAGE_DID_DETACH_DESCRIPTION}
111     */
112    public static final TransformMethodSignature CONTAINING_PAGE_DID_DETACH_SIGNATURE = new TransformMethodSignature(
113            "containingPageDidDetach");
114
115    /**
116     * Description for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidDetach()}.
117     *
118     * @since 5.3
119     * @deprecated Deprecated in 5.3, with {@link org.apache.tapestry5.annotations.PageDetached}.
120     */
121    public static final MethodDescription CONTAINING_PAGE_DID_DETACH_DESCRIPTION = PlasticUtils.getMethodDescription(PageLifecycleListener.class, "containingPageDidDetach");
122
123    /**
124     * Signature for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidAttach()}.
125     *
126     * @deprecated Deprecated in Tapestry 5.3, use {@link #CONTAINING_PAGE_DID_ATTACH_DESCRIPTION}
127     */
128    public static final TransformMethodSignature CONTAINING_PAGE_DID_ATTACH_SIGNATURE = new TransformMethodSignature(
129            "containingPageDidAttach");
130
131    /**
132     * Description for {@link org.apache.tapestry5.runtime.PageLifecycleListener#containingPageDidAttach()}.
133     *
134     * @since 5.3
135     * @deprecated Deprecated in 5.3, along with {@link org.apache.tapestry5.annotations.PageAttached}.
136     */
137    public static final MethodDescription CONTAINING_PAGE_DID_ATTACH_DESCRIPTION = PlasticUtils.getMethodDescription(PageLifecycleListener.class, "containingPageDidAttach");
138
139    /**
140     * Signature for {@link org.apache.tapestry5.runtime.PageLifecycleListener#restoreStateBeforePageAttach()}
141     *
142     * @since 5.1.0.1
143     * @deprecated Deprecated in 5.3, with no replacement.
144     */
145    public static final TransformMethodSignature RESTORE_STATE_BEFORE_PAGE_ATTACH_SIGNATURE = new TransformMethodSignature(
146            "restoreStateBeforePageAttach");
147
148    /**
149     * Signature for {@link org.apache.tapestry5.runtime.Component#setupRender(MarkupWriter, Event)}.
150     *
151     * @see org.apache.tapestry5.annotations.SetupRender
152     * @deprecated Deprecated in Tapestry 5.3, use {@link #SETUP_RENDER_DESCRIPTION}
153     */
154    public static final TransformMethodSignature SETUP_RENDER_SIGNATURE = renderPhaseSignature("setupRender");
155
156    /**
157     * Description for {@link org.apache.tapestry5.runtime.Component#setupRender(MarkupWriter, Event)}.
158     *
159     * @see org.apache.tapestry5.annotations.SetupRender
160     * @since 5.3
161     */
162    public static final MethodDescription SETUP_RENDER_DESCRIPTION = renderPhaseDescription("setupRender");
163
164    /**
165     * Signature for {@link org.apache.tapestry5.runtime.Component#beginRender(MarkupWriter, Event)}.
166     *
167     * @see org.apache.tapestry5.annotations.BeginRender
168     * @deprecated Deprecated in Tapestry 5.3, use {@link #BEGIN_RENDER_DESCRIPTION}
169     */
170    public static final TransformMethodSignature BEGIN_RENDER_SIGNATURE = renderPhaseSignature("beginRender");
171
172    /**
173     * Description for {@link org.apache.tapestry5.runtime.Component#beginRender(MarkupWriter, Event)}.
174     *
175     * @see org.apache.tapestry5.annotations.BeginRender
176     * @since 5.3
177     */
178    public static final MethodDescription BEGIN_RENDER_DESCRIPTION = renderPhaseDescription("beginRender");
179
180    /**
181     * Signature for {@link org.apache.tapestry5.runtime.Component#beforeRenderTemplate(MarkupWriter, Event)}.
182     *
183     * @see org.apache.tapestry5.annotations.BeforeRenderTemplate
184     * @deprecated Deprecated in Tapestry 5.3, use {@link #BEFORE_RENDER_TEMPLATE_DESCRIPTION}
185     */
186    public static final TransformMethodSignature BEFORE_RENDER_TEMPLATE_SIGNATURE = renderPhaseSignature("beforeRenderTemplate");
187
188    /**
189     * Description for {@link org.apache.tapestry5.runtime.Component#beforeRenderTemplate(MarkupWriter, Event)}.
190     *
191     * @see org.apache.tapestry5.annotations.BeforeRenderTemplate
192     * @since 5.3
193     */
194    public static final MethodDescription BEFORE_RENDER_TEMPLATE_DESCRIPTION = renderPhaseDescription("beforeRenderTemplate");
195
196    /**
197     * Signature for {@link org.apache.tapestry5.runtime.Component#afterRenderTemplate(MarkupWriter, Event)}.
198     *
199     * @see org.apache.tapestry5.annotations.BeforeRenderTemplate
200     * @deprecated Deprecated in Tapestry 5.3, use {@link #AFTER_RENDER_TEMPLATE_DESCRIPTION}
201     */
202    public static final TransformMethodSignature AFTER_RENDER_TEMPLATE_SIGNATURE = renderPhaseSignature("afterRenderTemplate");
203
204    /**
205     * Description for {@link org.apache.tapestry5.runtime.Component#afterRenderTemplate(MarkupWriter, Event)}.
206     *
207     * @see org.apache.tapestry5.annotations.BeforeRenderTemplate
208     * @since 5.3
209     */
210    public static final MethodDescription AFTER_RENDER_TEMPLATE_DESCRIPTION = renderPhaseDescription("afterRenderTemplate");
211
212    /**
213     * Signature for {@link org.apache.tapestry5.runtime.Component#beforeRenderBody(MarkupWriter, Event)}.
214     *
215     * @see org.apache.tapestry5.annotations.BeforeRenderBody
216     * @deprecated Deprecated in Tapestry 5.3, use {@link #BEFORE_RENDER_BODY_DESCRIPTION}
217     */
218    public static final TransformMethodSignature BEFORE_RENDER_BODY_SIGNATURE = renderPhaseSignature("beforeRenderBody");
219
220    /**
221     * Description for {@link org.apache.tapestry5.runtime.Component#beforeRenderBody(MarkupWriter, Event)}.
222     *
223     * @see org.apache.tapestry5.annotations.BeforeRenderBody
224     * @since 5.3
225     */
226    public static final MethodDescription BEFORE_RENDER_BODY_DESCRIPTION = renderPhaseDescription("beforeRenderBody");
227
228    /**
229     * Signature for {@link org.apache.tapestry5.runtime.Component#afterRenderBody(MarkupWriter, Event)}.
230     *
231     * @see org.apache.tapestry5.annotations.AfterRenderBody
232     * @deprecated Deprecated in Tapestry 5.3, use {@link #AFTER_RENDER_BODY_DESCRIPTION}
233     */
234    public static final TransformMethodSignature AFTER_RENDER_BODY_SIGNATURE = renderPhaseSignature("afterRenderBody");
235
236
237    /**
238     * Description for {@link org.apache.tapestry5.runtime.Component#afterRenderBody(MarkupWriter, Event)}.
239     *
240     * @see org.apache.tapestry5.annotations.AfterRenderBody
241     * @since 5.3
242     */
243    public static final MethodDescription AFTER_RENDER_BODY_DESCRIPTION = renderPhaseDescription("afterRenderBody");
244
245    /**
246     * Signature for {@link org.apache.tapestry5.runtime.Component#afterRender(MarkupWriter, Event)}
247     *
248     * @see org.apache.tapestry5.annotations.AfterRender
249     * @deprecated Deprecated in Tapestry 5.3, use {@link #AFTER_RENDER_DESCRIPTION}
250     */
251    public static final TransformMethodSignature AFTER_RENDER_SIGNATURE = renderPhaseSignature("afterRender");
252
253    /**
254     * Description for {@link org.apache.tapestry5.runtime.Component#afterRender(MarkupWriter, Event)}
255     *
256     * @see org.apache.tapestry5.annotations.AfterRender
257     * @since 5.3
258     */
259    public static final MethodDescription AFTER_RENDER_DESCRIPTION = renderPhaseDescription("afterRender");
260
261    /**
262     * Signature for {@link org.apache.tapestry5.runtime.Component#cleanupRender(MarkupWriter, Event)}.
263     *
264     * @see org.apache.tapestry5.annotations.CleanupRender
265     * @deprecated Deprecated in Tapestry 5.3, use {@link #CLEANUP_RENDER_DESCRIPTION}
266     */
267    public static final TransformMethodSignature CLEANUP_RENDER_SIGNATURE = renderPhaseSignature("cleanupRender");
268
269    /**
270     * Description for {@link org.apache.tapestry5.runtime.Component#cleanupRender(MarkupWriter, Event)}.
271     *
272     * @see org.apache.tapestry5.annotations.CleanupRender
273     * @since 5.3
274     */
275    public static final MethodDescription CLEANUP_RENDER_DESCRIPTION = renderPhaseDescription("cleanupRender");
276
277    private static TransformMethodSignature renderPhaseSignature(String name)
278    {
279        return new TransformMethodSignature(Modifier.PUBLIC, "void", name, RENDER_PHASE_METHOD_PARAMETERS, null);
280    }
281
282    private static MethodDescription renderPhaseDescription(String name)
283    {
284        return new MethodDescription(Modifier.PUBLIC, "void", name, RENDER_PHASE_METHOD_PARAMETERS, null, null);
285    }
286
287}