Package org.apache.tapestry.engine

Source Code of org.apache.tapestry.engine.RequestCycle

/* $$ Clover has instrumented this file $$ */// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.apache.tapestry.engine;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.tapestry.IComponent;
import org.apache.tapestry.IEngine;
import org.apache.tapestry.IForm;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.RenderRewoundException;
import org.apache.tapestry.StaleLinkException;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.event.ChangeObserver;
import org.apache.tapestry.event.ObservedChangeEvent;
import org.apache.tapestry.request.RequestContext;

/**
*  Provides the logic for processing a single request cycle.  Provides access to
*  the {@link IEngine engine} and the {@link RequestContext}.
*
@author Howard Lewis Ship
*
**/

public class RequestCycle implements IRequestCycle, ChangeObserver
{public static com.cortexeb.tools.clover.d __CLOVER_102_0 = com.cortexeb.tools.clover.aq.getRecorder(new char[] {67,58,92,119,111,114,107,115,112,97,99,101,92,106,97,107,97,114,116,97,45,116,97,112,101,115,116,114,121,92,102,114,97,109,101,119,111,114,107,92,116,97,114,103,101,116,92,99,108,111,118,101,114,45,100,98},1096998272901L);
    private static final Log LOG = LogFactory.getLog(RequestCycle.class);

    private IPage _page;
    private IEngine _engine;
    private IEngineService _service;

    private RequestContext _requestContext;

    private IMonitor _monitor;

    private HttpServletResponse _response;

    /**
     *  A mapping of pages loaded during the current request cycle.
     *  Key is the page name, value is the {@link IPage} instance.
     *
     **/

    private Map _loadedPages;

    /**
     * A mapping of page recorders for the current request cycle.
     * Key is the page name, value is the {@link IPageRecorder} instance.
     *
     **/

    private Map _loadedRecorders;

    private boolean _rewinding = false;

    private Map _attributes;

    private int _actionId;
    private int _targetActionId;
    private IComponent _targetComponent;

    /** @since 2.0.3 **/

    private Object[] _serviceParameters;

    /**
     *  Standard constructor used to render a response page.
     *
     **/

    public RequestCycle(
        IEngine engine,
        RequestContext requestContext,
        IEngineService service,
        IMonitor monitor)
    {try { __CLOVER_102_0.M[548]++;
        __CLOVER_102_0.S[2286]++;_engine = engine;
        __CLOVER_102_0.S[2287]++;_requestContext = requestContext;
        __CLOVER_102_0.S[2288]++;_service = service;
        __CLOVER_102_0.S[2289]++;_monitor = monitor;
    } finally { }}

    /**
     *  Called at the end of the request cycle (i.e., after all responses have been
     *  sent back to the client), to release all pages loaded during the request cycle.
     *
     **/

    public void cleanup()
    {try { __CLOVER_102_0.M[549]++;
        __CLOVER_102_0.S[2290]++;if ((((_loadedPages == null) && (++__CLOVER_102_0.CT[424] != 0)) || (++__CLOVER_102_0.CF[424] == 0))){
            __CLOVER_102_0.S[2291]++;return;}

        __CLOVER_102_0.S[2292]++;IPageSource source = _engine.getPageSource();
        __CLOVER_102_0.S[2293]++;Iterator i = _loadedPages.values().iterator();

        __CLOVER_102_0.S[2294]++;while ((((i.hasNext()) && (++__CLOVER_102_0.CT[425] != 0)) || (++__CLOVER_102_0.CF[425] == 0))){
        {
            __CLOVER_102_0.S[2295]++;IPage page = (IPage) i.next();

            __CLOVER_102_0.S[2296]++;source.releasePage(page);
        }}

        __CLOVER_102_0.S[2297]++;_loadedPages = null;
        __CLOVER_102_0.S[2298]++;_loadedRecorders = null;

    } finally { }}

