You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2006/02/06 11:59:20 UTC
svn commit: r375245 - in
/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix:
framework/BundleImpl.java framework/Felix.java moduleloader/IContent.java
moduleloader/JarContent.java
Author: rickhall
Date: Mon Feb 6 02:59:19 2006
New Revision: 375245
URL: http://svn.apache.org/viewcvs?rev=375245&view=rev
Log:
Initial implementation of Bundle.getEntryPaths().
Modified:
incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java
incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IContent.java
incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/JarContent.java
Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=375245&r1=375244&r2=375245&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleImpl.java Mon Feb 6 02:59:19 2006
@@ -60,6 +60,11 @@
return m_felix.getBundleEntry(this, name);
}
+ public Enumeration getEntryPaths(String path)
+ {
+ return m_felix.getBundleEntryPaths(this, path);
+ }
+
public Dictionary getHeaders()
{
return m_felix.getBundleHeaders(this);
@@ -165,12 +170,6 @@
public Enumeration getResources(String name) throws IOException
{
// TODO: Implement Bundle.getResources()
- return null;
- }
-
- public Enumeration getEntryPaths(String path)
- {
- // TODO: Implement Bundle.getEntryPaths()
return null;
}
Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java?rev=375245&r1=375244&r2=375245&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java Mon Feb 6 02:59:19 2006
@@ -984,6 +984,29 @@
.getContentLoader()).getResourceFromContent(name);
}
+ /**
+ * Implementation for Bundle.getEntryPaths().
+ **/
+ protected Enumeration getBundleEntryPaths(BundleImpl bundle, String path)
+ {
+ if (bundle.getInfo().getState() == Bundle.UNINSTALLED)
+ {
+ throw new IllegalStateException("The bundle is uninstalled.");
+ }
+// TODO: SECURITY - Implement correct check.
+ else if (System.getSecurityManager() != null)
+ {
+ AccessController.checkPermission(m_adminPerm);
+ }
+ // Strip leading '/' if present.
+ if (path.charAt(0) == '/')
+ {
+ path = path.substring(1);
+ }
+ return bundle.getInfo().getCurrentModule()
+ .getContentLoader().getContent().getEntryPaths(path);
+ }
+
protected ServiceReference[] getBundleRegisteredServices(BundleImpl bundle)
{
if (bundle.getInfo().getState() == Bundle.UNINSTALLED)
Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IContent.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IContent.java?rev=375245&r1=375244&r2=375245&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IContent.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/IContent.java Mon Feb 6 02:59:19 2006
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.Enumeration;
public interface IContent
{
@@ -27,5 +28,5 @@
public byte[] getEntry(String name);
public InputStream getEntryAsStream(String name)
throws IOException;
- public String[] getEntryPaths(String path);
+ public Enumeration getEntryPaths(String path);
}
Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/JarContent.java
URL: http://svn.apache.org/viewcvs/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/JarContent.java?rev=375245&r1=375244&r2=375245&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/JarContent.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/moduleloader/JarContent.java Mon Feb 6 02:59:19 2006
@@ -17,8 +17,8 @@
package org.apache.felix.moduleloader;
import java.io.*;
-import java.io.File;
-import java.io.IOException;
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
@@ -224,9 +224,31 @@
return is;
}
- public String[] getEntryPaths(String path)
+ public synchronized Enumeration getEntryPaths(String path)
{
- return null;
+ if (!m_opened)
+ {
+ throw new IllegalStateException("JarContent is not open");
+ }
+
+ // Open JAR file if not already opened.
+ if (m_jarFile == null)
+ {
+ try
+ {
+ openJarFile();
+ }
+ catch (IOException ex)
+ {
+ System.err.println("JarResourceSource: " + ex);
+ return null;
+ }
+ }
+
+ // Wrap entries enumeration to filter non-matching entries.
+ Enumeration e = new FilteredEnumeration(m_jarFile.entries(), path);
+ // Spec says to return null if there are no entries.
+ return (e.hasMoreElements()) ? e : null;
}
private void openJarFile() throws IOException
@@ -240,5 +262,50 @@
public String toString()
{
return "JAR " + m_file.getPath();
+ }
+
+ private static class FilteredEnumeration implements Enumeration
+ {
+ private Enumeration m_enumeration = null;
+ private String m_path = null;
+ private Object m_next = null;
+
+ public FilteredEnumeration(Enumeration enumeration, String path)
+ {
+ m_enumeration = enumeration;
+ // Add a '/' to the end if not present.
+ m_path = (path.length() > 0) && (path.charAt(path.length() - 1) != '/')
+ ? path + "/" : path;
+ m_next = findNext();
+ }
+
+ public boolean hasMoreElements()
+ {
+ return (m_next != null);
+ }
+
+ public Object nextElement()
+ {
+ if (m_next == null)
+ {
+ throw new NoSuchElementException("No more entry paths.");
+ }
+ Object last = m_next;
+ m_next = findNext();
+ return last;
+ }
+
+ private Object findNext()
+ {
+ while (m_enumeration.hasMoreElements())
+ {
+ ZipEntry entry = (ZipEntry) m_enumeration.nextElement();
+ if (entry.getName().startsWith(m_path))
+ {
+ return entry.getName();
+ }
+ }
+ return null;
+ }
}
}