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