Package org.apache.tapestry.engine

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

/* $$ 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.IComponent;
import org.apache.tapestry.IDirect;
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.RequestContext;
import org.apache.tapestry.request.ResponseOutputStream;
import org.apache.tapestry.services.ResponseRenderer;

/**
* Implementation of the direct service, which encodes the page and component id in the service
* context, and passes application-defined parameters as well.
*
* @author Howard Lewis Ship
* @since 1.0.9
*/

public class DirectService extends AbstractService
{public static com.cortexeb.tools.clover.d __CLOVER_80_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_80_0.M[3031]++;

        // New since 1.0.1, we use the component to determine
        // the page, not the cycle. Through the use of tricky
        // things such as Block/InsertBlock, it is possible
        // that a component from a page different than
        // the response page will render.
        // In 1.0.6, we start to record *both* the render page
        // and the component page (if different), as the extended
        // context.

        __CLOVER_80_0.S[12468]++;IPage renderPage = cycle.getPage();
        __CLOVER_80_0.S[12469]++;IPage componentPage = component.getPage();

        __CLOVER_80_0.S[12470]++;boolean complex = renderPage != componentPage;

        __CLOVER_80_0.S[12471]++;String[] context = (((complex ) && (++__CLOVER_80_0.CT[2136] != 0)) || (++__CLOVER_80_0.CF[2136] == 0))? new String[4] : new String[3];

        __CLOVER_80_0.S[12472]++;int i = 0;

        __CLOVER_80_0.S[12473]++;String stateful = (((cycle.getEngine().isStateful() ) && (++__CLOVER_80_0.CT[2137] != 0)) || (++__CLOVER_80_0.CF[2137] == 0))? STATEFUL_ON : STATEFUL_OFF;

        __CLOVER_80_0.S[12474]++;context[i++] = stateful;

        __CLOVER_80_0.S[12475]++;if ((((complex) && (++__CLOVER_80_0.CT[2138] != 0)) || (++__CLOVER_80_0.CF[2138] == 0))){
            __CLOVER_80_0.S[12476]++;context[i++] = renderPage.getPageName();}

        __CLOVER_80_0.S[12477]++;context[i++] = componentPage.getPageName();
        __CLOVER_80_0.S[12478]++;context[i++] = component.getIdPath();

        __CLOVER_80_0.S[12479]++;return constructLink(cycle, Tapestry.DIRECT_SERVICE, context, parameters, true);
    } finally { }}

    public void service(IEngineServiceView engine, IRequestCycle cycle, ResponseOutputStream output)
            throws ServletException, IOException
    {try { __CLOVER_80_0.M[3032]++;
        __CLOVER_80_0.S[12480]++;IDirect direct;
        __CLOVER_80_0.S[12481]++;int count = 0;
        __CLOVER_80_0.S[12482]++;String componentPageName;
        __CLOVER_80_0.S[12483]++;IPage componentPage;
        __CLOVER_80_0.S[12484]++;RequestContext requestContext = cycle.getRequestContext();
        __CLOVER_80_0.S[12485]++;String[] serviceContext = getServiceContext(requestContext);

        __CLOVER_80_0.S[12486]++;if ((((serviceContext != null) && (++__CLOVER_80_0.CT[2139] != 0)) || (++__CLOVER_80_0.CF[2139] == 0))){
            __CLOVER_80_0.S[12487]++;count = serviceContext.length;}

        __CLOVER_80_0.S[12488]++;if ((((count != 3 && count != 4) && (++__CLOVER_80_0.CT[2140] != 0)) || (++__CLOVER_80_0.CF[2140] == 0))){
            __CLOVER_80_0.S[12489]++;throw new ApplicationRuntimeException(Tapestry
                    .getMessage("DirectService.context-parameters"));}

        __CLOVER_80_0.S[12490]++;boolean complex = count == 4;

        __CLOVER_80_0.S[12491]++;int i = 0;
        __CLOVER_80_0.S[12492]++;String stateful = serviceContext[i++];
        __CLOVER_80_0.S[12493]++;String pageName = serviceContext[i++];

        __CLOVER_80_0.S[12494]++;if ((((complex) && (++__CLOVER_80_0.CT[2141] != 0)) || (++__CLOVER_80_0.CF[2141] == 0))){
            __CLOVER_80_0.S[12495]++;componentPageName = serviceContext[i++];}
        else{
            __CLOVER_80_0.S[12496]++;componentPageName = pageName;}

        __CLOVER_80_0.S[12497]++;String componentPath = serviceContext[i++];

        __CLOVER_80_0.S[12498]++;IPage page = cycle.getPage(pageName);

        __CLOVER_80_0.S[12499]++;cycle.activate(page);

        __CLOVER_80_0.S[12500]++;if ((((complex) && (++__CLOVER_80_0.CT[2142] != 0)) || (++__CLOVER_80_0.CF[2142] == 0))){
            __CLOVER_80_0.S[12501]++;componentPage = cycle.getPage(componentPageName);}
        else{
            __CLOVER_80_0.S[12502]++;componentPage = page;}

        __CLOVER_80_0.S[12503]++;IComponent component = componentPage.getNestedComponent(componentPath);

        __CLOVER_80_0.S[12504]++;try
        {
            __CLOVER_80_0.S[12505]++;direct = (IDirect) component;
        }
        catch (ClassCastException ex)
        {
            __CLOVER_80_0.S[12506]++;throw new ApplicationRuntimeException(Tapestry.format(
                    "DirectService.component-wrong-type",
                    component.getExtendedId()), component, null, ex);
        }

        // Check for a StateSession only the session was stateful when
        // the Gesture was created.

        __CLOVER_80_0.S[12507]++;if ((((stateful.equals(STATEFUL_ON) && direct.isStateful()) && (++__CLOVER_80_0.CT[2143] != 0)) || (++__CLOVER_80_0.CF[2143] == 0))){
        {
            __CLOVER_80_0.S[12508]++;HttpSession session = cycle.getRequestContext().getSession();

            __CLOVER_80_0.S[12509]++;if ((((session == null || session.isNew()) && (++__CLOVER_80_0.CT[2144] != 0)) || (++__CLOVER_80_0.CF[2144] == 0))){
                __CLOVER_80_0.S[12510]++;throw new StaleSessionException(Tapestry.format(
                        "DirectService.stale-session-exception",
                        direct.getExtendedId()), direct.getPage());}
        }}

        __CLOVER_80_0.S[12511]++;Object[] parameters = getParameters(cycle);

        __CLOVER_80_0.S[12512]++;cycle.setServiceParameters(parameters);
        __CLOVER_80_0.S[12513]++;direct.trigger(cycle);

        // Render the response. This will be the response page (the first element in the context)
        // unless the direct (or its delegate) changes it.

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

    public String getName()
    {try { __CLOVER_80_0.M[3033]++;
        __CLOVER_80_0.S[12515]++;return Tapestry.DIRECT_SERVICE;
    } finally { }}

    /** @since 3.1 */
    public void setResponseRenderer(ResponseRenderer responseRenderer)
    {try { __CLOVER_80_0.M[3034]++;
        __CLOVER_80_0.S[12516]++;_responseRenderer = responseRenderer;
    } finally { }}
}
TOP

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

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.