    public IEngineService getService()
    {try { __CLOVER_102_0.M[550]++;
        __CLOVER_102_0.S[2299]++;return _service;
    } finally { }}

    public String encodeURL(String URL)
    {try { __CLOVER_102_0.M[551]++;
        __CLOVER_102_0.S[2300]++;if ((((_response == null) && (++__CLOVER_102_0.CT[426] != 0)) || (++__CLOVER_102_0.CF[426] == 0))){
            __CLOVER_102_0.S[2301]++;_response = _requestContext.getResponse();}

        __CLOVER_102_0.S[2302]++;return _response.encodeURL(URL);
    } finally { }}

    public IEngine getEngine()
    {try { __CLOVER_102_0.M[552]++;
        __CLOVER_102_0.S[2303]++;return _engine;
    } finally { }}

    public Object getAttribute(String name)
    {try { __CLOVER_102_0.M[553]++;
        __CLOVER_102_0.S[2304]++;if ((((_attributes == null) && (++__CLOVER_102_0.CT[427] != 0)) || (++__CLOVER_102_0.CF[427] == 0))){
            __CLOVER_102_0.S[2305]++;return null;}

        __CLOVER_102_0.S[2306]++;return _attributes.get(name);
    } finally { }}

    public IMonitor getMonitor()
    {try { __CLOVER_102_0.M[554]++;
        __CLOVER_102_0.S[2307]++;return _monitor;
    } finally { }}

    public String getNextActionId()
    {try { __CLOVER_102_0.M[555]++;
        __CLOVER_102_0.S[2308]++;return Integer.toHexString(++_actionId);
    } finally { }}

    public IPage getPage()
    {try { __CLOVER_102_0.M[556]++;
        __CLOVER_102_0.S[2309]++;return _page;
    } finally { }}

    /**
     *  Gets the page from the engines's {@link IPageSource}.
     *
     **/

    public IPage getPage(String name)
    {try { __CLOVER_102_0.M[557]++;
        __CLOVER_102_0.S[2310]++;IPage result = null;

        __CLOVER_102_0.S[2311]++;if ((((name == null) && (++__CLOVER_102_0.CT[428] != 0)) || (++__CLOVER_102_0.CF[428] == 0))){
            __CLOVER_102_0.S[2312]++;throw new NullPointerException(Tapestry.getMessage("RequestCycle.invalid-null-name"));}

        __CLOVER_102_0.S[2313]++;if ((((_loadedPages != null) && (++__CLOVER_102_0.CT[429] != 0)) || (++__CLOVER_102_0.CF[429] == 0))){
            __CLOVER_102_0.S[2314]++;result = (IPage) _loadedPages.get(name);}

        __CLOVER_102_0.S[2315]++;if ((((result == null) && (++__CLOVER_102_0.CT[430] != 0)) || (++__CLOVER_102_0.CF[430] == 0))){
        {
            __CLOVER_102_0.S[2316]++;_monitor.pageLoadBegin(name);

            __CLOVER_102_0.S[2317]++;IPageSource pageSource = _engine.getPageSource();

            __CLOVER_102_0.S[2318]++;result = pageSource.getPage(this, name, _monitor);

            __CLOVER_102_0.S[2319]++;result.setRequestCycle(this);

            // Get the recorder that will eventually observe and record
            // changes to persistent properties of the page.  If the page
            // has never emitted any page changes, then it will
            // not have a recorder.

            __CLOVER_102_0.S[2320]++;IPageRecorder recorder = getPageRecorder(name);

            __CLOVER_102_0.S[2321]++;if ((((recorder != null) && (++__CLOVER_102_0.CT[431] != 0)) || (++__CLOVER_102_0.CF[431] == 0))){
            {
                // Have it rollback the page to the prior state.  Note that
                // the page has a null observer at this time.

                __CLOVER_102_0.S[2322]++;recorder.rollback(result);

                // Now, have the page use the recorder for any future
                // property changes.

                __CLOVER_102_0.S[2323]++;result.setChangeObserver(recorder);

                // And, if this recorder observed changes in a prior request cycle
                // (and was locked after committing in that cycle), it's time
                // to unlock.

                __CLOVER_102_0.S[2324]++;recorder.setLocked(false);
            }}
            else{
            {
                // No page recorder for the page.  We'll observe its
                // changes and create the page recorder dynamically
                // if it emits any.

                __CLOVER_102_0.S[2325]++;result.setChangeObserver(this);
            }}

            __CLOVER_102_0.S[2326]++;_monitor.pageLoadEnd(name);

            __CLOVER_102_0.S[2327]++;if ((((_loadedPages == null) && (++__CLOVER_102_0.CT[432] != 0)) || (++__CLOVER_102_0.CF[432] == 0))){
                __CLOVER_102_0.S[2328]++;_loadedPages = new HashMap();}

            __CLOVER_102_0.S[2329]++;_loadedPages.put(name, result);
        }}

        __CLOVER_102_0.S[2330]++;return result;
    } finally { }}

