use of org.osgi.service.metatype.AttributeDefinition in project ddf by codice.
the class ConfigurationAdminTest method getConfigAdmin.
private ConfigurationAdmin getConfigAdmin() throws IOException, InvalidSyntaxException {
final BundleContext testBundleContext = mock(BundleContext.class);
final MetaTypeService testMTS = mock(MetaTypeService.class);
ConfigurationAdminExt configurationAdminExt = new ConfigurationAdminExt(CONFIGURATION_ADMIN) {
@Override
BundleContext getBundleContext() {
return testBundleContext;
}
@Override
MetaTypeService getMetaTypeService() {
return testMTS;
}
@Override
public boolean isPermittedToViewService(String servicePid) {
return true;
}
};
ConfigurationAdmin configurationAdmin = new ConfigurationAdmin(CONFIGURATION_ADMIN, configurationAdminExt);
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 (TYPE type : 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.getBundle()).thenReturn(testBundle);
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(), anyString())).thenReturn(testConfig);
when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs);
when(testBundleContext.getAllServiceReferences(anyString(), anyString())).thenReturn(testServRefs);
return configurationAdmin;
}
use of org.osgi.service.metatype.AttributeDefinition in project ddf by codice.
the class SourceConfigurationHandler method getMetatypeDefaults.
private Map<String, Object> getMetatypeDefaults(String factoryPid) {
Map<String, Object> properties = new HashMap<>();
ObjectClassDefinition bundleMetatype = getObjectClassDefinition(factoryPid);
if (bundleMetatype != null) {
for (AttributeDefinition attributeDef : bundleMetatype.getAttributeDefinitions(ObjectClassDefinition.ALL)) {
if (attributeDef.getID() != null) {
if (attributeDef.getDefaultValue() != null) {
if (attributeDef.getCardinality() == 0) {
properties.put(attributeDef.getID(), getAttributeValue(attributeDef.getDefaultValue()[0], attributeDef.getType()));
} else {
properties.put(attributeDef.getID(), attributeDef.getDefaultValue());
}
} else if (attributeDef.getCardinality() != 0) {
properties.put(attributeDef.getID(), new String[0]);
}
}
}
}
return properties;
}
use of org.osgi.service.metatype.AttributeDefinition in project bndtools by bndtools.
the class TemplateParamsWizardPage method updateUI.
void updateUI() {
if (currentPanel != null && !currentPanel.isDisposed()) {
currentPanel.dispose();
currentPanel = null;
}
Composite panel = new Composite(container, SWT.NONE);
panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
skip = true;
if (template == null) {
setErrorMessage(null);
setMessage("No template is loaded", WARNING);
} else {
GridLayout layout = new GridLayout(2, false);
layout.horizontalSpacing = 15;
panel.setLayout(layout);
List<Control> fieldControls = new LinkedList<>();
try {
ocd = template.getMetadata();
int count = 0;
Set<String> requiredIds = new HashSet<>();
for (AttributeDefinition ad : ocd.getAttributeDefinitions(ObjectClassDefinition.REQUIRED)) {
requiredIds.add(ad.getID());
}
AttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
for (AttributeDefinition ad : ads) {
String attrib = ad.getID();
if (!fixedAttribs.contains(attrib)) {
Label label = new Label(panel, SWT.NONE);
String labelText = ad.getID();
if (requiredIds.contains(ad.getID())) {
label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
}
label.setText(labelText);
Control fieldControl = createFieldControl(panel, ad);
fieldControl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
fieldControls.add(fieldControl);
skip = false;
count++;
}
}
if (count == 0) {
setMessage("No editable parameters for template: " + ocd.getName(), INFORMATION);
} else {
setMessage("Edit parameters for template: " + ocd.getDescription(), INFORMATION);
}
setErrorMessage(null);
} catch (Exception e) {
setErrorMessage("Error loading template metadata: " + e.getMessage());
for (Control fieldControl : fieldControls) {
fieldControl.setEnabled(false);
}
}
}
currentPanel = panel;
container.layout(true, true);
updateValidation();
}
use of org.osgi.service.metatype.AttributeDefinition in project bndtools by bndtools.
the class TemplateParamsWizardPage method updateValidation.
private void updateValidation() {
boolean complete = true;
// Check required attribs
AttributeDefinition[] ads = ocd != null ? ocd.getAttributeDefinitions(ObjectClassDefinition.REQUIRED) : new AttributeDefinition[0];
for (AttributeDefinition ad : ads) {
// Skip attribs provided the wizard
if (fixedAttribs.contains(ad.getID()))
continue;
String value = values.get(ad.getID());
if (value == null || value.trim().isEmpty()) {
complete = false;
break;
}
}
// Validate values
// TODO
setPageComplete(complete);
}
use of org.osgi.service.metatype.AttributeDefinition in project ddf by codice.
the class ServiceManagerImpl method getMetatypeDefaults.
@Override
public Map<String, Object> getMetatypeDefaults(String symbolicName, String factoryPid) {
Map<String, Object> properties = new HashMap<>();
ObjectClassDefinition bundleMetatype = getObjectClassDefinition(symbolicName, factoryPid);
if (bundleMetatype != null) {
for (AttributeDefinition attributeDef : bundleMetatype.getAttributeDefinitions(ObjectClassDefinition.ALL)) {
if (attributeDef.getID() != null) {
if (attributeDef.getDefaultValue() != null) {
if (attributeDef.getCardinality() == 0) {
properties.put(attributeDef.getID(), getAttributeValue(attributeDef.getDefaultValue()[0], attributeDef.getType()));
} else {
properties.put(attributeDef.getID(), attributeDef.getDefaultValue());
}
} else if (attributeDef.getCardinality() != 0) {
properties.put(attributeDef.getID(), new String[0]);
}
}
}
} else {
LOGGER.debug("Metatype was null, returning an empty properties Map");
}
return properties;
}
Aggregations