01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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.internal.services;
16:
17: import org.apache.tapestry.Link;
18: import org.apache.tapestry.internal.structure.Page;
19: import org.apache.tapestry.runtime.Component;
20: import org.apache.tapestry.services.ActionResponseGenerator;
21: import org.apache.tapestry.services.ComponentClassResolver;
22: import org.apache.tapestry.services.ComponentEventResultProcessor;
23:
24: /**
25: * Used when a component event handler returns a class value. The value is interpreted as the page
26: * class. A link to the page will be sent.
27: *
28: * @see LinkActionResponseGenerator
29: */
30: public class ClassResultProcessor implements
31: ComponentEventResultProcessor<Class> {
32: private ComponentClassResolver _resolver;
33:
34: private final RequestPageCache _requestPageCache;
35:
36: private final LinkFactory _linkFactory;
37:
38: public ClassResultProcessor(ComponentClassResolver resolver,
39: RequestPageCache requestPageCache, LinkFactory linkFactory) {
40: _resolver = resolver;
41: _requestPageCache = requestPageCache;
42: _linkFactory = linkFactory;
43: }
44:
45: public ActionResponseGenerator processComponentEvent(Class value,
46: Component component, String methodDescripion) {
47: String className = value.getName();
48: String pageName = _resolver
49: .resolvePageClassNameToPageName(className);
50: Page page = _requestPageCache.get(pageName);
51: Link link = _linkFactory.createPageLink(page, false);
52: return new LinkActionResponseGenerator(link);
53: }
54:
55: }
|