use of org.osgi.service.metatype.MetaTypeInformation in project ddf by codice.
the class AdminConsoleServiceTest method getConfigAdmin.
private AdminConsoleService getConfigAdmin() throws IOException, InvalidSyntaxException, NotCompliantMBeanException {
final BundleContext testBundleContext = mock(BundleContext.class);
final MetaTypeService testMTS = mock(MetaTypeService.class);
ConfigurationAdminImpl configurationAdminImpl = new ConfigurationAdminImpl(CONFIGURATION_ADMIN, new ArrayList<>()) {
@Override
BundleContext getBundleContext() {
return testBundleContext;
}
@Override
MetaTypeService getMetaTypeService() {
return testMTS;
}
@Override
public boolean isPermittedToViewService(String servicePid) {
return true;
}
@Override
public boolean isPermittedToViewService(String servicePid, Subject subject) {
return true;
}
};
AdminConsoleService configurationAdmin = new AdminConsoleService(CONFIGURATION_ADMIN, configurationAdminImpl) {
@Override
public boolean isPermittedToViewService(String servicePid) {
return true;
}
};
configurationAdmin.setGuestClaimsHandlerExt(mockGuestClaimsHandlerExt);
Dictionary<String, Object> testProp = new Hashtable<>();
testProp.put(TEST_KEY, TEST_VALUE);
when(testConfig.getPid()).thenReturn(TEST_PID);
when(testConfig.getFactoryPid()).thenReturn(TEST_FACTORY_PID);
when(testConfig.getBundleLocation()).thenReturn(TEST_LOCATION);
when(testConfig.getProperties()).thenReturn(testProp);
Bundle testBundle = mock(Bundle.class);
Dictionary bundleHeaders = mock(Dictionary.class);
MetaTypeInformation testMTI = mock(MetaTypeInformation.class);
ObjectClassDefinition testOCD = mock(ObjectClassDefinition.class);
ServiceReference testRef1 = mock(ServiceReference.class);
ServiceReference[] testServRefs = { testRef1 };
ArrayList<AttributeDefinition> attDefs = new ArrayList<>();
for (int cardinality : CARDINALITIES) {
for (AdminConsoleService.TYPE type : AdminConsoleService.TYPE.values()) {
AttributeDefinition testAttDef = mock(AttributeDefinition.class);
when(testAttDef.getCardinality()).thenReturn(cardinality);
when(testAttDef.getType()).thenReturn(type.getType());
when(testAttDef.getID()).thenReturn(getKey(cardinality, type));
attDefs.add(testAttDef);
}
}
when(testRef1.getProperty(Constants.SERVICE_PID)).thenReturn(TEST_PID);
when(testRef1.getBundle()).thenReturn(testBundle);
when(testBundle.getLocation()).thenReturn(TEST_LOCATION);
when(testBundle.getHeaders(anyString())).thenReturn(bundleHeaders);
when(bundleHeaders.get(Constants.BUNDLE_NAME)).thenReturn(TEST_BUNDLE_NAME);
when(testOCD.getName()).thenReturn(TEST_OCD);
when(testOCD.getAttributeDefinitions(ObjectClassDefinition.ALL)).thenReturn(attDefs.toArray(new AttributeDefinition[attDefs.size()]));
when(testMTI.getFactoryPids()).thenReturn(new String[] { TEST_FACTORY_PID });
when(testMTI.getPids()).thenReturn(new String[] { TEST_PID });
when(testMTI.getObjectClassDefinition(anyString(), anyString())).thenReturn(testOCD);
when(testMTS.getMetaTypeInformation(testBundle)).thenReturn(testMTI);
when(testBundleContext.getBundles()).thenReturn(new Bundle[] { testBundle });
when(CONFIGURATION_ADMIN.listConfigurations(anyString())).thenReturn(new Configuration[] { testConfig });
when(CONFIGURATION_ADMIN.getConfiguration(anyString(), any())).thenReturn(testConfig);
when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs);
when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs);
return configurationAdmin;
}
use of org.osgi.service.metatype.MetaTypeInformation in project karaf by apache.
the class MetaServiceCaller method getPidsWithMetaInfo.
public static List<String> getPidsWithMetaInfo(BundleContext context) {
return withMetaTypeService(context, metatypeService -> {
List<String> pids1 = new ArrayList<>();
Bundle[] bundles = context.getBundles();
if (metatypeService != null) {
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;
});
}
use of org.osgi.service.metatype.MetaTypeInformation in project karaf by apache.
the class MetaServiceCaller method getMetatype.
private static MetaInfo getMetatype(BundleContext context, MetaTypeService metaTypeService, String pid) {
if (metaTypeService != null) {
for (Bundle bundle : context.getBundles()) {
MetaTypeInformation info = metaTypeService.getMetaTypeInformation(bundle);
if (info == null) {
continue;
}
String[] pids = info.getPids();
for (String cPid : pids) {
if (cPid.equals(pid)) {
return new MetaInfo(info.getObjectClassDefinition(cPid, null), false);
}
}
pids = info.getFactoryPids();
for (String cPid : pids) {
if (cPid.equals(pid)) {
return new MetaInfo(info.getObjectClassDefinition(cPid, null), true);
}
}
}
}
return null;
}
use of org.osgi.service.metatype.MetaTypeInformation in project ddf by codice.
the class ConfigurationAdminExt 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.
* @return Map of <code>ObjectClassDefinition</code> objects indexed by the PID (or factory PID)
* to which they pertain
*/
private Map getObjectClassDefinitions(final IdGetter idGetter) {
Locale locale = Locale.getDefault();
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.toString());
} 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 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;
}
Aggregations