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 java.util.Locale;
18:
19: import org.apache.tapestry.internal.event.InvalidationEventHubImpl;
20: import org.apache.tapestry.internal.events.InvalidationListener;
21: import org.apache.tapestry.internal.structure.Page;
22: import org.apache.tapestry.services.ComponentClassResolver;
23: import org.apache.tapestry.services.PersistentFieldManager;
24:
25: public class PageLoaderImpl extends InvalidationEventHubImpl implements
26: PageLoader, InvalidationListener {
27: private final ComponentTemplateSource _templateSource;
28:
29: private final PageElementFactory _pageElementFactory;
30:
31: private final LinkFactory _linkFactory;
32:
33: private final PersistentFieldManager _persistentFieldManager;
34:
35: private final ComponentClassResolver _resolver;
36:
37: public PageLoaderImpl(ComponentTemplateSource templateSource,
38: PageElementFactory pageElementFactory,
39: LinkFactory linkFactory,
40: PersistentFieldManager persistentFieldManager,
41: ComponentClassResolver resolver) {
42: _templateSource = templateSource;
43: _pageElementFactory = pageElementFactory;
44: _linkFactory = linkFactory;
45: _persistentFieldManager = persistentFieldManager;
46: _resolver = resolver;
47: }
48:
49: public Page loadPage(String logicalPageName, Locale locale) {
50: // For the moment, the processors are used once and discarded. Perhaps it is worth the
51: // effort to pool them for reuse, but not too likely.
52:
53: PageLoaderProcessor processor = new PageLoaderProcessor(
54: _templateSource, _pageElementFactory, _linkFactory,
55: _persistentFieldManager);
56:
57: String pageClassName = _resolver
58: .resolvePageNameToClassName(logicalPageName);
59:
60: return processor.loadPage(logicalPageName, pageClassName,
61: locale);
62: }
63:
64: /**
65: * When the page loader receives an invalidation event, it respawns the event for its listeners.
66: * Those listeners will include page caches and the like.
67: */
68: public void objectWasInvalidated() {
69: fireInvalidationEvent();
70: }
71:
72: }
|