Package org.codehaus.aspectwerkz.definition

Examples of org.codehaus.aspectwerkz.definition.PointcutDefinition


    public void testPointcutTag() {
        try {
            final AspectWerkzDefinition aspectwerkz = XmlDefinitionParser.parseNoCache(m_input.toURL());
            Iterator it = ((AspectDefinition)aspectwerkz.getAspectDefinitions().iterator().
                    next()).getPointcutDefs().iterator();
            PointcutDefinition pointcut2 = (PointcutDefinition)it.next();
            assertEquals("method", pointcut2.getType());
            assertEquals("stop", pointcut2.getName());
            assertEquals("services.*", pointcut2.getClassPattern());
            assertEquals("* stop(..)", pointcut2.getPattern());
            PointcutDefinition pointcut1 = (PointcutDefinition)it.next();
            assertEquals("setField", pointcut1.getType());
            assertEquals("setFieldTest", pointcut1.getName());
            assertEquals("services.*", pointcut1.getClassPattern());
            assertEquals("boolean m_isRunning", pointcut1.getPattern());
        }
        catch (Exception e) {
            System.out.println(e);
            fail();
        }
View Full Code Here


     * @param aspectDef the aspect definition
     */
    private static void handlePointcutDefinitions(final Element aspectElement,
                                                  final AspectDefinition aspectDef) {
        for (Iterator it2 = aspectDef.getPointcutDefs().iterator(); it2.hasNext();) {
            PointcutDefinition pointcutDef = (PointcutDefinition)it2.next();

            Element pointcutDefElement = aspectElement.addElement("pointcut-def");
            pointcutDefElement.addAttribute("name", pointcutDef.getName());
            pointcutDefElement.addAttribute("type", pointcutDef.getType());
            pointcutDefElement.addAttribute("non-reentrant", pointcutDef.getNonReentrant());

            StringBuffer fullPattern = new StringBuffer();
            String type = pointcutDef.getType();
            if (type.equalsIgnoreCase(PointcutDefinition.METHOD) ||
                    type.equalsIgnoreCase(PointcutDefinition.GET_FIELD) ||
                    type.equalsIgnoreCase(PointcutDefinition.SET_FIELD)) {
                String classPattern = pointcutDef.getClassPattern();
                String pattern = pointcutDef.getPattern();
                int space = pattern.indexOf(' ');
                String returnType = pattern.substring(0, space + 1);
                String methodName = pattern.substring(space + 1);
                fullPattern.append(returnType);
                fullPattern.append(classPattern);
                fullPattern.append('.');
                fullPattern.append(methodName);
            }
            else if (type.equalsIgnoreCase(PointcutDefinition.THROWS)) {
                String classPattern = pointcutDef.getClassPattern();
                String pattern = pointcutDef.getPattern();
                int delimiter = pattern.indexOf('#');
                String methodPattern = pattern.substring(0, delimiter);
                String exception = pattern.substring(delimiter + 1);
                int space = methodPattern.indexOf(' ');
                String returnType = methodPattern.substring(0, space + 1);
                String methodName = methodPattern.substring(space + 1);
                fullPattern.append(returnType);
                fullPattern.append(classPattern);
                fullPattern.append('.');
                fullPattern.append(methodName);
                fullPattern.append('#');
                fullPattern.append(exception);
            }
            else if (type.equalsIgnoreCase(PointcutDefinition.CALLER_SIDE)) {
                String callerClassPattern = pointcutDef.getClassPattern();
                String pattern = pointcutDef.getPattern();
                int delimiter = pattern.indexOf('#');
                String calleeClassPattern = pattern.substring(0, delimiter);
                String methodPattern = pattern.substring(delimiter + 1);
                int space = methodPattern.indexOf(' ');
                String returnType = methodPattern.substring(0, space + 1);
                String methodName = methodPattern.substring(space + 1);
                fullPattern.append(callerClassPattern);
                fullPattern.append("->");
                fullPattern.append(returnType);
                fullPattern.append(calleeClassPattern);
                fullPattern.append(".");
                fullPattern.append(methodName);
                ;
            }
            else if (type.equals(PointcutDefinition.CFLOW)) {
                String pattern = pointcutDef.getPattern();
                int delimiter = pattern.indexOf('#');
                String classPattern = pattern.substring(0, delimiter);
                String methodPattern = pattern.substring(delimiter + 1);
                int space = methodPattern.indexOf(' ');
                String returnType = methodPattern.substring(0, space + 1);
                String methodName = methodPattern.substring(space + 1);
                fullPattern.append(returnType);
                fullPattern.append(classPattern);
                fullPattern.append(".");
                fullPattern.append(methodName);
            }
            else {
                throw new RuntimeException("invalid pointcut type: " + pointcutDef.getType());
            }

            pointcutDefElement.addAttribute("pattern", fullPattern.toString());
        }
    }
View Full Code Here

                    String attribute = attributes[k];

                    String expression = pointcutName + counter;

                    // create and add a new pointcut definition
                    PointcutDefinition pointcutDef = new PointcutDefinition();
                    pointcutDef.setName(expression);
                    pointcutDef.setClassPattern(className);
                    pointcutDef.setPattern(createMethodPattern(javaMethods[i]));
                    pointcutDef.setType(PointcutDefinition.METHOD);
                    definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT).
                            addPointcutDef(pointcutDef);

                    // create a new controller definition
                    ControllerDefinition controllerDef = new ControllerDefinition();
