felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r372822 - in /incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader: ./ search/ search/compatibility/ search/selection/
Date Fri, 27 Jan 2006 12:31:30 GMT
Author: rickhall
Date: Fri Jan 27 04:31:01 2006
New Revision: 372822

URL: http://svn.apache.org/viewcvs?rev=372822&view=rev
Log:
EXPERIMENTAL!
The changes reflect a major refactoring to the Module Loader layer in
Felix. They are necessary for a variety of reasons, but were instigated
by the immediate need to find a clean way to implement Bundle.getEntry()
related methods, which entailed changing the module abstraction of
the Module Loader.

Previously, a module was largely defined as being a set of resource
sources that returned bytes that were converted into either resources
or classes by the module's class loader. The resource sources were mapped
onto the bundle JAR file and any corresponding embedded JAR files. One
issue with this approach is that it was not cleanly possible to access
the "raw" module contents without breaking the module abstraction, which
was necessary for Bundle.getEntry() related methods. Another issue is
that there is no clean way for a module to have a source for classes
that is not a set of bytes; for example, the system bundle actually has
the system class loader as a source, since it needs to fake exporting
classes on the class path.

The new module abstraction addresses these sorts of issues by defining
a module as having a content loader. The content loader is defined as
having content, where the interpretation of that content is determined
by the content loader implementation. For example, an OSGi content loader
knows about embedded JAR files and bundle class path. Access to the "raw"
module content is made possible through the content object.

It is very likely that these interfaces will change, so only look at
this code to get an understanding of what it going on.

Added:
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContent.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContentLoader.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IExport.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IImport.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModule.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleCallback.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IPackage.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java
      - copied, changed from r370894, incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/SearchPolicy.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IWire.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/JarContent.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/LibrarySource.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleCallbackImpl.java   (with props)
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java
      - copied, changed from r370894, incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleManager.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java
      - copied, changed from r370894, incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/Module.java
