|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
NamespaceClassSearchPageClassProvider.java | 100% | 100% | 100% | 100% |
|
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 java.util.ArrayList;
|
|
18 |
import java.util.Iterator;
|
|
19 |
import java.util.List;
|
|
20 |
import java.util.StringTokenizer;
|
|
21 |
|
|
22 |
import org.apache.hivemind.ClassResolver;
|
|
23 |
import org.apache.tapestry.INamespace;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* Searches for a class with a name matching the page name. Searches in the default Java package,
|
|
27 |
* and possibly additional packages defined as meta-data within the namespace.
|
|
28 |
*
|
|
29 |
* @author Howard M. Lewis Ship
|
|
30 |
* @since 4.0
|
|
31 |
*/
|
|
32 |
public class NamespaceClassSearchPageClassProvider implements PageClassProvider |
|
33 |
{ |
|
34 |
private ClassResolver _classResolver;
|
|
35 |
|
|
36 |
/**
|
|
37 |
* Property, defined as meta data of the containing namespace, that defines a comma-seperated
|
|
38 |
* list of packages to search for page classes within.
|
|
39 |
*/
|
|
40 |
|
|
41 |
public static final String PACKAGES_NAME = "org.apache.tapestry.page-class-packages"; |
|
42 |
|
|
43 | 47 |
public String providePageClassName(PageClassProviderContext context)
|
44 |
{ |
|
45 | 47 |
List packages = buildPackageSearchList(context.getNamespace()); |
46 | 47 |
String pageClassName = context.getPageName().replace('/', '.'); |
47 |
|
|
48 | 47 |
Iterator i = packages.iterator(); |
49 | 47 |
while (i.hasNext())
|
50 |
{ |
|
51 | 48 |
String packagePrefix = (String) i.next(); |
52 | 48 |
String className = packagePrefix + pageClassName; |
53 |
|
|
54 | 48 |
Class clazz = _classResolver.checkForClass(className); |
55 |
|
|
56 | 48 |
if (clazz != null) |
57 | 1 |
return className;
|
58 |
} |
|
59 |
|
|
60 | 46 |
return null; |
61 |
} |
|
62 |
|
|
63 |
/**
|
|
64 |
* Returns a List of String -- prefixes to apply to the page name to form a fully qualified
|
|
65 |
* class name.
|
|
66 |
*/
|
|
67 |
|
|
68 | 49 |
List buildPackageSearchList(INamespace namespace) |
69 |
{ |
|
70 | 49 |
List result = new ArrayList();
|
71 |
|
|
72 | 49 |
String packages = namespace.getPropertyValue(PACKAGES_NAME); |
73 |
|
|
74 | 49 |
if (packages != null) |
75 |
{ |
|
76 | 3 |
StringTokenizer tokenizer = new StringTokenizer(packages, ", "); |
77 |
|
|
78 | 3 |
while (tokenizer.hasMoreTokens())
|
79 |
{ |
|
80 | 4 |
String packageName = tokenizer.nextToken(); |
81 |
|
|
82 | 4 |
result.add(packageName + ".");
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
// Search in the default package as well.
|
|
87 |
|
|
88 | 49 |
result.add("");
|
89 |
|
|
90 | 49 |
return result;
|
91 |
} |
|
92 |
|
|
93 | 23 |
public void setClassResolver(ClassResolver classResolver) |
94 |
{ |
|
95 | 23 |
_classResolver = classResolver; |
96 |
} |
|
97 |
} |
|