*/
private static void registerCFlowPointcuts(final String uuid, final SystemDefinition definition) {
// get all aspects definitions
for (Iterator it1 = definition.getAspectDefinitions().iterator(); it1.hasNext();) {
AspectDefinition aspectDef = (AspectDefinition)it1.next();
PointcutManager aspect = SystemLoader.getSystem(uuid).getAspectManager().
getPointcutManager(aspectDef.getName());
for (Iterator it2 = aspectDef.getAllAdvices().iterator(); it2.hasNext();) {
AdviceDefinition adviceDef = (AdviceDefinition)it2.next();
Expression expression = adviceDef.getExpression();
for (Iterator it3 = expression.getCflowExpressions().entrySet().iterator(); it3.hasNext();) {
Map.Entry entry = (Map.Entry)it3.next();
Expression value = (Expression)entry.getValue();
if (value instanceof ExpressionExpression) {
// recursive
// TODO ALEX exprexpr using exprexpr
// like pc cflow = "a or b"
// .. pc exec = "c IN cflow"
(new Exception("todo")).printStackTrace();
}
else {
// get the referenced cflow poincut definition
PointcutDefinition cflowPointcutDef = aspectDef.getPointcutDef(value.getName());
// if null, it is an anonymous cflow like in "execution(..) AND cflow(...)"
// create a new PoincutDef lately to bind it
// TODO check me - not needed since anonymous are autonamed ?
if (cflowPointcutDef == null) {
cflowPointcutDef = new PointcutDefinition();
cflowPointcutDef.setName(value.getName());
cflowPointcutDef.setType(PointcutType.CFLOW);
cflowPointcutDef.setExpression(value.getExpression());
}
// create call pointcut
Pointcut pointcut = new Pointcut(uuid, value);
// register the cflow advices in the system and create the cflow system aspect
// (if it does not already exist)
org.codehaus.aspectwerkz.System system = SystemLoader.getSystem(uuid);
if (!system.getAspectManager().hasAspect(CFlowSystemAspect.NAME)) {
AspectDefinition cflowAspect = new AspectDefinition(
CFlowSystemAspect.NAME,
CFlowSystemAspect.CLASS_NAME
);
cflowAspect.setDeploymentModel(CFlowSystemAspect.DEPLOYMENT_MODEL);
cflowAspect.addPointcut(cflowPointcutDef);
Class cflowAspectClass = CFlowSystemAspect.class;
try {
// add the cflow pre advice
cflowAspect.addBeforeAdvice(
new AdviceDefinition(
CFlowSystemAspect.PRE_ADVICE,
AdviceDefinition.BEFORE_ADVICE,
cflowAspect.getName(),
cflowAspect.getClassName(),
value,
cflowAspectClass.getDeclaredMethod(
CFlowSystemAspect.PRE_ADVICE,
new Class[]{JoinPoint.class}
),
CFlowSystemAspect.PRE_ADVICE_INDEX,
cflowAspect
)
);
// add the cflow post advice
cflowAspect.addAfterAdvice(
new AdviceDefinition(
CFlowSystemAspect.POST_ADVICE,
AdviceDefinition.AFTER_ADVICE,
cflowAspect.getName(),
cflowAspect.getClassName(),
value,
cflowAspectClass.getDeclaredMethod(
CFlowSystemAspect.POST_ADVICE,
new Class[]{JoinPoint.class}
),
CFlowSystemAspect.POST_ADVICE_INDEX,
cflowAspect
)
);
}
catch (NoSuchMethodException e) {
; // TODO: why ignore exception? ALEX??
}
// add the advice to the aspectwerkz definition
definition.addAspect(cflowAspect);
// add the advice to the aspectwerkz system
registerAspect(uuid, cflowAspect, new HashMap());
}
// add references to the cflow advices to the cflow pointcut
pointcut.addBeforeAdvice(CFlowSystemAspect.PRE_ADVICE);
pointcut.addAfterAdvice(CFlowSystemAspect.POST_ADVICE);
// add the call pointcut
aspect.addPointcut(pointcut);
}
}
//TODO ALEX - is this commented code needed?
// // add a mapping between the cflow pattern and the method patterns affected