Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
NamespaceClassSearchComponentClassProvider |
|
| 1.0;1 |
1 | // Copyright 2005 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.pageload; |
|
16 | ||
17 | import org.apache.tapestry.INamespace; |
|
18 | import org.apache.tapestry.services.ClassFinder; |
|
19 | ||
20 | /** |
|
21 | * Searches for a class with a name matching the page name. Searches in the |
|
22 | * default Java package, and possibly additional packages defined as meta-data |
|
23 | * within the namespace. |
|
24 | * |
|
25 | * @author Howard M. Lewis Ship |
|
26 | * @since 4.0 |
|
27 | */ |
|
28 | 2 | public class NamespaceClassSearchComponentClassProvider implements |
29 | ComponentClassProvider |
|
30 | { |
|
31 | ||
32 | /** |
|
33 | * Property, defined as meta data of the containing namespace, that defines |
|
34 | * a comma-seperated list of packages to search for page or component |
|
35 | * classes within. |
|
36 | */ |
|
37 | private String _packagesName; |
|
38 | ||
39 | private ClassFinder _classFinder; |
|
40 | ||
41 | public String provideComponentClassName( |
|
42 | ComponentClassProviderContext context) |
|
43 | { |
|
44 | 2 | INamespace namespace = context.getNamespace(); |
45 | 2 | String packages = namespace.getPropertyValue(_packagesName); |
46 | ||
47 | 2 | String componentClassName = context.getName().replace('/', '.'); |
48 | ||
49 | 2 | Class clazz = _classFinder.findClass(packages, componentClassName); |
50 | ||
51 | 2 | return clazz == null ? null : clazz.getName(); |
52 | } |
|
53 | ||
54 | public void setPackagesName(String packagesName) |
|
55 | { |
|
56 | 2 | _packagesName = packagesName; |
57 | 2 | } |
58 | ||
59 | public void setClassFinder(ClassFinder classFinder) |
|
60 | { |
|
61 | 2 | _classFinder = classFinder; |
62 | 2 | } |
63 | } |