[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: New ClassLoader initial checkin

adrian@jboss.org do-not-reply at jboss.com
Fri Apr 27 07:08:15 EDT 2007


Some details

Loaders

A lot of the code is based on Loaders, well really DelegateLoaders.
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/Loader.java
which do what you might expect.

Although I can support raw Loaders in some places (e.g. as parents of a Domain), 
most places need DelegateLoaders. That is a Loader associated with a ClassLoaderPolicy
and transitively a ClassLoader.

DelegateLoaders

The DelegateLoaders are Loaders associated with a Policy.
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/DelegateLoader.java
They can also implement additional rules. e.g. for handling imports or exports
you can add a filter.
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/filter/FilteredDelegateLoader.java

ClassFilter

ClassFilters let you decide what parts of a delegate classloader you are going to
import or export.
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/filter/ClassFilter.java
There are some standard ones defined like EVERYTHING and NOTHING in that class.

Examples.

A DelegateLoader that imports only a certain package

  | new FilteredDelegateLoader(policy, new PackageClassFilter(new String[] { "com.acme" });
  | 

Only importing java.* and javax.* from the parent of your domain

  | ClassLoadingSystem system = ClassLoadingSystem.getInstance();
  | system.createAndRegisterDomain("MyDomain", ParentPolicy.BEFORE_BUT_ONLY_JAVA);
  | 
See https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/spi/ParentPolicy.java
for more on the parent policy.

Domains allow multiple hierarchies and not just delegation to another domain.

  | Loader parent = ...;
  | system.createAndRegisterDomain("MyDomain", ParentPolicy.BEFORE, parent);
  | 
this works because ClassLoadingDomains are also Loaders.

If you don't specify a parent then it uses the ClassLoader that defines
the org.jboss.classloader classes as the parent, via an adapter
https://svn.jboss.org/repos/jbossas/projects/microcontainer/trunk/classloader/src/main/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4041344#4041344

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4041344



More information about the jboss-dev-forums mailing list