Removed:
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/DefaultURLPolicy.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/JarResourceSource.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/Module.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleClassLoader.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleManager.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleURLConnection.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleURLStreamHandler.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ResourceSource.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/SearchPolicy.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/URLPolicy.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/CompatibilityPolicy.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/ExhaustiveSearchPolicy.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/ImportSearchPolicy.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/ResolveException.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/ResolveListener.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/SelectionPolicy.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/SelfContainedSearchPolicy.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/ValidationException.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/ValidationListener.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/compatibility/
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/search/selection/
Modified:
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java
    incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleListener.java

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContent.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContent.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContent.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContent.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,31 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.moduleloader;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public interface IContent
+{
+    public void open();
+    public void close();
+    public boolean hasEntry(String name);
+    public byte[] getEntry(String name);
+    public InputStream getEntryAsStream(String name)
+        throws IOException;
+    public String[] getEntryPaths(String path);
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContentLoader.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContentLoader.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContentLoader.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContentLoader.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,38 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.moduleloader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+public interface IContentLoader
+{
+    public IContent getContent();
+
+    public void setModuleCallback(IModuleCallback callback);
+    public IModuleCallback getModuleCallback();
+
+    public Class getClass(String name);
+    public URL getResource(String name);
+
+    // getResourceAsStream() was used instead of getResourceBytes()
+    // because the content loader for the system bundle must delegate
+    // to "ParentClassLoader.getResourceAsStream()".
+    public InputStream getResourceAsStream(String name)
+        throws IOException;
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IContentLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IExport.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IExport.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IExport.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IExport.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,8 @@
+package org.apache.felix.moduleloader;
+
+
+public interface IExport extends IPackage
+{
+    public String[] getUses();
+    public boolean isIncluded(String name);
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IExport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IImport.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IImport.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IImport.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IImport.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,10 @@
+package org.apache.felix.moduleloader;
+
+import org.osgi.framework.Version;
+
+public interface IImport extends IPackage
+{
+    public Version getVersionHigh();
+    public boolean isOptional();
+    public boolean isSatisfied(IExport export);
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IImport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModule.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModule.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModule.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModule.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,34 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.moduleloader;
+
+import java.net.URL;
+
+public interface IModule
+{
+    public String getId();
+    public ISearchPolicy getSearchPolicy();
+    public IURLPolicy getURLPolicy();
+    public IContentLoader getContentLoader();
+
+    public Object[][] getAttributes();
+    public Object getAttribute(String key, Object defaultValue);
+    public void setAttribute(String key, Object value);
+
+    public Class getClass(String name);
+    public URL getResource(String name);
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleCallback.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleCallback.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleCallback.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleCallback.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,13 @@
+package org.apache.felix.moduleloader;
+
+import java.net.URL;
+
+import org.apache.felix.moduleloader.ResourceNotFoundException;
+
+public interface IModuleCallback
+{
+    public Class findClass(String name) throws ClassNotFoundException;
+    public URL findResource(String name) throws ResourceNotFoundException;
+
+    public URL createURL(String path);
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,31 @@
+/*
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.moduleloader;
+
+public interface IModuleFactory
+{
+    public ISearchPolicy getSearchPolicy();
+
+    public IModule[] getModules();
+    public IModule getModule(String id);
+    public IModule createModule(
+        String id, IContentLoader contentLoader, Object[][] attrs);
+
+    public void removeModule(IModule module);
+    public void addModuleListener(ModuleListener l);
+    public void removeModuleListener(ModuleListener l);
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IModuleFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IPackage.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IPackage.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IPackage.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IPackage.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,13 @@
+package org.apache.felix.moduleloader;
+
+import org.apache.felix.framework.searchpolicy.R4Attribute;
+import org.apache.felix.framework.searchpolicy.R4Directive;
+import org.osgi.framework.Version;
+
+public interface IPackage
+{
+    public String getName();
+    public R4Directive[] getDirectives();
+    public R4Attribute[] getAttributes();
+    public Version getVersion();
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IPackage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java (from r370894, incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/SearchPolicy.java)
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java?p2=incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java&p1=incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/SearchPolicy.java&r1=370894&r2=372822&rev=372822&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/SearchPolicy.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ISearchPolicy.java Fri Jan 27 04:31:01 2006
@@ -1,5 +1,5 @@
 /*
- *   Copyright 2005 The Apache Software Foundation
+ *   Copyright 2006 The Apache Software Foundation
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -18,217 +18,17 @@
 
 import java.net.URL;
 
-/**
- * <p>
- * This interface represents a policy to define the most basic behavior
- * of how classes, resources, and native libraries within a specific instance
- * of <tt>ModuleManager</tt> are found. A <tt>ModuleManager</tt> manages a set of
- * <tt>Module</tt>s, each of which is a potential source of classes, resources,
- * and native libraries. The search policy makes it possible to consult these
- * sources without hard-coding assumptions about application behavior
- * or structure. Applicaitons inject their own specific class loading policy
- * by creating a custom search policy or by selecting a pre-existing search
- * policy that matches their needs.
- * </p>
- * <p>
- * The search policy is used by <tt>ModuleClassLoader</tt>, of which, there
- * is one per <tt>Module</tt> within a given <tt>ModuleManager</tt> instance.
- * The search policy is consulted by the <tt>ModuleClassLoader</tt> whenever
- * there is a request for a class, resource, or native library. The search
- * policy will generally search other modules in an application-specific
- * way in order to find the requested item; for example, an application may
- * use a policy where module's may import from one another. If the search
- * policy provides an answer, then the <tt>ModuleClassLoader</tt> will use
- * this to answer the originating request.
- * </p>
- * <p>
- * <b><i>Important:</i></b> The search policy <i>searches</i> modules in
- * some application-specific manner in order to find a class or resource.
- * This <i>search</i> is instigated, either directly or indirectly, by calls
- * to <tt>ModuleClassLoader.loadClass()</tt> and <tt>ModuleClassLoader.getResource()</tt>,
- * respectively. In order for the search policy to load a class or resource,
- * it must <b>not</b> use <tt>ModuleClassLoader.loadClass()</tt> or
- * <tt>ModuleClassLoader.getResource()</tt> again, because this would result
- * in an infinite loop. Instead, the <tt>ModuleClassLoader</tt> offers the
- * the methods <tt>ModuleClassLoader.loadClassFromModule()</tt> and
- * <tt>ModuleClassLoader.getResourceFromModule()</tt> to search a given module
- * and to avoid an infinite loop.
- * </p>
- * <pre>
- *     ...
- *     public Class findClass(Module module, String name)
- *     {
- *         Module[] modules = m_mgr.getModules();
- *         for (int i = 0; i < modules.length; i++)
- *         {
- *             try {
- *                 Class clazz = modules[i].getClassLoader().loadClassFromModule(name);
- *                 if (clazz != null)
- *                 {
- *                     return clazz;
- *                 }
- *             } catch (Throwable th) {
- *             }
- *         }
- *
- *         return null;
- *     }
- *     ...
- * </pre>
- * <p>
- * In the above code, the search policy "exhaustively" searches every module in the
- * <tt>ModuleManager</tt> to find the requested resource. Note that this policy
- * will also search the module that originated the request, which is not totally
- * necessary since returning <tt>null</tt> will cause the <tt>ModuleClassLoader</tt>
- * to search the originating module's <tt>ResourceSource</tt>s.
- * </p>
-**/
-public interface SearchPolicy
-{
-    /**
-     * <p>
-     * This method is called once by the <tt>ModuleManager</tt> to
-     * give the search policy instance a reference to its associated
-     * module manager. This method should be implemented such that
-     * it cannot be called twice; calling this method a second time
-     * should produce an illegal state exception.
-     * </p>
-     * @param mgr the module manager associated with this search policy.
-     * @throws java.lang.IllegalStateException if the method is called
-     *         more than once.
-    **/
-    public void setModuleManager(ModuleManager mgr)
-        throws IllegalStateException;
+import org.apache.felix.moduleloader.ResourceNotFoundException;
 
-    /**
-     * <p>
-     * The <tt>ModuleClassLoader</tt> calls this method before performing
-     * the call to <tt>ClassLoader.defineClass()</tt> to give the search policy
-     * an opportunity to define the <tt>Package</tt> object for the specified
-     * package. The method should return an array of <tt>String</tt> values for
-     * each of the following: specTitle, specVersion, specVendor, implTitle,
-     * implVersion, and implVendor. See <tt>ClassLoader.definePackage()</tt>
-     * for more details. The returned array may contain <tt>null</tt>s, but
-     * the return array must have six elements.
-     * </p>
-     * @param module the module requesting a class from the package.
-     * @param pkgName the package name of the class being requested.
-     * @return an array containing values for creating the <tt>Package</tt>
-     *         object for the specified package.
-    **/
-    public Object[] definePackage(Module module, String pkgName);
-
-    /**
-     * <p>
-     * When a module instigates a class load operation, this method is called
-     * to find the desired class for the instigating module. This method is
-     * called <b>before</b> searching the module's resource sources for the class.
-     * How the class is found is dependent upon the search policy implementation.
-     * </p>
-     * <p>
-     * This method may return <tt>null</tt> or throw an exception if the
-     * specified class is not found. Whether a specific search policy
-     * implementation should do one or the other depends on the details
-     * of the specific search policy. The <tt>ModuleClassLoader</tt>
-     * first delegates to this method, then to the local resources
-     * sources of the module, and then finally to then the
-     * <tt>SearchPolicy.findClassAfterModule()</tt> method. If this method
-     * returns null, then the search for the class will continue to these
-     * latter two steps. On the other hand, if this method returns a class
-     * or throws an exception, then the latter two steps will not be searched.
-     * </p>
-     * <p>
-     * <b>Important:</b> If the implementation of this method delegates
-     * the class loading to a <tt>ModuleClassLoader</tt> of another module,
-     * then it should <b>not</b> use the method <tt>ModuleClassLoader.loadClass()</tt>
-     * to load the class; it should use <tt>ModuleClassLoader.loadClassFromModule()</tt>
-     * instead. This is necessary to eliminate an infinite loop that would
-     * occur otherwise. Also, with respect to the <tt>ModuleLoader</tt> framework,
-     * this method will only be called by a single thread at a time and is only
-     * intended to be called by <tt>ModuleClassLoader.loadClass()</tt>.
-     * </p>
-     * @param parent the parent class loader of the delegating class loader.
-     * @param module the target module that is loading the class.
-     * @param name the name of the class being loaded.
-     * @return the class if found, <tt>null</tt> otherwise.
-     * @throws java.lang.ClassNotFoundException if the class could not be
-     *         found and the entire search operation should fail.
-    **/
-    public Class findClassBeforeModule(ClassLoader parent, Module module, String name)
-        throws ClassNotFoundException;
+public interface ISearchPolicy
+{
+    public IModuleFactory getModuleFactory();
+    public void setModuleFactory(IModuleFactory factory);
 
-    /**
-     * <p>
-     * When a module instigates a class load operation, this method is called
-     * to find the desired class for the instigating module. This method is
-     * called <b>after</b> searching the module's resource sources for the class.
-     * How the class is found is dependent upon the search policy implementation.
-     * </p>
-     * <p>
-     * The <tt>ModuleClassLoader</tt> first delegates to the
-     * <tt>SearchPolicy.findClassBeforeModule() method, then to the local
-     * resources sources of the module, and then finally to this method.
-     * This method is the last attempt to find the class and if it fails
-     * (by either return <tt>null</tt> or throwing an exception), then the
-     * result of the entire class load will fail.
-     * </p>
-     * <p>
-     * <b>Important:</b> If the implementation of this method delegates
-     * the class loading to a <tt>ModuleClassLoader</tt> of another module,
-     * then it should <b>not</b> use the method <tt>ModuleClassLoader.loadClass()</tt>
-     * to load the class; it should use <tt>ModuleClassLoader.loadClassFromModule()</tt>
-     * instead. This is necessary to eliminate an infinite loop that would
-     * occur otherwise. Also, with respect to the <tt>ModuleLoader</tt> framework,
-     * this method will only be called by a single thread at a time and is only
-     * intended to be called by <tt>ModuleClassLoader.loadClass()</tt>.
-     * </p>
-     * @param parent the parent class loader of the delegating class loader.
-     * @param module the target module that is loading the class.
-     * @param name the name of the class being loaded.
-     * @return the class if found, <tt>null</tt> otherwise.
-     * @throws java.lang.ClassNotFoundException if the class could not be
-     *         found and the entire search operation should fail.
-    **/
-    public Class findClassAfterModule(ClassLoader parent, Module module, String name)
+    public Class findClass(IModule module, String name)
         throws ClassNotFoundException;
-
-    /**
-     * <p>
-     * This method tries to find the specified resource for the specified
-     * module. How the resource is found or whether it is actually retrieved
-     * from the specified module is dependent upon the implementation. The
-     * default <tt>ModuleClassLoader.getResource()</tt> method does not do
-     * any searching on its own.
-     * </p>
-     * <p>
-     * This method may return <tt>null</tt> or throw an exception if the
-     * specified resource is not found. Whether a specific search policy
-     * implementation should do one or the other depends on the details
-     * of the specific search policy. The <tt>ModuleClassLoader</tt>
-     * first delegates to this method and then to the local resource
-     * sources of the module. If this method returns null, then the local
-     * resource sources will be searched. On the other hand, if this method
-     * throws an exception, then the local resource sources will not be
-     * searched.
-     * </p>
-     * <p>
-     * <b>Important:</b> If the implementation of this method delegates
-     * the resource loading to a <tt>ModuleClassLoader</tt> of another module,
-     * then it should not use the method <tt>ModuleClassLoader.getResource()</tt>
-     * to get the resource; it should use <tt>ModuleClassLoader.getResourceFromModule()</tt>
-     * instead. This is necessary to eliminate an infinite loop that would
-     * occur otherwise. Also, with respect to the <tt>ModuleLoader</tt> framework,
-     * this method will only be called by a single thread at a time and is not
-     * intended to be called directly.
-     * </p>
-     * @param parent the parent class loader of the delegating class loader.
-     * @param module the target module that is loading the resource.
-     * @param name the name of the resource being loaded.
-     * @return a <tt>URL</tt> to the resource if found, <tt>null</tt> otherwise.
-     * @throws org.apache.felix.moduleloader.ResourceNotFoundException if the
-     *         resource could not be found and the entire search operation
-     *         should fail.
-    **/
-    public URL findResource(ClassLoader parent, Module module, String name)
+    public URL findResource(IModule module, String name)
         throws ResourceNotFoundException;
+
+    public URL createURL(IModule module, String path);
 }

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,8 @@
+package org.apache.felix.moduleloader;
+
+import java.net.URL;
+
+public interface IURLPolicy
+{
+    public URL createURL(IModule m_module, String path);
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IURLPolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IWire.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IWire.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IWire.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IWire.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,12 @@
+package org.apache.felix.moduleloader;
+
+import java.net.URL;
+
+public interface IWire
+{
+    public IModule getImportingModule();
+    public IModule getExportingModule();
+    public IExport getExport();
+    public Class getClass(String name);
+    public URL getResource(String name);
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/IWire.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/JarContent.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/JarContent.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/JarContent.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/JarContent.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,228 @@
+package org.apache.felix.moduleloader;
+
+import java.io.*;
+import java.io.File;
+import java.io.IOException;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+
+public class JarContent implements IContent
+{
+    private static final int BUFSIZE = 4096;
+
+    private File m_file = null;
+    private JarFile m_jarFile = null;
+    private boolean m_opened = false;
+
+    public JarContent(File file)
+    {
+        m_file = file;
+    }
+
+    protected void finalize()
+    {
+        if (m_jarFile != null)
+        {
+            try
+            {
+                m_jarFile.close();
+            }
+            catch (IOException ex)
+            {
+                // Not much we can do, so ignore it.
+            }
+        }
+    }
+
+    public void open()
+    {
+        m_opened = true;
+    }
+
+    public synchronized void close()
+    {
+        try
+        {
+            if (m_jarFile != null)
+            {
+                m_jarFile.close();
+            }
+        }
+        catch (Exception ex)
+        {
+            System.err.println("JarContent: " + ex);
+        }
+
+        m_jarFile = null;
+        m_opened = false;
+    }
+
+    public synchronized boolean hasEntry(String name) throws IllegalStateException
+    {
+        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("JarContent: " + ex);
+                return false;
+            }
+        }
+
+        try
+        {
+            ZipEntry ze = m_jarFile.getEntry(name);
+            return ze != null;
+        }
+        catch (Exception ex)
+        {
+            return false;
+        }
+        finally
+        {
+        }
+    }
+
+    public synchronized byte[] getEntry(String name) throws IllegalStateException
+    {
+        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;
+            }
+        }
+
+        // Get the embedded resource.
+        InputStream is = null;
+        ByteArrayOutputStream baos = null;
+
+        try
+        {
+            ZipEntry ze = m_jarFile.getEntry(name);
+            if (ze == null)
+            {
+                return null;
+            }
+            is = m_jarFile.getInputStream(ze);
+            if (is == null)
+            {
+                return null;
+            }
+            baos = new ByteArrayOutputStream(BUFSIZE);
+            byte[] buf = new byte[BUFSIZE];
+            int n = 0;
+            while ((n = is.read(buf, 0, buf.length)) >= 0)
+            {
+                baos.write(buf, 0, n);
+            }
+            return baos.toByteArray();
+
+        }
+        catch (Exception ex)
+        {
+            return null;
+        }
+        finally
+        {
+            try
+            {
+                if (baos != null) baos.close();
+            }
+            catch (Exception ex)
+            {
+            }
+            try
+            {
+                if (is != null) is.close();
+            }
+            catch (Exception ex)
+            {
+            }
+        }
+    }
+
+    public synchronized InputStream getEntryAsStream(String name)
+        throws IllegalStateException, IOException
+    {
+        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;
+            }
+        }
+
+        // Get the embedded resource.
+        InputStream is = null;
+
+        try
+        {
+            ZipEntry ze = m_jarFile.getEntry(name);
+            if (ze == null)
+            {
+                return null;
+            }
+            is = m_jarFile.getInputStream(ze);
+            if (is == null)
+            {
+                return null;
+            }
+        }
+        catch (Exception ex)
+        {
+            return null;
+        }
+
+        return is;
+    }
+
+    public String[] getEntryPaths(String path)
+    {
+        return null;
+    }
+
+    private void openJarFile() throws IOException
+    {
+        if (m_jarFile == null)
+        {
+            m_jarFile = new JarFile(m_file);
+        }
+    }
+
+    public String toString()
+    {
+        return "JAR " + m_file.getPath();
+    }
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/JarContent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/LibrarySource.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/LibrarySource.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/LibrarySource.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/LibrarySource.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,67 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.felix.moduleloader;
+
+/**
+ * <p>
+ * This interface represents a source for obtaining native libraries for a
+ * given module via the module's class loader. The main goal of a library
+ * source is to map a library name to a path in the file system.
+ * </p>
+ * <p>
+ * All library sources are initialized before first usage via a call
+ * to the <a href="#open()"><tt>LibrarySource.open()</tt></a> method and
+ * are also deinitialized via a call to
+ * <a href="#open()"><tt>LibrarySource.close()</tt></a>. Library sources
+ * should be implemented such that they can be opened, closed, and then
+ * re-opened.
+ * </p>
+ * @see org.apache.felix.moduleloader.ModuleImpl
+ * @see org.apache.felix.moduleloader.ModuleClassLoader
+**/
+public interface LibrarySource
+{
+    /**
+     * <p>
+     * This method initializes the library source. It is called when
+     * the associated module is added to the <tt>ModuleManager</tt>. It
+     * is acceptable for implementations to ignore duplicate calls to this
+     * method if the library source is already opened.
+     * </p>
+    **/
+    public void open();
+
+    /**
+     * <p>
+     * This method de-initializes the library source. It is called when
+     * the associated module is removed from the <tt>ModuleManager</tt> or
+     * when the module is reset by the <tt>ModuleManager</tt>.
+     * </p>
+    **/
+    public void close();
+
+    /**
+     * <p>
+     * Returns a file system path to the specified library.
+     * </p>
+     * @param name the name of the library that is being requested.
+     * @return a file system path to the specified library.
+     * @throws java.lang.IllegalStateException if the resource source has not
+     *         been opened.
+    **/
+    public String getPath(String name) throws IllegalStateException;
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/LibrarySource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleCallbackImpl.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleCallbackImpl.java?rev=372822&view=auto
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleCallbackImpl.java (added)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleCallbackImpl.java Fri Jan 27 04:31:01 2006
@@ -0,0 +1,37 @@
+package org.apache.felix.moduleloader;
+
+import java.net.URL;
+
+import org.apache.felix.moduleloader.ResourceNotFoundException;
+
+public class ModuleCallbackImpl implements IModuleCallback
+{
+    private IModule m_module = null;
+
+    ModuleCallbackImpl(IModule module)
+    {
+        m_module = module;
+    }
+
+    public Class findClass(String name)
+        throws ClassNotFoundException
+    {
+        return m_module.getSearchPolicy().findClass(m_module, name);
+    }
+
+    public URL findResource(String name) throws ResourceNotFoundException
+    {
+        return m_module.getSearchPolicy().findResource(m_module, name);
+    }
+
+    public URL createURL(String path)
+    {
+        return m_module.getURLPolicy().createURL(m_module, path);
+    }
+
+// TODO: FIX - REMOVE.
+    public String toString()
+    {
+        return m_module.toString();
+    }
+}
\ No newline at end of file

Propchange: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleCallbackImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java?rev=372822&r1=372821&r2=372822&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleEvent.java Fri Jan 27 04:31:01 2006
@@ -25,13 +25,13 @@
  * events, a <tt>ModuleListener</tt> must be added to the <tt>ModuleManager</tt>
  * instance.
  * </p>
- * @see org.apache.felix.moduleloader.ModuleManager
- * @see org.apache.felix.moduleloader.Module
+ * @see org.apache.felix.moduleloader.ModuleFactoryImpl
+ * @see org.apache.felix.moduleloader.ModuleImpl
  * @see org.apache.felix.moduleloader.ModuleListener
 **/
 public class ModuleEvent extends EventObject
 {
-    private Module m_module = null;
+    private IModule m_module = null;
 
     /**
      * <p>
@@ -42,9 +42,9 @@
      * @param mgr the source of the event.
      * @param module the subject of the event.
     **/
-    public ModuleEvent(ModuleManager mgr, Module module)
+    public ModuleEvent(IModuleFactory factory, IModule module)
     {
-        super(mgr);
+        super(factory);
         m_module = module;
     }
 
@@ -54,7 +54,7 @@
      * </p>
      * @return the module that is the subject of the event.
     **/
-    public Module getModule()
+    public IModule getModule()
     {
         return m_module;
     }

Copied: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java (from r370894, incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleManager.java)
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java?p2=incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java&p1=incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleManager.java&r1=370894&r2=372822&rev=372822&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleManager.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleFactoryImpl.java Fri Jan 27 04:31:01 2006
@@ -1,234 +1,45 @@
-/*
- *   Copyright 2005 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
 package org.apache.felix.moduleloader;
 
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
 
-/**
- * <p>
- * The <tt>ModuleManager</tt> class is the core facility for defining a
- * re-usable, policy-driven class loader for applications that require
- * flexible class loading mechanisms. The <tt>ModuleManager</tt> is not
- * class loader itself, but it supports the concept of a
- * <a href="Module.html"><tt>Module</tt></a>,
- * which is a unit of organization for application classes and resources.
- * The <tt>ModuleManager</tt> has only a handful of methods that allow
- * an application to add, remove, reset, and query modules; the intent
- * is to place as few assumptions in the <tt>ModuleManager</tt> as possible.
- * </p>
- * <p>
- * The idea is simple, allow the application to map itself into modules
- * however it sees fit and let the <tt>ModuleManager</tt> assume the
- * responsibility of managing the modules and loading classes and resources
- * from them as necessary via <a href="ModuleClassLoader.html"><tt>ModuleClassLoader</tt></a>s
- * that are associated with each module. In order to achieve this goal, though, the
- * <tt>ModuleManager</tt> must make at least one assumption on behalf of
- * the application. This assumption is that the loading of classes and resources
- * from the available modules must happen using a search algorithm
- * that is particular to the application itself. As a result of this assumption,
- * the <tt>ModuleManager</tt> requires that the application provide a concrete
- * implementation of the <a href="SearchPolicy.html"><tt>SearchPolicy</tt></a>
- * interface.
- * </p>
- * <p>
- * The search policy allows the <tt>ModuleLoader</tt> to let applications inject
- * their own particular class loading policies, without dictating strict or
- * constraining base assumptions. Of course, it is likely that many applications
- * will use the same or very similar search policies. Because of this, another
- * goal of the <tt>ModuleLoader</tt> approach is to foster a common library of
- * search policies that applications are free to use or customize as they see
- * fit. These common search policies are analagous to patterns, where each search
- * policy is viewable as a <i>class loading pattern</i>. Some initial search
- * policies included with the <tt>ModuleLoader</tt> are
- * <a href="search/ExhaustiveSearchPolicy.html"><tt>ExhaustiveSearchPolicy</tt></a>,
- * <a href="search/SelfContainedSearchPolicy.html"><tt>SelfContainedSearchPolicy</tt></a>, and
- * <a href="search/ImportSearchPolicy.html"><tt>ImportSearchPolicy</tt></a>.
- * </p>
- * <p>
- * Due to the fact that class loaders are tied to security and resource loading,
- * the search policy alone is not sufficient for the <tt>ModuleLoader</tt> to
- * perform its function. To fulfill these other purposes, the <tt>ModuleLoader</tt>
- * introduces another policy interface, called the <a href="URLPolicy.html"><tt>URLPolicy</tt></a>.
- * The <tt>URLPolicy</tt> allows the application to inject its particular policy
- * for to purposes:
- * </p>
- * <ol>
- *   <li>Creating the <tt>URL</tt> associated with loading a resource, such as
- *       the <tt>URL</tt> returned from a call to <tt>Class.getResource()</tt>.
- *   </li>
- *   <li>Creating the <tt>URL</tt> that will be associated with a class's
- *       <tt>CodeSource</tt> when defining the class for purposes of security
- *       and assigning permissions.
- *   </li>
- * </ol>
- * <p>
- * The <tt>ModuleLoader</tt> defines a default <tt>URLPolicy</tt>, called
- * <a href="DefaultURLPolicy.html"><tt>DefaultURLPolicy</tt></a>, that provides
- * a simple <tt>URLStreamHandler</tt> for accessing resources inside of modules
- * and that returns <tt>null</tt> for the <tt>CodeSource</tt> <tt>URL</tt>.
- * Applications only need to supply their own <tt>URLPolicy</tt> if the default
- * one does not provide the appropriate behavior.
- * </p>
- * <p>
- * It is possible for an application to create multiple instances of the
- * <tt>ModuleManager</tt> within a single JVM, but it is not possible to
- * share modules across multiple <tt>ModuleManager</tt>s. A given <tt>ModuleManager</tt>
- * can only have one <tt>SelectionPolicy</tt> and one <tt>URLPolicy</tt>.
- * </p>
- * @see org.apache.felix.moduleloader.Module
- * @see org.apache.felix.moduleloader.ModuleClassLoader
- * @see org.apache.felix.moduleloader.SearchPolicy
- * @see org.apache.felix.moduleloader.URLPolicy
- * @see org.apache.felix.moduleloader.DefaultURLPolicy
-**/
-public class ModuleManager
+
+
+public class ModuleFactoryImpl implements IModuleFactory
 {
-    private List m_moduleList = new ArrayList();
+    private ISearchPolicy m_searchPolicy = null;
+    private IURLPolicy m_urlPolicy = null;
     private Map m_moduleMap = new HashMap();
-    private SearchPolicy m_searchPolicy = null;
-    private URLPolicy m_urlPolicy = null;
+
     private ModuleListener[] m_listeners = null;
     private static final ModuleListener[] m_noListeners = new ModuleListener[0];
 
-    /**
-     * <p>
-     * Constructs a <tt>ModuleManager</tt> instance using the specified
-     * search policy and the default <tt>URL</tt> policy.
-     * </p>
-     * @param searchPolicy the search policy that the instance should use.
-     * @see org.apache.felix.moduleloader.SearchPolicy
-    **/
-    public ModuleManager(SearchPolicy searchPolicy)
-    {
-        this(searchPolicy, null);
-    }
-
-    /**
-     * <p>
-     * Constructs a <tt>ModuleManager</tt> instance using the specified
-     * search policy and the specified <tt>URL</tt> policy.
-     * </p>
-     * @param searchPolicy the search policy that the instance should use.
-     * @param urlPolicy the <tt>URL</tt> policy that the instance should use.
-     * @see org.apache.felix.moduleloader.SearchPolicy
-     * @see org.apache.felix.moduleloader.URLPolicy
-    **/
-    public ModuleManager(SearchPolicy searchPolicy, URLPolicy urlPolicy)
+    public ModuleFactoryImpl(ISearchPolicy searchPolicy, IURLPolicy urlPolicy)
     {
         m_listeners = m_noListeners;
         m_searchPolicy = searchPolicy;
-        m_searchPolicy.setModuleManager(this);
-
-        if (urlPolicy == null)
-        {
-            m_urlPolicy = new DefaultURLPolicy();
-        }
-        else
-        {
-            m_urlPolicy = urlPolicy;
-        }
+        m_searchPolicy.setModuleFactory(this);
     }
 
-    /**
-     * <p>
-     * Returns the <tt>URL</tt> policy used by this instance.
-     * </p>
-     * @return the <tt>URL</tt> policy used by this instance.
-     * @see org.apache.felix.moduleloader.URLPolicy
-    **/
-    public URLPolicy getURLPolicy()
-    {
-        return m_urlPolicy;
-    }
-
-    /**
-     * <p>
-     * Returns the search policy used by this instance.
-     * </p>
-     * @return the search policy used by this instance.
-     * @see org.apache.felix.moduleloader.SearchPolicy
-    **/
-    public SearchPolicy getSearchPolicy()
+    public ISearchPolicy getSearchPolicy()
     {
         return m_searchPolicy;
     }
 
-    /**
-     * <p>
-     * Returns an array of all modules being managed by the
-     * <tt>ModuleManager</tt> instance. The array contains a snapshot of
-     * all modules in the <tt>ModuleManager</tt> at the time when this
-     * method was called.
-     * </p>
-     * @return an array of all modules being managed by the <tt>ModuleManager</tt>
-     *         instance.
-     * @see org.apache.felix.moduleloader.Module
-    **/
-    public synchronized Module[] getModules()
+    public synchronized IModule[] getModules()
     {
-        Module[] modules = new Module[m_moduleList.size()];
-        return (Module[]) m_moduleList.toArray(modules);
+        return (IModule[]) m_moduleMap.values().toArray(new IModule[m_moduleMap.size()]);
     }
 
-    /**
-     * <p>
-     * Returns a module associated with the specified identifier.
-     * </p>
-     * @param id the identifier for the module to be retrieved.
-     * @return the module associated with the identifier or <tt>null</tt>.
-     * @see org.apache.felix.moduleloader.Module
-    **/
-    public synchronized Module getModule(String id)
+    public synchronized IModule getModule(String id)
     {
-        return (Module) m_moduleMap.get(id);
+        return (IModule) m_moduleMap.get(id);
     }
 
-    /**
-     * <p>
-     * Adds a module to the module manager. The module will have the specified
-     * unique identifier, with the associated attributes, resource sources, and
-     * library sources. If the identifier is not unique, then an exception is
-     * thrown.
-     * </p>
-     * @param id the unique identifier of the new module.
-     * @param attributes an array of key-value attribute pairs to
-     *        associate with the module.
-     * @param resSources an array of <tt>ResourceSource</tt>s to associate
-     *        with the module.
-     * @param libSources an array of <tt>LibrarySource</tt>s to associate
-     *        with the module.
-     * @return the newly created module.
-     * @throws java.lang.IllegalArgumentException if the module identifier
-     *         is not unique.
-     * @see org.apache.felix.moduleloader.Module
-     * @see org.apache.felix.moduleloader.ResourceSource
-     * @see org.apache.felix.moduleloader.LibrarySource
-    **/
-    public Module addModule(String id, Object[][] attributes,
-        ResourceSource[] resSources, LibrarySource[] libSources)
+    public IModule createModule(
+        String id, IContentLoader contentLoader, Object[][] attrs)
     {
-        return addModule(id, attributes, resSources, libSources, false);
-    }
-
-    public Module addModule(String id, Object[][] attributes,
-        ResourceSource[] resSources, LibrarySource[] libSources,
-        boolean useParentSource)
-    {
-        Module module = null;
+        IModule module = null;
 
         // Use a synchronized block instead of synchronizing the
         // method, so we can fire our event outside of the block.
@@ -236,8 +47,7 @@
         {
             if (m_moduleMap.get(id) == null)
             {
-                module = new Module(this, id, attributes, resSources, libSources, useParentSource);
-                m_moduleList.add(module);
+                module = new ModuleImpl(id, m_searchPolicy, m_urlPolicy, contentLoader, attrs);
                 m_moduleMap.put(id, module);
             }
             else
@@ -252,74 +62,7 @@
         return module;
     }
 
-    /**
-     * <p>
-     * Resets a given module. In resetting a module, the module's associated
-     * class loader is thrown away; it is the application's responsibility to
-     * determine when and how that application code stops using classes (and
-     * subsequent instances) from the class loader of the reset module.
-     * This method allows the associated elements of the module (i.e.,
-     * attributes, resource sources, and library sources) to be changed also;
-     * if these elements have not changed then they simply need to be passed
-     * back in from the existing module. This method is useful in situations
-     * where the underlying module needs to be changed at run time, such as
-     * might be necessary if a module was updated.
-     * </p>
-     * <p>
-     * The same effect could be achieved by first removing and then re-adding
-     * a module, but with one subtle different. By removing and then re-adding
-     * a module, a new module is created and, thus, all existing references
-     * become invalid. By explicitly having this method, the <tt>ModuleManager</tt>
-     * maintains the integrity of the module reference, which is more intuitive
-     * in the case where an updated module is intended to be the same module,
-     * only updated.
-     * </p>
-     * @param module the module reset.
-     * @param attributes an array of key-value attribute pairs to
-     *        associate with the module.
-     * @param resSources an array of <tt>ResourceSource</tt>s to associate
-     *        with the module.
-     * @param libSources an array of <tt>LibrarySource</tt>s to associate
-     *        with the module.
-     * @see org.apache.felix.moduleloader.Module
-     * @see org.apache.felix.moduleloader.ResourceSource
-     * @see org.apache.felix.moduleloader.LibrarySource
-    **/
-    public void resetModule(
-        Module module, Object[][] attributes,
-        ResourceSource[] resSources, LibrarySource[] libSources)
-    {
-        // Use a synchronized block instead of synchronizing the
-        // method, so we can fire our event outside of the block.
-        synchronized (this)
-        {
-            module = (Module) m_moduleMap.get(module.getId());
-            if (module != null)
-            {
-                module.reset(attributes, resSources, libSources);
-            }
-            else
-            {
-                // Don't fire event.
-                return;
-            }
-        }
-
-        // Fire event here instead of inside synchronized block.
-        fireModuleReset(module);
-    }
-
-    /**
-     * <p>
-     * Removes the specified module from the <tt>ModuleManager</tt>. Removing
-     * a module only removed the module from the <tt>ModuleManager</tt>. It is
-     * the application's responsibility to determine when and how application code
-     * stop using classes (and subsequent instances) that were loaded from
-     * the class loader of the removed module.
-     * </p>
-     * @param module the module to remove.
-    **/
-    public void removeModule(Module module)
+    public void removeModule(IModule module)
     {
         // Use a synchronized block instead of synchronizing the
         // method, so we can fire our event outside of the block.
@@ -328,11 +71,7 @@
             if (m_moduleMap.get(module.getId()) != null)
             {
                 // Remove from data structures.
-                m_moduleList.remove(module);
                 m_moduleMap.remove(module.getId());
-
-                // Dispose of the module.
-                module.dispose();
             }
             else
             {
@@ -446,7 +185,7 @@
      * </p>
      * @param module the module that was added.
     **/
-    protected void fireModuleAdded(Module module)
+    protected void fireModuleAdded(IModule module)
     {
         // Event holder.
         ModuleEvent event = null;
@@ -473,7 +212,7 @@
      * </p>
      * @param module the module that was reset.
     **/
-    protected void fireModuleReset(Module module)
+    protected void fireModuleReset(IModule module)
     {
         // Event holder.
         ModuleEvent event = null;
@@ -501,7 +240,7 @@
      * </p>
      * @param module the module that was removed.
     **/
-    protected void fireModuleRemoved(Module module)
+    protected void fireModuleRemoved(IModule module)
     {
         // Event holder.
         ModuleEvent event = null;

Copied: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java (from r370894, incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/Module.java)
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java?p2=incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java&p1=incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/Module.java&r1=370894&r2=372822&rev=372822&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/Module.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleImpl.java Fri Jan 27 04:31:01 2006
@@ -1,80 +1,11 @@
-/*
- *   Copyright 2005 The Apache Software Foundation
- *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
- *
- */
 package org.apache.felix.moduleloader;
 
-import java.security.AccessController;
-import java.security.PrivilegedAction;
+import java.net.URL;
 import java.util.*;
 
-/**
- * <p>
- * The <tt>Module</tt> class is a grouping mechanism for application classes
- * and resources. Conceptually, most applications are grouped into
- * entities such as JAR files (containing classes and resources) and native
- * libraries. In some cases, these entities are core application classes and
- * resources, while in other cases, these entities are ancillary, such as
- * dynamically loaded plug-ins. Applications place some level of semantics
- * onto these types of entities or <i>modules</i>, but for the <tt>ModuleLoader</tt>,
- * no particular semantics are attached to modules (other than they are a grouping
- * mechanism for classes and resources). This means that the application
- * is free to map itself into modules any way that is appropriate.
- * </p>
- * <p>
- * A module has the following features:
- * </p>
- * <ul>
- *   <li>A unique identifier within the scope of its <tt>ModuleManager</tt>.
- *   </li>
- *   <li>A set of key-value attribute pairs.
- *   </li>
- *   <li>A set of resource sources from which it is possible to
- *       retrieve classes and resources.
- *   </li>
- *   <li>A set of native library sources from which it is possible
- *       to retrieve native libraries.
- *   </li>
- * </ul>
- * <p>
- * A module's identifier must be unique within the scope of its
- * <tt>ModuleManager</tt>, but there is no meaning associated with it. The
- * set of attribute-value pairs attached to the module have no meaning to
- * the <tt>ModuleManager</tt>, nor does it consult them at all. The point
- * of these attributes is to attach meta-data for use by
- * <a href="SearchPolicy.html"><tt>SearchPolicy</tt></a> implementations.
- * Attributes are represented as an array of <tt>Object</tt>
- * arrays, i.e., <tt>Object[][]</tt>. Each element in the attribute array is
- * a two-element <tt>Object</tt> array, where <tt>Module.KEY_IDX</tt> is the attribute's
- * key and <tt>Module.VALUE_IDX</tt> is the attribute's value.
- * </p>
- * <p>
- * The actual contents of a module is contained in two sets of sources
- * for its resources and native libraries,
- * <a href="ResourceSource.html"><tt>ResourceSource</tt></a>s
- * and <a href="LibrarySource.html"><tt>LibrarySource</tt></a>s, respectively.
- * Each module also has a <a href="ModuleClassLoader.html"><tt>ModuleClassLoader</tt></a>
- * associated with it. The <tt>ModuleClassLoader</tt> consults these two types
- * of sources to find classes, resources, and native libraries.
- * </p>
- * @see org.apache.felix.moduleloader.ModuleManager
- * @see org.apache.felix.moduleloader.ModuleClassLoader
- * @see org.apache.felix.moduleloader.ResourceSource
- * @see org.apache.felix.moduleloader.LibrarySource
-**/
-public class Module
+import org.apache.felix.moduleloader.ResourceNotFoundException;
+
+public class ModuleImpl implements IModule
 {
     /**
      * This is the index used to retrieve the key of an attribute;
@@ -87,271 +18,104 @@
     **/
     public static final int VALUE_IDX = 1;
 
-    private ModuleManager m_mgr = null;
     private String m_id = null;
-    private boolean m_useParentSource = false;
-    private Map m_attributeMap = new HashMap();
-    private ResourceSource[] m_resSources = null;
-    private LibrarySource[] m_libSources = null;
-    private ModuleClassLoader m_loader = null;
-
-    /**
-     * <p>
-     * Constructs a <tt>Module</tt> instance that will be associated with
-     * the specified <tt>ModuleManager</tt> and will have the specified
-     * identifier, attributes, resource sources, and library sources. In general,
-     * modules should not be created directly, but should be created by making
-     * a call to <tt>ModuleManager.addModule()</tt>.
-     * </p>
-     * @param mgr the <tt>ModuleManager</tt> that will be associated to
-     *       the instance.
-     * @param id the identifier of the instance.
-     * @param attributes the set of attributes associated with the instance.
-     * @param resSources the set of <tt>ResourceSource</tt>s associated with
-     *        the instance.
-     * @param libSources the set of <tt>LibrarySource</tt>s associated with
-     *        the instance.
-     * @param useParentSource a flag indicating whether or not the parent
-     *        class loader should be used as a resource source; this is an
-     *        ugly hack to allow a module to masquerade as the system
-     *        class loader.
-     * @see org.apache.felix.moduleloader.ModuleManager
-     * @see org.apache.felix.moduleloader.ResourceSource
-     * @see org.apache.felix.moduleloader.LibrarySource
-    **/
-    public Module(
-        ModuleManager mgr, String id, Object[][] attributes,
-        ResourceSource[] resSources, LibrarySource[] libSources,
-        boolean useParentSource)
+    private ISearchPolicy m_searchPolicy = null;
+    private IURLPolicy m_urlPolicy = null;
+    private IContentLoader m_contentLoader = null;
+    private Map m_attrMap = new HashMap();
+
+    ModuleImpl(
+        String id, ISearchPolicy searchPolicy, IURLPolicy urlPolicy,
+        IContentLoader contentLoader, Object[][] attrs)
     {
-        m_mgr = mgr;
         m_id = id;
-        m_useParentSource = useParentSource;
-        initialize(attributes, resSources, libSources);
+        m_searchPolicy = searchPolicy;
+        m_urlPolicy = urlPolicy;
+        m_contentLoader = contentLoader;
+        m_contentLoader.setModuleCallback(new ModuleCallbackImpl(this));
+        initialize(attrs);
     }
 
-    /**
-     * <p>
-     * Returns the identifier of the module.
-     * </p>
-     * @return the identifier of the module.
-    **/
     public String getId()
     {
         return m_id;
     }
 
-    /**
-     * <p>
-     * Returns the attribute set associated with this module. Attributes
-     * are represented as an array of <tt>Object</tt> arrays, i.e.,
-     * <tt>Object[][]</tt>. Each element in the attribute array is
-     * two-element <tt>Object</tt> array, where <tt>Module.KEY_IDX</tt>
-     * is the index to the attribute key and <tt>Module.VALUE_IDX</tt>
-     * is the index to the attribute value. The returned array is a
-     * copy and may be freely modified.
-     * </p>
-     * @return the attribute set associated with this module.
-    **/
-    public synchronized Object[][] getAttributes()
-    {
-        Set s = m_attributeMap.entrySet();
-        Object[][] attributes = new Object[s.size()][];
-        Iterator iter = s.iterator();
-        for (int i = 0; iter.hasNext(); i++)
-        {
-            Map.Entry entry = (Map.Entry) iter.next();
-            attributes[i] = new Object[] { entry.getKey(), entry.getValue() };
-        }
-        return attributes;
-    }
-
-    /**
-     * <p>
-     * Returns the attribute value associated with the specified key.
-     * </p>
-     * @param key the key of the attribute whose value is to be retrieved.
-     * @return the attribute's value or <tt>null</tt>.
-    **/
-    public synchronized Object getAttribute(String key)
+    public ISearchPolicy getSearchPolicy()
     {
-        return m_attributeMap.get(key);
+        return m_searchPolicy;
     }
 
-    /**
-     * <p>
-     * Sets the attribute value associated with the specified key. The
-     * attribute will be added if it does not currently exist.
-     * </p>
-     * @param key the key of the attribute whose value is to be set.
-     * @param value the new value to be associated with the attribute key.
-    **/
-    public synchronized void setAttribute(String key, Object value)
+    public IURLPolicy getURLPolicy()
     {
-        m_attributeMap.put(key, value);
+        return m_urlPolicy;
     }
 
-    /**
-     * <p>
-     * Returns the array of <tt>ResourceSource</tt>s associated with
-     * the module. The returned array is not a copy and therefore should
-     * not be modified.
-     * </p>
-     * @return the array of <tt>ResourceSource</tt>s associated with
-     *         the module.
-     * @see org.apache.felix.moduleloader.ResourceSource
-    **/
-    public ResourceSource[] getResourceSources()
+    public IContentLoader getContentLoader()
     {
-        return m_resSources;
+        return m_contentLoader;
     }
 
-    /**
-     * <p>
-     * Returns the array of <tt>LibrarySource</tt>s associated with
-     * the module. The returned array is not a copy and therefore should
-     * not be modified.
-     * </p>
-     * @return the array of <tt>LibrarySource</tt>s associated with
-     *         the module.
-     * @see org.apache.felix.moduleloader.LibrarySource
-    **/
-    public LibrarySource[] getLibrarySources()
-    {
-        return m_libSources;
-    }
-
-    /**
-     * <p>
-     * Returns the <tt>ModuleClassLoader</tt> associated with this module.
-     * If a security manager is installed, then this method uses a privileged
-     * action to avoid a security exception being thrown to the caller.
-     * </p>
-     * @return the <tt>ModuleClassLoader</tt> associated with this module.
-     * @see org.apache.felix.moduleloader.ModuleClassLoader
-    **/
-    public synchronized ModuleClassLoader getClassLoader()
+    public synchronized Object[][] getAttributes()
     {
-        if (m_loader == null)
+        Set s = m_attrMap.entrySet();
+        Object[][] attrs = new Object[s.size()][];
+        Iterator iter = s.iterator();
+        for (int i = 0; iter.hasNext(); i++)
         {
-            if (System.getSecurityManager() != null)
-            {
-                m_loader = (ModuleClassLoader) AccessController.doPrivileged(
-                    new GetClassLoaderPrivileged(m_mgr, this, m_useParentSource));
-            }
-            else
-            {
-                m_loader = new ModuleClassLoader(m_mgr, this, m_useParentSource);
-            }
+            Map.Entry entry = (Map.Entry) iter.next();
+            attrs[i] = new Object[] { entry.getKey(), entry.getValue() };
         }
-
-        return m_loader;
+        return attrs;
     }
 
-    /**
-     * <p>
-     * Returns the module's identifier.
-     * </p>
-     * @return the module's identifier.
-    **/
-    public String toString()
+    public synchronized Object getAttribute(String key, Object defaultValue)
     {
-        return m_id;
+        Object value = m_attrMap.get(key);
+        return (value == null) ? defaultValue : value;
     }
 
-    /**
-     * <p>
-     * Resets the module by throwing away its associated class loader and
-     * re-initializing its attributes, resource sources, and library sources
-     * with the specified values.
-     * </p>
-     * @param attributes the new attributes to be associated with the module.
-     * @param resSources the new resource sources to be associated with the module.
-     * @param libSources the new library sources to be associated with the module.
-     * @see org.apache.felix.moduleloader.ResourceSource
-     * @see org.apache.felix.moduleloader.LibrarySource
-    **/
-    protected synchronized void reset(
-        Object[][] attributes, ResourceSource[] resSources,
-        LibrarySource[] libSources)
-    {
-        // Throw away class loader.
-        m_loader = null;
-        // Clear attribute map.
-        m_attributeMap.clear();
-        // Close all sources.
-        dispose();
-        // Re-initialize.
-        initialize(attributes, resSources, libSources);
+    public synchronized void setAttribute(String key, Object value)
+    {
+        m_attrMap.put(key, value);
     }
 
-    /**
-     * <p>
-     * Disposes the module by closing all resource and library sources.
-     * </p>
-    **/
-    protected synchronized void dispose()
+    public Class getClass(String name)
     {
-        // Close sources.
-        for (int i = 0; (m_resSources != null) && (i < m_resSources.length); i++)
+        try
         {
-            m_resSources[i].close();
+            return m_searchPolicy.findClass(this, name);
         }
-        for (int i = 0; (m_libSources != null) && (i < m_libSources.length); i++)
+        catch (ClassNotFoundException ex)
         {
-            m_libSources[i].close();
+            ex.printStackTrace();
         }
+        return null;
     }
 
-    /**
-     * <p>
-     * Initializes the module by copying the specified attribute array into
-     * a map and opening all resource and library sources.
-     * </p>
-     * @param attributes the attributes to be put into a map.
-     * @param resSources the resource sources to be opened.
-     * @param libSources the library sources to be opened.
-     * @see org.apache.felix.moduleloader.ResourceSource
-     * @see org.apache.felix.moduleloader.LibrarySource
-    **/
-    private void initialize(
-        Object[][] attributes, ResourceSource[] resSources, LibrarySource[] libSources)
+    public URL getResource(String name)
     {
-        for (int i = 0; (attributes != null) && (i < attributes.length); i++)
-        {
-            m_attributeMap.put(attributes[i][KEY_IDX], attributes[i][VALUE_IDX]);
-        }
-
-        m_resSources = resSources;
-        m_libSources = libSources;
-
-        // Open sources.
-        for (int i = 0; (m_resSources != null) && (i < m_resSources.length); i++)
+        try
         {
-            m_resSources[i].open();
+            return m_searchPolicy.findResource(this, name);
         }
-        for (int i = 0; (m_libSources != null) && (i < m_libSources.length); i++)
+        catch (ResourceNotFoundException ex)
         {
-            m_libSources[i].open();
+            ex.printStackTrace();
         }
+        return null;
     }
 
-    private static class GetClassLoaderPrivileged implements PrivilegedAction
+    private void initialize(Object[][] attrs)
     {
-        private ModuleManager m_mgr = null;
-        private Module m_module = null;
-        private boolean m_useParentSource = false;
-
-        public GetClassLoaderPrivileged(ModuleManager mgr, Module module, boolean useParentSource)
+        for (int i = 0; (attrs != null) && (i < attrs.length); i++)
         {
-            m_mgr = mgr;
-            m_module = module;
-            m_useParentSource = useParentSource;
+            m_attrMap.put(attrs[i][KEY_IDX], attrs[i][VALUE_IDX]);
         }
+    }
 
-        public Object run()
-        {
-            return new ModuleClassLoader(m_mgr, m_module, m_useParentSource);
-        }
+    public String toString()
+    {
+        return m_id;
     }
 }

Modified: incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleListener.java
URL: http://svn.apache.org/viewcvs/incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleListener.java?rev=372822&r1=372821&r2=372822&view=diff
==============================================================================
--- incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleListener.java (original)
+++ incubator/felix/sandbox/rickhall/framework-branch/src/main/java/org/apache/felix/moduleloader/ModuleListener.java Fri Jan 27 04:31:01 2006
@@ -24,7 +24,7 @@
  * To receive events, an implementation of this listener must be added
  * to the <tt>ModuleManager</tt> instance.
  * </p>
- * @see org.apache.felix.moduleloader.ModuleManager
+ * @see org.apache.felix.moduleloader.ModuleFactoryImpl
  * @see org.apache.felix.moduleloader.ModuleEvent
 **/
 public interface ModuleListener extends EventListener



Mime
View raw message