commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Tripodi <>
Subject [Lang] a bit of commons-style code in search of a home
Date Sun, 12 Sep 2010 14:42:05 GMT
Hi all guys,
during my last year of work I've met a replicated behavior in
different projects, like the classpath analysis. Scanning the
classpath could be useful to dynamically find services implementations
or to generate custom documentation, or some other uses nobody has not
envisioned yet.
Follow below a short list of met use cases:

- Misko Hevery of Google developed a light yet powerful classpath
explorer, but it seems the project has a very low activity, you can
find more info on;

- The MyBatis (formerly Apache iBatis) project added an utility class
to discover MyBatis components from the classpath

- The Jersey (JAX-RS) project has a config parameter,
"", where users can specify
packages where look for JSR311 components, like showed at "1.2.
Deploying the root resource" on

For this reason, I think that something from the threes can be reused
and improved to create a common stuff to scan the classpath.

First of all, no more package-based filter policy only, but rather
something closer to an expression language, like

    Filter filter = and(

Second, since analyzing the classpath is an operation that could take
a long time, I think that the "scan" operation should accept one (or
optionally more) classpath handler, each one accepts one filter (as
described above) associated to one (or optionally more) classpath
entry handler. To be more clear, I'd like to show an example:

scan(new ClassPathHandler(and(
                new ClassPathEntryHandler() {

                    public void doHandle(ClassPathEntry classPathEntry) {
                        Class<?> type = classPathEntry.getClazz();
                        // manipulate the class

                new ClassPathEntryHandler() {

                    public void doHandle(ClassPathEntry classPathEntry) {
                        if (log.isInfoEnabled()) {
                  "Plugged in my ACME system " +

            ), new ClassPathHandler(any(), new ClassPathEntryHandler() {

                public void doHandle(ClassPathEntry classPathEntry) {
                        if (log.isDebugEnabled()) {
                            log.debug("Plugged class " + classPathEntry);


Finally, the bootstrap:
 * a classpath could be created starting from the JVM one (the
System.getProperty("java.class.path")) or from a custom one (like the
one in a Servlet context);
 * a custom ClassLoader or the default
Thread.currentThread().getContextClassLoader() is needed to resolve
classpath entries to Class<?> object;
 * an error Handler (a default one is provided) is needed to catch
eventual errors that could occur while scanning the classpath.
That could be resumed in a chained builders, like:

ClassPath classPath =  new ClassPathBuilder()

A codebase for this already exists, I committed it on Google-Code
( and licensed it under ASL2.0. If you
guys agree I'd be more than happy to port it under Commons-Lang (at
least my instinct suggested Lang as the better place).

WDYT? Thanks in advance and thanks for reading, I hop you'ven't got bored :P
Have a nice day,

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message