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