Examples of AspectWerkzDefinition


Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

        }
    }

    public void testPointcutTag() {
        try {
            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());
View Full Code Here

Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

     * Only to be used when ONE definition is used per JVM.
     *
     * @return the default system
     */
    public synchronized static System getDefaultSystem() {
        final AspectWerkzDefinition definition =
                DefinitionLoader.getDefinition(System.DEFAULT_SYSTEM);

        System system = null;
        try {
            system = (System)s_systems.get(System.DEFAULT_SYSTEM);
            if (system == null) {
                if (definition.isXmlDef()) {
                    //TODO: remove the sync bloc - unsafe see AW-98
                    synchronized (s_systems) {
                        system = (System)XML_DEF_SYSTEM_CONSTRUCTOR.newInstance(
                                new Object[]{System.DEFAULT_SYSTEM, definition}
                        );
                        s_systems.put(System.DEFAULT_SYSTEM, system);
                    }
                }
                else if (definition.isAttribDef()) {
                    //TODO: remove the sync bloc - unsafe see AW-98
                    synchronized (s_systems) {
                        system = (System)ATTRIB_DEF_SYSTEM_CONSTRUCTOR.newInstance(
                                new Object[]{System.DEFAULT_SYSTEM, definition}
                        );
View Full Code Here

Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

     * @return the system for the UUID specified
     */
    public synchronized static System getSystem(final String uuid) {
        if (uuid == null) throw new IllegalArgumentException("uuid can not be null");

        final AspectWerkzDefinition definition = DefinitionLoader.getDefinition(uuid);

        System system = null;
        try {
            system = (System)s_systems.get(uuid);
            if (system == null) {
                if (definition.isXmlDef()) {
                    //TODO: remove the sync bloc - unsafe see AW-98
                    synchronized (s_systems) {
                        // TODO: makes the clapp test fail, why?
                        system = (System)XML_DEF_SYSTEM_CONSTRUCTOR.newInstance(
                                new Object[]{uuid, definition}
                        );
//                        system = new org.codehaus.aspectwerkz.xmldef.XmlDefSystem(uuid, definition);
                        s_systems.put(uuid, system);
                    }
                }
                else if (definition.isAttribDef()) {
                    //TODO: remove the sync bloc - unsafe see AW-98
                    synchronized (s_systems) {
                        system = (System)ATTRIB_DEF_SYSTEM_CONSTRUCTOR.newInstance(
                                new Object[]{uuid, definition}
                        );
View Full Code Here

Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

     */
    public void transformCode(final Context context, final Klass klass) {

        // loop over all the definitions
        for (Iterator it = m_definitions.iterator(); it.hasNext();) {
            AspectWerkzDefinition definition = (AspectWerkzDefinition)it.next();

            definition.loadAspects(context.getLoader());

            final ClassGen cg = klass.getClassGen();
            ClassMetaData classMetaData = BcelMetaDataMaker.
                    createClassMetaData(context.getJavaClass(cg));

            if (classFilter(definition, classMetaData, cg)) {
                return;
            }

            final InstructionFactory factory = new InstructionFactory(cg);
            final ConstantPoolGen cpg = cg.getConstantPool();
            final Method[] methods = cg.getMethods();

            // get the index for the <clinit> method (if there is one)
            boolean noClinitMethod = true;
            int indexClinit = -1;
            for (int i = 0; i < methods.length; i++) {
                if (methods[i].getName().equals("<clinit>")) {
                    indexClinit = i;
                    noClinitMethod = false;
                    break;
                }
            }

            // build and sort the method lookup list
            final List methodLookupList = new ArrayList();
            for (int i = 0; i < methods.length; i++) {
                Method method = methods[i];

                MethodMetaData methodMetaData = BcelMetaDataMaker.createMethodMetaData(methods[i]);
                if (methodFilter(definition, classMetaData, methodMetaData, method)) {
                    continue;
                }
                methodLookupList.add(methods[i]);

                // TODO: does not work, needs to be thought through more
                // if advised swap add the prefixed one as well to enable second-round instrumentation
//                String originalPrefixedName =
//                        TransformationUtil.ORIGINAL_METHOD_PREFIX +
//                        methods[i].getName();
//                Method[] declaredMethods = cg.getMethods();
//                for (int j = 0; j < declaredMethods.length; j++) {
//                    Method declaredMethod = declaredMethods[j];
//                    if (declaredMethod.getName().startsWith(originalPrefixedName)) {
//                        methodLookupList.add(declaredMethod);
//                    }
//                }
            }

            Collections.sort(methodLookupList, BCELMethodComparator.getInstance());

            final Map methodSequences = new HashMap();
            final List newMethods = new ArrayList();
            Method clInitMethod = null;
            boolean isClassAdvised = false;

            for (int i = 0; i < methods.length; i++) {
                Method method = methods[i];
                MethodMetaData methodMetaData = BcelMetaDataMaker.createMethodMetaData(method);

                if (methodFilter(definition, classMetaData, methodMetaData, method)
                        || !method.isStatic()) {
                    continue;
                }

                isClassAdvised = true;

                // TODO: does not work, needs to be thought through more
                // if advised swap the method to the prefixed one
//                String originalPrefixedName =
//                        TransformationUtil.ORIGINAL_METHOD_PREFIX +
//                        methods[i].getName();
//                Method[] declaredMethods = cg.getMethods();
//                for (int j = 0; j < declaredMethods.length; j++) {
//                    Method declaredMethod = declaredMethods[j];
//                    if (declaredMethod.getName().startsWith(originalPrefixedName)) {
//                        method = declaredMethod;
//                    }
//                }

                final MethodGen mg = new MethodGen(method, cg.getClassName(), cpg);

                // take care of identification of overloaded methods by
                // inserting a sequence number
                if (methodSequences.containsKey(method.getName())) {
                    int sequence = ((Integer)methodSequences.get(methods[i].getName())).intValue();
                    methodSequences.remove(method.getName());
                    sequence++;
                    methodSequences.put(method.getName(), new Integer(sequence));
                }
                else {
                    methodSequences.put(method.getName(), new Integer(1));
                }

                final int methodLookupId = methodLookupList.indexOf(method);
                final int methodSequence = ((Integer)methodSequences.get(method.getName())).intValue();

                addStaticJoinPointField(cpg, cg, mg, methodSequence);

                // get the join point controller
                final String controllerClassName = definition.getJoinPointController(
                        classMetaData, methodMetaData
                );

                if (noClinitMethod) {
                    // no <clinit> method exists
                    if (clInitMethod == null) {
                        clInitMethod = createClInitMethodWithStaticJoinPointField(
                                cpg, cg,
                                method,
                                factory,
                                methodSequence
                        );
                    }
                    else {
                        clInitMethod = createStaticJoinPointField(
                                cpg, cg, clInitMethod,
                                method,
                                factory,
                                methodSequence
                        );
                    }
                }
                else {
                    // we have a <clinit> method
                    methods[indexClinit] = createStaticJoinPointField(
                            cpg, cg, methods[indexClinit],
                            method,
                            factory,
                            methodSequence
                    );
                }

                // create a proxy method for the original method
                newMethods.add(createProxyMethod(
                        cpg, cg,
                        methodMetaData.getName(),
                        mg, factory,
                        methodLookupId,
                        methodSequence,
                        method.getAccessFlags(),
                        definition.getUuid(),
                        controllerClassName
                ));

                // add a prefix to the original method
                methods[i] = addPrefixToMethod(
                        mg, method, methodSequence, definition.getUuid()
                );

                mg.setMaxLocals();
                mg.setMaxStack();
            }
View Full Code Here

Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

    public void transformInterface(final Context context, final Klass klass) {
        if (ADD_UUID == null) return; // do not do any transformations

        // loop over all the definitions
        for (Iterator it = m_definitions.iterator(); it.hasNext();) {
            AspectWerkzDefinition definition = (AspectWerkzDefinition)it.next();

            definition.loadAspects(context.getLoader());

            final ClassGen cg = klass.getClassGen();
            final ConstantPoolGen cpg = cg.getConstantPool();
            final InstructionFactory factory = new InstructionFactory(cg);
View Full Code Here

Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

     */
    public void transformCode(final Context context, final Klass klass) {
        if (ADD_UUID == null) return; // do not do any transformations

        for (Iterator it = m_definitions.iterator(); it.hasNext();) {
            AspectWerkzDefinition definition = (AspectWerkzDefinition)it.next();

            final ClassGen cg = klass.getClassGen();
            if (classFilter(cg, definition)) {
                return;
            }
View Full Code Here

Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

        Set repository = new HashSet();
        m_metaDataRepository.put(loader, repository); // add the loader here already to prevent recursive calls

        List definitions = DefinitionLoader.getDefinitionsForTransformation();
        for (Iterator it = definitions.iterator(); it.hasNext();) {
            AspectWerkzDefinition definition = (AspectWerkzDefinition)it.next();
            definition.buildMixinMetaDataRepository(repository, loader);
        }
    }
View Full Code Here

Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

     */
    public void transformCode(final Context context, final Klass klass) {

        // loop over all the definitions
        for (Iterator it = m_definitions.iterator(); it.hasNext();) {
            AspectWerkzDefinition definition = (AspectWerkzDefinition)it.next();

            definition.loadAspects(context.getLoader());

            final ClassGen cg = klass.getClassGen();
            ClassMetaData classMetaData = BcelMetaDataMaker.createClassMetaData(context.getJavaClass(cg));

            if (classFilter(definition, classMetaData, cg)) {
                return;
            }

            final InstructionFactory factory = new InstructionFactory(cg);
            final ConstantPoolGen cpg = cg.getConstantPool();
            final Method[] methods = cg.getMethods();

            // get the indexes for the <init> methods
            List initIndexes = new ArrayList();
            for (int i = 0; i < methods.length; i++) {
                if (methods[i].getName().equals("<init>")) {
                    initIndexes.add(new Integer(i));
                }
            }

            // build and sort the method lookup list
            final List methodLookupList = new ArrayList();
            for (int i = 0; i < methods.length; i++) {
                MethodMetaData methodMetaData = BcelMetaDataMaker.createMethodMetaData(methods[i]);
                if (methodFilter(definition, classMetaData, methodMetaData, methods[i])) {
                    continue;
                }
                methodLookupList.add(methods[i]);
            }

            Collections.sort(methodLookupList, BCELMethodComparator.getInstance());

            final Map methodSequences = new HashMap();
            final List proxyMethods = new ArrayList();
            boolean isClassAdvised = false;
            for (int i = 0; i < methods.length; i++) {
                MethodMetaData methodMetaData = BcelMetaDataMaker.createMethodMetaData(methods[i]);
                // filter the methods
                if (methodFilter(definition, classMetaData, methodMetaData, methods[i]) ||
                        methods[i].isStatic()) {
                    continue;
                }

                isClassAdvised = true;
                final MethodGen mg = new MethodGen(methods[i], cg.getClassName(), cpg);

                // take care of identification of overloaded methods by inserting a sequence number
                if (methodSequences.containsKey(methods[i].getName())) {
                    int sequence = ((Integer)methodSequences.get(methods[i].getName())).intValue();
                    methodSequences.remove(methods[i].getName());
                    sequence++;
                    methodSequences.put(methods[i].getName(), new Integer(sequence));
                }
                else {
                    methodSequences.put(methods[i].getName(), new Integer(1));
                }

                final int methodLookupId = methodLookupList.indexOf(methods[i]);
                final int methodSequence = ((Integer)methodSequences.
                        get(methods[i].getName())).intValue();

                //handleCallToOverriddenSuperClassMethod(mg, cg, cpg, factory, methodSequence, context);

                addJoinPointField(cpg, cg, mg, methodSequence);

                // get the join point controller
                final String controllerClassName = definition.getJoinPointController(
                        classMetaData,
                        methodMetaData
                );

                // advise all the constructors
                for (Iterator it2 = initIndexes.iterator(); it2.hasNext();) {
                    final int initIndex = ((Integer)it2.next()).intValue();

                    methods[initIndex] = createJoinPointField(
                            cpg, cg,
                            methods[initIndex],
                            methods[i],
                            factory,
                            methodSequence
                    ).getMethod();
                }

                proxyMethods.add(createProxyMethod(
                        cpg, cg, mg,
                        factory,
                        methodLookupId,
                        methodSequence,
                        methods[i].getAccessFlags(),
                        definition.getUuid(),
                        controllerClassName
                ));

                methods[i] = addPrefixToMethod(mg, methods[i], methodSequence, definition.getUuid());

                mg.setMaxStack();
            }

            if (isClassAdvised) {
View Full Code Here

Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

            if (definitionFile.exists()) {
                // grab the first xmldef definition
                List definitions = DefinitionLoader.loadDefinitionsFromFile(fileName);
                for (Iterator it = definitions.iterator(); it.hasNext();) {
                    AspectWerkzDefinition def = (AspectWerkzDefinition)it.next();
                    if (def.isXmlDef()) {
                        definition = (AspectWerkzDefinitionImpl)def;
                        break;
                    }
                }
            }
View Full Code Here

Examples of org.codehaus.aspectwerkz.definition.AspectWerkzDefinition

     */
    public void transformCode(final Context context, final Klass klass) {

        // loop over all the definitions
        for (Iterator it = m_definitions.iterator(); it.hasNext();) {
            AspectWerkzDefinition definition = (AspectWerkzDefinition)it.next();

            definition.loadAspects(context.getLoader());

            final ClassGen cg = klass.getClassGen();
            ClassMetaData classMetaData = BcelMetaDataMaker.
                    createClassMetaData(context.getJavaClass(cg));

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.