long bundleId = bundleCounter.incrementAndGet();
try
{
BundleStore bundleStore = store.allocateBundleStore(bundleId, location);
ArchiveStore archiveStore = store.allocateArchiveStore(framework, bundleId, inputStream);
if (!archiveStore.getBundleNativeCodeList().isEmpty()) archiveStore.assignNativeCodeDescriptions(resolveNativeCodeDependencies(archiveStore.getBundleNativeCodeList()));
confirmRequiredExecutionEnvironment(archiveStore.getBundleRequiredExecutionEnvironment());
BundleController bundle = new BundleController(framework, bundleStore);
Generation generation = allocateGeneration(bundle, archiveStore);
bundle.getGenerations().put(archiveStore.getGeneration(), generation);
bundle.setCurrentGeneration(generation);
NameVersionKey key = new NameVersionKey(archiveStore.getBundleSymbolicName(), archiveStore.getBundleVersion());
if (nameVersions.containsKey(key)) throw new BundleException("Bundle already registered with name " + key.getSymbolicName() + " and version " + key.getVersion());
SecurityUtils.checkAdminPermission(bundle, AdminPermission.LIFECYCLE);
if (generation instanceof ExtensionGeneration) SecurityUtils.checkAdminPermission(bundle, AdminPermission.EXTENSIONLIFECYCLE);
nameVersions.put(key, bundle);
locations.put(location, bundle);
installedbundles.put(bundleId, bundle);
bundles.put(bundleId, bundle);
framework.getResolver().added(generation);
bundleStore.markModified();
generation.setState(Bundle.INSTALLED);
fireBundleEvent(new BundleEvent(BundleEvent.INSTALLED, bundle));