Package org.apache.tapestry.engine

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

/* $$ 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.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;

import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.tapestry.IAction;
import org.apache.tapestry.IComponent;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.StaleSessionException;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.request.ResponseOutputStream;

/**
*  A context-sensitive service related to {@link org.apache.tapestry.form.Form}
*  and {@link org.apache.tapestry.link.ActionLink}.  Encodes
*  the page, component and an action id in the service context.
*
@author Howard Lewis Ship
@since 1.0.9
*
**/

public class ActionService extends AbstractService
{public static com.cortexeb.tools.clover.d __CLOVER_73_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);
    /**
     *  Encoded into URL if engine was stateful.
     *
     *  @since 3.0
     **/

    private static final String STATEFUL_ON = "1";

    /**
     *  Encoded into URL if engine was not stateful.
     *
     *  @since 3.0
     **/

    private static final String STATEFUL_OFF = "0";

    public ILink getLink(IRequestCycle cycle, IComponent component, Object[] parameters)
    {try { __CLOVER_73_0.M[431]++;
        __CLOVER_73_0.S[1820]++;if ((((parameters == null || parameters.length != 1) && (++__CLOVER_73_0.CT[339] != 0)) || (++__CLOVER_73_0.CF[339] == 0))){
            __CLOVER_73_0.S[1821]++;throw new IllegalArgumentException(
                Tapestry.format("service-single-parameter", Tapestry.ACTION_SERVICE));}

        __CLOVER_73_0.S[1822]++;String stateful = (((cycle.getEngine().isStateful() ) && (++__CLOVER_73_0.CT[340] != 0)) || (++__CLOVER_73_0.CF[340] == 0))? STATEFUL_ON : STATEFUL_OFF;
        __CLOVER_73_0.S[1823]++;IPage componentPage = component.getPage();
        __CLOVER_73_0.S[1824]++;IPage responsePage = cycle.getPage();

        __CLOVER_73_0.S[1825]++;boolean complex = (componentPage != responsePage);

        __CLOVER_73_0.S[1826]++;String[] serviceContext = new String[(((complex ) && (++__CLOVER_73_0.CT[341] != 0)) || (++__CLOVER_73_0.CF[341] == 0))? 5 : 4];

        __CLOVER_73_0.S[1827]++;int i = 0;

        __CLOVER_73_0.S[1828]++;serviceContext[i++] = stateful;
        __CLOVER_73_0.S[1829]++;serviceContext[i++] = responsePage.getPageName();
        __CLOVER_73_0.S[1830]++;serviceContext[i++] = (String) parameters[0];

        // Because of Block/InsertBlock, the component may not be on
        // the same page as the response page and we need to make
        // allowances for this.

        __CLOVER_73_0.S[1831]++;if ((((complex) && (++__CLOVER_73_0.CT[342] != 0)) || (++__CLOVER_73_0.CF[342] == 0))){
            __CLOVER_73_0.S[1832]++;serviceContext[i++] = componentPage.getPageName();}

        __CLOVER_73_0.S[1833]++;serviceContext[i++] = component.getIdPath();

        __CLOVER_73_0.S[1834]++;return constructLink(cycle, Tapestry.ACTION_SERVICE, serviceContext, null, true);
    } finally { }}

    public void service(
        IEngineServiceView engine,
        IRequestCycle cycle,
        ResponseOutputStream output)
        throws ServletException, IOException
    {try { __CLOVER_73_0.M[432]++;
        __CLOVER_73_0.S[1835]++;IAction action = null;
        __CLOVER_73_0.S[1836]++;String componentPageName;
        __CLOVER_73_0.S[1837]++;int count = 0;

        __CLOVER_73_0.S[1838]++;String[] serviceContext = getServiceContext(cycle.getRequestContext());

        __CLOVER_73_0.S[1839]++;if ((((serviceContext != null) && (++__CLOVER_73_0.CT[343] != 0)) || (++__CLOVER_73_0.CF[343] == 0))){
            __CLOVER_73_0.S[1840]++;count = serviceContext.length;}

        __CLOVER_73_0.S[1841]++;if ((((count != 4 && count != 5) && (++__CLOVER_73_0.CT[344] != 0)) || (++__CLOVER_73_0.CF[344] == 0))){
            __CLOVER_73_0.S[1842]++;throw new ApplicationRuntimeException(
                Tapestry.getMessage("ActionService.context-parameters"));}

        __CLOVER_73_0.S[1843]++;boolean complex = count == 5;

        __CLOVER_73_0.S[1844]++;int i = 0;
        __CLOVER_73_0.S[1845]++;String stateful = serviceContext[i++];
        __CLOVER_73_0.S[1846]++;String pageName = serviceContext[i++];
        __CLOVER_73_0.S[1847]++;String targetActionId = serviceContext[i++];

        __CLOVER_73_0.S[1848]++;if ((((complex) && (++__CLOVER_73_0.CT[345] != 0)) || (++__CLOVER_73_0.CF[345] == 0))){
            __CLOVER_73_0.S[1849]++;componentPageName = serviceContext[i++];}
        else{
            __CLOVER_73_0.S[1850]++;componentPageName = pageName;}

        __CLOVER_73_0.S[1851]++;String targetIdPath = serviceContext[i++];

        __CLOVER_73_0.S[1852]++;IPage page = cycle.getPage(pageName);

    // Setup the page for the rewind, then do the rewind.

    __CLOVER_73_0.S[1853]++;cycle.activate(page);
   
        __CLOVER_73_0.S[1854]++;IPage componentPage = cycle.getPage(componentPageName);
        __CLOVER_73_0.S[1855]++;IComponent component = componentPage.getNestedComponent(targetIdPath);

        __CLOVER_73_0.S[1856]++;try
        {
            __CLOVER_73_0.S[1857]++;action = (IAction) component;
        }
        catch (ClassCastException ex)
        {
            __CLOVER_73_0.S[1858]++;throw new ApplicationRuntimeException(
                Tapestry.format("ActionService.component-wrong-type", component.getExtendedId()),
                component,
                null,
                ex);
        }

        // Only perform the stateful check if the application was stateful
        // when the URL was rendered.

        __CLOVER_73_0.S[1859]++;if ((((stateful.equals(STATEFUL_ON) && action.getRequiresSession()) && (++__CLOVER_73_0.CT[346] != 0)) || (++__CLOVER_73_0.CF[346] == 0))){
        {
            __CLOVER_73_0.S[1860]++;HttpSession session = cycle.getRequestContext().getSession();

            __CLOVER_73_0.S[1861]++;if ((((session == null || session.isNew()) && (++__CLOVER_73_0.CT[347] != 0)) || (++__CLOVER_73_0.CF[347] == 0))){
                __CLOVER_73_0.S[1862]++;throw new StaleSessionException();}
        }}

        __CLOVER_73_0.S[1863]++;cycle.rewindPage(targetActionId, action);

        // During the rewind, a component may change the page.  This will take
        // effect during the second render, which renders the HTML response.

        // Render the response.

        __CLOVER_73_0.S[1864]++;engine.renderResponse(cycle, output);
    } finally { }}

    public String getName()
    {try { __CLOVER_73_0.M[433]++;
        __CLOVER_73_0.S[1865]++;return Tapestry.ACTION_SERVICE;
    } finally { }}

}
TOP

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

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.