    /**
     *  Returns the page recorder for the named page.  This may come
     *  from the cycle's cache of page recorders or, if not yet encountered
     *  in this request cycle, the {@link IEngine#getPageRecorder(String, IRequestCycle)} is
     *  invoked to get the recorder, if it exists.
     *
     **/

    protected IPageRecorder getPageRecorder(String name)
    {try { __CLOVER_102_0.M[558]++;
        __CLOVER_102_0.S[2331]++;IPageRecorder result = null;

        __CLOVER_102_0.S[2332]++;if ((((_loadedRecorders != null) && (++__CLOVER_102_0.CT[433] != 0)) || (++__CLOVER_102_0.CF[433] == 0))){
            __CLOVER_102_0.S[2333]++;result = (IPageRecorder) _loadedRecorders.get(name);}

        __CLOVER_102_0.S[2334]++;if ((((result != null) && (++__CLOVER_102_0.CT[434] != 0)) || (++__CLOVER_102_0.CF[434] == 0))){
            __CLOVER_102_0.S[2335]++;return result;}

        __CLOVER_102_0.S[2336]++;result = _engine.getPageRecorder(name, this);

        __CLOVER_102_0.S[2337]++;if ((((result == null) && (++__CLOVER_102_0.CT[435] != 0)) || (++__CLOVER_102_0.CF[435] == 0))){
            __CLOVER_102_0.S[2338]++;return null;}

        __CLOVER_102_0.S[2339]++;if ((((_loadedRecorders == null) && (++__CLOVER_102_0.CT[436] != 0)) || (++__CLOVER_102_0.CF[436] == 0))){
            __CLOVER_102_0.S[2340]++;_loadedRecorders = new HashMap();}

        __CLOVER_102_0.S[2341]++;_loadedRecorders.put(name, result);

        __CLOVER_102_0.S[2342]++;return result;
    } finally { }}

    /**
     *
     *  Gets the page recorder from the loadedRecorders cache, or from the engine
     *  (putting it into loadedRecorders).  If the recorder does not yet exist,
     *  it is created.
     *
     *  @see IEngine#createPageRecorder(String, IRequestCycle)
     *  @since 2.0.3
     *
     **/

    private IPageRecorder createPageRecorder(String name)
    {try { __CLOVER_102_0.M[559]++;
        __CLOVER_102_0.S[2343]++;IPageRecorder result = getPageRecorder(name);

        __CLOVER_102_0.S[2344]++;if ((((result == null) && (++__CLOVER_102_0.CT[437] != 0)) || (++__CLOVER_102_0.CF[437] == 0))){
        {
            __CLOVER_102_0.S[2345]++;result = _engine.createPageRecorder(name, this);

            __CLOVER_102_0.S[2346]++;if ((((_loadedRecorders == null) && (++__CLOVER_102_0.CT[438] != 0)) || (++__CLOVER_102_0.CF[438] == 0))){
                __CLOVER_102_0.S[2347]++;_loadedRecorders = new HashMap();}

            __CLOVER_102_0.S[2348]++;_loadedRecorders.put(name, result);
        }}

        __CLOVER_102_0.S[2349]++;return result;
    } finally { }}

