    001    // Copyright 2009 The Apache Software Foundation
    002    //
    003    // Licensed under the Apache License, Version 2.0 (the "License");
    004    // you may not use this file except in compliance with the License.
    005    // You may obtain a copy of the License at
    006    //
    007    //     http://www.apache.org/licenses/LICENSE-2.0
    008    //
    009    // Unless required by applicable law or agreed to in writing, software
    010    // distributed under the License is distributed on an "AS IS" BASIS,
    011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012    // See the License for the specific language governing permissions and
    013    // limitations under the License.
    014
    015    package org.apache.tapestry5.ioc;
    016
    017    import org.apache.tapestry5.ioc.def.ServiceDef;
    018
    019    /**
    020     * Definition of a service advisor, which (by default) is derived from a service advisor method. Service advisor methods
    021     * are static or instance methods on module classes prefixed with "advise". When a service is realized, a list of
    022     * matching AdvisorDefs is generated, then ordered, and from each a {@link org.apache.tapestry5.ioc.ServiceAdvisor} is
    023     * obtained and invoked.
    024     * <p/>
    025     * Note: service decorators (via {@link org.apache.tapestry5.ioc.def.DecoratorDef} are applied <em>around</em> the
    026     * interceptor generated via service advisors, (for compatibility with Tapestry 5.0). In general, you should use service
    027     * decoration or service advice, not both.
    028     *
    029     * @since 5.1.0.0
    030     */
    031    public interface AdvisorDef
    032    {
    033        /**
    034         * Returns the id of the advisor, which is derived from the advisor method name.
    035         */
    036        String getAdvisorId();
    037
    038        /**
    039         * Returns ordering constraints for this advisor, to order it relative to other advisors.
    040         *
    041         * @return zero or more constraint strings
    042         */
    043        String[] getConstraints();
    044
    045        /**
    046         * Creates an object that can provide the service advice (in the default case, by invoking the advise method on the
    047         * module class or instance).
    048         *
    049         * @param moduleSource used to obtain the module instance
    050         * @param resources    used to provide injections into the advise method
    051         * @return advisor
    052         */
    053        ServiceAdvisor createAdvisor(ModuleBuilderSource moduleSource, ServiceResources resources);
    054
    055        /**
    056         * Used to determine which services may be advised. When advising a service, first the advisors that target the
    057         * service are identified, then ordering occurs, then the {@link org.apache.tapestry5.ioc.ServiceAdvisor}s are
    058         * obtained and invoked.
    059         *
    060         * @param serviceDef identifies a service that may be advised
    061         * @return true if this advisor applies to the service
    062         */
    063        boolean matches(ServiceDef serviceDef);
    064    }