use of org.apache.aries.application.modelling.ParsedServiceElements in project aries by apache.
the class ApplicationServiceModeller method computeRequirementsAndCapabilities.
@Override
public ServiceModel computeRequirementsAndCapabilities(Resource resource, IDirectory directory) throws SubsystemException {
try {
ServiceModelImpl model = new ServiceModelImpl();
ParsedServiceElements elements = manager.getServiceElements(directory);
for (ExportedService service : elements.getServices()) {
model.capabilities.add(new BasicCapability.Builder().namespace(ServiceNamespace.SERVICE_NAMESPACE).attribute(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, new ArrayList<String>(service.getInterfaces())).attributes(service.getServiceProperties()).resource(resource).build());
}
for (ImportedService service : elements.getReferences()) {
StringBuilder builder = new StringBuilder();
String serviceInterface = service.getInterface();
String filter = service.getFilter();
if (serviceInterface != null && filter != null) {
builder.append("(&");
}
if (serviceInterface != null) {
builder.append('(').append(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE).append('=').append(serviceInterface).append(')');
}
if (filter != null)
builder.append(filter);
if (serviceInterface != null && filter != null) {
builder.append(')');
}
if (builder.length() > 0) {
model.requirements.add(new BasicRequirement.Builder().namespace(ServiceNamespace.SERVICE_NAMESPACE).directive(Namespace.REQUIREMENT_FILTER_DIRECTIVE, builder.toString()).directive(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, service.isOptional() ? Namespace.RESOLUTION_OPTIONAL : Namespace.RESOLUTION_MANDATORY).directive(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, service.isMultiple() ? Namespace.CARDINALITY_MULTIPLE : Namespace.CARDINALITY_SINGLE).resource(resource).build());
}
}
return model;
} catch (ModellerException e) {
throw new SubsystemException(e);
}
}
use of org.apache.aries.application.modelling.ParsedServiceElements in project aries by apache.
the class ModelledResourceManagerImpl method getServiceElements.
private ParsedServiceElements getServiceElements(BundleManifest bundleMf, IDirectory archive) throws ModellerException {
Set<ExportedService> services = new HashSet<ExportedService>();
Set<ImportedService> references = new HashSet<ImportedService>();
try {
ParsedServiceElements pse = getBlueprintServiceElements(bundleMf, findBlueprints(bundleMf, archive));
services.addAll(pse.getServices());
references.addAll(pse.getReferences());
for (ServiceModeller sm : modellingPlugins) {
pse = sm.modelServices(bundleMf, archive);
services.addAll(pse.getServices());
references.addAll(pse.getReferences());
}
return new ParsedServiceElementsImpl(services, references);
} catch (Exception e) {
throw new ModellerException(e);
}
}
use of org.apache.aries.application.modelling.ParsedServiceElements in project aries by apache.
the class AbstractParserProxy method parseAllServiceElements.
public ParsedServiceElements parseAllServiceElements(InputStream blueprintToParse) throws Exception {
_logger.debug(LOG_ENTRY, "parseAllServiceElements", new Object[] { blueprintToParse });
ComponentDefinitionRegistry cdr = parseCDR(blueprintToParse);
Collection<ExportedService> services = parseCDRForServices(cdr, false);
Collection<ImportedService> references = parseCDRForReferences(cdr);
ParsedServiceElements result = _modellingManager.getParsedServiceElements(services, references);
_logger.debug(LOG_EXIT, "parseAllServiceElements", new Object[] { result });
return result;
}
use of org.apache.aries.application.modelling.ParsedServiceElements in project aries by apache.
the class ModelledResourceManagerImpl method getModelledResource.
public ModelledResource getModelledResource(String uri, IDirectory bundle) throws ModellerException {
_logger.debug(LOG_ENTRY, "getModelledResource", new Object[] { uri, bundle });
if (bundle != null) {
BundleManifest bm = BundleManifest.fromBundle(bundle);
ParsedServiceElements pse = getServiceElements(bm, bundle);
return model(uri, bm, pse);
} else {
// The bundle does not exist
ModellerException me = new ModellerException(MessageUtil.getMessage("INVALID_BUNDLE_LOCATION", bundle));
_logger.debug(LOG_EXIT, "getModelledResource", me);
throw me;
}
}
use of org.apache.aries.application.modelling.ParsedServiceElements in project aries by apache.
the class ModelledResourceManagerImpl method getBlueprintServiceElements.
private ParsedServiceElements getBlueprintServiceElements(BundleManifest bundleMf, Iterable<InputStream> blueprints) throws ModellerException {
_logger.debug(LOG_ENTRY, "getServiceElements", new Object[] { bundleMf, blueprints });
Set<ExportedService> services = new HashSet<ExportedService>();
Set<ImportedService> references = new HashSet<ImportedService>();
try {
for (InputStream is : blueprints) {
try {
ParsedServiceElements pse = getParserProxy().parseAllServiceElements(is);
services.addAll(pse.getServices());
references.addAll(pse.getReferences());
} finally {
IOUtils.close(is);
}
}
} catch (Exception e) {
ModellerException m = new ModellerException(e);
_logger.debug(LOG_EXIT, "getServiceElements", m);
throw m;
}
ParsedServiceElements result = _modellingManager.getParsedServiceElements(services, references);
_logger.debug(LOG_EXIT, "getServiceElements", result);
return result;
}
Aggregations