01: // Copyright 2006, 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.commons.logging.Log;
18: import org.apache.tapestry.ComponentResources;
19: import org.apache.tapestry.Link;
20: import org.apache.tapestry.internal.structure.Page;
21: import org.apache.tapestry.runtime.Component;
22: import org.apache.tapestry.services.ActionResponseGenerator;
23: import org.apache.tapestry.services.ComponentEventResultProcessor;
24:
25: public class ComponentInstanceResultProcessor implements
26: ComponentEventResultProcessor<Component> {
27: private final RequestPageCache _requestPageCache;
28:
29: private final LinkFactory _linkFactory;
30:
31: private final Log _log;
32:
33: public ComponentInstanceResultProcessor(
34: final RequestPageCache requestPageCache,
35: LinkFactory linkFactory, Log log) {
36: _requestPageCache = requestPageCache;
37: _linkFactory = linkFactory;
38: _log = log;
39: }
40:
41: public ActionResponseGenerator processComponentEvent(
42: Component value, Component component,
43: String methodDescription) {
44: ComponentResources resources = value.getComponentResources();
45:
46: if (resources.getContainer() != null)
47: _log.warn(ServicesMessages.componentInstanceIsNotAPage(
48: methodDescription, component, value));
49:
50: // We have all these layers and layers between us and the page instance, but its easy to
51: // extract the page class name and quickly re-resolve that to the page instance.
52:
53: Page page = _requestPageCache.get(resources.getPageName());
54:
55: Link link = _linkFactory.createPageLink(page, false);
56:
57: return new LinkActionResponseGenerator(link);
58: }
59: }
|