Search in sources :

Example 1 with ModellerException

use of org.apache.aries.application.modelling.ModellerException 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);
    }
}
Also used : ExportedService(org.apache.aries.application.modelling.ExportedService) SubsystemException(org.osgi.service.subsystem.SubsystemException) ModellerException(org.apache.aries.application.modelling.ModellerException) ImportedService(org.apache.aries.application.modelling.ImportedService) ParsedServiceElements(org.apache.aries.application.modelling.ParsedServiceElements)

Example 2 with ModellerException

use of org.apache.aries.application.modelling.ModellerException 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);
    }
}
Also used : ServiceModeller(org.apache.aries.application.modelling.ServiceModeller) ExportedService(org.apache.aries.application.modelling.ExportedService) ModellerException(org.apache.aries.application.modelling.ModellerException) ImportedService(org.apache.aries.application.modelling.ImportedService) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) ModellerException(org.apache.aries.application.modelling.ModellerException) HashSet(java.util.HashSet) ParsedServiceElements(org.apache.aries.application.modelling.ParsedServiceElements)

Example 3 with ModellerException

use of org.apache.aries.application.modelling.ModellerException in project aries by apache.

the class ModelledResourceManagerImpl method getServiceElements.

public ParsedServiceElements getServiceElements(InputStreamProvider archive) throws ModellerException {
    ICloseableDirectory dir = null;
    try {
        dir = FileSystem.getFSRoot(archive.open());
        BundleManifest bm = BundleManifest.fromBundle(dir);
        return getServiceElements(bm, dir);
    } catch (IOException e) {
        throw new ModellerException(e);
    } finally {
        IOUtils.close(dir);
    }
}
Also used : ICloseableDirectory(org.apache.aries.util.filesystem.ICloseableDirectory) BundleManifest(org.apache.aries.util.manifest.BundleManifest) ModellerException(org.apache.aries.application.modelling.ModellerException) IOException(java.io.IOException)

Example 4 with ModellerException

use of org.apache.aries.application.modelling.ModellerException in project aries by apache.

the class ModelledResourceManagerImpl method model.

private ModelledResource model(String uri, BundleManifest bm, ParsedServiceElements pse) throws ModellerException {
    Attributes attributes = bm.getRawAttributes();
    ModelledResource mbi = null;
    try {
        mbi = _modellingManager.getModelledResource(uri, attributes, pse.getReferences(), pse.getServices());
    } catch (InvalidAttributeException iae) {
        ModellerException me = new ModellerException(iae);
        _logger.debug(LOG_EXIT, "getModelledResource", me);
        throw me;
    }
    _logger.debug(LOG_EXIT, "getModelledResource", mbi);
    return mbi;
}
Also used : InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) Attributes(java.util.jar.Attributes) ModellerException(org.apache.aries.application.modelling.ModellerException) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 5 with ModellerException

use of org.apache.aries.application.modelling.ModellerException 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;
    }
}
Also used : BundleManifest(org.apache.aries.util.manifest.BundleManifest) ModellerException(org.apache.aries.application.modelling.ModellerException) ParsedServiceElements(org.apache.aries.application.modelling.ParsedServiceElements)

Aggregations

ModellerException (org.apache.aries.application.modelling.ModellerException)7 IOException (java.io.IOException)4 ParsedServiceElements (org.apache.aries.application.modelling.ParsedServiceElements)4 MalformedURLException (java.net.MalformedURLException)3 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)3 ExportedService (org.apache.aries.application.modelling.ExportedService)3 ImportedService (org.apache.aries.application.modelling.ImportedService)3 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 BundleManifest (org.apache.aries.util.manifest.BundleManifest)2 InputStream (java.io.InputStream)1 Attributes (java.util.jar.Attributes)1 ZipInputStream (java.util.zip.ZipInputStream)1 ModelledResource (org.apache.aries.application.modelling.ModelledResource)1 ServiceModeller (org.apache.aries.application.modelling.ServiceModeller)1 ICloseableDirectory (org.apache.aries.util.filesystem.ICloseableDirectory)1 IFile (org.apache.aries.util.filesystem.IFile)1 AnnotationDeployer (org.apache.openejb.config.AnnotationDeployer)1 AppModule (org.apache.openejb.config.AppModule)1 EjbModule (org.apache.openejb.config.EjbModule)1