Bundle installBundle(
Bundle origin, String location, InputStream is)
throws BundleException
{
BundleArchive ba = null;
BundleImpl existing, bundle = null;
// Acquire an install lock.
acquireInstallLock(location);
try
{
// Check to see if the framework is still running;
if ((getState() == Bundle.STOPPING) ||
(getState() == Bundle.UNINSTALLED))
{
throw new BundleException("The framework has been shutdown.");
}
// If bundle location is already installed, then
// return it as required by the OSGi specification.
existing = (BundleImpl) getBundle(location);
if (existing == null)
{
// First generate an identifier for it.
long id = getNextId();
try
{
// Add the bundle to the cache.
ba = m_cache.create(id, getInitialBundleStartLevel(), location, is);
}
catch (Exception ex)
{
throw new BundleException(
"Unable to cache bundle: " + location, ex);
}
finally
{
try
{
if (is != null) is.close();
}
catch (IOException ex)
{
m_logger.log(
Logger.LOG_ERROR,
"Unable to close input stream.", ex);
}
}
try
{
// Acquire the global lock to create the bundle,
// since this impacts the global state.
boolean locked = acquireGlobalLock();
if (!locked)
{
throw new BundleException(
"Unable to acquire the global lock to install the bundle.");
}
try
{
bundle = new BundleImpl(this, origin, ba);
}
finally
{
// Always release the global lock.
releaseGlobalLock();
}
if (!bundle.isExtension())
{
Object sm = System.getSecurityManager();
if (sm != null)
{
((SecurityManager) sm).checkPermission(
new AdminPermission(bundle, AdminPermission.LIFECYCLE));
}
}
else
{
m_extensionManager.addExtensionBundle(this, bundle);
m_resolver.addRevision(m_extensionManager.getRevision());
}
}
catch (Throwable ex)
{
// Remove bundle from the cache.
try
{
if (bundle != null)
{
bundle.closeAndDelete();
}
else if (ba != null)
{
ba.closeAndDelete();
}
}
catch (Exception ex1)
{
m_logger.log(bundle,