Search in sources :

Example 1 with ServiceDeclaration

use of org.apache.aries.application.ServiceDeclaration in project aries by apache.

the class ApplicationMetadataImpl method setup.

/**
   * setup the application metadata from the appManifest
   * @param appManifest     application.mf manifest
   */
private void setup(Manifest appManifest) {
    Map<String, String> appMap = readManifestIntoMap(appManifest);
    // configure the appSymbolicName and appVersion
    this.appSymbolicName = appMap.get(AppConstants.APPLICATION_SYMBOLIC_NAME);
    this.appVersion = new Version(appMap.get(AppConstants.APPLICATION_VERSION));
    this.appName = appMap.get(AppConstants.APPLICATION_NAME);
    this.appScope = this.appSymbolicName + "_" + this.appVersion.toString();
    if (this.appSymbolicName == null || this.appVersion == null) {
        throw new IllegalArgumentException("Failed to create ApplicationMetadataImpl object from Manifest " + appManifest);
    }
    // configure appContents
    // use parseImportString as we don't allow appContents to be duplicate
    String applicationContents = appMap.get(AppConstants.APPLICATION_CONTENT);
    Map<String, Map<String, String>> appContentsMap = ManifestHeaderProcessor.parseImportString(applicationContents);
    for (Map.Entry<String, Map<String, String>> e : appContentsMap.entrySet()) {
        this.appContents.add(new ContentImpl(e.getKey(), e.getValue()));
    }
    String useBundleStr = appMap.get(AppConstants.APPLICATION_USE_BUNDLE);
    if (useBundleStr != null) {
        Map<String, Map<String, String>> useBundleMap = ManifestHeaderProcessor.parseImportString(useBundleStr);
        for (Map.Entry<String, Map<String, String>> e : useBundleMap.entrySet()) {
            this.useBundle.add(new ContentImpl(e.getKey(), e.getValue()));
        }
    }
    String allServiceImports = appMap.get(AppConstants.APPLICATION_IMPORT_SERVICE);
    List<String> serviceImports = ManifestHeaderProcessor.split(allServiceImports, ",");
    for (String s : serviceImports) {
        try {
            ServiceDeclaration dec = new ServiceDeclarationImpl(s);
            importServices.add(dec);
        } catch (InvalidSyntaxException ise) {
            _logger.warn("APPUTILS0013E", new Object[] { s, appSymbolicName });
        }
    }
    String allServiceExports = appMap.get(AppConstants.APPLICATION_EXPORT_SERVICE);
    List<String> serviceExports = ManifestHeaderProcessor.split(allServiceExports, ",");
    for (String s : serviceExports) {
        try {
            ServiceDeclaration dec = new ServiceDeclarationImpl(s);
            exportServices.add(dec);
        } catch (InvalidSyntaxException ise) {
            _logger.warn("APPUTILS0014E", new Object[] { s, appSymbolicName });
        }
    }
}
Also used : ServiceDeclaration(org.apache.aries.application.ServiceDeclaration) Version(org.osgi.framework.Version) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ServiceDeclaration

use of org.apache.aries.application.ServiceDeclaration in project aries by apache.

the class ApplicationMetadataImplTest method testMetadataCreation.

