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.tapestry.internal.structure.Page;
18: import org.apache.tapestry.runtime.Component;
19: import org.apache.tapestry.services.ComponentSource;
20:
21: public class ComponentSourceImpl implements ComponentSource {
22: private final RequestPageCache _pageCache;
23:
24: public ComponentSourceImpl(RequestPageCache pageCache) {
25: _pageCache = pageCache;
26: }
27:
28: public Component getComponent(String componentId) {
29: int colonx = componentId.indexOf(':');
30:
31: if (colonx < 0) {
32: Page page = _pageCache.get(componentId);
33:
34: return page.getRootComponent();
35: }
36:
37: String pageName = componentId.substring(0, colonx);
38:
39: Page page = _pageCache.get(pageName);
40: String nestedId = componentId.substring(colonx + 1);
41:
42: return page.getComponentElementByNestedId(nestedId)
43: .getComponent();
44: }
45:
46: public Component getPage(String pageName) {
47: Page page = _pageCache.get(pageName);
48:
49: return page.getRootComponent();
50: }
51:
52: }
|