Package org.codehaus.aspectwerkz.aspect.management

Examples of org.codehaus.aspectwerkz.aspect.management.Pointcut


        if (joinPoint == null) {
            Map joinPointMetaDataMap = s_registry.getJoinPointMetaData(m_classHash, handlerHash);
            JoinPointMetaData joinPointMetaData = (JoinPointMetaData) joinPointMetaDataMap.get(PointcutType.HANDLER);
            AdviceIndexInfo[] adviceIndexes = joinPointMetaData.adviceIndexes;
            List cflowExpressions = joinPointMetaData.cflowExpressions;
            Pointcut cflowPointcut = joinPointMetaData.cflowPointcut;
            initCflowManagement(cflowPointcut, joinPointInfo);
            joinPoint = createCatchClauseJoinPoint(
                exceptionInstance.getClass(),
                m_targetClass,
                handlerSignature,
View Full Code Here


        m_logString = "";
        reorderAdvicesTestMethod();
        assertEquals("before1 before2 invocation after2 after1 ", m_logString);

        // get the pointcut by name (can also be retrieved by method meta-data)
        Pointcut pointcut = SystemLoader.getSystem(this.getClass()).getAspectManager("tests")
                .getPointcutManager(ASPECT_NAME).getPointcut("pc1 || pc2 || pc3");

        // get the advices
        List advices = pointcut.getAroundAdviceIndexTuples();
        NameIndexTuple tuple1 = (NameIndexTuple)advices.get(0);
        NameIndexTuple tuple2 = (NameIndexTuple)advices.get(1);

        // reorder the advices
        advices.set(0, tuple2);
        advices.set(1, tuple1);

        // set the reordered advices
        pointcut.setAroundAdviceIndexTuples(advices);
    }
View Full Code Here

            methodMetaData =
            JavaMethodInfo.getMethodInfo(getClass().getMethod("addAdviceTestMethod", new Class[]{}));
        } catch (NoSuchMethodException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
        Pointcut methodPointcut = (Pointcut)SystemLoader.getSystem(this.getClass()).getAspectManager("tests")
                .getPointcutManager(ASPECT_NAME)
                .getPointcuts(
                        new ExpressionContext(
                                PointcutType.EXECUTION,
                                methodMetaData, null
                        )
                ).get(0);
        methodPointcut.addAroundAdvice("test.aspect.DynamicDeploymentTestAspect.advice2");
        m_logString = "";
        addAdviceTestMethod();
        assertEquals("before1 before2 invocation after2 after1 ", m_logString);

        // remove it for other tests
        methodPointcut.removeAroundAdvice("test.aspect.DynamicDeploymentTestAspect.advice2");
    }
View Full Code Here

                    )
            );
        } catch (NoSuchMethodException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
        Pointcut methodPointcut = (Pointcut)SystemLoader.getSystem(this).getAspectManager("tests")
                .getPointcutManager(ASPECT_NAME)
                .getPointcuts(
                        new ExpressionContext(
                                PointcutType.EXECUTION,
                                methodMetaData, null
                        )
                ).get(0);
        List advices = methodPointcut.getAroundAdviceIndexTuples();
        NameIndexTuple adviceTuple = (NameIndexTuple)advices.remove(0);
        methodPointcut.setAroundAdviceIndexTuples(advices);
        m_logString = "";
        removeAdviceTestMethod();
        assertEquals("before2 invocation after2 ", m_logString);

        // restore it for other tests
        advices.add(0, adviceTuple);
        methodPointcut.setAroundAdviceIndexTuples(advices);
    }
View Full Code Here

            } catch (NoSuchMethodException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }

            // get an existing pointcut
            Pointcut methodPointcut = (Pointcut)SystemLoader.getSystem(this).getAspectManager("tests")
                    .getPointcutManager(ASPECT_NAME)
                    .getPointcuts(
                            new ExpressionContext(
                                    PointcutType.EXECUTION,
                                    methodMetaData, null
                            )
                    )
                    .get(0);

            // add the new advice to the pointcut
            methodPointcut.addAroundAdvice("test.aspects.DynamicallyCreatedAspect.advice1");

            // check that it is executed
            m_logString = "";
            createAspectTestMethod();
            assertEquals("before2 beforeNew invocation afterNew after2 ", m_logString);

            //remove it for other tests
            methodPointcut.removeAroundAdvice("test.aspects.DynamicallyCreatedAspect.advice1");
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }
View Full Code Here

                continue;
            }
            PointcutManager pointcutManager = aspectManager.getPointcutManager(aspectDef.getName());
            for (Iterator it2 = aspectDef.getAroundAdvices().iterator(); it2.hasNext();) {
                AdviceDefinition adviceDef = (AdviceDefinition)it2.next();
                Pointcut pointcut = pointcutManager.getPointcut(adviceDef.getExpressionInfo().getExpressionAsString());
                if (pointcut == null) {
                    pointcut = new Pointcut(aspectManager, adviceDef.getExpressionInfo());
                    pointcutManager.addPointcut(pointcut);
                }
                pointcut.addAroundAdvice(aspectDef.getName() + '/' + adviceDef.getName());
            }
            for (Iterator it2 = aspectDef.getBeforeAdvices().iterator(); it2.hasNext();) {
                AdviceDefinition adviceDef = (AdviceDefinition)it2.next();
                Pointcut pointcut = pointcutManager.getPointcut(adviceDef.getExpressionInfo().getExpressionAsString());
                if (pointcut == null) {
                    pointcut = new Pointcut(aspectManager, adviceDef.getExpressionInfo());
                    pointcutManager.addPointcut(pointcut);
                }
                pointcut.addBeforeAdvice(aspectDef.getName() + '/' + adviceDef.getName());
            }
            for (Iterator it2 = aspectDef.getAfterAdvices().iterator(); it2.hasNext();) {
                AdviceDefinition adviceDef = (AdviceDefinition)it2.next();
                Pointcut pointcut = pointcutManager.getPointcut(adviceDef.getExpressionInfo().getExpressionAsString());
                if (pointcut == null) {
                    pointcut = new Pointcut(aspectManager, adviceDef.getExpressionInfo());
                    pointcutManager.addPointcut(pointcut);
                }
                pointcut.addAfterAdvice(aspectDef.getName() + '/' + adviceDef.getName());
            }
        }
    }
