And How It Is Used by Data Federator Designer Team
And How It Is Used by Data Federator Designer Team
AOP introduction
– AOP-the big picture
– AOP vocabulary
AspectJ introduction
– AspectJ Pointcut Model
– Dynamic crosscutting
– Static crosscutting
– @AspectJ syntax
Examples
– Designer validity check framework
– Designer locking mechanism
– Source Definer open/close aspect
– Policy enforcement
– Type-hierarchy modifications
What is a concern.
A specific requirement that a software system must address
in order to satisfy the overall system goals.
What is a core concern.
A core concern captures the central functionality of a
module.
What is a crosscutting concern.
A crosscutting concern captures requirements that cross
multiple modules.
Symtoms of crosscutting concerns:
– Code tangling
– Code scattering
What is AOP.
programming paradigm that increase the modularity of a
software system by allowing the separation of crosscutting
concerns.
Implementation of a security concern using Implementation of a security concern using AOP techniques.
conventional techniques.
Join Point
an identifiable point in the execution of the system.
Pointcut
A set of join points that satisfies a criteria.
The pointcat can collect the join points context.
Implementing a crosscutting concern will require selecting a specific join point.
Dynamic crosscutting
Construct to alter the program behavior.
Contains 2 parts; a pointcut to select join points and an advice to provide behavior
before, after or around the selected join points.
Static crosscutting
Construct to alter the static structure of the system.
Aspect
Module containing all the crosscutting constructs and so will contain all the crosscutting
logic.
Weaving
Introduction of the crosscutting logic/constructs into the target modules.
Field access The access to read a field. get(public static !final * Account+.*)
cflowbelow(<Pointcut>)
Lexical Select join points occurring inside within(Account)
Structure the lexical scope of specified
based classes, aspects, and methods. traced() && !within(TraceAspect)
withincode(*Account.debit(..))
Advices types:
Before advice
Executed before the execution of the captured join point
After advice
Executed after the execution of the join point
After (finally) – regardless of the outcome
– after() : call(* Account.*(..)) {......}
After returning normally
– after() returning : call(* Account.*(..)) {...}
– after( ) returning(Object value) : callPointCut( ) { /*use the value*/}
After throwing an exception
– after() throwing : execution(* Controller+.*(..)) {...}
– after() throwing (Throwable ex) : execution(* * (..)){...}
Around advice
Surrounds the advised join points
Can execute the join point with the same or different context any number (including 0
times)
Can bypass the advised join point completely or execute the join poit with a different
context
Example
public aspect AroundAdviceRecipe {
pointcut callBazPointCut( ) : call(int MyClass.baz( ));
Inter-type declarations
Member introduction
– Declare the new methods and attributes to be added to the existing class within the
aspect.
Type-hierarchy modifications
– Introduce a new inheritance relationship between classes.
– Add an interface to a class.
Annotation supplementation
– Add annotations to the advised join points.
Weave-time error and warning declarations
extend the capabilities of the compiler to enforce application specific rules (see the
examples).
Exception softening
Specify a set of exceptions that should be converted to uncaught exceptions when raised
on the join points selected by a specific pointcut.
The goal
Verify the validity of the name attribute on the domain objects.
How to use it
@ValidityCheck
public void setName(String name) {…}
or
@ValidityCheck(
checkerClass = TableNameChecker.class,
messageKey = ValidityCheckMessages
.VALIDITY_EXCEPTION_NOT_VALID_TABLE)
public void setName(String name) {...}
How it’s working
@Aspect
public class ValidityCheckerAspect {
@Pointcut("execution(@ValidityCheck * *(..))")
void validityCheckPointcutOnMethod() {}
@Before("validityCheckPointcutOnMethod()")
public void verifyValidationCheckOnMethod(JoinPoint thisJoinPoint) {…}
The goal
Lock the projects opened/created by a user.
Remove the lock when the project is closed/deleted.
Verify if a user can open/save/delete/import a project.
How it’s working
@Aspect
public class LockingServiceAspect {
@Pointcut("execution(public void com.bobj.datafederator.designer.domain."
+ "ProjectDaoService.save(..)) && args(p)")
void projectSavePointcut(Project p) {}
@Around("projectSavePointcut(project)")
public Object projectSaveJoinAdvice(Project project, ProceedingJoinPoint jp)throws Throwable
{…}
@AfterReturning("dfUserCloseProjectPointcut(projectId)")
public void dfUserCloseProjectAdvice(String projectId) {…}
The goal
Any operation should be forbidden on a closed DataFederatorSourceDefiner
How it‘s working
public aspect SourceDefinerStateAspect {
pointcut isClosed(DataFederatorSourceDefiner b) :
execution (public !static * DataFederatorSourceDefiner+.* (..))
&& target(b) && !execution(public void open(..)) && !execution(public void close(..))
&& !execution(public boolean isClosed());
The goal
extend the capabilities of the compiler to enforce application specific rules
– No System.out.* in the code
– No non final public fields
How it’s working
@Aspect
The goal
Add a new interface to a class and inject the interface implementation also.
How it’s working
@Aspect
final class ObserverAspect {
/**
* the classes annotated with the
* {@link com.google.code.aoplib4j.aspectj.gof.observer.Subject} annotation
* will automatically
* implement the {@link GofSubject} interface and the implementation
* will be {@link GofSubjectImpl}.
*/
@DeclareParents(
value = "@com.google.code.aoplib4j.aspectj.gof.observer.Subject *",
defaultImpl = GofSubjectImpl.class)
private GofSubject subject = null;