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;
import org.apache.tapestry.services.ResponseRenderer;

/**
* 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},1097439627296L);
    /** @since 3.1 */
    private ResponseRenderer _responseRenderer;

    /**
     * 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[3022]++;
        __CLOVER_73_0.S[12408]++;if ((((parameters == null || parameters.length != 1) && (++__CLOVER_73_0.CT[2126] != 0)) || (++__CLOVER_73_0.CF[2126] == 0))){
            __CLOVER_73_0.S[12409]++;throw new IllegalArgumentException(Tapestry.format(
                    "service-single-parameter",
                    Tapestry.ACTION_SERVICE));}

        __CLOVER_73_0.S[12410]++;String stateful = (((cycle.getEngine().isStateful() ) && (++__CLOVER_73_0.CT[2127] != 0)) || (++__CLOVER_73_0.CF[2127] == 0))? STATEFUL_ON : STATEFUL_OFF;
        __CLOVER_73_0.S[12411]++;IPage componentPage = component.getPage();
        __CLOVER_73_0.S[12412]++;IPage responsePage = cycle.getPage();

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

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

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

        __CLOVER_73_0.S[12416]++;serviceContext[i++] = stateful;
        __CLOVER_73_0.S[12417]++;serviceContext[i++] = responsePage.getPageName();
        __CLOVER_73_0.S[12418]++;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[12419]++;if ((((complex) && (++__CLOVER_73_0.CT[2129] != 0)) || (++__CLOVER_73_0.CF[2129] == 0))){
            __CLOVER_73_0.S[12420]++;serviceContext[i++] = componentPage.getPageName();}

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

        __CLOVER_73_0.S[12422]++;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[3023]++;
        __CLOVER_73_0.S[12423]++;IAction action = null;
        __CLOVER_73_0.S[12424]++;String componentPageName;
        __CLOVER_73_0.S[12425]++;int count = 0;

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

        __CLOVER_73_0.S[12427]++;if ((((serviceContext != null) && (++__CLOVER_73_0.CT[2130] != 0)) || (++__CLOVER_73_0.CF[2130] == 0))){
            __CLOVER_73_0.S[12428]++;count = serviceContext.length;}

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

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

        __CLOVER_73_0.S[12432]++;int i = 0;
        __CLOVER_73_0.S[12433]++;String stateful = serviceContext[i++];
        __CLOVER_73_0.S[12434]++;String pageName = serviceContext[i++];
        __CLOVER_73_0.S[12435]++;String targetActionId = serviceContext[i++];

        __CLOVER_73_0.S[12436]++;if ((((complex) && (++__CLOVER_73_0.CT[2132] != 0)) || (++__CLOVER_73_0.CF[2132] == 0))){
            __CLOVER_73_0.S[12437]++;componentPageName = serviceContext[i++];}
        else{
            __CLOVER_73_0.S[12438]++;componentPageName = pageName;}

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

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

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

        __CLOVER_73_0.S[12441]++;cycle.activate(page);

        __CLOVER_73_0.S[12442]++;IPage componentPage = cycle.getPage(componentPageName);
        __CLOVER_73_0.S[12443]++;IComponent component = componentPage.getNestedComponent(targetIdPath);

        __CLOVER_73_0.S[12444]++;try
        {
            __CLOVER_73_0.S[12445]++;action = (IAction) component;
        }
        catch (ClassCastException ex)
        {
            __CLOVER_73_0.S[12446]++;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[12447]++;if ((((stateful.equals(STATEFUL_ON) && action.getRequiresSession()) && (++__CLOVER_73_0.CT[2133] != 0)) || (++__CLOVER_73_0.CF[2133] == 0))){
        {
            __CLOVER_73_0.S[12448]++;HttpSession session = cycle.getRequestContext().getSession();

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

        __CLOVER_73_0.S[12451]++;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 that response.

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

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

    /** @since 3.1 */
    public void setResponseRenderer(ResponseRenderer responseRenderer)
    {try { __CLOVER_73_0.M[3025]++;
        __CLOVER_73_0.S[12454]++;_responseRenderer = responseRenderer;
    } 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.