// Verify that only manifest version 2 is specified.
String manifestVersion = getManifestVersion(m_headerMap);
if ((manifestVersion != null) && !manifestVersion.equals("2"))
{
throw new BundleException(
"Unknown 'Bundle-ManifestVersion' value: " + manifestVersion);
}
// Create lists to hold capabilities and requirements.
List<BundleCapabilityImpl> capList = new ArrayList();
//
// Parse bundle version.
//
m_bundleVersion = Version.emptyVersion;
if (headerMap.get(Constants.BUNDLE_VERSION) != null)
{
try
{
m_bundleVersion = Version.parseVersion(
(String) headerMap.get(Constants.BUNDLE_VERSION));
}
catch (RuntimeException ex)
{
// R4 bundle versions must parse, R3 bundle version may not.
if (getManifestVersion().equals("2"))
{
throw ex;
}
m_bundleVersion = Version.emptyVersion;
}
}
//
// Parse bundle symbolic name.
//
BundleCapabilityImpl bundleCap = parseBundleSymbolicName(owner, m_headerMap);
if (bundleCap != null)
{
m_bundleSymbolicName = (String)
bundleCap.getAttributes().get(BundleRevision.BUNDLE_NAMESPACE);
// Add a bundle capability and a host capability to all
// non-fragment bundles. A host capability is the same
// as a require capability, but with a different capability
// namespace. Bundle capabilities resolve required-bundle
// dependencies, while host capabilities resolve fragment-host
// dependencies.
if (headerMap.get(Constants.FRAGMENT_HOST) == null)
{
// All non-fragment bundles have host capabilities.
capList.add(bundleCap);
// A non-fragment bundle can choose to not have a host capability.
String attachment =
bundleCap.getDirectives().get(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE);
attachment = (attachment == null)
? Constants.FRAGMENT_ATTACHMENT_RESOLVETIME
: attachment;
if (!attachment.equalsIgnoreCase(Constants.FRAGMENT_ATTACHMENT_NEVER))
{
Map<String, Object> hostAttrs =
new HashMap<String, Object>(bundleCap.getAttributes());
Object value = hostAttrs.remove(BundleRevision.BUNDLE_NAMESPACE);
hostAttrs.put(BundleRevision.HOST_NAMESPACE, value);
capList.add(new BundleCapabilityImpl(
owner, BundleRevision.HOST_NAMESPACE,
bundleCap.getDirectives(),
hostAttrs));
}
}
//
// Add the osgi.identity capability.
//
capList.add(addIdentityCapability(owner, headerMap, bundleCap));
}
// Verify that bundle symbolic name is specified.
if (getManifestVersion().equals("2") && (m_bundleSymbolicName == null))
{
throw new BundleException(
"R4 bundle manifests must include bundle symbolic name.");
}
//
// Parse Fragment-Host.