use of org.eclipse.equinox.region.RegionDigraphVisitor in project aries by apache.
the class WovenClassListener method addSharingPolicyUpdates.
private void addSharingPolicyUpdates(final DynamicImportPackageRequirement requirement, final BasicSubsystem scopedSubsystem, final Collection<BundleCapability> providers, Map<Region, RegionUpdaterInfo> updates) {
final List<BasicSubsystem> subsystems = new ArrayList<BasicSubsystem>();
final Map<Region, BasicSubsystem> regionToSubsystem = new HashMap<Region, BasicSubsystem>();
regionToSubsystem(scopedSubsystem, regionToSubsystem);
scopedSubsystem.getRegion().visitSubgraph(new RegionDigraphVisitor() {
private final List<BasicSubsystem> visited = new ArrayList<BasicSubsystem>();
@Override
public void postEdgeTraverse(RegionFilter filter) {
// Nothing.
}
@Override
public boolean preEdgeTraverse(RegionFilter filter) {
return true;
}
@Override
public boolean visit(Region region) {
BasicSubsystem subsystem = regionToSubsystem.get(region);
if (subsystem == null || subsystem.isRoot()) {
// sharing policy.
return false;
}
if (!visited.isEmpty() && !subsystem.equals(scopedParent(visited.get(visited.size() - 1)))) {
// We're only interested in walking up the scoped parent tree.
return false;
}
visited.add(subsystem);
if (!requirement.getPackageName().contains("*")) {
for (BundleCapability provider : providers) {
BundleRevision br = provider.getResource();
if (region.contains(br.getBundle())) {
// satisfied.
return false;
}
}
}
boolean allowed = false;
Set<FilteredRegion> filters = region.getEdges();
for (FilteredRegion filteredRegion : filters) {
RegionFilter filter = filteredRegion.getFilter();
if (filter.isAllowed(providers.iterator().next())) {
// The region already allows matching capabilities
// through so there is no need to update the sharing
// policy.
allowed = true;
break;
}
}
if (!allowed) {
// The subsystem region requires a sharing policy update.
subsystems.add(subsystem);
}
// Visit the next region.
return true;
}
});
// Collect the information for the necessary sharing policy updates.
for (BasicSubsystem subsystem : subsystems) {
Region tail = subsystem.getRegion();
Region head = scopedParent(subsystem).getRegion();
RegionUpdaterInfo info = updates.get(tail);
if (info == null) {
info = new RegionUpdaterInfo(tail, head);
updates.put(tail, info);
}
info.requirement(requirement);
}
}
Aggregations