Use BundleRevisionImpl instead of BundleRevision in fields to avoid casts
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1734033 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 2f2aa5f..8f844f5 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -66,7 +66,7 @@
private final Felix __m_felix;
private final BundleArchive m_archive;
- private final List<BundleRevision> m_revisions = new ArrayList<BundleRevision>(0);
+ private final List<BundleRevisionImpl> m_revisions = new ArrayList<BundleRevisionImpl>(0);
private volatile int m_state;
private boolean m_useDeclaredActivationPolicy;
private BundleActivator m_activator = null;
@@ -110,7 +110,7 @@
m_context = null;
m_installingBundle = installingBundle;
- BundleRevision revision = createRevision(false);
+ BundleRevisionImpl revision = createRevision(false);
addRevision(revision);
}
@@ -166,13 +166,13 @@
{
// Remove the bundle's associated revisions from the resolver state
// and close them.
- for (BundleRevision br : m_revisions)
+ for (BundleRevisionImpl br : m_revisions)
{
// Remove the revision from the resolver state.
getFramework().getResolver().removeRevision(br);
// Close the revision's content.
- ((BundleRevisionImpl) br).close();
+ br.close();
}
}
@@ -917,9 +917,9 @@
synchronized boolean isExtension()
{
- for (BundleRevision revision : m_revisions)
+ for (BundleRevisionImpl revision : m_revisions)
{
- if (((BundleRevisionImpl) revision).isExtension())
+ if (revision.isExtension())
{
return true;
}
@@ -1216,7 +1216,7 @@
m_archive.revise(location, is);
try
{
- BundleRevision revision = createRevision(true);
+ BundleRevisionImpl revision = createRevision(true);
addRevision(revision);
}
catch (Exception ex)
@@ -1243,13 +1243,13 @@
// system bundle needs to add its revision directly to the bundle,
// since it doesn't have an archive from which it will be created,
// which is the normal case.
- synchronized void addRevision(BundleRevision revision) throws Exception
+ synchronized void addRevision(BundleRevisionImpl revision) throws Exception
{
m_revisions.add(0, revision);
try
{
- getFramework().setBundleProtectionDomain(this, (BundleRevisionImpl) revision);
+ getFramework().setBundleProtectionDomain(revision);
}
catch (Exception ex)
{
@@ -1267,7 +1267,7 @@
}
}
- private BundleRevision createRevision(boolean isUpdate) throws Exception
+ private BundleRevisionImpl createRevision(boolean isUpdate) throws Exception
{
// Get and parse the manifest from the most recent revision and
// create an associated revision object for it.
@@ -1356,7 +1356,7 @@
for (int i = m_revisions.size() - 1; (i >= 0) && (pd == null); i--)
{
- pd = ((BundleRevisionImpl) m_revisions.get(i)).getProtectionDomain();
+ pd = m_revisions.get(i).getProtectionDomain();
}
return pd;
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java b/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
index 9c3befc..56fc827 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
@@ -46,6 +46,7 @@
import java.util.jar.JarOutputStream;
import org.apache.felix.framework.cache.Content;
import org.apache.felix.framework.cache.JarContent;
+import org.osgi.framework.Bundle;
import org.osgi.framework.PackagePermission;
import org.osgi.framework.wiring.BundleRevision;
@@ -253,7 +254,7 @@
if (revision != null)
{
- Content content = ((BundleRevisionImpl) m_revision.get()).getContent();
+ Content content = revision.getContent();
if (content instanceof JarContent)
{
return Felix.m_secureAction.openJarFile(((JarContent) content).getFile());
@@ -268,7 +269,7 @@
try
{
output = new FileOutputStream(target);
- input = new BundleInputStream(revision.getContent());
+ input = new BundleInputStream(content);
byte[] buffer = new byte[64 * 1024];
for (int i = input.read(buffer);i != -1; i = input.read(buffer))
{
@@ -330,18 +331,16 @@
};
}
- private static URL create(BundleImpl bundle) throws MalformedURLException
+ private static URL create(BundleRevisionImpl revision) throws MalformedURLException
{
- String location = bundle._getLocation();
+ RevisionAsJarURL handler = new RevisionAsJarURL(revision);
+
+ String location = revision.getBundle()._getLocation();
if (location.startsWith("reference:"))
{
location = location.substring("reference:".length());
}
-
- BundleRevisionImpl revision = bundle.adapt(BundleRevisionImpl.class);
- RevisionAsJarURL handler = new RevisionAsJarURL(revision);
-
URL url;
try
{
@@ -370,38 +369,33 @@
}
}
- private final WeakReference m_felix;
- private final WeakReference m_bundle;
+ private final WeakReference<BundleRevisionImpl> m_revision;
private final int m_hashCode;
private final String m_toString;
- private final WeakReference m_revision;
private volatile PermissionCollection m_woven;
- BundleProtectionDomain(Felix felix, BundleImpl bundle, Object certificates)
+ BundleProtectionDomain(BundleRevisionImpl revision, Object certificates)
throws MalformedURLException
{
super(
new CodeSource(
- RevisionAsJarURL.create(bundle),
+ RevisionAsJarURL.create(revision),
(Certificate[]) certificates),
null, null, null);
- m_felix = new WeakReference(felix);
- m_bundle = new WeakReference(bundle);
- m_revision = new WeakReference(bundle.adapt(BundleRevisionImpl.class));
- m_hashCode = bundle.hashCode();
- m_toString = "[" + bundle + "]";
+ m_revision = new WeakReference<BundleRevisionImpl>(revision);
+ m_hashCode = revision.hashCode();
+ m_toString = "[" + revision + "]";
}
- BundleRevision getRevision()
+ BundleRevisionImpl getRevision()
{
- return (BundleRevision) m_revision.get();
+ return m_revision.get();
}
public boolean implies(Permission permission)
{
- Felix felix = (Felix) m_felix.get();
- return (felix != null) ?
- felix.impliesBundlePermission(this, permission, false) : false;
+ Felix felix = getFramework();
+ return felix != null && felix.impliesBundlePermission(this, permission, false);
}
boolean superImplies(Permission permission)
@@ -411,9 +405,8 @@
public boolean impliesDirect(Permission permission)
{
- Felix felix = (Felix) m_felix.get();
- return (felix != null) ?
- felix.impliesBundlePermission(this, permission, true) : false;
+ Felix felix = getFramework();
+ return felix != null && felix.impliesBundlePermission(this, permission, true);
}
boolean impliesWoven(Permission permission)
@@ -432,7 +425,13 @@
BundleImpl getBundle()
{
- return (BundleImpl) m_bundle.get();
+ BundleRevisionImpl revision = m_revision.get();
+ return revision != null ? revision.getBundle() : null;
+ }
+
+ Felix getFramework() {
+ BundleRevisionImpl revision = m_revision.get();
+ return revision != null ? revision.getBundle().getFramework() : null;
}
public int hashCode()
@@ -450,7 +449,7 @@
{
return false;
}
- return m_bundle.get() == ((BundleProtectionDomain) other).m_bundle.get();
+ return m_revision.get() == ((BundleProtectionDomain) other).m_revision.get();
}
public String toString()
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 541365b..d16e78f 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
@@ -134,7 +134,7 @@
private final Logger m_logger;
private final Map m_configMap;
private final Map m_headerMap = new StringMap();
- private final BundleRevision m_systemBundleRevision;
+ private final BundleRevisionImpl m_systemBundleRevision;
private volatile List<BundleCapability> m_capabilities = Collections.EMPTY_LIST;
private volatile Set<String> m_exportNames = Collections.EMPTY_SET;
private volatile Object m_securityContext = null;
@@ -359,7 +359,7 @@
return aliasCaps;
}
- public BundleRevision getRevision()
+ public BundleRevisionImpl getRevision()
{
return m_systemBundleRevision;
}
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 e6ad8f4..543d81c 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -871,7 +871,7 @@
{
if (bundle != this)
{
- setBundleProtectionDomain((BundleImpl) bundle, ((BundleImpl) bundle).adapt(BundleRevisionImpl.class));
+ setBundleProtectionDomain(((BundleImpl) bundle).adapt(BundleRevisionImpl.class));
}
}
catch (Exception ex)
@@ -925,18 +925,19 @@
}
}
- void setBundleProtectionDomain(BundleImpl bundleImpl, BundleRevisionImpl revisionImpl) throws Exception
+ void setBundleProtectionDomain(BundleRevisionImpl revisionImpl) throws Exception
{
Object certificates = null;
SecurityProvider sp = getFramework().getSecurityProvider();
if ((sp != null) && (System.getSecurityManager() != null))
{
+ BundleImpl bundleImpl = revisionImpl.getBundle();
sp.checkBundle(bundleImpl);
Map signers = (Map) sp.getSignerMatcher(bundleImpl, Bundle.SIGNERS_TRUSTED);
- certificates = signers.keySet().toArray(new java.security.cert.Certificate[0]);
+ certificates = signers.keySet().toArray(new java.security.cert.Certificate[signers.size()]);
}
revisionImpl.setProtectionDomain(
- new BundleProtectionDomain(this, bundleImpl, certificates));
+ new BundleProtectionDomain(revisionImpl, certificates));
}
/**