Package org.codehaus.aspectwerkz.definition

Examples of org.codehaus.aspectwerkz.definition.AspectDefinition


     * @param visibleFrom class loader of the advised class from all is visible
     * @param containerClass the container class
     * @param qName the aspect qualified name
     */
    private static AspectContainer createAspectContainer(final ClassLoader visibleFrom, final Class containerClass, final String qName) {
        AspectDefinition aspectDefinition = lookupAspectDefinition(visibleFrom, qName);

        Class aspectClass = null;
        try {
            aspectClass = ContextClassLoader.forName(visibleFrom, aspectDefinition.getClassName());
        } catch (Throwable t) {
            throw new NoAspectBoundException(t, qName);
        }

        try {
            Constructor constructor = containerClass.getConstructor(new Class[]{AspectContext.class});
            final AspectContext aspectContext = new AspectContext(
                    aspectDefinition.getSystemDefinition().getUuid(),
                    aspectClass,
                    aspectDefinition.getName(),
                    aspectDefinition.getDeploymentModel(),
                    aspectDefinition,
                    aspectDefinition.getParameters()
            );
            final AspectContainer container = (AspectContainer) constructor.newInstance(new Object[]{aspectContext});
            aspectContext.setContainer(container);
            return container;
        } catch (InvocationTargetException e) {
View Full Code Here


        final ClassInfo aspectClassInfo = JavaClassInfo.getClassInfo(aspectClass);

        // create a new aspect def and fill it up with the annotation def from the aspect class
        final SystemDefinition systemDef = SystemDefinitionContainer.getVirtualDefinitionAt(deployLoader);
        final AspectDefinition newAspectDef = new AspectDefinition(className, aspectClassInfo, systemDef);
        final Set newExpressions = getNewExpressionsForAspect(
                aspectClass, newAspectDef, systemDef, deploymentScope, deploymentHandle
        );

        redefine(newExpressions);
View Full Code Here

        final DeploymentHandle deploymentHandle = new DeploymentHandle(aspect, deployLoader);

        final SystemDefinition systemDef = SystemDefinitionContainer.getVirtualDefinitionAt(deployLoader);
        try {
            final Document document = XmlParser.createDocument(xmlDef);
            final AspectDefinition newAspectDef = DocumentParser.parseAspectDefinition(document, systemDef, aspect);
            final Set newExpressions = getNewExpressionsForAspect(
                    aspect, newAspectDef, systemDef, deploymentScope, deploymentHandle
            );

            redefine(newExpressions);
View Full Code Here

        // since the system hierarchy holds reference, they will see the change
        Set systemDefs = SystemDefinitionContainer.getDefinitionsAt(loader);

        for (Iterator it = systemDefs.iterator(); it.hasNext();) {
            SystemDefinition systemDef = (SystemDefinition) it.next();
            final AspectDefinition aspectDef = systemDef.getAspectDefinition(className);
            if (aspectDef != null) {

                final Set newExpressions = new HashSet();
                for (Iterator it2 = aspectDef.getAdviceDefinitions().iterator(); it2.hasNext();) {
                    AdviceDefinition adviceDef = (AdviceDefinition) it2.next();
                    ExpressionInfo oldExpression = adviceDef.getExpressionInfo();
                    if (oldExpression == null) { // if null, then already undeployed
                        continue;
                    }
View Full Code Here

        AspectModelManager.defineAspect(classInfo, newAspectDef, aspectLoader);

        AspectAnnotationParser.parse(classInfo, newAspectDef, aspectLoader);

        AspectDefinition aspectDef = systemDef.getAspectDefinition(aspectName);
        if (aspectDef != null) {
            // if in def already reuse some of the settings that can have been overridded by XML def
            newAspectDef.setContainerClassName(aspectDef.getContainerClassName());
            newAspectDef.setDeploymentModel(aspectDef.getDeploymentModel());
        }

        systemDef.addAspectOverwriteIfExists(newAspectDef);

        final Set newExpressions = new HashSet();
View Full Code Here



        SystemDefinition def = SystemDefinitionContainer.getVirtualDefinitionAt(cl);

        AspectDefinition aspectDef = new AspectDefinition(aspectInfo.getName(), aspectInfo, def);

        AdviceDefinition adviceDef = AdviceDefinition.newInstance(

                "invoke",// as per AOPAlliance

                AdviceType.AROUND,

                "execution("+pointcut+")",

                null,

                aspectInfo.getName(),

                aspectInfo.getName(),

                aspectInfo.getMethod(ReflectHelper.calculateHash(AOP_ALLIANCE_METHOD_AROUND)),

                aspectDef

        );



        // make it an AOP Alliance aspect for the compiler

        aspectDef.setAspectModel(ASPECT_MODEL_TYPE);

        aspectDef.setContainerClassName(ASPECT_CONTAINER_CLASS_NAME);



        // add the advice

        aspectDef.addAroundAdviceDefinition(adviceDef);



        // add the aspect
View Full Code Here

     * @param definition the AspectWerkz definition
     */
    private static void handleAspectDefinitions(final Element root,
                                                final AspectWerkzDefinition 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);
            handleIntroductionWeavingRules(aspectElement, aspectDef);
            handleAdviceWeavingRules(aspectElement, aspectDef);
View Full Code Here

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

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

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

        IntroductionWeavingRule weavingRule = new IntroductionWeavingRule();
        weavingRule.setClassPattern(className);

        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;
                }
                weavingRule.addIntroductionRef(introductionRef);
            }
            aspectDefinition.addIntroductionWeavingRule(weavingRule);
        }
    }
View Full Code Here

    public void testAspectTag() {
        try {
            AspectWerkzDefinition aspectwerkz = XmlDefinitionParser.parseNoCache(m_input.toURL());
            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.*", ((IntroductionWeavingRule)aspect.getIntroductionWeavingRules().get(0)).getClassPattern());
            assertEquals("loggable", (String)((IntroductionWeavingRule)aspect.getIntroductionWeavingRules().get(0)).getIntroductionRefs().get(0));
            assertEquals("services.*", ((IntroductionWeavingRule)aspect.getIntroductionWeavingRules().get(1)).getClassPattern());
            assertEquals("loggable", (String)((IntroductionWeavingRule)aspect.getIntroductionWeavingRules().get(1)).getIntroductionRefs().get(0));
            assertEquals("start && stop", ((AdviceWeavingRule)aspect.getAdviceWeavingRules().get(0)).getExpression());
            assertEquals("logging", (String)((AdviceWeavingRule)aspect.getAdviceWeavingRules().get(0)).getAdviceRefs().get(0));
            assertEquals("start || stop", ((AdviceWeavingRule)aspect.getAdviceWeavingRules().get(1)).getExpression());
            assertEquals("logging", (String)((AdviceWeavingRule)aspect.getAdviceWeavingRules().get(1)).getAdviceRefs().get(0));
        }
        catch (Exception e) {
            System.out.println(e);
            fail();
        }
View Full Code Here

        // TODO: how to do this class define lazyly and not pass in a classloader ?
        // could be done in the JIT jp clinit when 1+ advice has a cflow binding
        Class aspectClass = CflowCompiler.compileCflowAspectAndAttachToClassLoader(loader, m_cflowID);
        ClassInfo cflowAspectInfo = JavaClassInfo.getClassInfo(aspectClass);

        AspectDefinition aspectDef = new AspectDefinition(
                aspectName.replace('/', '.'),
                cflowAspectInfo,
                systemDefinition
        );
        aspectDef.addBeforeAdviceDefinition(
                new AdviceDefinition(
                        CFLOW_ENTER_ADVICE.getName(),
                        AdviceType.BEFORE,
                        null,
                        aspectName,
                        aspectName,
                        m_cflowSubExpression,
                        CFLOW_ENTER_ADVICE,
                        aspectDef
                )
        );
        aspectDef.addAfterAdviceDefinition(
                new AdviceDefinition(
                        CFLOW_EXIT_ADVICE.getName(),
                        AdviceType.AFTER_FINALLY,
                        null,
                        aspectName,
View Full Code Here

TOP

Related Classes of org.codehaus.aspectwerkz.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.