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 });
}
}
}
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")));
}
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;
}
Aggregations