]> git.argeo.org Git - gpl/argeo-slc.git/blob - sandbox/argeo.slc.executionflow/src/main/java/org/argeo/slc/executionflow/ExecutionAspect.java
Introduce aspects and execution parameters
[gpl/argeo-slc.git] / sandbox / argeo.slc.executionflow / src / main / java / org / argeo / slc / executionflow / ExecutionAspect.java
1 package org.argeo.slc.executionflow;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.aspectj.lang.JoinPoint;
6 import org.aspectj.lang.ProceedingJoinPoint;
7 import org.aspectj.lang.annotation.After;
8 import org.aspectj.lang.annotation.Around;
9 import org.aspectj.lang.annotation.Aspect;
10 import org.aspectj.lang.annotation.Before;
11 import org.aspectj.lang.annotation.Pointcut;
12
13 @Aspect
14 public class ExecutionAspect {
15 private static Log log = LogFactory.getLog(ExecutionAspect.class);
16
17 // @Around("execution(void org.argeo.slc.executionflow.ExecutionFlow.execute()) && target(org.argeo.slc.executionflow.ExecutionFlow)")
18 public void registerFlow(ProceedingJoinPoint pjp) throws Throwable {
19 try {
20 log.debug("registerFlow " + pjp.getTarget().getClass());
21 ExecutionContext.enterFlow((ExecutionFlow) pjp.getTarget());
22 pjp.proceed();
23 } finally {
24 ExecutionContext.leaveFlow((ExecutionFlow) pjp.getTarget());
25 }
26 }
27
28 @Before("flowExecution()")
29 public void beforeFlow(JoinPoint jp) throws Throwable {
30 //log.debug("this " + jp.getThis().getClass());
31 //log.debug("target " + jp.getTarget().getClass());
32 // Thread.dumpStack();
33 ExecutionFlow executionFlow = (ExecutionFlow) jp.getTarget();
34 ExecutionContext.enterFlow(executionFlow);
35 }
36
37 @After("flowExecution()")
38 public void afterFlow(JoinPoint jp) throws Throwable {
39 //log.debug("this " + jp.getThis().getClass());
40 //log.debug("target " + jp.getTarget().getClass());
41 ExecutionFlow executionFlow = (ExecutionFlow) jp.getTarget();
42 ExecutionContext.leaveFlow(executionFlow);
43 }
44
45 @Pointcut("execution(void org.argeo.slc.executionflow.ExecutionFlow.execute())")
46 public void flowExecution() {
47 }
48 }