Package org.codehaus.aspectwerkz.xmldef.definition

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


    public void testAspectTag() {
        try {
            AspectWerkzDefinition aspectwerkz = (AspectWerkzDefinition)XmlParser.parseNoCache(m_input.toURL()).get(0);
            Iterator it1 = aspectwerkz.getAspectDefinitions().iterator();
            it1.next();// SystemAspect @todo check this with Jonas (side effect of precedence fix)
            AspectDefinition aspect = (AspectDefinition)it1.next();
            assertEquals("Logger", aspect.getName());
            assertEquals("Service", aspect.getExtends());
            assertEquals("services.*", ((BindIntroductionRule)aspect.getBindIntroductionRules().get(0)).getExpression().getExpression());
            assertEquals("loggable", (String)((BindIntroductionRule)aspect.getBindIntroductionRules().get(0)).getIntroductionRefs().get(0));
            assertEquals("services.*", ((BindIntroductionRule)aspect.getBindIntroductionRules().get(1)).getExpression().getExpression());
            assertEquals("loggable", (String)((BindIntroductionRule)aspect.getBindIntroductionRules().get(1)).getIntroductionRefs().get(0));
            assertEquals("start && stop", ((BindAdviceRule)aspect.getBindAdviceRules().get(0)).getExpression().getExpression());
            assertEquals("logging", (String)((BindAdviceRule)aspect.getBindAdviceRules().get(0)).getAdviceRefs().get(0));
            assertEquals("start || stop", ((BindAdviceRule)aspect.getBindAdviceRules().get(1)).getExpression().getExpression());
            assertEquals("logging", (String)((BindAdviceRule)aspect.getBindAdviceRules().get(1)).getAdviceRefs().get(0));
        }
        catch (Exception e) {
            System.out.println(e);
            fail();
        }
View Full Code Here


     * @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(Expression.createRootExpression(
                aspectDef.getName(), 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 AspectWerkzDefinitionImpl definition,
            final String className,
            final QDoxParser qdoxParser) {

        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(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(pointcutName);
                        pointcutDef.setExpression(expression);
                        pointcutDef.setType(PointcutType.EXECUTION);
                        pointcutDef.setNonReentrant(isNonReentrant);
                        aspectDef.addPointcutDef(pointcutDef);

                        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();
                            bindAdviceRule.setExpression(
                                    Expression.createExecutionExpression(
                                            aspectDef.getName(),
                                            expression,
                                            "",
                                            pointcutName
                                    ));
                            // TODO: how to handle cflow?
//                            bindAdviceRule.setCFlowExpression(cflowRef);
                            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(pointcutName);
                        pointcutDef.setExpression(expression);
                        pointcutDef.setType(PointcutType.SET);
                        aspectDef.addPointcutDef(pointcutDef);

                        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(
                                    Expression.createSetExpression(
                                            aspectDef.getName(),
                                            expression,
                                            "",
                                            pointcutName
                                    ));
                            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(pointcutName);
                        pointcutDef.setExpression(expression);
                        pointcutDef.setType(PointcutType.GET);
                        aspectDef.addPointcutDef(pointcutDef);
                        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(
                                    Expression.createGetExpression(
                                            aspectDef.getName(),
                                            expression,
                                            "",
                                            pointcutName
                                    ));
                            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(pointcutName);
                        pointcutDef.setExpression(expression);
                        pointcutDef.setType(PointcutType.THROWS);
                        aspectDef.addPointcutDef(pointcutDef);

                        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(Expression.createThrowsExpression(
                                    aspectDef.getName(),
                                    expression,
                                    "",
                                    pointcutName
                            ));
                            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(pointcutName);
                        pointcutDef.setExpression(expression);
                        pointcutDef.setType(PointcutType.CALL);
                        aspectDef.addPointcutDef(pointcutDef);


                        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(Expression.createCallExpression(
                                    aspectDef.getName(),
                                    expression,
                                    "",
                                    pointcutName
                            ));
                            bindAdviceRule.addAdviceRef(adviceRef);
                            aspectDef.addBindAdviceRule(bindAdviceRule);

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

    public void testAspectTag() {
        try {
            AspectWerkzDefinition aspectwerkz = (AspectWerkzDefinition)XmlParser.parseNoCache(m_input.toURL()).get(0);
            Iterator it1 = aspectwerkz.getAspectDefinitions().iterator();
            it1.next();// SystemAspect @todo check this with Jonas (side effect of precedence fix)
            AspectDefinition aspect = (AspectDefinition)it1.next();
            assertEquals("Logger", aspect.getName());
            assertEquals("Service", aspect.getExtends());
            assertEquals("services.*", ((BindIntroductionRule)aspect.getBindIntroductionRules().get(0)).getExpression().getExpression());
            assertEquals("loggable", (String)((BindIntroductionRule)aspect.getBindIntroductionRules().get(0)).getIntroductionRefs().get(0));
            assertEquals("services.*", ((BindIntroductionRule)aspect.getBindIntroductionRules().get(1)).getExpression().getExpression());
            assertEquals("loggable", (String)((BindIntroductionRule)aspect.getBindIntroductionRules().get(1)).getIntroductionRefs().get(0));
            assertEquals("start && stop", ((BindAdviceRule)aspect.getBindAdviceRules().get(0)).getExpression().getExpression());
            assertEquals("logging", (String)((BindAdviceRule)aspect.getBindAdviceRules().get(0)).getAdviceRefs().get(0));
            assertEquals("start || stop", ((BindAdviceRule)aspect.getBindAdviceRules().get(1)).getExpression().getExpression());
            assertEquals("logging", (String)((BindAdviceRule)aspect.getBindAdviceRules().get(1)).getAdviceRefs().get(0));
        }
        catch (Exception e) {
            System.out.println(e);
            fail();
        }
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.