001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.pageload; 016 017 import org.apache.tapestry.INamespace; 018 import org.apache.tapestry.services.ClassFinder; 019 020 /** 021 * Searches for a class with a name matching the page name. Searches in the default Java package, 022 * and possibly additional packages defined as meta-data within the namespace. 023 * 024 * @author Howard M. Lewis Ship 025 * @since 4.0 026 */ 027 public class NamespaceClassSearchComponentClassProvider implements ComponentClassProvider 028 { 029 /** 030 * Property, defined as meta data of the containing namespace, that defines a comma-seperated 031 * list of packages to search for page or component classes within. 032 */ 033 private String _packagesName; 034 035 private ClassFinder _classFinder; 036 037 public String provideComponentClassName(ComponentClassProviderContext context) 038 { 039 INamespace namespace = context.getNamespace(); 040 String packages = namespace.getPropertyValue(_packagesName); 041 042 String componentClassName = context.getName().replace('/', '.'); 043 044 Class clazz = _classFinder.findClass(packages, componentClassName); 045 046 return clazz == null ? null : clazz.getName(); 047 } 048 049 public void setPackagesName(String packagesName) 050 { 051 _packagesName = packagesName; 052 } 053 054 public void setClassFinder(ClassFinder classFinder) 055 { 056 _classFinder = classFinder; 057 } 058 }