for (String pkgName : clause.m_paths)
{
// Verify that java.* packages are not exported.
if (pkgName.startsWith("java."))
{
throw new BundleException(
"Exporting java.* packages not allowed: "
+ pkgName);
}
// The character "." has no meaning in the OSGi spec except
// when placed on the bundle class path. Some people, however,
// mistakenly think it means the default package when imported
// or exported. This is not correct. It is invalid.
else if (pkgName.equals("."))
{
throw new BundleException("Exporing '.' is invalid.");
}
// Make sure a package name was specified.
else if (pkgName.length() == 0)
{
throw new BundleException(
"Exported package names cannot be zero length.");
}
}
// Check for "version" and "specification-version" attributes
// and verify they are the same if both are specified.
Object v = clause.m_attrs.get(Constants.VERSION_ATTRIBUTE);
Object sv = clause.m_attrs.get(Constants.PACKAGE_SPECIFICATION_VERSION);
if ((v != null) && (sv != null))
{
// Verify they are equal.
if (!((String) v).trim().equals(((String) sv).trim()))
{
throw new IllegalArgumentException(
"Both version and specification-version are specified, but they are not equal.");
}
}
// Always add the default version if not specified.
if ((v == null) && (sv == null))
{
v = Version.emptyVersion;
}
// Ensure that only the "version" attribute is used and convert
// it to the appropriate type.
if ((v != null) || (sv != null))
{
// Convert version attribute to type Version.
clause.m_attrs.remove(Constants.PACKAGE_SPECIFICATION_VERSION);
v = (v == null) ? sv : v;
clause.m_attrs.put(
Constants.VERSION_ATTRIBUTE,
Version.parseVersion(v.toString()));
}
// If this is an R4 bundle, then make sure it doesn't specify
// bundle symbolic name or bundle version attributes.
if (mv.equals("2"))
{
// Find symbolic name and version attribute, if present.
if (clause.m_attrs.containsKey(Constants.BUNDLE_VERSION_ATTRIBUTE)
|| clause.m_attrs.containsKey(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE))
{
throw new BundleException(
"Exports must not specify bundle symbolic name or bundle version.");
}
// Now that we know that there are no bundle symbolic name and version
// attributes, add them since the spec says they are there implicitly.
clause.m_attrs.put(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, bsn);
clause.m_attrs.put(Constants.BUNDLE_VERSION_ATTRIBUTE, bv);
}
else if (!mv.equals("2"))
{
// R3 bundles cannot have directives on their exports.
if (!clause.m_dirs.isEmpty())
{
throw new BundleException("R3 exports cannot contain directives.");
}
// Remove and ignore all attributes other than version.
// NOTE: This is checking for "version" rather than "specification-version"
// because the package class normalizes to "version" to avoid having