Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Class loading problem

I imagine we could make the 'fetching of classes' a pluggable thing so
if you have another strategy for getting hold of them, you could
supply it.  Possibly another method on the weaving context (that you
could override in your MonitorWeavingContext).  You should raise an
enhancement request for this change.

Andy

On 2 June 2010 06:32, "C. Knappe (GSD)" <cknappe@xxxxxxxxxxxxxxxx> wrote:
>
> Hello,
>
> I am working on a custom class loading system which gets classes from a database. Before defining the classes in this loader I use a ClassLoaderWeavingAdaptor.
>
> I do:
>
>        ClassLoaderWeavingAdaptor clwa = new ClassLoaderWeavingAdaptor();
>        clwa.initialize(this, new MonitorWeavingContext(this)); // this is the database class loader instance
>
>
> The WeavingContext looks like this..
>
>        private class MonitorWeavingContext extends DefaultWeavingContext {
>
>                private ClassLoader loader;
>
>                public MonitorWeavingContext(ClassLoader loader) {
>                        super(loader);
>                        this.loader = loader;
>                }
>
>                @Override
>                public List<Definition> getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) {
>                        System.out.println("CALLED getDefinitions for " + loader);
>                        List<Definition> definitions = new ArrayList<Definition>();
>                        Definition d = new Definition();
>                        d.getAspectClassNames().add("com.gsdsoftware.sys.AppStateWriter");
>                        d.appendWeaverOptions("-Xjoinpoints:synchronization");
> //                      d.appendWeaverOptions("-debug");
> //                      d.appendWeaverOptions("-verbose");
>                        d.appendWeaverOptions("-showWeaveInfo");
>                        definitions.add(d);
>                        return definitions;
>                }
>
>                @Override
>                public String getClassLoaderName(){
>                        System.out.println("getClassLoaderName");
>                        return this.loader.getClass().getName();
>                }
>
>                @Override
>                public ClassLoader getClassLoader(){
>                        System.out.println("getClassLoader...");
>                        return this.loader;
>                }
>        }
>
>
> after having initialized the Adaptor I call:
>
>        clwa.weaveClass(name, bytes, true);
>
> The problem is, that in the weaving process some classes are needed which comes also from database.
>
> I changed the private method lookupJavaClass(ClassPathManager classPath, String name) in BcelWorld java file.
> In my case the ClassPathManager is null and the delegate (Repository) does not find the class.
> So after the ClassNotFoundException is throw by Repository.loadClass(name) I added code to get JavaClass from database.
>
> Code block looks like this:
>
>                if (classPath == null) {
>                        try {
>
>                                ensureRepositorySetup();
>                                JavaClass jc = delegate.loadClass(name);
>                                if (trace.isTraceEnabled()) {
>                                        trace.event("lookupJavaClass", this, new Object[] { name, jc });
>                                }
>                                return jc;
>                        } catch (ClassNotFoundException e) {
>
>                                // cknappe
>                                JavaClass jc = null;
>                                DBLoader myLoader = (DBLoader) this.loaderRef.getClassLoader();
>
>                                ClassParser parser = new ClassParser(myLoader.getResourceAsStream(name), name);
>                                try {
>                                        jc = parser.parse();
>                                        return jc;
>                                } catch (ClassFormatException cfex) {
>
>                                } catch (IOException ioex) {
>
>                                }
>                                // cknappe
>
>                                if (trace.isTraceEnabled()) {
>                                        trace.error("Unable to find class '" + name + "' in repository", e);
>                                }
>                                return null;
>                        }
>                }
>
> This works fine for me but I wonder if there should not be an other way to get this thing work without changing aspectj code.
>
> Thanks a lot for your replies.
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-dev
>


Back to the top