use of org.osgi.resource.Capability in project aries by apache.
the class ResolveContext method findProviders.
@Override
public List<Capability> findProviders(Requirement requirement) {
ArrayList<Capability> capabilities = new ArrayList<Capability>();
Resource resource = requirement.getResource();
if (isResolved(resource) && Utils.isEffectiveResolve(requirement)) {
processAlreadyResolvedResource(resource, requirement, capabilities);
} else {
installDependenciesOfRequirerIfNecessary(requirement);
processNewlyResolvedResource(resource, requirement, capabilities);
}
capabilities.trimToSize();
return capabilities;
}
use of org.osgi.resource.Capability in project aries by apache.
the class RawSubsystemResource method createFakeResource.
private static Resource createFakeResource(SubsystemManifest manifest) {
Header<?> importServiceHeader = manifest.getHeaders().get(APPLICATION_IMPORT_SERVICE_HEADER);
if (importServiceHeader == null) {
return null;
}
List<Capability> modifiableCaps = new ArrayList<Capability>();
final List<Capability> fakeCapabilities = Collections.unmodifiableList(modifiableCaps);
Resource fakeResource = new Resource() {
@Override
public List<Capability> getCapabilities(String namespace) {
if (namespace == null) {
return fakeCapabilities;
}
List<Capability> results = new ArrayList<Capability>();
for (Capability capability : fakeCapabilities) {
if (namespace.equals(capability.getNamespace())) {
results.add(capability);
}
}
return results;
}
@Override
public List<Requirement> getRequirements(String namespace) {
return Collections.emptyList();
}
};
modifiableCaps.add(new OsgiIdentityCapability(fakeResource, Constants.ResourceTypeSynthesized, new Version(1, 0, 0), Constants.ResourceTypeSynthesized));
Map<String, Map<String, String>> serviceImports = ManifestHeaderProcessor.parseImportString(importServiceHeader.getValue());
for (Entry<String, Map<String, String>> serviceImport : serviceImports.entrySet()) {
Collection<String> objectClasses = new ArrayList<String>(Arrays.asList(serviceImport.getKey()));
String filter = serviceImport.getValue().get(IdentityNamespace.REQUIREMENT_FILTER_DIRECTIVE);
BasicCapability.Builder capBuilder = new BasicCapability.Builder();
capBuilder.namespace(ServiceNamespace.SERVICE_NAMESPACE);
capBuilder.attribute(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, objectClasses);
if (filter != null)
capBuilder.attributes(new HashMap<String, Object>(SimpleFilter.attributes(filter)));
capBuilder.attribute("service.imported", "");
capBuilder.resource(fakeResource);
modifiableCaps.add(capBuilder.build());
}
return fakeResource;
}
use of org.osgi.resource.Capability in project aries by apache.
the class RawSubsystemResource method getCapabilities.
@Override
public List<Capability> getCapabilities(String namespace) {
if (namespace == null)
return Collections.unmodifiableList(capabilities);
ArrayList<Capability> result = new ArrayList<Capability>(capabilities.size());
for (Capability capability : capabilities) if (namespace.equals(capability.getNamespace()))
result.add(capability);
result.trimToSize();
return Collections.unmodifiableList(result);
}
use of org.osgi.resource.Capability in project aries by apache.
the class RawSubsystemResource method computeRequirements.
private List<Requirement> computeRequirements(SubsystemManifest manifest) throws ResolutionException {
if (isComposite(manifest)) {
// Composites determine their own requirements.
return manifest.toRequirements(this);
}
// Gather up all of the content resources for the subsystem.
SubsystemContentHeader header = manifest.getSubsystemContentHeader();
if (header == null) {
// Empty subsystems (i.e. subsystems with no content) are allowed.
return Collections.emptyList();
}
List<Requirement> requirements = header.toRequirements(this);
List<Resource> resources = new ArrayList<Resource>(requirements.size());
// TODO Do we need the system repository in here (e.g., for features)?
// What about the preferred provider repository?
// Search the local repository and service repositories for content.
RepositoryServiceRepository serviceRepo = new RepositoryServiceRepository();
// TODO Should we search the service repositories first, the assumption
// being they will contain more current content than the subsystem
// archive?
CompositeRepository compositeRepo = new CompositeRepository(localRepository, serviceRepo);
for (Requirement requirement : requirements) {
Collection<Capability> capabilities = compositeRepo.findProviders(requirement);
if (!capabilities.isEmpty()) {
resources.add(capabilities.iterator().next().getResource());
}
}
if (fakeImportServiceResource != null) {
// Add the fake resource so the dependency calculator knows not to
// return service requirements that are included in
// Application-ImportService.
resources.add(fakeImportServiceResource);
}
// dependencies not satisfied by the content resources themselves.
return new DependencyCalculator(resources).calculateDependencies();
}
use of org.osgi.resource.Capability in project aries by apache.
the class RawSubsystemResource method computeFileCapabilities.
private List<Capability> computeFileCapabilities(FileResource resource, IFile file, SubsystemManifest manifest) {
SubsystemContentHeader ssch = manifest.getSubsystemContentHeader();
if (ssch == null)
return Collections.emptyList();
for (Clause c : ssch.getClauses()) {
Attribute er = c.getAttribute(ContentHandler.EMBEDDED_RESOURCE_ATTRIBUTE);
if (er != null) {
if (file.getName().equals(er.getValue())) {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(ContentHandler.EMBEDDED_RESOURCE_ATTRIBUTE, er.getValue());
return Collections.<Capability>singletonList(new OsgiIdentityCapability(resource, c.getSymbolicName(), c.getVersionRange().getLeft(), c.getType(), attrs));
}
}
}
return Collections.emptyList();
}
Aggregations