interface @Concerns

The @Concerns annotation defines which Concerns should be considered for inclusion in the Invocation Stacks. They are typically defined on the Composite declaration, but can be declared on MixinTypes and MixinImplementations as well.

Description

A Concern is an interceptor of one or more methods. The @Concerns annotation declares which Concern classes should be put up as candidates for each method in the Invocation Stack.

Ordering


The order of the declarations are important. They are evaluated from left to right, from current class to the superclasses, and superclasses are in the order declared in the "extends" clause left-to-right. It is also known as "breadth-first".
It means that a Concern that is declared more to the left, will be placed higher in the interceptor stack.

Inclusion
A Concern declared via the @Concerns annotation is only a candidate. The decision if it is included in the Invocation Stack for each method is determined by;

  • Does the Concern implement the method or is the Concern a generic InvocationHandler? If not, exclude the Concern.
  • Does the Concern specify an @AppliesTo and @AppliesTo referencing a AppliesToFilter, call the filter and see if the method fulfill the requirement. If it doesn't evaluate to true, exclude the Concern.
  • Does the Concern specify an @AppliesTo and @AppliesTo referencing an annotation, check that the MixinType method or class has the annotation. If not, exclude the Concern.
  • Does the Concern specify an @AppliesTo and @AppliesTo referencing an interface, check that the Mixin Implementation implements that interface. If not, exclude the Concern.\
  • Otherwise, include the Concern candidate for the method.

Declaration

package org.qi4j.composite;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This annotation is used by composites and mixins to declare what Concerns
* should be applied to the type or specific method.
*/
@Retention( RetentionPolicy.RUNTIME )
@Target( { ElementType.TYPE, ElementType.METHOD } )
@Documented
public @interface Concerns
{
    Class<?>[] value();
}

Example

To declare the standard ValidationConcern, which operates together with Constraints, just include that in the Composite declaration like this;
import org.qi4j.entity.EntityComposite;
import org.qi4j.library.auth.AuthorizationConcern;

@Concerns( { AuthorizationConcern.class } )
public interface BankAccountEntity extends BankAccount, EntityComposite
{}

import org.qi4j.library.auth.RequiresPermission;

public interface BankAccount
{
    @RequiresPermission
    Money checkBalance();

    @RequiresPermission
    void transfer( BankAccount toAccount, Money amount );
}

public class BankAccountMixin
    implements BankAccount
{
    @This private BankAccountBalance accountBalance;

    public Money checkBalance()
    {
        return accountBalance.amount().get();
    }
}

public interface BankAccountBalance
{
    Property<Money> amount();
}

The domain developer don't need to know how the authorization is happening. And it can be changed without going back and modifying potentially hundreds or even thousands of entity types.

The Authorization library contains the building blocks to hook in any authentication and authorization mechanism, but the AuthorizationConcern defined in the EntityComposite above stays the same.

Powered by SiteVisionexternal link.