    public RequestContext getRequestContext()
    {try { __CLOVER_102_0.M[560]++;
        __CLOVER_102_0.S[2350]++;return _requestContext;
    } finally { }}

    public boolean isRewinding()
    {try { __CLOVER_102_0.M[561]++;
        __CLOVER_102_0.S[2351]++;return _rewinding;
    } finally { }}

    public boolean isRewound(IComponent component) throws StaleLinkException
    {try { __CLOVER_102_0.M[562]++;
        // If not rewinding ...

        __CLOVER_102_0.S[2352]++;if ((((!_rewinding) && (++__CLOVER_102_0.CT[439] != 0)) || (++__CLOVER_102_0.CF[439] == 0))){
            __CLOVER_102_0.S[2353]++;return false;}

        __CLOVER_102_0.S[2354]++;if ((((_actionId != _targetActionId) && (++__CLOVER_102_0.CT[440] != 0)) || (++__CLOVER_102_0.CF[440] == 0))){
            __CLOVER_102_0.S[2355]++;return false;}

        // OK, we're there, is the page is good order?

        __CLOVER_102_0.S[2356]++;if ((((component == _targetComponent) && (++__CLOVER_102_0.CT[441] != 0)) || (++__CLOVER_102_0.CF[441] == 0))){
            __CLOVER_102_0.S[2357]++;return true;}

        // Woops.  Mismatch.

        __CLOVER_102_0.S[2358]++;throw new StaleLinkException(
            component,
            Integer.toHexString(_targetActionId),
            _targetComponent.getExtendedId());
    } finally { }}

    public void removeAttribute(String name)
    {try { __CLOVER_102_0.M[563]++;
        __CLOVER_102_0.S[2359]++;if ((((LOG.isDebugEnabled()) && (++__CLOVER_102_0.CT[442] != 0)) || (++__CLOVER_102_0.CF[442] == 0))){
            __CLOVER_102_0.S[2360]++;LOG.debug("Removing attribute " + name);}

        __CLOVER_102_0.S[2361]++;if ((((_attributes == null) && (++__CLOVER_102_0.CT[443] != 0)) || (++__CLOVER_102_0.CF[443] == 0))){
            __CLOVER_102_0.S[2362]++;return;}

        __CLOVER_102_0.S[2363]++;_attributes.remove(name);
    } finally { }}

    /**
     *  Renders the page by invoking
     * {@link IPage#renderPage(IMarkupWriter, IRequestCycle)}
     *  This clears all attributes.
     *
     **/

    public void renderPage(IMarkupWriter writer)
    {try { __CLOVER_102_0.M[564]++;
        __CLOVER_102_0.S[2364]++;String pageName = _page.getPageName();
        __CLOVER_102_0.S[2365]++;_monitor.pageRenderBegin(pageName);

        __CLOVER_102_0.S[2366]++;_rewinding = false;
        __CLOVER_102_0.S[2367]++;_actionId = -1;
        __CLOVER_102_0.S[2368]++;_targetActionId = 0;

        // Forget any attributes from a previous render cycle.

        __CLOVER_102_0.S[2369]++;if ((((_attributes != null) && (++__CLOVER_102_0.CT[444] != 0)) || (++__CLOVER_102_0.CF[444] == 0))){
            __CLOVER_102_0.S[2370]++;_attributes.clear();}

        __CLOVER_102_0.S[2371]++;try
        {
            __CLOVER_102_0.S[2372]++;_page.renderPage(writer, this);

        }
        catch (ApplicationRuntimeException ex)
        {
            // Nothing much to add here.

            __CLOVER_102_0.S[2373]++;throw ex;
        }
        catch (Throwable ex)
        {
            // But wrap other exceptions in a RequestCycleException ... this
            // will ensure that some of the context is available.

            __CLOVER_102_0.S[2374]++;throw new ApplicationRuntimeException(ex.getMessage(), _page, null, ex);
        }
        finally
        {
            __CLOVER_102_0.S[2375]++;_actionId = 0;
            __CLOVER_102_0.S[2376]++;_targetActionId = 0;
        }

        __CLOVER_102_0.S[2377]++;_monitor.pageRenderEnd(pageName);

    } finally { }}

