KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > digester > plugins > strategies > FinderFromDfltMethod


1 /* $Id: FinderFromDfltMethod.java 179714 2005-06-03 03:53:39Z skitching $
2  *
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17  
18 package org.apache.commons.digester.plugins.strategies;
19
20 import java.util.Properties JavaDoc;
21 import java.lang.reflect.Method JavaDoc;
22
23 import org.apache.commons.digester.Digester;
24 import org.apache.commons.digester.plugins.RuleFinder;
25 import org.apache.commons.digester.plugins.RuleLoader;
26 import org.apache.commons.digester.plugins.PluginException;
27
28 /**
29  * A rule-finding algorithm which looks for a method with a specific name
30  * on the plugin class.
31  *
32  * @since 1.6
33  */

34
35 public class FinderFromDfltMethod extends RuleFinder {
36     public static String JavaDoc DFLT_METHOD_NAME = "addRules";
37
38     private String JavaDoc methodName;
39     
40     /** See {@link #findLoader}. */
41     public FinderFromDfltMethod() {
42         this(DFLT_METHOD_NAME);
43     }
44
45     /**
46      * Create a rule-finder which invokes a specific method on the plugin
47      * class whenever dynamic rules for a plugin need to be loaded. See the
48      * findRules method for more info.
49      *
50      * @param methodName must be non-null.
51      */

52     public FinderFromDfltMethod(String JavaDoc methodName) {
53         this.methodName = methodName;
54     }
55     
56     /**
57      * If there exists on the plugin class a method with name matching the
58      * constructor's methodName value then locate the appropriate Method on
59      * the plugin class and return an object encapsulating that info.
60      * <p>
61      * If there is no matching method then just return null.
62      * <p>
63      * The returned object (when non-null) will invoke the target method
64      * on the plugin class whenever its addRules method is invoked. The
65      * target method is expected to have the following prototype:
66      * <code> public static void xxxxx(Digester d, String patternPrefix); </code>
67      */

68     public RuleLoader findLoader(Digester d, Class JavaDoc pluginClass, Properties JavaDoc p)
69                         throws PluginException {
70
71         Method JavaDoc rulesMethod = LoaderFromClass.locateMethod(pluginClass, methodName);
72         if (rulesMethod == null) {
73             return null;
74         }
75         
76         return new LoaderFromClass(pluginClass, rulesMethod);
77     }
78 }
79
80
Popular Tags