in atomos/src/main/java/org/apache/felix/atomos/impl/base/AtomosBase.java [454:530]
final Bundle installAtomosContent(String prefix,
AtomosContentBase atomosContent)
throws BundleException
{
if (prefix == null)
{
prefix = "atomos";
}
if (prefix.indexOf(':') != -1)
{
throw new IllegalArgumentException("The prefix cannot contain ':'");
}
prefix = prefix + ':';
debug("Installing atomos content: %s%s", prefix,
atomosContent.getAtomosLocation());
BundleContext bc = context.get();
if (bc == null)
{
throw new IllegalStateException("Framework has not been initialized.");
}
String location = atomosContent.getAtomosLocation();
if (!Constants.SYSTEM_BUNDLE_LOCATION.equals(location))
{
location = prefix + location;
}
AtomosLayerBase atomosLayer = (AtomosLayerBase) atomosContent.getAtomosLayer();
if (atomosLayer.isNotValid())
{
throw new BundleException("Atomos layer has been uninstalled.",
BundleException.INVALID_OPERATION);
}
String existingLoc = getByAtomosContent(atomosContent);
if (existingLoc != null)
{
Bundle existing = bc.getBundle(existingLoc);
if (existing != null)
{
if (Constants.SYSTEM_BUNDLE_LOCATION.equals(existingLoc)
|| (existingLoc.equals(location)
&& atomosContent.getBundle() == existing))
{
return existing;
}
throw new BundleException(
"Atomos content is already connected with bundle: "
+ existing,
BundleException.DUPLICATE_BUNDLE_ERROR);
}
}
atomosContent.disconnect();
atomosContent.connect(location);
Bundle result = null;
try
{
result = bc.installBundle(location);
}
finally
{
// check if the layer is still valid
if (atomosLayer.isNotValid())
{
// The atomosLayer became invalid while installing
if (result != null)
{
result.uninstall();
result = null;
}
}
}
return result;
}