org.qi4j.api.common
Interface AppliesToFilter

All Known Implementing Classes:
ApplicationEventMethodFilter, AssociationMixin.AssociationFilter, BeanShellMixin.AppliesTo, ExcludeCompositeFilter, GroovyMixin.AppliesTo, InvalidateCacheOnSettersSideEffect.AppliesTo, JavaScriptMixin.AppliesTo, JRubyMixin.AppliesTo, ManyAssociationMixin.AssociationFilter, PropertyMixin.PropertyFilter

public interface AppliesToFilter

Implementations of this interface can be specified in the @AppliesTo.

AppliesTo filters are one of the driving technologies in Qi4j. They allow you to apply fragments (Mixins, Concerns, SideEffects), often generic ones, depending on the context that they are evaluated under. This mechanism is heavily used internally in Qi4j to achieve many other features.

The starting point is the basic use of AppliesToFilter, where the @AppliesTo annotation is given an AppliesToFilter implementation as an argument, for instance at a Mixin implementation;


 @AppliesTo( MyAppliesToFilter.class )
 public class SomeMixin
     implements InvocationHandler
 {

 }

 public class MyAppliesToFilter
     implements AppliesToFilter
 {
     public boolean appliesTo( Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass )
     {
         return method.getName().startsWith( "my" );
     }
 }
 
In the case above, the generic mixin will only be applied to the methods that that is defined by the AppliesToFilter. This is the primary way to define limits on the application of generic fragments, since especially mixins are rarely applied to all methods.


Field Summary
static AppliesToFilter ALWAYS
          This is an internal AppliesToFilter which is assigned if no other AppliesToFilters are found for a given fragment.
 
Method Summary
 boolean appliesTo(Method method, Class<?> mixin, Class<?> compositeType, Class<?> fragmentClass)
          Check if the Fragment should be applied or not.
 

Field Detail

ALWAYS

static final AppliesToFilter ALWAYS
This is an internal AppliesToFilter which is assigned if no other AppliesToFilters are found for a given fragment.

There is no reason for user code to use this AppliesToFilter directly, and should be perceived as an internal class in Qi4j.

Method Detail

appliesTo

boolean appliesTo(Method method,
                  Class<?> mixin,
                  Class<?> compositeType,
                  Class<?> fragmentClass)
Check if the Fragment should be applied or not. Will be call when applied to Mixins, Concerns, SideEffects.

Parameters:
method - method that is invoked
mixin - mixin implementation for the method
compositeType - composite type
fragmentClass - fragment that is being applies
Returns:
true if the filter passes, otherwise false