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 ComponentClassProvider |
29 | { |
|
30 | ||
31 | /** |
|
32 | * Property, defined as meta data of the containing namespace, that defines |
|
33 | * a comma-seperated list of packages to search for page or component |
|
34 | * classes within. |
|
35 | */ |
|
36 | private String _packagesName; |
|
37 | ||
38 | private ClassFinder _classFinder; |
|
39 | ||
40 | public String provideComponentClassName(ComponentClassProviderContext context) |
|
41 | { |
|
42 | 2 | INamespace namespace = context.getNamespace(); |
43 | 2 | String packages = namespace.getPropertyValue(_packagesName); |
44 | ||
45 | 2 | String componentClassName = context.getName().replace('/', '.'); |
46 | ||
47 | 2 | Class clazz = _classFinder.findClass(packages, componentClassName); |
48 | ||
49 | 2 | return clazz == null ? null : clazz.getName(); |
50 | } |
|
51 | ||
52 | public void setPackagesName(String packagesName) |
|
53 | { |
|
54 | 2 | _packagesName = packagesName; |
55 | 2 | } |
56 | ||
57 | public void setClassFinder(ClassFinder classFinder) |
|
58 | { |
|
59 | 2 | _classFinder = classFinder; |
60 | 2 | } |
61 | } |