    /**
     *  Rewinds an individual form by invoking
     *  {@link IForm#rewind(IMarkupWriter, IRequestCycle)}.
     *
     * <p>The process is expected to end with a {@link RenderRewoundException}.
     * If the entire page is renderred without this exception being thrown, it means
     * that the target action id was not valid, and a
     * {@link ApplicationRuntimeException}
     * is thrown.
     *
     * <p>This clears all attributes.
     *
     *  @since 1.0.2
     **/

    public void rewindForm(IForm form, String targetActionId)
    {try { __CLOVER_102_0.M[565]++;
        __CLOVER_102_0.S[2378]++;IPage page = form.getPage();
        __CLOVER_102_0.S[2379]++;String pageName = page.getPageName();

        __CLOVER_102_0.S[2380]++;_rewinding = true;

        __CLOVER_102_0.S[2381]++;_monitor.pageRewindBegin(pageName);

        __CLOVER_102_0.S[2382]++;if ((((_attributes != null) && (++__CLOVER_102_0.CT[445] != 0)) || (++__CLOVER_102_0.CF[445] == 0))){
            __CLOVER_102_0.S[2383]++;_attributes.clear();}

        // Fake things a little for getNextActionId() / isRewound()

        __CLOVER_102_0.S[2384]++;_targetActionId = Integer.parseInt(targetActionId, 16);
        __CLOVER_102_0.S[2385]++;_actionId = _targetActionId - 1;

        __CLOVER_102_0.S[2386]++;_targetComponent = form;

        __CLOVER_102_0.S[2387]++;try
        {
            __CLOVER_102_0.S[2388]++;page.beginPageRender();

            __CLOVER_102_0.S[2389]++;form.rewind(NullWriter.getSharedInstance(), this);

            // Shouldn't get this far, because the form should
            // throw the RenderRewoundException.

            __CLOVER_102_0.S[2390]++;throw new StaleLinkException(
                Tapestry.format("RequestCycle.form-rewind-failure", form.getExtendedId()),
                form);
        }
        catch (RenderRewoundException ex)
        {
            // This is acceptible and expected.
        }
        catch (ApplicationRuntimeException ex)
        {
            // RequestCycleExceptions don't need to be wrapped.
            __CLOVER_102_0.S[2391]++;throw ex;
        }
        catch (Throwable ex)
        {
            // But wrap other exceptions in a ApplicationRuntimeException ... this
            // will ensure that some of the context is available.

            __CLOVER_102_0.S[2392]++;throw new ApplicationRuntimeException(ex.getMessage(), page, null, ex);
        }
        finally
        {
            __CLOVER_102_0.S[2393]++;_actionId = 0;
            __CLOVER_102_0.S[2394]++;_targetActionId = 0;
            __CLOVER_102_0.S[2395]++;_targetComponent = null;

            __CLOVER_102_0.S[2396]++;page.endPageRender();

            __CLOVER_102_0.S[2397]++;_monitor.pageRewindEnd(pageName);

            __CLOVER_102_0.S[2398]++;_rewinding = false;
        }
    } finally { }}