View Full Code Here

        for (Iterator it1 = definition.getAspectDefinitions().iterator(); it1.hasNext();) {
            AspectDefinition aspectDef = (AspectDefinition)it1.next();
            PointcutManager pointcutManager = aspectManager.getPointcutManager(aspectDef.getName());
            List cflowPointcuts = pointcutManager.getCflowPointcuts();
            for (Iterator it2 = cflowPointcuts.iterator(); it2.hasNext();) {
                Pointcut cflowPointcut = (Pointcut)it2.next();
                ExpressionInfo expressionInfo = cflowPointcut.getExpressionInfo();

                // register the cflow advices in the system and create the cflow system pointcutManager
                // (if it does not already exist)
                if (!aspectManager.hasAspect(CFlowSystemAspect.NAME)) {
                    AspectDefinition cflowAspectDef = new AspectDefinition(
                            CFlowSystemAspect.NAME,
                            CFlowSystemAspect.CLASS_NAME,
                            aspectManager.getUuid()
                    );
                    PointcutDefinition pointcutDef = new PointcutDefinition(expressionInfo.getExpressionAsString());
                    cflowAspectDef.setDeploymentModel(CFlowSystemAspect.DEPLOYMENT_MODEL);
                    cflowAspectDef.addPointcut(pointcutDef);
                    try {
                        AdviceDefinition beforeAdviceDefinition = new AdviceDefinition(
                                CFlowSystemAspect.PRE_ADVICE,
                                AdviceDefinition.BEFORE_ADVICE,
                                cflowAspectDef.getName(),
                                cflowAspectDef.getClassName(),
                                expressionInfo,
                                CFlowSystemAspect.class
                                .getDeclaredMethod(
                                        CFlowSystemAspect.PRE_ADVICE,
                                        new Class[]{
                                            JoinPoint.class
                                        }
                                ),
                                CFlowSystemAspect.PRE_ADVICE_INDEX,
                                cflowAspectDef
                        );
                        cflowAspectDef.addBeforeAdvice(beforeAdviceDefinition);
                        AdviceDefinition afterAdviceDefinition = new AdviceDefinition(
                                CFlowSystemAspect.POST_ADVICE,
                                AdviceDefinition.AFTER_ADVICE,
                                cflowAspectDef.getName(),
                                cflowAspectDef.getClassName(),
                                expressionInfo,
                                CFlowSystemAspect.class
                                .getDeclaredMethod(
                                        CFlowSystemAspect.POST_ADVICE,
                                        new Class[]{
                                            JoinPoint.class
                                        }
                                ),
                                CFlowSystemAspect.POST_ADVICE_INDEX,
                                cflowAspectDef
                        );
                        cflowAspectDef.addAfterAdvice(afterAdviceDefinition);
                    } catch (NoSuchMethodException e) {
                        ; // TODO: why ignore exception? ALEX??
                    }
                    definition.addAspect(cflowAspectDef);
                    registerAspect(aspectManager, cflowAspectDef, new HashMap());
                }
                cflowPointcut.addBeforeAdvice(CFlowSystemAspect.NAME + '/' + CFlowSystemAspect.PRE_ADVICE);
                cflowPointcut.addAfterAdvice(CFlowSystemAspect.NAME + '/' + CFlowSystemAspect.POST_ADVICE);
            }
        }
    }
