Eliminated the URL policy abstraction. (FELIX-851)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@744260 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 264aeea..8e63108 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -27,7 +27,6 @@
import org.apache.felix.framework.cache.BundleArchive;
import org.apache.felix.framework.ext.SecurityProvider;
import org.apache.felix.framework.searchpolicy.ModuleImpl;
-import org.apache.felix.framework.searchpolicy.URLPolicyImpl;
import org.apache.felix.moduleloader.IModule;
import org.osgi.framework.*;
@@ -586,7 +585,8 @@
return m_state;
}
- void setState(int i)
+ // This method should not be called directly.
+ void __setState(int i)
{
m_state = i;
}
@@ -940,6 +940,7 @@
Map headerMap = m_archive.getRevision(
m_archive.getRevisionCount() - 1).getManifestHeader();
+ // Create the module instance.
final int revision = m_archive.getRevisionCount() - 1;
ModuleImpl module = new ModuleImpl(
getFramework().getLogger(),
@@ -948,7 +949,8 @@
this,
Long.toString(getBundleId()) + "." + Integer.toString(revision),
headerMap,
- m_archive.getRevision(revision).getContent());
+ m_archive.getRevision(revision).getContent(),
+ getFramework().getBundleStreamHandler());
// Verify that the bundle symbolic name + version is unique.
if (module.getManifestVersion().equals("2"))
@@ -974,15 +976,6 @@
}
}
- // Set the module's URL policy.
-// TODO: REFACTOR - Pass into constructor?
- module.setURLPolicy(
-// TODO: REFACTOR - SUCKS NEEDING URL POLICY PER MODULE.
- new URLPolicyImpl(
- getFramework().getLogger(),
- getFramework().getBundleStreamHandler(),
- module));
-
return module;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
index 3599841..4af230f 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -615,7 +615,7 @@
{
ExtensionManagerModule(Felix felix) throws BundleException
{
- super(m_logger, null, null, felix, "0", null, null);
+ super(m_logger, null, null, felix, "0", null, null, null);
}
public Map getHeaders()
@@ -702,16 +702,6 @@
return ExtensionManager.this;
}
- public synchronized void setURLPolicy(IURLPolicy urlPolicy)
- {
- m_urlPolicy = urlPolicy;
- }
-
- public synchronized IURLPolicy getURLPolicy()
- {
- return m_urlPolicy;
- }
-
public URL getEntry(String name)
{
// There is no content for the system bundle, so return null.
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 372fd2a..a49397a 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -4104,7 +4104,7 @@
{
synchronized (m_bundleLock)
{
- bundle.setState(state);
+ bundle.__setState(state);
m_bundleLock.notifyAll();
}
}
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
index a82452e..6c1e4ba 100644
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
@@ -24,7 +24,9 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLStreamHandler;
import java.security.ProtectionDomain;
import java.security.SecureClassLoader;
import java.util.ArrayList;
@@ -62,6 +64,7 @@
private final String m_id;
private final IContent m_content;
private final Map m_headerMap;
+ private final URLStreamHandler m_streamHandler;
private final String m_manifestVersion;
private final Version m_version;
@@ -82,7 +85,6 @@
private IContent[] m_contentPath;
private IContent[] m_fragmentContents = null;
- private IURLPolicy m_urlPolicy = null;
private ModuleClassLoader m_classLoader;
private ProtectionDomain m_protectionDomain = null;
private static SecureAction m_secureAction = new SecureAction();
@@ -99,7 +101,8 @@
public ModuleImpl(
Logger logger, Map configMap, FelixResolver resolver,
- Bundle bundle, String id, Map headerMap, IContent content)
+ Bundle bundle, String id, Map headerMap, IContent content,
+ URLStreamHandler streamHandler)
throws BundleException
{
m_logger = logger;
@@ -109,6 +112,7 @@
m_id = id;
m_headerMap = headerMap;
m_content = content;
+ m_streamHandler = streamHandler;
// We need to special case the system bundle module, which does not
// have a content.
@@ -600,7 +604,7 @@
if (name.equals("/"))
{
// Just pick a class path index since it doesn't really matter.
- url = getURLPolicy().createURL(1, name);
+ url = createURL(1, name);
}
else if (name.startsWith("/"))
{
@@ -615,7 +619,7 @@
{
if (contentPath[i].hasEntry(name))
{
- url = getURLPolicy().createURL(i + 1, name);
+ url = createURL(i + 1, name);
}
}
@@ -803,7 +807,7 @@
{
for (int i = 0; i < contentPath.length; i++)
{
- v.addElement(getURLPolicy().createURL(i + 1, name));
+ v.addElement(createURL(i + 1, name));
}
}
else
@@ -823,7 +827,7 @@
// that we can differentiate between module content URLs
// (where the path will start with 0) and module class
// path URLs.
- v.addElement(getURLPolicy().createURL(i + 1, name));
+ v.addElement(createURL(i + 1, name));
}
}
}
@@ -841,7 +845,7 @@
// the root of the bundle according to the spec.
if (name.equals("/"))
{
- url = getURLPolicy().createURL(0, "/");
+ url = createURL(0, "/");
}
if (url == null)
@@ -858,7 +862,7 @@
// Module content URLs start with 0, whereas module
// class path URLs start with the index into the class
// path + 1.
- url = getURLPolicy().createURL(0, name);
+ url = createURL(0, name);
}
}
@@ -892,6 +896,32 @@
return getContentPath()[index - 1].getEntryAsStream(urlPath);
}
+ private URL createURL(int port, String path)
+ {
+ // Add a slash if there is one already, otherwise
+ // the is no slash separating the host from the file
+ // in the resulting URL.
+ if (!path.startsWith("/"))
+ {
+ path = "/" + path;
+ }
+
+ try
+ {
+ return m_secureAction.createURL(
+ FelixConstants.BUNDLE_URL_PROTOCOL,
+ m_id, port, path, m_streamHandler);
+ }
+ catch (MalformedURLException ex)
+ {
+ m_logger.log(
+ Logger.LOG_ERROR,
+ "Unable to create resource URL.",
+ ex);
+ }
+ return null;
+ }
+
//
// Fragment and dependency management methods.
//
@@ -1086,16 +1116,6 @@
m_classLoader = null;
}
- public synchronized void setURLPolicy(IURLPolicy urlPolicy)
- {
- m_urlPolicy = urlPolicy;
- }
-
- public synchronized IURLPolicy getURLPolicy()
- {
- return m_urlPolicy;
- }
-
public synchronized void setSecurityContext(Object securityContext)
{
m_protectionDomain = (ProtectionDomain) securityContext;
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/Resolver.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/Resolver.java
index a229b28..18774ab 100644
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/Resolver.java
+++ b/framework/src/main/java/org/apache/felix/framework/searchpolicy/Resolver.java
@@ -51,8 +51,6 @@
// Returns a map of resolved bundles where the key is the module
// and the value is an array of wires.
- // TODO: RESOLVER - The caller must ensure this is not called currently;
- // this may not be important if no state is shared.
public Map resolve(ResolverState state, IModule rootModule) throws ResolveException
{
// If the module is already resolved, then we can just return.
diff --git a/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java b/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java
deleted file mode 100644
index dcd9560..0000000
--- a/framework/src/main/java/org/apache/felix/framework/searchpolicy/URLPolicyImpl.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.framework.searchpolicy;
-
-import java.net.*;
-
-import org.apache.felix.framework.Logger;
-import org.apache.felix.framework.util.FelixConstants;
-import org.apache.felix.framework.util.SecureAction;
-import org.apache.felix.moduleloader.IModule;
-import org.apache.felix.moduleloader.IURLPolicy;
-
-public class URLPolicyImpl implements IURLPolicy
-{
- private Logger m_logger = null;
- private URLStreamHandler m_streamHandler = null;
- private IModule m_module = null;
- private static SecureAction m_secureAction = new SecureAction();
-
-// TODO: ML - IT SUCKS HAVING A URL POLICY OBJECT PER MODULE!
- public URLPolicyImpl(Logger logger, URLStreamHandler streamHandler, IModule module)
- {
- m_logger = logger;
- m_streamHandler = streamHandler;
- m_module = module;
- }
-
- public URL createURL(int port, String path)
- {
- // Add a slash if there is one already, otherwise
- // the is no slash separating the host from the file
- // in the resulting URL.
- if (!path.startsWith("/"))
- {
- path = "/" + path;
- }
-
- try
- {
- return m_secureAction.createURL(
- FelixConstants.BUNDLE_URL_PROTOCOL,
- m_module.getId(), port, path, m_streamHandler);
- }
- catch (MalformedURLException ex)
- {
- m_logger.log(
- Logger.LOG_ERROR,
- "Unable to create resource URL.",
- ex);
- }
- return null;
- }
-}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/moduleloader/IModule.java b/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
index 91d6b5d..55cfe5b 100644
--- a/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
+++ b/framework/src/main/java/org/apache/felix/moduleloader/IModule.java
@@ -28,8 +28,6 @@
public interface IModule
{
- void setURLPolicy(IURLPolicy urlPolicy);
- IURLPolicy getURLPolicy();
void setSecurityContext(Object securityContext);
Object getSecurityContext();