use of org.osgi.service.metatype.MetaTypeInformation in project karaf by apache.
the class MetaCompleter method updateMeta.
private synchronized void updateMeta() {
List<String> pids = MetaServiceCaller.withMetaTypeService(context, metatypeService -> {
List<String> pids1 = new ArrayList<>();
Bundle[] bundles = context.getBundles();
for (Bundle bundle : bundles) {
MetaTypeInformation info = metatypeService.getMetaTypeInformation(bundle);
if (info == null) {
continue;
}
if (info.getFactoryPids() != null) {
pids1.addAll(Arrays.asList(info.getFactoryPids()));
}
if (info.getPids() != null) {
pids1.addAll(Arrays.asList(info.getPids()));
}
}
return pids1;
});
if (pids != null) {
delegate.getStrings().clear();
delegate.getStrings().addAll(pids);
}
}
use of org.osgi.service.metatype.MetaTypeInformation in project felix by apache.
the class StoreResourceTask method getMetaTypeOCD.
/**
* Determines the object class definition matching the specified designate.
*
* @param data The meta data containing 'local' object class definitions.
* @param designate The designate whose object class definition should be determined.
* @return
* @throws ResourceProcessorException
*/
private ObjectClassDefinition getMetaTypeOCD(MetaData data, Designate designate) throws ResourceProcessorException {
boolean isFactoryConfig = isFactoryConfig(designate);
Bundle bundle = getBundle(designate.getBundleLocation(), isFactoryConfig);
if (bundle == null) {
return null;
}
MetaTypeInformation mti = m_metaService.getMetaTypeInformation(bundle);
if (mti == null) {
return null;
}
String pid = isFactoryConfig ? pid = designate.getFactoryPid() : designate.getPid();
try {
ObjectClassDefinition tempOcd = mti.getObjectClassDefinition(pid, null);
// tempOcd will always have a value, if pid was not known IAE will be thrown
String ocdRef = designate.getObject().getOcdRef();
if (ocdRef.equals(tempOcd.getID())) {
return tempOcd;
}
} catch (IllegalArgumentException iae) {
// let null be returned
}
return null;
}
use of org.osgi.service.metatype.MetaTypeInformation in project felix by apache.
the class MetaTypeServiceImplTest method testAfterCretionManagedServiceFactory.
public void testAfterCretionManagedServiceFactory() {
MetaTypeService mts = new MetaTypeServiceImpl(bundleContext);
MetaTypeInformation mti = mts.getMetaTypeInformation(bundleContext.getBundle());
// assert still empty
checkEmpty(mti);
// register a service with PID
String factoryPid = "testAfterCreation_factory";
MockManagedServiceFactory service = new MockManagedServiceFactory();
Dictionary props = new Hashtable();
props.put(Constants.SERVICE_PID, factoryPid);
ServiceRegistration sr = bundleContext.registerService(ManagedServiceFactory.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 be empty
assertTrue(mti.getPids() == null || mti.getPids().length == 0);
// pids must contain pid
assertNotNull(mti.getFactoryPids());
assertTrue(mti.getFactoryPids().length == 1);
assertEquals(factoryPid, mti.getFactoryPids()[0]);
// change the service PID
String factoryPid2 = "testAfterCreation2";
Dictionary props2 = new Hashtable();
props2.put(Constants.SERVICE_PID, factoryPid2);
sr.setProperties(props2);
// pids must contain pid2
assertNotNull(mti.getFactoryPids());
assertTrue(mti.getFactoryPids().length == 1);
assertEquals(factoryPid2, mti.getFactoryPids()[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 MetaTypeServiceSupport method getObjectClassDefinitions.
/**
* Returns the <code>ObjectClassDefinition</code> objects for the IDs
* returned by the <code>idGetter</code>. Depending on the
* <code>idGetter</code> implementation this will be for factory PIDs or
* plain PIDs.
*
* @param idGetter The {@link IdGetter} used to get the list of factory PIDs
* or PIDs from <code>MetaTypeInformation</code> objects.
* @param locale The name of the locale to get the object class definitions
* for.
* @return Map of <code>ObjectClassDefinition</code> objects indexed by the
* PID (or factory PID) to which they pertain
*/
private Map getObjectClassDefinitions(final IdGetter idGetter, final String locale) {
final Map objectClassesDefinitions = new HashMap();
final MetaTypeService mts = this.getMetaTypeService();
if (mts != null) {
final Bundle[] bundles = this.getBundleContext().getBundles();
for (int i = 0; i < bundles.length; i++) {
final MetaTypeInformation mti = mts.getMetaTypeInformation(bundles[i]);
if (mti != null) {
final String[] idList = idGetter.getIds(mti);
for (int j = 0; idList != null && j < idList.length; j++) {
// After getting the list of PIDs, a configuration might be
// removed. So the getObjectClassDefinition will throw
// an exception, and this will prevent ALL configuration from
// being displayed. By catching it, the configurations will be
// visible
ObjectClassDefinition ocd = null;
try {
ocd = mti.getObjectClassDefinition(idList[j], locale);
} catch (IllegalArgumentException ignore) {
// ignore - just don't show this configuration
}
if (ocd != null) {
objectClassesDefinitions.put(idList[j], ocd);
}
}
}
}
}
return objectClassesDefinitions;
}
use of org.osgi.service.metatype.MetaTypeInformation in project ddf by codice.
the class ApplicationServiceBean method checkForMetaTypesForService.
/**
* Checks to see if there are any metatypes out there for a particular service.
*
* @param metatypeInformations - Where we'll look for metatypes that match our service from.
* @param service - our service we want metatypes for.
* @return true if there is, and the service should be added, or false if it shouldn't be.
*/
private boolean checkForMetaTypesForService(Set<MetaTypeInformation> metatypeInformations, Map<String, Object> service) {
String id = (String) service.get("id");
boolean ifFactory = (Boolean) service.get("factory");
if (ifFactory) {
for (MetaTypeInformation information : metatypeInformations) {
if (information != null) {
for (String pid : information.getFactoryPids()) {
if (pid.equals(id)) {
return true;
}
}
}
}
} else {
for (MetaTypeInformation information : metatypeInformations) {
if (information != null) {
for (String pid : information.getPids()) {
if (pid.equals(id)) {
return true;
}
}
}
}
}
return false;
}
Aggregations