View Full Code Here

                                                         final ReflectionInfo reflectInfo,
                                                         final ReflectionInfo withinInfo) {

        List adviceIndexInfoList = new ArrayList();
        List cflowExpressionList = new ArrayList();
        Pointcut cflowPointcut = null;

        ExpressionContext ctx = new ExpressionContext(type, reflectInfo, withinInfo);//AVAJ null?
        AspectManager[] aspectManagers = system.getAspectManagers();
        for (int i = 0; i < aspectManagers.length; i++) {
            AspectManager aspectManager = aspectManagers[i];

            /// grab the first one found, one single cflow pointcut is enough per join point
            if (cflowPointcut == null) {
                List cflowPointcuts = aspectManager.getCflowPointcuts(ctx);
                if (!cflowPointcuts.isEmpty()) {
                    cflowPointcut = (Pointcut) cflowPointcuts.get(0);
                }
            }

            // get all matching pointcuts from all managers
            for (Iterator it = aspectManager.getPointcuts(ctx).iterator(); it.hasNext();) {
                Pointcut pointcut = (Pointcut) it.next();

                AdviceInfo[] aroundAdviceIndexes = pointcut.getAroundAdviceIndexes();
                AdviceInfo[] beforeAdviceIndexes = pointcut.getBeforeAdviceIndexes();
                AdviceInfo[] afterFinallyAdviceIndexes = pointcut.getAfterFinallyAdviceIndexes();
                AdviceInfo[] afterReturningAdviceIndexes = pointcut.getAfterReturningAdviceIndexes();
                AdviceInfo[] afterThrowingAdviceIndexes = pointcut.getAfterThrowingAdviceIndexes();

                AdviceIndexInfo adviceIndexInfo = new AdviceIndexInfo(
                        aroundAdviceIndexes,
                        beforeAdviceIndexes,
                        afterFinallyAdviceIndexes,
                        afterReturningAdviceIndexes,
                        afterThrowingAdviceIndexes
                );

                // compute target args to advice args mapping, it is a property of each *advice*

                // refresh the arg index map
                pointcut.getExpressionInfo().getArgsIndexMapper().match(ctx);

                //TODO can we do cache, can we do in another visitor
                //TODO skip map when no args()

                for (int j = 0; j < aroundAdviceIndexes.length; j++) {
                    setMethodArgumentIndexes(pointcut.getAroundAdviceName(j), pointcut, ctx, aroundAdviceIndexes[j]);
                }

                for (int j = 0; j < beforeAdviceIndexes.length; j++) {
                    setMethodArgumentIndexes(pointcut.getBeforeAdviceName(j), pointcut, ctx, beforeAdviceIndexes[j]);
                }

                for (int j = 0; j < afterFinallyAdviceIndexes.length; j++) {
                    setMethodArgumentIndexes(
                            pointcut.getAfterFinallyAdviceName(j), pointcut, ctx, afterFinallyAdviceIndexes[j]
                    );
                }

                for (int j = 0; j < afterReturningAdviceIndexes.length; j++) {
                    setMethodArgumentIndexes(
                            pointcut.getAfterReturningAdviceName(j), pointcut, ctx, afterReturningAdviceIndexes[j]
                    );
                }

                for (int j = 0; j < afterThrowingAdviceIndexes.length; j++) {
                    setMethodArgumentIndexes(
                            pointcut.getAfterThrowingAdviceName(j), pointcut, ctx, afterThrowingAdviceIndexes[j]
                    );

                }

                adviceIndexInfoList.add(adviceIndexInfo);

                // collect the cflow expressions for the matching pointcuts (if they have one)
                if (pointcut.getExpressionInfo().hasCflowPointcut()) {
                    cflowExpressionList.add(pointcut.getExpressionInfo().getCflowExpressionRuntime());
                }
            }
        }

        // turn the lists into arrays for performance reasons
View Full Code Here

        if (joinPoint == null) {
            Map joinPointMetaDataMap = s_registry.getJoinPointMetaData(m_classHash, methodHash);
            JoinPointMetaData joinPointMetaData = (JoinPointMetaData) joinPointMetaDataMap.get(PointcutType.EXECUTION);
            AdviceIndexInfo[] adviceIndexes = joinPointMetaData.adviceIndexes;
            List cflowExpressions = joinPointMetaData.cflowExpressions;
            Pointcut cflowPointcut = joinPointMetaData.cflowPointcut;
            initCflowManagement(cflowPointcut, joinPointInfo);
            switch (joinPointType) {
                case JoinPointType.METHOD_EXECUTION:
                    joinPoint = createMethodJoinPoint(
                        methodHash,
View Full Code Here

        if (joinPoint == null) {
            Map joinPointMetaDataMap = s_registry.getJoinPointMetaData(m_classHash, methodHash);
            JoinPointMetaData joinPointMetaData = (JoinPointMetaData) joinPointMetaDataMap.get(PointcutType.CALL);
            AdviceIndexInfo[] adviceIndexes = joinPointMetaData.adviceIndexes;
            List cflowExpressions = joinPointMetaData.cflowExpressions;
            Pointcut cflowPointcut = joinPointMetaData.cflowPointcut;
            initCflowManagement(cflowPointcut, joinPointInfo);
            switch (joinPointType) {
                case JoinPointType.METHOD_CALL:

                    // TODO: make diff between target and this instances
View Full Code Here

TOP

Related Classes of org.codehaus.aspectwerkz.aspect.management.Pointcut

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.