Package org.codehaus.aspectwerkz.aspect.management

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


        methodMetaData.setName("addAdviceTestMethod");
        methodMetaData.setParameterTypes(new String[]{});
        methodMetaData.setReturnType("void");
        methodMetaData.setExceptionTypes(new String[]{});

        Pointcut methodPointcut = (Pointcut)SystemLoader.getSystem("tests").
                getAspectManager().
                getPointcutManager(ASPECT_NAME).
                getExecutionPointcuts(m_classMetaData, methodMetaData).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


        methodMetaData.setName("removeAdviceTestMethod");
        methodMetaData.setParameterTypes(new String[]{});
        methodMetaData.setReturnType("void");
        methodMetaData.setExceptionTypes(new String[]{});

        Pointcut methodPointcut = (Pointcut)SystemLoader.getSystem("tests").
                getAspectManager().
                getPointcutManager(ASPECT_NAME).
                getExecutionPointcuts(m_classMetaData, methodMetaData).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

            methodMetaData.setParameterTypes(new String[]{});
            methodMetaData.setReturnType("void");
            methodMetaData.setExceptionTypes(new String[]{});

            // get an existing pointcut
            Pointcut methodPointcut = (Pointcut)SystemLoader.getSystem("tests").
                    getAspectManager().
                    getPointcutManager(ASPECT_NAME).
                    getExecutionPointcuts(m_classMetaData, methodMetaData).
                    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

            PointcutManager pointcutManager = SystemLoader.getSystem(uuid).
                    getAspectManager().getPointcutManager(aspectDef.getName());

            for (Iterator it2 = aspectDef.getAroundAdvices().iterator(); it2.hasNext();) {
                AdviceDefinition adviceDef = (AdviceDefinition)it2.next();
                Pointcut pointcut = pointcutManager.getPointcut(adviceDef.getExpression().getExpression());
                if (pointcut == null) {
                    pointcut = new Pointcut(uuid, adviceDef.getExpression());
                    pointcutManager.addPointcut(pointcut);
                }
                pointcut.addAroundAdvice(adviceDef.getName());
            }

            for (Iterator it2 = aspectDef.getBeforeAdvices().iterator(); it2.hasNext();) {
                AdviceDefinition adviceDef = (AdviceDefinition)it2.next();
                Pointcut pointcut = pointcutManager.getPointcut(adviceDef.getExpression().getExpression());
                if (pointcut == null) {
                    pointcut = new Pointcut(uuid, adviceDef.getExpression());
                    pointcutManager.addPointcut(pointcut);
                }
                pointcut.addBeforeAdvice(adviceDef.getName());
                //TODO - check me: Handler PC supports only beforeAdvice
                //TODO - .. this is not explicit here
            }

            for (Iterator it2 = aspectDef.getAfterAdvices().iterator(); it2.hasNext();) {
                AdviceDefinition adviceDef = (AdviceDefinition)it2.next();
                Pointcut pointcut = pointcutManager.getPointcut(adviceDef.getExpression().getExpression());
                if (pointcut == null) {
                    pointcut = new Pointcut(uuid, adviceDef.getExpression());
                    pointcutManager.addPointcut(pointcut);
                }
                pointcut.addAfterAdvice(adviceDef.getName());
            }
        }

        registerCFlowPointcuts(uuid, definition);
    }
View Full Code Here

                            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);
                    }
                }