    /**
     *  Rewinds the page by invoking
     *  {@link IPage#renderPage(IMarkupWriter, IRequestCycle)}.
     *
     * <p>The process is expected to end with a {@link RenderRewoundException}.
     * If the entire page is renderred without this exception being thrown, it means
     * that the target action id was not valid, and a
     * {@link ApplicationRuntimeException}
     * is thrown.
     *
     * <p>This clears all attributes.
     *
     **/

    public void rewindPage(String targetActionId, IComponent targetComponent)
    {try { __CLOVER_102_0.M[566]++;
        __CLOVER_102_0.S[2399]++;String pageName = _page.getPageName();

        __CLOVER_102_0.S[2400]++;_rewinding = true;

        __CLOVER_102_0.S[2401]++;_monitor.pageRewindBegin(pageName);

        __CLOVER_102_0.S[2402]++;if ((((_attributes != null) && (++__CLOVER_102_0.CT[446] != 0)) || (++__CLOVER_102_0.CF[446] == 0))){
            __CLOVER_102_0.S[2403]++;_attributes.clear();}

        __CLOVER_102_0.S[2404]++;_actionId = -1;

        // Parse the action Id as hex since that's whats generated
        // by getNextActionId()
        __CLOVER_102_0.S[2405]++;_targetActionId = Integer.parseInt(targetActionId, 16);
        __CLOVER_102_0.S[2406]++;_targetComponent = targetComponent;

        __CLOVER_102_0.S[2407]++;try
        {
            __CLOVER_102_0.S[2408]++;_page.renderPage(NullWriter.getSharedInstance(), this);

            // Shouldn't get this far, because the target component should
            // throw the RenderRewoundException.

            __CLOVER_102_0.S[2409]++;throw new StaleLinkException(_page, targetActionId, targetComponent.getExtendedId());
        }
        catch (RenderRewoundException ex)
        {
            // This is acceptible and expected.
        }
        catch (ApplicationRuntimeException ex)
        {
            // ApplicationRuntimeExceptions don't need to be wrapped.
            __CLOVER_102_0.S[2410]++;throw ex;
        }
        catch (Throwable ex)
        {
            // But wrap other exceptions in a RequestCycleException ... this
            // will ensure that some of the context is available.

            __CLOVER_102_0.S[2411]++;throw new ApplicationRuntimeException(ex.getMessage(), _page, null, ex);
        }
        finally
        {

            __CLOVER_102_0.S[2412]++;_actionId = 0;
            __CLOVER_102_0.S[2413]++;_targetActionId = 0;
            __CLOVER_102_0.S[2414]++;_targetComponent = null;

            __CLOVER_102_0.S[2415]++;_monitor.pageRewindEnd(pageName);

            __CLOVER_102_0.S[2416]++;_rewinding = false;
        }

    } finally { }}

    public void setAttribute(String name, Object value)
    {try { __CLOVER_102_0.M[567]++;
        __CLOVER_102_0.S[2417]++;if ((((LOG.isDebugEnabled()) && (++__CLOVER_102_0.CT[447] != 0)) || (++__CLOVER_102_0.CF[447] == 0))){
            __CLOVER_102_0.S[2418]++;LOG.debug("Set attribute " + name + " to " + value);}

        __CLOVER_102_0.S[2419]++;if ((((_attributes == null) && (++__CLOVER_102_0.CT[448] != 0)) || (++__CLOVER_102_0.CF[448] == 0))){
            __CLOVER_102_0.S[2420]++;_attributes = new HashMap();}

        __CLOVER_102_0.S[2421]++;_attributes.put(name, value);
    } finally { }}

    public void setPage(IPage value)
    {try { __CLOVER_102_0.M[568]++;
        __CLOVER_102_0.S[2422]++;if ((((LOG.isDebugEnabled()) && (++__CLOVER_102_0.CT[449] != 0)) || (++__CLOVER_102_0.CF[449] == 0))){
            __CLOVER_102_0.S[2423]++;LOG.debug("Set page to " + value);}

        __CLOVER_102_0.S[2424]++;_page = value;
    } finally { }}

