public void start(StartContext context) throws StartException {
ServiceController<?> controller = context.getController();
log.debugf("Starting: %s in mode %s", controller.getName(), controller.getMode());
final Map<ServiceName, OSGiModule> pendingServices = new LinkedHashMap<ServiceName, OSGiModule>();
try {
final BundleManagerService bundleManager = injectedBundleManager.getValue();
final ServiceContainer serviceContainer = context.getController().getServiceContainer();
final ServiceTarget serviceTarget = context.getChildTarget();
final File modulesDir = injectedEnvironment.getValue().getModulesDir();
final File bundlesDir = new File(modulesDir.getPath() + "/../bundles").getCanonicalFile();
for (OSGiModule moduleMetaData : subsystemState.getModules()) {
ServiceName serviceName;
ModuleIdentifier identifier = moduleMetaData.getIdentifier();
File bundleFile = getRepositoryEntry(bundlesDir, identifier);
if (bundleFile != null) {
URL url = bundleFile.toURI().toURL();
BundleInfo info = BundleInfo.createBundleInfo(url);
Deployment dep = DeploymentFactory.createDeployment(info);
Integer startLevel = moduleMetaData.getStartLevel();
if (startLevel != null)
dep.setStartLevel(startLevel.intValue());
serviceName = bundleManager.installBundle(serviceTarget, dep);
} else {
ModuleLoader moduleLoader = Module.getBootModuleLoader();
Module module = moduleLoader.loadModule(identifier);
OSGiMetaData metadata = getModuleMetadata(module);
serviceName = bundleManager.registerModule(serviceTarget, module, metadata);
}
pendingServices.put(serviceName, moduleMetaData);
}
// Install a service that has a dependency on all pending bundle INSTALLED services