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.def; 014 015import org.apache.tapestry5.ioc.ModuleBuilderSource; 016import org.apache.tapestry5.ioc.ServiceDecorator; 017import org.apache.tapestry5.ioc.ServiceResources; 018 019/** 020 * Definition of a service decorator, which (by default) is derived from a service decorator method. 021 * 022 * A note on decorator scheduling. The scheduling is based on the desired order of <em>behavior</em>. Thus, if logging 023 * should occur before security checks, and security checks should occur before transaction management, then the desired 024 * decorator order is Logging, Security, Transactions. This might be specified as having Security occur after Logging, 025 * and Transactions occur after Security. It might also be specified by having Logging ordered "before:*", and 026 * Transactions ordered "after:*" with no specified scheduling for Security. 027 * 028 * Once this order is established, decorators are <em>applied</em> in reverse order. Each decorator's job is to create 029 * an <em>interceptor</em> for the service, that delegates to the next implementation. This implies that the decorators 030 * are executed last to first. In the above example, the core service implementation would be passed to the Transaction 031 * decorator, resulting in the Transaction interceptor. The Transaction interceptor would be passed to the Security 032 * decorator, resulting in the Security interceptor. The Security interceptor would be passed to the Logging decorator, 033 * resulting in the Logging interceptor. Thus at runtime, the Logging interceptor will execute first, then delegate to 034 * the Security interceptor, which would delegate to the Transaction interceptor, which would finally delegate to the 035 * core service implementation. 036 * 037 * Service decorators are part of the initial version of Tapestry IoC. Starting in release 5.1, their use has been 038 * deprecated, in favor of {@link org.apache.tapestry5.ioc.AdvisorDef}, which is based on {@link 039 * org.apache.tapestry5.ioc.services.AspectInterceptorBuilder}. 040 * 041 * Note: service decorators are applied <em>around</em> the interceptor generated via any {@link 042 * org.apache.tapestry5.ioc.AdvisorDef}s (for compatibility with Tapestry 5.0). In general, you should use service 043 * decoration or service advice, not both. 044 */ 045public interface DecoratorDef 046{ 047 /** 048 * Returns the id of the decorator, which is derived from the decorator method name. 049 */ 050 String getDecoratorId(); 051 052 /** 053 * Returns zero or more ordering constraint strings, used to order the decorated relative to the other decorators. 054 */ 055 056 String[] getConstraints(); 057 058 /** 059 * Creates an object that can perform the decoration (in the default case, by invoking the decorator method on the 060 * module class or instance. 061 * 062 * @param moduleSource access to the the module instance associated with the module containing the decorator (not 063 * necessarily the module containing the service being decorated) 064 * @param resources the resources visible <em>to the decorator</em> (which may be in a different module than the 065 * service being decorated). Other resource properties (serviceId, serviceInterface, log, etc.) 066 * are for the service being decorated. 067 */ 068 ServiceDecorator createDecorator(ModuleBuilderSource moduleSource, 069 ServiceResources resources); 070 071 /** 072 * Used to determine which services may be decorated by this decorator. When decorating a service, first the 073 * decorators that target the service are identified, then ordering occurs, then the {@link ServiceDecorator}s are 074 * invoked. 075 * 076 * @param serviceDef 077 * @return true if the decorator applies to the service 078 */ 079 boolean matches(ServiceDef serviceDef); 080}