    public void setPage(String name)
    {try { __CLOVER_102_0.M[569]++;
        __CLOVER_102_0.S[2425]++;if ((((LOG.isDebugEnabled()) && (++__CLOVER_102_0.CT[450] != 0)) || (++__CLOVER_102_0.CF[450] == 0))){
            __CLOVER_102_0.S[2426]++;LOG.debug("Set page to " + name);}

        __CLOVER_102_0.S[2427]++;_page = getPage(name);
    } finally { }}

    /**
     *  Invokes {@link IPageRecorder#commit()} on each page recorder loaded
     *  during the request cycle (even recorders marked for discard).
     *
     **/

    public void commitPageChanges()
    {try { __CLOVER_102_0.M[570]++;
        __CLOVER_102_0.S[2428]++;if ((((LOG.isDebugEnabled()) && (++__CLOVER_102_0.CT[451] != 0)) || (++__CLOVER_102_0.CF[451] == 0))){
            __CLOVER_102_0.S[2429]++;LOG.debug("Committing page changes");}

        __CLOVER_102_0.S[2430]++;if ((((_loadedRecorders == null || _loadedRecorders.isEmpty()) && (++__CLOVER_102_0.CT[452] != 0)) || (++__CLOVER_102_0.CF[452] == 0))){
            __CLOVER_102_0.S[2431]++;return;}

        __CLOVER_102_0.S[2432]++;Iterator i = _loadedRecorders.values().iterator();

        __CLOVER_102_0.S[2433]++;while ((((i.hasNext()) && (++__CLOVER_102_0.CT[453] != 0)) || (++__CLOVER_102_0.CF[453] == 0))){
        {
            __CLOVER_102_0.S[2434]++;IPageRecorder recorder = (IPageRecorder) i.next();

            __CLOVER_102_0.S[2435]++;recorder.commit();
        }}
    } finally { }}

    /**
     *  For pages without a {@link IPageRecorder page recorder},
     *  we're the {@link ChangeObserver change observer}.
     *  If such a page actually emits a change, then
     *  we'll obtain a new page recorder from the
     *  {@link IEngine engine}, set the recorder
     *  as the page's change observer, and forward the event
     *  to the newly created recorder.  In addition, the
     *  new page recorder is remembered so that it will
     *  be committed by {@link #commitPageChanges()}.
     *
     **/

    public void observeChange(ObservedChangeEvent event)
    {try { __CLOVER_102_0.M[571]++;
        __CLOVER_102_0.S[2436]++;IPage page = event.getComponent().getPage();
        __CLOVER_102_0.S[2437]++;String pageName = page.getPageName();

        __CLOVER_102_0.S[2438]++;if ((((LOG.isDebugEnabled()) && (++__CLOVER_102_0.CT[454] != 0)) || (++__CLOVER_102_0.CF[454] == 0))){
            __CLOVER_102_0.S[2439]++;LOG.debug("Observed change in page " + pageName + "; creating page recorder.");}

        __CLOVER_102_0.S[2440]++;IPageRecorder recorder = createPageRecorder(pageName);

        __CLOVER_102_0.S[2441]++;page.setChangeObserver(recorder);

        __CLOVER_102_0.S[2442]++;recorder.observeChange(event);
    } finally { }}

    /**
     *  Finds the page and its page recorder, creating the page recorder if necessary.
     *  The page recorder is marked for discard regardless of its current state.
     *
     *  <p>This may make the application stateful even if the page recorder does
     *  not yet exist.
     *
     *  <p>The page recorder will be discarded at the end of the current request cycle.
     *
     *  @since 2.0.2
     *
     **/

