Source code: org/apache/tapestry/engine/DirectService.java
1 /* $$ Clover has instrumented this file $$ */// Copyright 2004 The Apache Software Foundation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package org.apache.tapestry.engine;
16
17 import java.io.IOException;
18
19 import javax.servlet.ServletException;
20 import javax.servlet.http.HttpSession;
21
22 import org.apache.hivemind.ApplicationRuntimeException;
23 import org.apache.tapestry.IComponent;
24 import org.apache.tapestry.IDirect;
25 import org.apache.tapestry.IPage;
26 import org.apache.tapestry.IRequestCycle;
27 import org.apache.tapestry.StaleSessionException;
28 import org.apache.tapestry.Tapestry;
29 import org.apache.tapestry.request.RequestContext;
30 import org.apache.tapestry.request.ResponseOutputStream;
31
32 /**
33 * Implementation of the direct service, which encodes the page and component id in
34 * the service context, and passes application-defined parameters as well.
35 *
36 * @author Howard Lewis Ship
37 * @since 1.0.9
38 *
39 **/
40
41 public class DirectService extends AbstractService
42 {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},1096998272901L);
43 /**
44 * Encoded into URL if engine was stateful.
45 *
46 * @since 3.0
47 **/
48
49 private static final String STATEFUL_ON = "1";
50
51 /**
52 * Encoded into URL if engine was not stateful.
53 *
54 * @since 3.0
55 **/
56
57 private static final String STATEFUL_OFF = "0";
58
59 public ILink getLink(IRequestCycle cycle, IComponent component, Object[] parameters)
60 {try { __CLOVER_80_0.M[460]++;
61
62 // New since 1.0.1, we use the component to determine
63 // the page, not the cycle. Through the use of tricky
64 // things such as Block/InsertBlock, it is possible
65 // that a component from a page different than
66 // the response page will render.
67 // In 1.0.6, we start to record *both* the render page
68 // and the component page (if different), as the extended
69 // context.
70
71 __CLOVER_80_0.S[1998]++;IPage renderPage = cycle.getPage();
72 __CLOVER_80_0.S[1999]++;IPage componentPage = component.getPage();
73
74 __CLOVER_80_0.S[2000]++;boolean complex = renderPage != componentPage;
75
76 __CLOVER_80_0.S[2001]++;String[] context = (((complex ) && (++__CLOVER_80_0.CT[375] != 0)) || (++__CLOVER_80_0.CF[375] == 0))? new String[4] : new String[3];
77
78 __CLOVER_80_0.S[2002]++;int i = 0;
79
80 __CLOVER_80_0.S[2003]++;String stateful = (((cycle.getEngine().isStateful() ) && (++__CLOVER_80_0.CT[376] != 0)) || (++__CLOVER_80_0.CF[376] == 0))? STATEFUL_ON : STATEFUL_OFF;
81
82 __CLOVER_80_0.S[2004]++;context[i++] = stateful;
83
84 __CLOVER_80_0.S[2005]++;if ((((complex) && (++__CLOVER_80_0.CT[377] != 0)) || (++__CLOVER_80_0.CF[377] == 0))){
85 __CLOVER_80_0.S[2006]++;context[i++] = renderPage.getPageName();}
86
87 __CLOVER_80_0.S[2007]++;context[i++] = componentPage.getPageName();
88 __CLOVER_80_0.S[2008]++;context[i++] = component.getIdPath();
89
90 __CLOVER_80_0.S[2009]++;return constructLink(cycle, Tapestry.DIRECT_SERVICE, context, parameters, true);
91 } finally { }}
92
93 public void service(
94 IEngineServiceView engine,
95 IRequestCycle cycle,
96 ResponseOutputStream output)
97 throws ServletException, IOException
98 {try { __CLOVER_80_0.M[461]++;
99 __CLOVER_80_0.S[2010]++;IDirect direct;
100 __CLOVER_80_0.S[2011]++;int count = 0;
101 __CLOVER_80_0.S[2012]++;String componentPageName;
102 __CLOVER_80_0.S[2013]++;IPage componentPage;
103 __CLOVER_80_0.S[2014]++;RequestContext requestContext = cycle.getRequestContext();
104 __CLOVER_80_0.S[2015]++;String[] serviceContext = getServiceContext(requestContext);
105
106 __CLOVER_80_0.S[2016]++;if ((((serviceContext != null) && (++__CLOVER_80_0.CT[378] != 0)) || (++__CLOVER_80_0.CF[378] == 0))){
107 __CLOVER_80_0.S[2017]++;count = serviceContext.length;}
108
109 __CLOVER_80_0.S[2018]++;if ((((count != 3 && count != 4) && (++__CLOVER_80_0.CT[379] != 0)) || (++__CLOVER_80_0.CF[379] == 0))){
110 __CLOVER_80_0.S[2019]++;throw new ApplicationRuntimeException(
111 Tapestry.getMessage("DirectService.context-parameters"));}
112
113 __CLOVER_80_0.S[2020]++;boolean complex = count == 4;
114
115 __CLOVER_80_0.S[2021]++;int i = 0;
116 __CLOVER_80_0.S[2022]++;String stateful = serviceContext[i++];
117 __CLOVER_80_0.S[2023]++;String pageName = serviceContext[i++];
118
119 __CLOVER_80_0.S[2024]++;if ((((complex) && (++__CLOVER_80_0.CT[380] != 0)) || (++__CLOVER_80_0.CF[380] == 0))){
120 __CLOVER_80_0.S[2025]++;componentPageName = serviceContext[i++];}
121 else{
122 __CLOVER_80_0.S[2026]++;componentPageName = pageName;}
123
124 __CLOVER_80_0.S[2027]++;String componentPath = serviceContext[i++];
125
126 __CLOVER_80_0.S[2028]++;IPage page = cycle.getPage(pageName);
127
128 __CLOVER_80_0.S[2029]++;cycle.activate(page);
129
130 __CLOVER_80_0.S[2030]++;if ((((complex) && (++__CLOVER_80_0.CT[381] != 0)) || (++__CLOVER_80_0.CF[381] == 0))){
131 __CLOVER_80_0.S[2031]++;componentPage = cycle.getPage(componentPageName);}
132 else{
133 __CLOVER_80_0.S[2032]++;componentPage = page;}
134
135 __CLOVER_80_0.S[2033]++;IComponent component = componentPage.getNestedComponent(componentPath);
136
137 __CLOVER_80_0.S[2034]++;try
138 {
139 __CLOVER_80_0.S[2035]++;direct = (IDirect) component;
140 }
141 catch (ClassCastException ex)
142 {
143 __CLOVER_80_0.S[2036]++;throw new ApplicationRuntimeException(
144 Tapestry.format("DirectService.component-wrong-type", component.getExtendedId()),
145 component,
146 null,
147 ex);
148 }
149
150 // Check for a StateSession only the session was stateful when
151 // the Gesture was created.
152
153 __CLOVER_80_0.S[2037]++;if ((((stateful.equals(STATEFUL_ON) && direct.isStateful()) && (++__CLOVER_80_0.CT[382] != 0)) || (++__CLOVER_80_0.CF[382] == 0))){
154 {
155 __CLOVER_80_0.S[2038]++;HttpSession session = cycle.getRequestContext().getSession();
156
157 __CLOVER_80_0.S[2039]++;if ((((session == null || session.isNew()) && (++__CLOVER_80_0.CT[383] != 0)) || (++__CLOVER_80_0.CF[383] == 0))){
158 __CLOVER_80_0.S[2040]++;throw new StaleSessionException(
159 Tapestry.format(
160 "DirectService.stale-session-exception",
161 direct.getExtendedId()),
162 direct.getPage());}
163 }}
164
165 __CLOVER_80_0.S[2041]++;Object[] parameters = getParameters(cycle);
166
167 __CLOVER_80_0.S[2042]++;cycle.setServiceParameters(parameters);
168 __CLOVER_80_0.S[2043]++;direct.trigger(cycle);
169
170 // Render the response. This will be the response page (the first element in the context)
171 // unless the direct (or its delegate) changes it.
172
173 __CLOVER_80_0.S[2044]++;engine.renderResponse(cycle, output);
174 } finally { }}
175
176 public String getName()
177 {try { __CLOVER_80_0.M[462]++;
178 __CLOVER_80_0.S[2045]++;return Tapestry.DIRECT_SERVICE;
179 } finally { }}
180 }