use of org.osgi.service.metatype.MetaTypeService in project felix by apache.
the class MetatypeSupport method check.
public boolean check(final Object obj, final Bundle providingBundle, final String pid) {
final MetaTypeService mts = (MetaTypeService) obj;
final MetaTypeInformation mti = mts.getMetaTypeInformation(providingBundle);
if (mti != null) {
try {
return mti.getObjectClassDefinition(pid, null) != null;
} catch (final IllegalArgumentException e) {
return false;
}
}
return false;
}
use of org.osgi.service.metatype.MetaTypeService in project felix by apache.
the class Activator method start.
/**
* Starts this bundle doing the following:
* <ol>
* <li>Register as listener for service events concerning the
* <code>LogService</code>
* <li>Try to get the <code>LogService</code>
* <li>Registers the <code>MetaTypeService</code> implementation provided
* by this bundle.
* </ol>
*
* @param context The <code>BundleContext</code> of this activator's bundle
*/
public void start(BundleContext context) {
// register for log service events
logService = new ServiceTracker(context, NAME_LOG_SERVICE, null);
logService.open();
// register the MetaTypeService now, that we are ready
Dictionary props = new Hashtable();
props.put(Constants.SERVICE_PID, "org.apache.felix.metatype.MetaTypeService");
props.put(Constants.SERVICE_DESCRIPTION, "MetaTypeService Specification 1.2 Implementation");
props.put(Constants.SERVICE_VENDOR, "Apache Software Foundation");
MetaTypeService metaTypeService = new MetaTypeServiceImpl(context);
context.registerService(MetaTypeService.class.getName(), metaTypeService, props);
}
use of org.osgi.service.metatype.MetaTypeService 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.MetaTypeService 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.MetaTypeService in project karaf by apache.
the class MetaServiceCaller method doWithMetaType.
/**
* Attempts to find MetaType information for the specified PID and
* invokes the supplied callback with the result of the search
*/
public static <T> T doWithMetaType(BundleContext context, String pid, Function<Optional<MetaInfo>, T> function) {
ServiceReference<MetaTypeService> ref = context.getServiceReference(MetaTypeService.class);
if (ref != null) {
try {
MetaTypeService metaService = context.getService(ref);
MetaInfo metaInfo = getMetatype(context, metaService, pid);
return function.apply(Optional.ofNullable(metaInfo));
} finally {
context.ungetService(ref);
}
}
return null;
}
Aggregations