Author: gnodet
Date: Tue Mar 8 08:41:38 2016
New Revision: 1734033
URL: http://svn.apache.org/viewvc?rev=1734033&view=rev
Log:
Use BundleRevisionImpl instead of BundleRevision in fields to avoid casts
Modified:
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
Modified:
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=1734033&r1=1734032&r2=1734033&view=diff
==============================================================================
---
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
(original)
+++
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
Tue Mar 8 08:41:38 2016
@@ -66,7 +66,7 @@ class BundleImpl implements Bundle, Bund
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 @@ class BundleImpl implements Bundle, Bund
m_context = null;
m_installingBundle = installingBundle;
- BundleRevision revision = createRevision(false);
+ BundleRevisionImpl revision = createRevision(false);
addRevision(revision);
}
@@ -166,13 +166,13 @@ class BundleImpl implements Bundle, Bund
{
// 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 @@ class BundleImpl implements Bundle, Bund
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 @@ class BundleImpl implements Bundle, Bund
m_archive.revise(location, is);
try
{
- BundleRevision revision = createRevision(true);
+ BundleRevisionImpl revision = createRevision(true);
addRevision(revision);
}
catch (Exception ex)
@@ -1243,13 +1243,13 @@ class BundleImpl implements Bundle, Bund
// 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 @@ class BundleImpl implements Bundle, Bund
}
}
- 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 @@ class BundleImpl implements Bundle, Bund
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;
Modified:
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
URL:
http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java?rev=1734033&r1=1734032&r2=1734033&view=diff
==============================================================================
---
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
(original)
+++
felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
Tue Mar 8 08:41:38 2016
@@ -46,6 +46,7 @@ import java.util.jar.JarFile;
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 @@ public class BundleProtectionDomain exte
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 @@ public class BundleProtectionDomain exte
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 @@ public class BundleProtectionDomain exte
};
}
- 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 @@ public class BundleProtectionDomain exte
}
}
- 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 class BundleProtectionDomain exte
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 @@ public class BundleProtectionDomain exte
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 @@ public class BundleProtectionDomain exte
{
return false;
}
- return m_bundle.get() == ((BundleProtectionDomain)
other).m_bundle.get();
+ return m_revision.get() == ((BundleProtectionDomain)
other).m_revision.get();
}
public String toString()
Modified:
felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
URL:
http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java?rev=1734033&r1=1734032&r2=1734033&view=diff
==============================================================================
---
felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
(original)
+++
felix/trunk/framework/src/main/java/org/apache/felix/framework/ExtensionManager.java
Tue Mar 8 08:41:38 2016
@@ -134,7 +134,7 @@ class ExtensionManager extends URLStream
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 @@ class ExtensionManager extends URLStream
return aliasCaps;
}
- public BundleRevision getRevision()
+ public BundleRevisionImpl getRevision()
{
return m_systemBundleRevision;
}
Modified:
felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL:
http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=1734033&r1=1734032&r2=1734033&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
Tue Mar 8 08:41:38 2016
@@ -871,7 +871,7 @@ public class Felix extends BundleImpl im
{
if (bundle != this)
{
- setBundleProtectionDomain((BundleImpl)
bundle, ((BundleImpl) bundle).adapt(BundleRevisionImpl.class));
+ setBundleProtectionDomain(((BundleImpl)
bundle).adapt(BundleRevisionImpl.class));
}
}
catch (Exception ex)
@@ -925,18 +925,19 @@ public class Felix extends BundleImpl im
}
}
- 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));
}
/**