View Full Code Here

                MethodInfo methodInfo = JavaMethodInfo.getMethodInfo(methodTuple.getWrapperMethod());
                ClassInfo withinInfo = JavaClassInfo.getClassInfo(targetClass);
                ExpressionContext ctx = new ExpressionContext(PointcutType.EXECUTION, methodInfo, methodInfo);//AVAJ
                for (int i = 0; i < aspectManagers.length; i++) {
                    for (Iterator it = aspectManagers[i].getPointcuts(ctx).iterator(); it.hasNext();) {
                        Pointcut pointcut = (Pointcut) it.next();
                        if (pointcut.getExpressionInfo().hasCflowPointcut()) {
                            cflowExpressionList.add(pointcut.getExpressionInfo().getCflowExpressionRuntime());
                        }
                    }
                }
                tuple.cflowExpressions = cflowExpressionList;
                tuple.expressionContext = ctx;
                break;
            case JoinPointType.METHOD_CALL:
                methodTuple = AspectRegistry.getMethodTuple(declaringClass, joinPointHash);
                methodSignature = new MethodSignatureImpl(methodTuple.getDeclaringClass(), methodTuple);
                tuple.signature = methodSignature;
                tuple.rtti = new MethodRttiImpl(methodSignature, thisInstance, targetInstance);
                methodInfo = JavaMethodInfo.getMethodInfo(methodTuple.getWrapperMethod());
                withinInfo = JavaClassInfo.getClassInfo(targetClass);
                ctx = new ExpressionContext(PointcutType.CALL, methodInfo, withinInfo);
                for (int i = 0; i < aspectManagers.length; i++) {
                    for (Iterator it = aspectManagers[i].getPointcuts(ctx).iterator(); it.hasNext();) {
                        Pointcut pointcut = (Pointcut) it.next();
                        if (pointcut.getExpressionInfo().hasCflowPointcut()) {
                            cflowExpressionList.add(pointcut.getExpressionInfo().getCflowExpressionRuntime());
                        }
                    }
                }
                tuple.cflowExpressions = cflowExpressionList;
                tuple.expressionContext = ctx;
                break;
            case JoinPointType.CONSTRUCTOR_EXECUTION:
                ConstructorTuple constructorTuple = AspectRegistry.getConstructorTuple(declaringClass, joinPointHash);
                ConstructorSignatureImpl constructorSignature = new ConstructorSignatureImpl(constructorTuple
                        .getDeclaringClass(), constructorTuple);
                tuple.signature = constructorSignature;
                tuple.rtti = new ConstructorRttiImpl(constructorSignature, thisInstance, targetInstance);
                ConstructorInfo constructorInfo = JavaConstructorInfo.getConstructorInfo(constructorTuple
                        .getWrapperConstructor());
                withinInfo = JavaClassInfo.getClassInfo(targetClass);
                ctx = new ExpressionContext(PointcutType.EXECUTION, constructorInfo, constructorInfo);//AVAJ
                for (int i = 0; i < aspectManagers.length; i++) {
                    for (Iterator it = aspectManagers[i].getPointcuts(ctx).iterator(); it.hasNext();) {
                        Pointcut pointcut = (Pointcut) it.next();
                        if (pointcut.getExpressionInfo().hasCflowPointcut()) {
                            cflowExpressionList.add(pointcut.getExpressionInfo().getCflowExpressionRuntime());
                        }
                    }
                }
                tuple.cflowExpressions = cflowExpressionList;
                tuple.expressionContext = ctx;
                break;
            case JoinPointType.CONSTRUCTOR_CALL:
                constructorTuple = AspectRegistry.getConstructorTuple(declaringClass, joinPointHash);
                constructorSignature = new ConstructorSignatureImpl(
                    constructorTuple.getDeclaringClass(),
                    constructorTuple);
                tuple.signature = constructorSignature;
                tuple.rtti = new ConstructorRttiImpl(constructorSignature, thisInstance, targetInstance);
                constructorInfo = JavaConstructorInfo.getConstructorInfo(constructorTuple.getWrapperConstructor());
                withinInfo = JavaClassInfo.getClassInfo(targetClass);
                ctx = new ExpressionContext(PointcutType.CALL, constructorInfo, withinInfo);
                for (int i = 0; i < aspectManagers.length; i++) {
                    for (Iterator it = aspectManagers[i].getPointcuts(ctx).iterator(); it.hasNext();) {
                        Pointcut pointcut = (Pointcut) it.next();
                        if (pointcut.getExpressionInfo().hasCflowPointcut()) {
                            cflowExpressionList.add(pointcut.getExpressionInfo().getCflowExpressionRuntime());
                        }
                    }
                }
                tuple.cflowExpressions = cflowExpressionList;
                tuple.expressionContext = ctx;
                break;
            case JoinPointType.FIELD_SET:
                Field field = AspectRegistry.getField(declaringClass, joinPointHash);
                FieldSignatureImpl fieldSignature = new FieldSignatureImpl(field.getDeclaringClass(), field);
                tuple.signature = fieldSignature;
                tuple.rtti = new FieldRttiImpl(fieldSignature, thisInstance, targetInstance);
                FieldInfo fieldInfo = JavaFieldInfo.getFieldInfo(field);
                withinInfo = JavaClassInfo.getClassInfo(targetClass);
                ctx = new ExpressionContext(PointcutType.SET, fieldInfo, withinInfo);//AVAJ
                for (int i = 0; i < aspectManagers.length; i++) {
                    for (Iterator it = aspectManagers[i].getPointcuts(ctx).iterator(); it.hasNext();) {
                        Pointcut pointcut = (Pointcut) it.next();
                        if (pointcut.getExpressionInfo().hasCflowPointcut()) {
                            cflowExpressionList.add(pointcut.getExpressionInfo().getCflowExpressionRuntime());
                        }
                    }
                }
                tuple.cflowExpressions = cflowExpressionList;
                tuple.expressionContext = ctx;
                break;
            case JoinPointType.FIELD_GET:
                field = AspectRegistry.getField(declaringClass, joinPointHash);
                fieldSignature = new FieldSignatureImpl(field.getDeclaringClass(), field);
                tuple.signature = fieldSignature;
                tuple.rtti = new FieldRttiImpl(fieldSignature, thisInstance, targetInstance);
                fieldInfo = JavaFieldInfo.getFieldInfo(field);
                withinInfo = JavaClassInfo.getClassInfo(targetClass);
                ctx = new ExpressionContext(PointcutType.GET, fieldInfo, withinInfo);//AVAJ
                for (int i = 0; i < aspectManagers.length; i++) {
                    for (Iterator it = aspectManagers[i].getPointcuts(ctx).iterator(); it.hasNext();) {
                        Pointcut pointcut = (Pointcut) it.next();
                        if (pointcut.getExpressionInfo().hasCflowPointcut()) {
                            cflowExpressionList.add(pointcut.getExpressionInfo().getCflowExpressionRuntime());
                        }
                    }
                }
                tuple.cflowExpressions = cflowExpressionList;
                tuple.expressionContext = ctx;
                break;
            case JoinPointType.HANDLER:
                CatchClauseSignatureImpl catchClauseSignature = new CatchClauseSignatureImpl(
                    declaringClass,
                    declaringClass,
                    "");
                tuple.signature = catchClauseSignature;
                tuple.rtti = new CatchClauseRttiImpl(catchClauseSignature, thisInstance, targetInstance);
                ClassInfo exceptionClassInfo = JavaClassInfo.getClassInfo(declaringClass);
                withinInfo = JavaClassInfo.getClassInfo(targetClass);//AVAJ within/withincode support ?
                ctx = new ExpressionContext(PointcutType.HANDLER, exceptionClassInfo, withinInfo);
                for (int i = 0; i < aspectManagers.length; i++) {
                    for (Iterator it = aspectManagers[i].getPointcuts(ctx).iterator(); it.hasNext();) {
                        Pointcut pointcut = (Pointcut) it.next();
                        if (pointcut.getExpressionInfo().hasCflowPointcut()) {
                            cflowExpressionList.add(pointcut.getExpressionInfo().getCflowExpressionRuntime());
                        }
                    }
                }
                tuple.cflowExpressions = cflowExpressionList;
                tuple.expressionContext = ctx;
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

        if (joinPoint == null) {
            Map joinPointMetaDataMap = s_registry.getJoinPointMetaData(m_classHash, fieldHash);
            JoinPointMetaData joinPointMetaData = (JoinPointMetaData) joinPointMetaDataMap.get(PointcutType.SET);
            AdviceIndexInfo[] adviceIndexes = joinPointMetaData.adviceIndexes;
            List cflowExpressions = joinPointMetaData.cflowExpressions;
            Pointcut cflowPointcut = joinPointMetaData.cflowPointcut;
            initCflowManagement(cflowPointcut, joinPointInfo);
            joinPoint = createFieldJoinPoint(
                fieldHash,
                JoinPointType.FIELD_SET,
                m_targetClass,
View Full Code Here

        if (joinPoint == null) {
            Map joinPointMetaDataMap = s_registry.getJoinPointMetaData(m_classHash, fieldHash);
            JoinPointMetaData joinPointMetaData = (JoinPointMetaData) joinPointMetaDataMap.get(PointcutType.GET);
            AdviceIndexInfo[] adviceIndexes = joinPointMetaData.adviceIndexes;
            List cflowExpressions = joinPointMetaData.cflowExpressions;
            Pointcut cflowPointcut = joinPointMetaData.cflowPointcut;
            initCflowManagement(cflowPointcut, joinPointInfo);
            joinPoint = createFieldJoinPoint(
                fieldHash,
                JoinPointType.FIELD_GET,
                m_targetClass,
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.