use of org.osgi.service.metatype.MetaTypeInformation in project felix by apache.
the class MetaTypeServiceImplTest method testAfterCretionManagedService.
public void testAfterCretionManagedService() {
MetaTypeService mts = new MetaTypeServiceImpl(bundleContext);
MetaTypeInformation mti = mts.getMetaTypeInformation(bundleContext.getBundle());
// assert still empty
checkEmpty(mti);
// register a service with PID
String pid = "testAfterCreation";
MockManagedService service = new MockManagedService();
Dictionary props = new Hashtable();
props.put(Constants.SERVICE_PID, pid);
ServiceRegistration sr = bundleContext.registerService(ManagedService.class.getName(), service, props);
// locales should contain MockMetaTypeProvider.LOCALES
assertNotNull(mti.getLocales());
assertTrue(mti.getLocales().length == 1);
assertEquals(MockMetaTypeProvider.LOCALES[0], mti.getLocales()[0]);
// pids must contain pid
assertNotNull(mti.getPids());
assertTrue(mti.getPids().length == 1);
assertEquals(pid, mti.getPids()[0]);
// change the service PID
String pid2 = "testAfterCreation2";
Dictionary props2 = new Hashtable();
props2.put(Constants.SERVICE_PID, pid2);
sr.setProperties(props2);
// pids must contain pid2
assertNotNull(mti.getPids());
assertTrue(mti.getPids().length == 1);
assertEquals(pid2, mti.getPids()[0]);
// factoryPids must be empty
assertTrue(mti.getFactoryPids() == null || mti.getFactoryPids().length == 0);
// unregister the service
sr.unregister();
// ensure everything is clear now again
checkEmpty(mti);
}
use of org.osgi.service.metatype.MetaTypeInformation in project felix by apache.
the class MetaTypeServiceImplTest method testEmpty.
public void testEmpty() {
MetaTypeService mts = new MetaTypeServiceImpl(bundleContext);
MetaTypeInformation mti = mts.getMetaTypeInformation(bundleContext.getBundle());
checkEmpty(mti);
}
use of org.osgi.service.metatype.MetaTypeInformation in project fabric8 by jboss-fuse.
the class MetaTypeFacade method metaTypeSummary.
@Override
public MetaTypeSummaryDTO metaTypeSummary() {
MetaTypeSummaryDTO answer = new MetaTypeSummaryDTO();
Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
MetaTypeInformation info = getMetaTypeInformation(bundle);
if (info != null) {
answer.addTypeInformation(bundle, info);
}
}
return answer;
}
use of org.osgi.service.metatype.MetaTypeInformation in project fabric8 by jboss-fuse.
the class MetaTypeFacade method getPidMetaTypeObject.
@Override
public MetaTypeObjectDTO getPidMetaTypeObject(String pid, String locale) {
Bundle[] bundles = bundleContext.getBundles();
MetaTypeObjectDTO answer = null;
for (Bundle bundle : bundles) {
MetaTypeInformation info = getMetaTypeInformation(bundle);
if (info != null) {
ObjectClassDefinition object = MetaTypeSummaryDTO.tryGetObjectClassDefinition(info, pid, locale);
if (object != null) {
if (answer == null) {
answer = new MetaTypeObjectDTO(object);
} else {
answer.appendObjectDefinition(object);
}
}
}
}
return answer;
}
use of org.osgi.service.metatype.MetaTypeInformation in project ddf by codice.
the class ConfigurationAdminImpl method listServices.
@Override
public List<Service> listServices(String serviceFactoryFilter, String serviceFilter) {
List<Service> serviceList = null;
List<Service> serviceFactoryList = null;
Map<Long, MetaTypeInformation> metaTypeInformationByBundle = new HashMap<>();
try {
// Get ManagedService instances
serviceList = getServices(ManagedService.class.getName(), serviceFilter, true);
Map<String, ObjectClassDefinition> configPidToOcdMap = getPidObjectClasses(metaTypeInformationByBundle);
// Get ManagedService Metatypes
List<Metatype> metatypeList = addMetaTypeNamesToMap(configPidToOcdMap, serviceFilter, SERVICE_PID);
// Get ManagedServiceFactory instances
serviceFactoryList = getServices(ManagedServiceFactory.class.getName(), serviceFactoryFilter, true);
// Get ManagedServiceFactory Metatypes
metatypeList.addAll(addMetaTypeNamesToMap(getFactoryPidObjectClasses(metaTypeInformationByBundle), serviceFactoryFilter, SERVICE_FACTORYPID));
for (Service service : serviceFactoryList) {
service.setFactory(true);
for (Metatype metatype : metatypeList) {
if (metatype.getId() != null && metatype.getId().equals(service.getId())) {
service.putAll(metatype);
}
}
Configuration[] configs = configurationAdmin.listConfigurations("(|(service.factoryPid=" + service.getId() + ")(service.factoryPid=" + service.getId() + "_disabled))");
if (configs != null) {
addConfigurationData(service, configs, configPidToOcdMap);
}
}
for (Service service : serviceList) {
service.setFactory(false);
for (Metatype metatype : metatypeList) {
if (metatype.getId() != null && metatype.getId().equals(service.getId())) {
service.putAll(metatype);
}
}
Configuration[] configs = configurationAdmin.listConfigurations("(" + SERVICE_PID + "=" + service.getId() + ")");
if (configs != null) {
addConfigurationData(service, configs, configPidToOcdMap);
}
}
serviceList.addAll(serviceFactoryList);
} catch (IOException e) {
LOGGER.warn("Unable to obtain list of Configuration objects from ConfigurationAdmin.", e);
} catch (InvalidSyntaxException e) {
LOGGER.info("Provided LDAP filter is incorrect: {}", LogSanitizer.sanitize(serviceFilter), e);
}
if (serviceList != null) {
return serviceList.stream().filter(service -> isPermittedToViewService(service.getId())).collect(Collectors.toList());
} else {
return new ArrayList<>();
}
}
Aggregations