Clover coverage report - Code Coverage for tapestry release 4.0-beta-1
Coverage timestamp: Fri Jun 24 2005 14:32:46 EDT
file stats: LOC: 101   Methods: 4
NCLOC: 50   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NamespaceClassSearchComponentClassProvider.java 100% 100% 100% 100%
coverage
 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 NamespaceClassSearchComponentClassProvider implements ComponentClassProvider
 33    {
 34    /**
 35    * Property, defined as meta data of the containing namespace, that defines a comma-seperated
 36    * list of packages to search for page or component classes within.
 37    */
 38    private String _packagesName;
 39   
 40    private ClassResolver _classResolver;
 41   
 42  83 public String provideComponentClassName(ComponentClassProviderContext context)
 43    {
 44  83 List packages = buildPackageSearchList(context.getNamespace());
 45  83 String pageClassName = context.getName().replace('/', '.');
 46   
 47  83 Iterator i = packages.iterator();
 48  83 while (i.hasNext())
 49    {
 50  84 String packagePrefix = (String) i.next();
 51  84 String className = packagePrefix + pageClassName;
 52   
 53  84 Class clazz = _classResolver.checkForClass(className);
 54   
 55  84 if (clazz != null)
 56  1 return className;
 57    }
 58   
 59  82 return null;
 60    }
 61   
 62    /**
 63    * Returns a List of String -- prefixes to apply to the page name to form a fully qualified
 64    * class name.
 65    */
 66   
 67  85 List buildPackageSearchList(INamespace namespace)
 68    {
 69  85 List result = new ArrayList();
 70   
 71  85 String packages = namespace.getPropertyValue(_packagesName);
 72   
 73  85 if (packages != null)
 74    {
 75  3 StringTokenizer tokenizer = new StringTokenizer(packages, ", ");
 76   
 77  3 while (tokenizer.hasMoreTokens())
 78    {
 79  4 String packageName = tokenizer.nextToken();
 80   
 81  4 result.add(packageName + ".");
 82    }
 83    }
 84   
 85    // Search in the default package as well.
 86   
 87  85 result.add("");
 88   
 89  85 return result;
 90    }
 91   
 92  36 public void setClassResolver(ClassResolver classResolver)
 93    {
 94  36 _classResolver = classResolver;
 95    }
 96   
 97  38 public void setPackagesName(String packagesName)
 98    {
 99  38 _packagesName = packagesName;
 100    }
 101    }