Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: [NEWSDELIVER] Multiple instances of the same class woven against different aspects in an Eclipse plugin [Cross-post]


Didier,

>I try to write an RCP app in which i need multiple instances of the same
>classes woven against different aspects.
I'm not quite sure I understand what you are trying to do. The JVM will only allow one version of a class in the system at once unless they are defined in different, unrelated bundles. Can you explain what you are trying to achieve.


The simplest way to try LTW is to use the Java 5 agent (http://www.eclipse.org/aspectj/doc/next/adk15notebook/ltw-agents.html). We have also just launched an Equinox incubator project to better support aspects in OSGi (http://www.eclipse.org/equinox/incubator/aspects/index.php). Over the next few weeks we will be filling out the Web site and populating the repository.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx

http://w3.hursley.ibm.com/~websterm/

To:        undisclosed-recipients:;
cc:        
Subject:        [NEWSDELIVER] Multiple instances of the same class woven against different aspects in an Eclipse plugin [Cross-post]



Hello,

[Sorry, i cross-posted this in eclipse.technology.aspectj,
eclipse.technology.ajdt, eclipse.technology.equinox because i did not
know exactely who could answer this.]

I try to write an RCP app in which i need multiple instances of the same
classes woven against different aspects.

I don't know how classloading works into the Eclipse OSGi runtime and i
did not find any articles about it on the web.

I tried to use the org.aspectj.weawer.loadtime.WeavingURLClassLoader
provided with AspectJ5 but i can't succeed making it to work inside a
plugin. It seems that my class is already loaded by a parent classloader
(the one of the plugin maybe).

I took care no other reference is made to the classes to weave. I just
refer to those classes via the reflective API via my weaving classloader
like this :

public class TestClassFactory
{
    public static TestInterface newTestClass(URL[] aspectURLs,
        ClassLoader parent) throws ClassNotFoundException
    {
        ClassLoader loader = createClassLoader(aspectURLs, parent);
        Class testClass =
loader.loadClass("org.beuz.lib.aspect1.TestClass");

        try
        {
            Constructor constructor = testClass.getConstructor(new
Class[] {});
            return (TestInterface) constructor.newInstance();
        }
        catch (Exception e)
        {
            // Should note occur
            e.printStackTrace();
        }
        return null;
    }

    private static ClassLoader createClassLoader(URL[] aspectURLs,
        ClassLoader parent)
    {
        if (parent == null)
        {
            parent = TestClassFactory.class.getClassLoader();
        }
        return new MyWeavingClassLoader(aspectURLs, parent);
    }

    private static class MyWeavingClassLoader extends WeavingURLClassLoader
    {
        public MyWeavingClassLoader(URL[] aspectURLs, ClassLoader parent)
        {
            super(parent);
            m_aspectURLs = aspectURLs;

        }

        private URL[] m_aspectURLs;

        @Override
        public URL[] getAspectURLs()
        {
            return m_aspectURLs;
        }
    }
}

Does someone knows how to do this ?

I can send my test with three minimal plugins if someone wants.

Thanks for your help,
Didier




Back to the top