    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.runtime;
    014
    015import org.apache.tapestry5.MarkupWriter;
    016import org.apache.tapestry5.annotations.OnEvent;
    017
    018/**
    019 * Interface that defines the lifecycle of a component, within a page, allowing for callbacks into the component for
    020 * many different events. This interface is part of the public API for Tapestry, but is <em>not</em> expected to be
    021 * directly implemented by component classes; it should only be implemented as part of the component class
    022 * transformation process.
    023 *
    024 * Most of the methods are related to render phases; see the corresponding annotations and component rendering
    025 * documentation to see how they relate to each other.
    026 *
    027 * Starting in 5.3 this interface no longer implements {@link PageLifecycleListener}. Normally, this would be an incompatible
    028 * change, but Component is not supposed to be directly implemented by user code.
    029 */
    030public interface Component extends ComponentResourcesAware
    031{
    032
    033    /**
    034     * Lifecycle method invoked at the end of the {@link org.apache.tapestry5.annotations.CleanupRender} render phase.
    035     * There is no annotation for this method, it is part of CleanupRender, but is always invoked. Its specific use is
    036     * to allow components to clean up cached parameter values.
    037     */
    038    void postRenderCleanup();
    039
    040    /**
    041     * Invoked before rendering a component (or its template).
    042     */
    043    void setupRender(MarkupWriter writer, Event event);
    044
    045    /**
    046     * Invoked to allow a component to render its tag (start tag and attributes).
    047     */
    048    void beginRender(MarkupWriter writer, Event event);
    049
    050    /**
    051     * This phase is only invoked for components with templates.
    052     */
    053    void beforeRenderTemplate(MarkupWriter writer, Event event);
    054
    055    /**
    056     * Invoked after rendering the template for a component (only for components with a template).
    057     */
    058    void afterRenderTemplate(MarkupWriter writer, Event event);
    059
    060    /**
    061     * Invoked just before rendering the body of component.
    062     */
    063    void beforeRenderBody(MarkupWriter writer, Event event);
    064
    065    /**
    066     * Invoked just after rendering the body of the component.
    067     */
    068    void afterRenderBody(MarkupWriter writer, Event event);
    069
    070    /**
    071     * Generally used to write the close tag matching any open tag written by {@link
    072     * #beginRender(org.apache.tapestry5.MarkupWriter, Event)}.
    073     */
    074    void afterRender(MarkupWriter writer, Event event);
    075
    076    /**
    077     * Generally used to perform final cleanup of the component after rendering.
    078     */
    079    void cleanupRender(MarkupWriter writer, Event event);
    080
    081    /**
    082     * Invoked to handle a component event. Methods with the {@link OnEvent} annotation (or the matching naming
    083     * convention) will be invoked until one returns a non-null value.
    084     *
    085     * @param event
    086     * @return true if any handler was found (and invoked), false otherwise
    087     * @throws RuntimeException wrapping any checked exceptions that are thrown by individual event handler methods
    088     */
    089    boolean dispatchComponentEvent(ComponentEvent event);
    090}