Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-01-05 04:13:14 -0500
committerEike Stepper2012-01-05 04:13:14 -0500
commit4902f67af1d5a8eda901024e60a1ce5b7bd04411 (patch)
tree231d6ffce3d9448692f9788e3e13f29bbc883424
parentc4d77b54ea1984b36ed152f69e920f9d0fade919 (diff)
downloadcdo-4902f67af1d5a8eda901024e60a1ce5b7bd04411.tar.gz
cdo-4902f67af1d5a8eda901024e60a1ce5b7bd04411.tar.xz
cdo-4902f67af1d5a8eda901024e60a1ce5b7bd04411.zip
[366290] Provide an OMBundle.getClasses() method
https://bugs.eclipse.org/bugs/show_bug.cgi?id=366290
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java33
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java38
2 files changed, 55 insertions, 16 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
index 13111b433c..a61c00f2be 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/bundle/AbstractBundle.java
@@ -385,14 +385,33 @@ public abstract class AbstractBundle implements OMBundle, OMBundle.DebugSupport,
int end = path.length() - CLASS_EXTENSION.length();
String className = path.substring(start, end).replace('/', '.');
- try
+ for (;;)
{
- ClassLoader classLoader = getAccessor().getClassLoader();
- return classLoader.loadClass(className);
- }
- catch (ClassNotFoundException ex)
- {
- //$FALL-THROUGH$
+ try
+ {
+ ClassLoader classLoader = getAccessor().getClassLoader();
+ Class<?> c = classLoader.loadClass(className);
+ if (c != null)
+ {
+ return c;
+ }
+ }
+ catch (NoClassDefFoundError ex)
+ {
+ //$FALL-THROUGH$
+ }
+ catch (ClassNotFoundException ex)
+ {
+ //$FALL-THROUGH$
+ }
+
+ int dot = className.indexOf('.');
+ if (dot == -1)
+ {
+ break;
+ }
+
+ className = className.substring(dot + 1);
}
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java
index 8090a07251..5c965fa0e1 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/OSGiBundle.java
@@ -25,6 +25,8 @@ import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Queue;
/**
* @author Eike Stepper
@@ -64,26 +66,44 @@ public class OSGiBundle extends AbstractBundle
public Iterator<Class<?>> getClasses()
{
- final Bundle bundle = getBundleContext().getBundle();
+ final Queue<String> folders = new LinkedList<String>();
+ folders.offer("/");
return new AbstractIterator<Class<?>>()
{
- private Enumeration<String> entryPaths = bundle.getEntryPaths("/");
+ private Enumeration<String> entryPaths;
@Override
protected Object computeNextElement()
{
- while (entryPaths.hasMoreElements())
+ for (;;)
{
- String entryPath = entryPaths.nextElement();
- Class<?> c = getClassFromBundle(entryPath);
- if (c != null)
+ while (entryPaths != null && entryPaths.hasMoreElements())
{
- return c;
+ String entryPath = entryPaths.nextElement();
+ if (entryPath.endsWith("/"))
+ {
+ folders.offer(entryPath);
+ }
+ else
+ {
+ Class<?> c = getClassFromBundle(entryPath);
+ if (c != null)
+ {
+ return c;
+ }
+ }
}
- }
- return END_OF_DATA;
+ String folder = folders.poll();
+ if (folder == null)
+ {
+ return END_OF_DATA;
+ }
+
+ Bundle bundle = getBundleContext().getBundle();
+ entryPaths = bundle.getEntryPaths(folder);
+ }
}
};
}

Back to the top