@Test
public void testMetadataCreation() throws Exception {
    ApplicationMetadataFactory manager = new ApplicationMetadataFactoryImpl();
    ApplicationMetadata app = manager.parseApplicationMetadata(getClass().getResourceAsStream("/META-INF/APPLICATION4.MF"));
    assertEquals("Travel Reservation", app.getApplicationName());
    assertEquals("com.travel.reservation", app.getApplicationSymbolicName());
    assertEquals(Version.parseVersion("1.2.0"), app.getApplicationVersion());
    List<Content> appContents = app.getApplicationContents();
    assertEquals(2, appContents.size());
    Content appContent1 = new ContentImpl("com.travel.reservation.business");
    Map<String, String> attrs = new HashMap<String, String>();
    attrs.put("version", "\"[1.1.0,1.2.0)\"");
    Content appContent2 = new ContentImpl("com.travel.reservation.web", attrs);
    assertTrue(appContents.contains(appContent2));
    assertTrue(appContents.contains(appContent1));
    List<ServiceDeclaration> importedService = app.getApplicationImportServices();
    assertEquals(2, importedService.size());
    assertTrue(importedService.contains(new ServiceDeclarationImpl("com.travel.flight.api")));
    assertTrue(importedService.contains(new ServiceDeclarationImpl("com.travel.rail.api")));
    List<ServiceDeclaration> exportedService = app.getApplicationExportServices();
    assertTrue(exportedService.contains(new ServiceDeclarationImpl("com.travel.reservation")));
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) HashMap(java.util.HashMap) Content(org.apache.aries.application.Content) ServiceDeclaration(org.apache.aries.application.ServiceDeclaration) ApplicationMetadataFactory(org.apache.aries.application.ApplicationMetadataFactory) ApplicationMetadataFactoryImpl(org.apache.aries.application.impl.ApplicationMetadataFactoryImpl) Test(org.junit.Test)

Example 3 with ServiceDeclaration

use of org.apache.aries.application.ServiceDeclaration in project aries by apache.

the class DeploymentManifestManagerImpl method createFakeBundle.

// create a 'mock' bundle that does nothing but export services required by 
// Application-ImportService
private ModelledResource createFakeBundle(Collection<ServiceDeclaration> appImportServices) throws InvalidAttributeException {
    _logger.debug(LOG_ENTRY, "createFakeBundle", new Object[] { appImportServices });
    Attributes attrs = new Attributes();
    attrs.putValue(Constants.BUNDLE_SYMBOLICNAME, FAKE_BUNDLE_NAME);
    attrs.putValue(Constants.BUNDLE_VERSION_ATTRIBUTE, "1.0");
    attrs.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
    // Build an ExportedService for every Application-ImportService entry
    Collection<ExportedService> exportedServices = new ArrayList<ExportedService>();
    for (ServiceDeclaration sDec : appImportServices) {
        Collection<String> ifaces = Arrays.asList(sDec.getInterfaceName());
        Filter filter = sDec.getFilter();
        Map<String, String> serviceProperties;
        if (filter != null) {
            serviceProperties = ManifestHeaderProcessor.parseFilter(filter.toString());
        } else {
            serviceProperties = new HashMap<String, String>();
        }
        serviceProperties.put("service.imported", "");
        exportedServices.add(modellingManager.getExportedService("", 0, ifaces, new HashMap<String, Object>(serviceProperties)));
    }
    ModelledResource fakeBundle = modellingManager.getModelledResource(null, attrs, null, exportedServices);
    _logger.debug(LOG_EXIT, "createFakeBundle", new Object[] { fakeBundle });
    return fakeBundle;
}
Also used : Filter(org.osgi.framework.Filter) HashMap(java.util.HashMap) ExportedService(org.apache.aries.application.modelling.ExportedService) ServiceDeclaration(org.apache.aries.application.ServiceDeclaration) Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Aggregations

HashMap (java.util.HashMap)3 ServiceDeclaration (org.apache.aries.application.ServiceDeclaration)3 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Attributes (java.util.jar.Attributes)1 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)1 ApplicationMetadataFactory (org.apache.aries.application.ApplicationMetadataFactory)1 Content (org.apache.aries.application.Content)1 ApplicationMetadataFactoryImpl (org.apache.aries.application.impl.ApplicationMetadataFactoryImpl)1 ExportedService (org.apache.aries.application.modelling.ExportedService)1 ModelledResource (org.apache.aries.application.modelling.ModelledResource)1 Test (org.junit.Test)1 Filter (org.osgi.framework.Filter)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 Version (org.osgi.framework.Version)1