| Line | Hits | Source |
|---|---|---|
| 1 | /* | |
| 2 | Chrysalis Web Framework [http://chrysalis.sourceforge.net] | |
| 3 | Copyright (c) 2002, 2003, 2004, Paul Strack | |
| 4 | ||
| 5 | All rights reserved. | |
| 6 | ||
| 7 | Redistribution and use in source and binary forms, with or without | |
| 8 | modification, are permitted provided that the following conditions are met: | |
| 9 | ||
| 10 | 1. Redistributions of source code must retain the above copyright notice, this | |
| 11 | list of conditions and the following disclaimer. | |
| 12 | ||
| 13 | 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 14 | this list of conditions and the following disclaimer in the documentation | |
| 15 | and/or other materials provided with the distribution. | |
| 16 | ||
| 17 | 3. Neither the name of the copyright holder nor the names of its contributors | |
| 18 | may be used to endorse or promote products derived from this software without | |
| 19 | specific prior written permission. | |
| 20 | ||
| 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | |
| 25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
| 28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 31 | */ | |
| 32 | ||
| 33 | package org.chwf.servlet.engine; | |
| 34 | ||
| 35 | import java.lang.reflect.Method; | |
| 36 | import java.util.HashMap; | |
| 37 | import java.util.Iterator; | |
| 38 | import java.util.Map; | |
| 39 | ||
| 40 | import org.chwf.servlet.Controller; | |
| 41 | ||
| 42 | /** | |
| 43 | * Class managing controller configuration data. | |
| 44 | * | |
| 45 | * @author Paul Strack | |
| 46 | */ | |
| 47 | ||
| 48 | 2 | public class ControllerConfig { |
| 49 | ||
| 50 | /** The controller class. */ | |
| 51 | private final Class controller; | |
| 52 | ||
| 53 | /** Method configurations. */ | |
| 54 | 41 | private final Map methodConfigs = new HashMap(); |
| 55 | ||
| 56 | /** | |
| 57 | * Constructor. | |
| 58 | * | |
| 59 | * @param controller The controller class. | |
| 60 | */ | |
| 61 | 41 | public ControllerConfig(Class controller) { |
| 62 | 41 | this.controller = controller; |
| 63 | 41 | Method[] methods = this.controller.getMethods(); |
| 64 | 968 | for (int i = 0; i < methods.length; i++) { |
| 65 | 927 | Method method = methods[i]; |
| 66 | 927 | if (isControllerMethod(method)) { |
| 67 | 78 | MethodConfig methodConfig = new MethodConfig(this, method); |
| 68 | 78 | methodConfigs.put(method.getName(), methodConfig); |
| 69 | } | |
| 70 | } | |
| 71 | 41 | } |
| 72 | ||
| 73 | /** | |
| 74 | * The controller class. | |
| 75 | * | |
| 76 | * @return The controller class. | |
| 77 | */ | |
| 78 | public Class getController() { | |
| 79 | 312 | return controller; |
| 80 | } | |
| 81 | ||
| 82 | /** | |
| 83 | * The controller method names. | |
| 84 | * | |
| 85 | * @return The controller method names. | |
| 86 | */ | |
| 87 | public Iterator getMethodNames() { | |
| 88 | 82 | return methodConfigs.keySet().iterator(); |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * The method configuration for the given method. | |
| 93 | * | |
| 94 | * @param methodName The method name. | |
| 95 | * @return The method configuration. | |
| 96 | */ | |
| 97 | public MethodConfig getMethodConfig(String methodName) { | |
| 98 | 156 | return (MethodConfig) methodConfigs.get(methodName); |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * Whether the method is a controller method. | |
| 103 | * | |
| 104 | * @param method The method. | |
| 105 | * @return Whether the method is a controller method. | |
| 106 | */ | |
| 107 | private static boolean isControllerMethod(Method method) { | |
| 108 | 927 | if (method.getDeclaringClass().equals(Controller.class)) { |
| 109 | 480 | return false; |
| 110 | } else { | |
| 111 | 447 | return !method.getDeclaringClass().equals(Object.class); |
| 112 | } | |
| 113 | } | |
| 114 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |