[jboss-dev-forums] [JBoss Microcontainer Development POJO Server] - Re: VFS doesn't support scanning

Guillaume Grossetie do-not-reply at jboss.com
Thu Sep 9 07:09:35 EDT 2010


Guillaume Grossetie [http://community.jboss.org/people/grossetieg] created the discussion

"Re: VFS doesn't support scanning"

To view the discussion, visit: http://community.jboss.org/message/560683#560683

--------------------------------------------------------------
Hi,

What is the right way to scan classes in a package with VFS ?
I've tried something like :
List<Class<? extends Enum<?>>> result = new ArrayList<Class<? extends Enum<?>>>();
ClassLoader cld = Thread.currentThread().getContextClassLoader();
if (null != cld) {
     final String pkgPath = packageName.replace('.', '/');
     URL resource = cld.getResource(pkgPath);
     VirtualFile file = VFS.getChild(resource);
 
     List<VirtualFile> children = file.getChildrenRecursively();
     for (VirtualFile child : children) {
          if (child.isFile()) {
               Class<?> clazz = Class.forName(packageName.concat(".").concat(child.getName().split("\\.")[0]));
               if (clazz.isEnum()) {
                    result.add((Class<Enum<?>>) clazz);
               }
          }
     }
}


But the package isn't a directory and getChildrenRecursively() return an empty list. We, previously in JBoss 4.2.3, used :
List<Class<? extends Enum<?>>> result = new ArrayList<Class<? extends Enum<?>>>();
ClassLoader cld = Thread.currentThread().getContextClassLoader();
if (null != cld) {
     String pkgPath = packageName.replace('.', '/');
     URL resource = cld.getResource(pkgPath);
     if (null != resource) {
          if (resource.getProtocol().equals("jar")) {
               int index = resource.getPath().indexOf('!');
               // on extrait le chemin du jar
               String fullJarPathWithName = resource.getPath().substring(5, index);
               List<Class<? extends Enum<?>>> classes = getEnumClassesFromJar(fullJarPathWithName, packageName, pkgPath);
               if (null != classes) {
                    result.addAll(classes);
               }
          }
     }
}


But with VFS the path doesn't contain ! anymore.

We also tried with a visitor pattern but without success. I've read the article at dzone but some classes doesn't exist anymore (SuffixVisitor in jboss-vfs.3.0.0.CR5.jar).

Thanks in advance.

Guillaume.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/560683#560683]

Start a new discussion in JBoss Microcontainer Development POJO Server at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2116]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20100909/9b8f26f1/attachment.html 


More information about the jboss-dev-forums mailing list