    public void discardPage(String name)
    {try { __CLOVER_102_0.M[572]++;
        __CLOVER_102_0.S[2443]++;if ((((LOG.isDebugEnabled()) && (++__CLOVER_102_0.CT[455] != 0)) || (++__CLOVER_102_0.CF[455] == 0))){
            __CLOVER_102_0.S[2444]++;LOG.debug("Discarding page " + name);}

        __CLOVER_102_0.S[2445]++;IPageRecorder recorder = _engine.getPageRecorder(name, this);

        __CLOVER_102_0.S[2446]++;if ((((recorder == null) && (++__CLOVER_102_0.CT[456] != 0)) || (++__CLOVER_102_0.CF[456] == 0))){
        {
            __CLOVER_102_0.S[2447]++;_page = getPage(name);

            __CLOVER_102_0.S[2448]++;recorder = createPageRecorder(name);

            __CLOVER_102_0.S[2449]++;_page.setChangeObserver(recorder);
        }}

        __CLOVER_102_0.S[2450]++;recorder.markForDiscard();
    } finally { }}

    /** @since 2.0.3 **/

    public Object[] getServiceParameters()
    {try { __CLOVER_102_0.M[573]++;
        __CLOVER_102_0.S[2451]++;return _serviceParameters;
    } finally { }}

    /** @since 2.0.3 **/

    public void setServiceParameters(Object[] serviceParameters)
    {try { __CLOVER_102_0.M[574]++;
        __CLOVER_102_0.S[2452]++;_serviceParameters = serviceParameters;
    } finally { }}

    /** @since 3.0 **/

    public void activate(String name)
    {try { __CLOVER_102_0.M[575]++;
        __CLOVER_102_0.S[2453]++;IPage page = getPage(name);

        __CLOVER_102_0.S[2454]++;activate(page);
    } finally { }}

    /** @since 3.0 */

    public void activate(IPage page)
    {try { __CLOVER_102_0.M[576]++;
        __CLOVER_102_0.S[2455]++;if ((((LOG.isDebugEnabled()) && (++__CLOVER_102_0.CT[457] != 0)) || (++__CLOVER_102_0.CF[457] == 0))){
            __CLOVER_102_0.S[2456]++;LOG.debug("Activating page " + page);}

        __CLOVER_102_0.S[2457]++;Tapestry.clearMethodInvocations();

        __CLOVER_102_0.S[2458]++;page.validate(this);

        __CLOVER_102_0.S[2459]++;Tapestry.checkMethodInvocation(
            Tapestry.ABSTRACTPAGE_VALIDATE_METHOD_ID,
            "validate()",
            page);

        __CLOVER_102_0.S[2460]++;setPage(page);
    } finally { }}

    /**
     * @since 3.0
     */
    public String toString()
    {try { __CLOVER_102_0.M[577]++;
        __CLOVER_102_0.S[2461]++;ToStringBuilder b = new ToStringBuilder(this);

        __CLOVER_102_0.S[2462]++;b.append("rewinding", _rewinding);

        __CLOVER_102_0.S[2463]++;if ((((_service != null) && (++__CLOVER_102_0.CT[458] != 0)) || (++__CLOVER_102_0.CF[458] == 0))){
            __CLOVER_102_0.S[2464]++;b.append("service", _service.getName());}

        __CLOVER_102_0.S[2465]++;b.append("serviceParameters", _serviceParameters);

        __CLOVER_102_0.S[2466]++;if ((((_loadedPages != null) && (++__CLOVER_102_0.CT[459] != 0)) || (++__CLOVER_102_0.CF[459] == 0))){
            __CLOVER_102_0.S[2467]++;b.append("loadedPages", _loadedPages.keySet());}

        __CLOVER_102_0.S[2468]++;b.append("attributes", _attributes);
        __CLOVER_102_0.S[2469]++;b.append("targetActionId", _targetActionId);
        __CLOVER_102_0.S[2470]++;b.append("targetComponent", _targetComponent);

        __CLOVER_102_0.S[2471]++;return b.toString();
    } finally { }}
}
TOP

Related Classes of org.apache.tapestry.engine.RequestCycle

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.