View Full Code Here

                    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.setClassPattern(className);
                        pointcutDef.setPattern(createMethodPattern(javaMethods[i]));
                        pointcutDef.setType(PointcutDefinition.METHOD);
                        pointcutDef.setNonReentrant(isNonReentrant);
                        definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT).
                                addPointcutDef(pointcutDef);

                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
View Full Code Here

                    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.setClassPattern(className);
                        pointcutDef.setPattern(createFieldPattern(javaFields[i]));
                        pointcutDef.setType(PointcutDefinition.SET_FIELD);
                        definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT).
                                addPointcutDef(pointcutDef);

                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
View Full Code Here

                    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.setClassPattern(className);
                        pointcutDef.setPattern(createFieldPattern(javaFields[i]));
                        pointcutDef.setType(PointcutDefinition.GET_FIELD);
                        definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT).
                                addPointcutDef(pointcutDef);

                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
View Full Code Here

                    }
                    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.setClassPattern(className);
                        pointcutDef.setPattern(createThrowsPattern(
                                exceptionClassPattern, javaMethods[i]));
                        pointcutDef.setType(PointcutDefinition.THROWS);
                        definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT).
                                addPointcutDef(pointcutDef);

                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
View Full Code Here

                    }
                    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.setClassPattern(callerClassPattern);
                        pointcutDef.setPattern(createCallerSidePattern(className, javaMethods[i]));
                        pointcutDef.setType(PointcutDefinition.CALLER_SIDE);
                        definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT).
                                addPointcutDef(pointcutDef);

                        String adviceAttribute = ((AdviceDefinition)it2.next()).getAttribute();
                        if (adviceAttribute == null) {
View Full Code Here

                // 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.setClassPattern("*");
                String callerSidePattern = createCallerSidePattern(className, javaMethods[i]);
                pointcutDef.setPattern(callerSidePattern);
                pointcutDef.setType(PointcutDefinition.CFLOW);

                definition.getAspectDefinition(AspectWerkzDefinition.SYSTEM_ASPECT).
                        addPointcutDef(pointcutDef);

                // create and add a new weaving rule def
View Full Code Here

            final AspectWerkzDefinition aspectwerkz = (AspectWerkzDefinition)XmlParser.parseNoCache(m_input.toURL()).get(0);
            Iterator itl = aspectwerkz.getAspectDefinitions().iterator();
            itl.next(); // SystemAspect @todo validate with Jonas (side effect of precedence fix)
            Iterator it = ((AspectDefinition)itl.next()).getPointcutDefs().iterator();
            it.next();//skip "start"
            PointcutDefinition pointcut2 = (PointcutDefinition)it.next();
            assertEquals("method", pointcut2.getType());
            assertEquals("stop", pointcut2.getName());
            assertEquals("* services.*.stop(..)", pointcut2.getExpression());
            // absract aspect pointcut are added thereafter
            // @todo review precedence
            it.next();//skip "callerSideTest"
            PointcutDefinition pointcut1 = (PointcutDefinition)it.next();
            assertEquals("setField", pointcut1.getType());
            assertEquals("setFieldTest", pointcut1.getName());
            assertEquals("boolean services.*.m_isRunning", pointcut1.getExpression());
        }
        catch (Exception e) {
            System.out.println(e);
            fail();
        }
View Full Code Here

TOP

Related Classes of org.codehaus.aspectwerkz.definition.PointcutDefinition

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.