in subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Subsystems.java [100:172]
public synchronized BasicSubsystem getRootSubsystem() {
if (root == null) {
File file = Activator.getInstance().getBundleContext().getDataFile("");
File[] fileArray = file.listFiles();
List<File> fileList = new ArrayList<File>(Arrays.asList(fileArray));
Collections.sort(fileList, new Comparator<File>() {
@Override
public int compare(File file1, File file2) {
String name1 = file1.getName();
String name2 = file2.getName();
return Long.valueOf(name1).compareTo(Long.valueOf(name2));
}
});
if (fileList.isEmpty()) {
// There are no persisted subsystems, including root.
SubsystemResource resource;
try {
resource = new SubsystemResource(file);
}
catch (SubsystemException e) {
throw e;
}
catch (Exception e) {
throw new SubsystemException(e);
}
Coordination coordination = Utils.createCoordination();
try {
root = new BasicSubsystem(resource);
// TODO This initialization is a bit brittle. The root subsystem
// must be gotten before anything else will be able to use the
// graph. At the very least, throw IllegalStateException where
// appropriate.
graph = new SubsystemGraph(root);
ResourceInstaller.newInstance(coordination, root, root).install();
populateRootSubsystem(root, coordination);
} catch (Exception e) {
coordination.fail(e);
} finally {
coordination.end();
}
}
else {
// There are persisted subsystems.
Coordination coordination = Utils.createCoordination();
Collection<BasicSubsystem> subsystems = new ArrayList<BasicSubsystem>(fileList.size());
try {
for (File f : fileList) {
BasicSubsystem s = new BasicSubsystem(f);
if (State.UNINSTALLED.equals(s.getState())) {
// left over cache, delete this
IOUtils.deleteRecursive(f);
} else {
subsystems.add(s);
addSubsystem(s);
}
}
root = getSubsystemById(0);
SubsystemIdentifier.setLastId(
Long.parseLong(
root.getDeploymentManifest().getHeaders().get(
DeploymentManifest.ARIESSUBSYSTEM_LASTID).getValue()));
graph = new SubsystemGraph(root);
ResourceInstaller.newInstance(coordination, root, root).install();
populateRootSubsystem(root, coordination);
} catch (Exception e) {
coordination.fail(e);
} finally {
coordination.end();
}
}
}
return root;
}