Package org.codehaus.aspectwerkz.xmldef.definition

Examples of org.codehaus.aspectwerkz.xmldef.definition.AspectDefinition


     * @param definition the AspectWerkz definition
     */
    private static void handleAspectDefinitions(final Element root,
                                                final AspectWerkzDefinitionImpl definition) {
        for (Iterator it = definition.getAspectDefinitions().iterator(); it.hasNext();) {
            AspectDefinition aspectDef = (AspectDefinition)it.next();

            Element aspectElement = root.addElement("aspect");
            aspectElement.addAttribute("name", aspectDef.getName());

            handlePointcutDefinitions(aspectElement, aspectDef);
            handleControllerDefinitions(aspectElement, aspectDef);
            handleBindIntroductionRules(aspectElement, aspectDef);
            handleBindAdviceRules(aspectElement, aspectDef);
View Full Code Here


    private static void parseIntroductionAttributes(
            final AspectWerkzDefinitionImpl definition,
            final String className,
            final QDoxParser qdoxParser) {

        AspectDefinition aspectDef = definition.getAspectDefinition(
                AspectWerkzDefinition.SYSTEM_ASPECT
        );

        JavaClass javaClass = qdoxParser.getJavaClass();
        DocletTag[] introductionTags = javaClass.getTagsByName(AttributeTag.INTRODUCTION);

        BindIntroductionRule bindIntroductionRule = new BindIntroductionRule();
        bindIntroductionRule.setExpression(ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                .createExpression(className, PointcutType.CLASS));

        for (int i = 0; i < introductionTags.length; i++) {
            if (introductionTags[i] == null) {
                continue;
            }
            String[] attributes = introductionTags[i].getParameters();
            for (int j = 0; j < attributes.length; j++) {
                final String introductionRef = definition.
                        getIntroductionNameByAttribute(attributes[j]);
                if (introductionRef == null) {
                    continue;
                }
                bindIntroductionRule.addIntroductionRef(introductionRef);
            }
            aspectDef.addBindIntroductionRule(bindIntroductionRule);
        }
    }
View Full Code Here

            final QDoxParser qdoxParser) {

        if (true) return;

        String pointcutName = CONTROLLER_POINTCUT_NAME + Strings.replaceSubString(className, ".", "_");
        AspectDefinition aspectDef = definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT);

        int counter = 0;
        final JavaMethod[] javaMethods = qdoxParser.getJavaMethods();
        for (int i = 0; i < javaMethods.length; i++) {

            DocletTag[] methodTags = javaMethods[i].getTagsByName(AttributeTag.CONTROLLER);
            for (int j = 0; j < methodTags.length; j++) {
                if (methodTags[j] == null) {
                    continue;
                }

                String[] attributes = methodTags[j].getParameters();
                for (int k = 0; k < attributes.length; k++) {
                    String attribute = attributes[k];

                    String expression = pointcutName + counter;

                    // create and add a new pointcut definition
                    PointcutDefinition pointcutDef = new PointcutDefinition();
                    pointcutDef.setName(pointcutName);
                    pointcutDef.setExpression(expression);
                    pointcutDef.setType(PointcutType.EXECUTION);
                    definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT).
                            addPointcutDef(pointcutDef);

                    // create a new controller definition
                    ControllerDefinition controllerDef = new ControllerDefinition();
                    controllerDef.setClassName(attribute);
                    //controllerDef.setExpression(ExpressionNamespace.getExpressionNamespace(aspectDef.getName()).createExecutionExpression(
                    controllerDef.setExpression(
                        ExpressionNamespace.getExpressionNamespace(aspectDef.getName()).getExpression(expression));
//
//                            ExpressionNamespace.getExpressionNamespace(aspectDef.getName()).createExpression(
//                            expression,
//                            pointcutName
//                    ));

//                    controllerDef.setExpression(Expression.createExecutionExpression(
//                            aspectDef.getName(),
//                            expression,
//                            "",
//                            pointcutName
//                    ));

                    aspectDef.addControllerDef(controllerDef);

                    counter++;
                    break;
                }
            }
View Full Code Here

            final AspectWerkzDefinitionImpl definition,
            final String className,
            final QDoxParser qdoxParser) {

        String pointcutName = METHOD_POINTCUT_NAME + Strings.replaceSubString(className, ".", "_");
        AspectDefinition aspectDef = definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT);

        int counter = 0;
        final JavaMethod[] javaMethods = qdoxParser.getJavaMethods();
        for (int i = 0; i < javaMethods.length; i++) {

            DocletTag[] methodTags = javaMethods[i].getTagsByName(AttributeTag.METHOD);
            for (int j = 0; j < methodTags.length; j++) {
                if (methodTags[j] == null) {
                    continue;
                }

                String cflowRef = methodTags[j].getNamedParameter("cflow");
                String isNonReentrant = methodTags[j].getNamedParameter("non-reentrant");

                String[] attributes = methodTags[j].getParameters();
                for (int k = 0; k < attributes.length; k++) {
                    String attribute = attributes[k];
                    if (attribute.startsWith("cflow=") || attribute.startsWith("non-reentrant=")) {
                        continue;
                    }

                    for (Iterator it2 = definition.getAdviceDefinitions().iterator(); it2.hasNext();) {
                        String expression = pointcutName + counter;

                        // create and add a new pointcut def
                        PointcutDefinition pointcutDef = new PointcutDefinition();
                        pointcutDef.setName(expression);
                        pointcutDef.setExpression(createExecutionPattern(className, javaMethods[i]));
                        pointcutDef.setType(PointcutType.EXECUTION);
                        pointcutDef.setNonReentrant(isNonReentrant);
                        aspectDef.addPointcutDef(pointcutDef);

                        ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                            .registerExpression(pointcutDef.getExpression(), "", expression, PointcutType.EXECUTION);

                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
                            continue;
                        }
                        if (adviceAttribute.equals(attribute)) {
                            // get the advice ref
                            String adviceRef = definition.getAdviceNameByAttribute(adviceAttribute);
                            if (adviceRef == null) {
                                // TODO: log a warning
                                continue; // attribute not mapped to an advice
                            }
                            // create and add a new rule
                            BindAdviceRule bindAdviceRule = new BindAdviceRule();
                            if (cflowRef != null) {
                                bindAdviceRule.setExpression(
                                    ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                        .createExpression(expression + " IN " + cflowRef));
                            } else {
                                bindAdviceRule.setExpression(
                                    ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                        .getExpression(expression));
                            }
                            bindAdviceRule.addAdviceRef(adviceRef);
                            aspectDef.addBindAdviceRule(bindAdviceRule);

                            counter++;
                            break;
                        }
                    }
View Full Code Here

    private static void parseSetFieldPointcutAttributes(
            final AspectWerkzDefinitionImpl definition,
            final String className,
            final QDoxParser qdoxParser) {

        AspectDefinition aspectDef = definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT);
        String pointcutName = SETFIELD_POINTCUT_NAME + Strings.replaceSubString(className, ".", "_");

        int counter = 0;
        final JavaField[] javaFields = qdoxParser.getJavaFields();
        for (int i = 0; i < javaFields.length; i++) {

            DocletTag[] setFieldTags = javaFields[i].getTagsByName(AttributeTag.SET_FIELD);
            for (int j = 0; j < setFieldTags.length; j++) {
                if (setFieldTags[j] == null) {
                    continue;
                }

                String[] setFieldAttributes = setFieldTags[j].getParameters();
                for (int k = 0; k < setFieldAttributes.length; k++) {

                    String attribute = setFieldAttributes[k];
                    for (Iterator it2 = definition.getAdviceDefinitions().iterator(); it2.hasNext();) {
                        String expression = pointcutName + counter;

                        // create and add a new pointcut def
                        PointcutDefinition pointcutDef = new PointcutDefinition();
                        pointcutDef.setName(expression);
                        pointcutDef.setExpression(createFieldPattern(className,javaFields[i]));
                        pointcutDef.setType(PointcutType.SET);
                        aspectDef.addPointcutDef(pointcutDef);

                        ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                .registerExpression(pointcutDef.getExpression(), "", expression, PointcutType.SET);

                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
                            continue;
                        }
                        if (adviceAttribute.equals(attribute)) {
                            // get the advice ref
                            String adviceRef = definition.getAdviceNameByAttribute(adviceAttribute);
                            if (adviceRef == null) {
                                // TODO: log a warning
                                continue; // attribute not mapped to an advice
                            }

                            // create and add a new weaving rule def
                            BindAdviceRule bindAdviceRule = new BindAdviceRule();
                            bindAdviceRule.setExpression(
                                    ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                        .getExpression(expression));

                            bindAdviceRule.addAdviceRef(adviceRef);
                            aspectDef.addBindAdviceRule(bindAdviceRule);

                            counter++;
                            break;
                        }
                    }
View Full Code Here

    private static void parseGetFieldPointcutAttributes(
            final AspectWerkzDefinitionImpl definition,
            final String className,
            final QDoxParser qdoxParser) {

        AspectDefinition aspectDef = definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT);
        String pointcutName = GETFIELD_POINTCUT_NAME + Strings.replaceSubString(className, ".", "_");

        int counter = 0;
        final JavaField[] javaFields = qdoxParser.getJavaFields();
        for (int i = 0; i < javaFields.length; i++) {

            DocletTag[] getFieldTags = javaFields[i].getTagsByName(AttributeTag.GET_FIELD);
            for (int j = 0; j < getFieldTags.length; j++) {
                if (getFieldTags[j] == null) {
                    continue;
                }

                String[] getFieldAttributes = getFieldTags[j].getParameters();
                for (int k = 0; k < getFieldAttributes.length; k++) {
                    String attribute = getFieldAttributes[k];

                    for (Iterator it2 = definition.getAdviceDefinitions().iterator(); it2.hasNext();) {
                        String expression = pointcutName + counter;

                        // create and add a new pointcut def
                        PointcutDefinition pointcutDef = new PointcutDefinition();
                        pointcutDef.setName(expression);
                        pointcutDef.setExpression(createFieldPattern(className,javaFields[i]));
                        pointcutDef.setType(PointcutType.GET);
                        aspectDef.addPointcutDef(pointcutDef);

                        ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                .registerExpression(pointcutDef.getExpression(), "", expression, PointcutType.GET);

                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
                            continue;
                        }
                        if (adviceAttribute.equals(attribute)) {
                            // get the advice ref
                            String adviceRef = definition.getAdviceNameByAttribute(adviceAttribute);
                            if (adviceRef == null) {
                                // TODO: log a warning
                                continue; // attribute not mapped to an advice
                            }

                            // create and add a new weaving rule def
                            BindAdviceRule bindAdviceRule = new BindAdviceRule();
                            bindAdviceRule.setExpression(
                                    ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                        .getExpression(expression));
                            bindAdviceRule.addAdviceRef(adviceRef);
                            aspectDef.addBindAdviceRule(bindAdviceRule);

                            counter++;
                            break;
                        }
                    }
View Full Code Here

    private static void parseThrowsPointcutAttributes(
            final AspectWerkzDefinitionImpl definition,
            final String className,
            final QDoxParser qdoxParser) {

        AspectDefinition aspectDef = definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT);
        String pointcutName = THROWS_POINTCUT_NAME + Strings.replaceSubString(className, ".", "_");

        int counter = 0;
        final JavaMethod[] javaMethods = qdoxParser.getJavaMethods();
        for (int i = 0; i < javaMethods.length; i++) {

            DocletTag[] throwsTags = javaMethods[i].getTagsByName(AttributeTag.THROWS);
            for (int j = 0; j < throwsTags.length; j++) {
                if (throwsTags[j] == null) {
                    continue;
                }

                String exceptionClassPattern = throwsTags[j].getNamedParameter("exception");

                if (exceptionClassPattern == null) {
                    throw new DefinitionException("exception class not specified for throws attribute at method <" + javaMethods[i].getName() + ">");
                }

                String[] attributes = throwsTags[j].getParameters();
                for (int k = 0; k < attributes.length; k++) {
                    String attribute = attributes[k];
                    if (attribute.startsWith("exception=")) {
                        continue;
                    }
                    for (Iterator it2 = definition.getAdviceDefinitions().iterator(); it2.hasNext();) {
                        String expression = pointcutName + counter;

                        // create and add a new pointcut def
                        PointcutDefinition pointcutDef = new PointcutDefinition();
                        pointcutDef.setName(expression);
                        pointcutDef.setExpression(createThrowsPattern(exceptionClassPattern, javaMethods[i]));
                        pointcutDef.setType(PointcutType.THROWS);
                        aspectDef.addPointcutDef(pointcutDef);

                        ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                .registerExpression(pointcutDef.getExpression(), "", expression, PointcutType.THROWS);

                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
                            continue;
                        }
                        if (adviceAttribute.equals(attribute)) {
                            // get the advice ref
                            String adviceRef = definition.getAdviceNameByAttribute(adviceAttribute);
                            if (adviceRef == null) {
                                // TODO: log a warning
                                continue; // attribute not mapped to an advice
                            }

                            BindAdviceRule bindAdviceRule = new BindAdviceRule();
                            bindAdviceRule.setExpression(
                                    ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                        .getExpression(expression));
                            bindAdviceRule.addAdviceRef(adviceRef);
                            aspectDef.addBindAdviceRule(bindAdviceRule);

                            counter++;
                            break;
                        }
                    }
View Full Code Here

    private static void parseCallerSidePointcutAttributes(
            final AspectWerkzDefinitionImpl definition,
            final String className,
            final QDoxParser qdoxParser) {

        AspectDefinition aspectDef = definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT);
        String pointcutName = CALLERSIDE_POINTCUT_NAME + Strings.replaceSubString(className, ".", "_");

        int counter = 0;
        final JavaMethod[] javaMethods = qdoxParser.getJavaMethods();
        for (int i = 0; i < javaMethods.length; i++) {

            DocletTag[] callerSideTags = javaMethods[i].getTagsByName(AttributeTag.CALLER_SIDE);
            for (int j = 0; j < callerSideTags.length; j++) {
                if (callerSideTags[j] == null) {
                    continue;
                }
                String callerClassPattern = callerSideTags[j].getNamedParameter("callerclass");
                if (callerClassPattern == null) {
                    throw new DefinitionException("caller class not specified for caller side attribute at method <" + javaMethods[i].getName() + ">");
                }

                String[] callerSideAttributes = callerSideTags[j].getParameters();
                for (int k = 0; k < callerSideAttributes.length; k++) {
                    String attribute = callerSideAttributes[k];
                    if (attribute.startsWith("callerclass=")) {
                        continue;
                    }
                    for (Iterator it2 = definition.getAdviceDefinitions().iterator(); it2.hasNext();) {
                        String expression = pointcutName + counter;

                        // create and add a new pointcut def
                        PointcutDefinition pointcutDef = new PointcutDefinition();
                        pointcutDef.setName(expression);
                        pointcutDef.setExpression(createCallerSidePattern(callerClassPattern, className, javaMethods[i]));
                        pointcutDef.setType(PointcutType.CALL);
                        aspectDef.addPointcutDef(pointcutDef);

                        ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                .registerExpression(
                                pointcutDef.getExpression(), "", expression, PointcutType.CALL
                        );


                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
                            continue;
                        }

                        if (adviceAttribute.equals(attribute)) {
                            // get the advice ref
                            String adviceRef = definition.getAdviceNameByAttribute(adviceAttribute);
                            if (adviceRef == null) {
                                // TODO: log a warning
                                continue; // attribute not mapped to an advice
                            }

                            // create and add a new weaving rule def
                            BindAdviceRule bindAdviceRule = new BindAdviceRule();
                            bindAdviceRule.setExpression(
                                    ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                                        .getExpression(expression));
                            bindAdviceRule.addAdviceRef(adviceRef);
                            aspectDef.addBindAdviceRule(bindAdviceRule);

                            counter++;
                            break;
                        }
                    }
View Full Code Here

    private static void parseCFlowPointcutAttributes(
            final AspectWerkzDefinitionImpl definition,
            final String className,
            final QDoxParser qdoxParser) {

        AspectDefinition aspectDef = definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT);

        final JavaMethod[] javaMethods = qdoxParser.getJavaMethods();
        for (int i = 0; i < javaMethods.length; i++) {

            DocletTag[] cflowTags = javaMethods[i].getTagsByName(AttributeTag.CFLOW);
            for (int j = 0; j < cflowTags.length; j++) {
                if (cflowTags[j] == null) {
                    continue;
                }
                String[] attributes = cflowTags[j].getParameters();
                if (attributes.length == 0) {
                    continue;
                }

                // get the user defined name for the cflow pointcut
                String name = attributes[0];

                // create and add a new pointcut def
                PointcutDefinition pointcutDef = new PointcutDefinition();
                pointcutDef.setName(name);
                pointcutDef.setExpression(createCallerSidePattern("*", className, javaMethods[i]));
                pointcutDef.setType(PointcutType.CFLOW);
                aspectDef.addPointcutDef(pointcutDef);

                ExpressionNamespace.getExpressionNamespace(aspectDef.getName())
                        .registerExpression(
                        pointcutDef.getExpression(), "", name, PointcutType.CFLOW
                );

                break;
View Full Code Here

TOP

Related Classes of org.codehaus.aspectwerkz.xmldef.definition.AspectDefinition

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.