001/* $Id: RuleFinder.java 992060 2010-09-02 19:09:47Z simonetripodi $
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements.  See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.commons.digester.plugins;
019
020import java.util.Properties;
021import org.apache.commons.digester.Digester;
022
023/**
024 * Each concrete implementation of RuleFinder is an algorithm for
025 * locating a source of digester rules for a plugin. The algorithm may 
026 * use info explicitly provided by the user as part of the plugin 
027 * declaration, or not (in which case the concrete RuleFinder subclass
028 * typically has Dflt as part of its name).
029 * <p>
030 * Instances of this class can also be regarded as a Factory for RuleLoaders,
031 * except that an instance of a RuleLoader is only created if the particular
032 * finder algorithm can locate a suitable source of rules given the plugin
033 * class and associated properties.
034 * <p>
035 * This is an abstract class rather than an interface in order to make
036 * it possible to enhance this class in future without breaking binary
037 * compatibility; it is possible to add methods to an abstract class, but
038 * not to an interface. 
039 *
040 * @since 1.6
041 */
042
043public abstract class RuleFinder {
044
045    /**
046     * Apply the finder algorithm to attempt to locate a source of
047     * digester rules for the specified plugin class.
048     * <p>
049     * This method is invoked when a plugin is declared by the user, either
050     * via an explicit use of PluginDeclarationRule, or implicitly via an
051     * "inline declaration" where the declaration and use are simultaneous.
052     * <p>
053     * If dynamic rules for the specified plugin class are located, then
054     * the RuleFinder will return a RuleLoader object encapsulating those
055     * rules, and this object will be invoked each time the user actually
056     * requests an instance of the declared plugin class, to load the
057     * custom rules associated with that plugin instance.
058     * <p>
059     * If no dynamic rules can be found, null is returned. This is not an
060     * error; merely an indication that this particular algorithm found
061     * no matches.
062     * <p>
063     * The properties object holds any xml attributes the user may have
064     * specified on the plugin declaration in order to indicate how to locate
065     * the plugin rules.
066     * <p>
067     * @throws PluginConfigurationException if the algorithm finds a source
068     * of rules, but there is something invalid about that source.
069     */
070
071     public abstract RuleLoader findLoader(
072                        Digester d, Class<?> pluginClass, 
073                        Properties p) throws PluginException;
074}
075