use of org.osgi.service.metatype.ObjectClassDefinition 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;
}
use of org.osgi.service.metatype.ObjectClassDefinition 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.ObjectClassDefinition in project ddf by codice.
the class ConfigurationAdminExt method addMetaTypeNamesToMap.
public List<Map<String, Object>> addMetaTypeNamesToMap(final Map ocdCollection, final String filterSpec, final String type) {
Filter filter = null;
if (filterSpec != null) {
try {
filter = getBundleContext().createFilter(filterSpec);
} catch (InvalidSyntaxException ignore) {
// don't care
}
}
List<Map<String, Object>> metatypeList = new ArrayList<Map<String, Object>>();
Iterator ei = ocdCollection.entrySet().iterator();
while (ei.hasNext()) {
Entry ociEntry = (Entry) ei.next();
final String pid = (String) ociEntry.getKey();
final ObjectClassDefinition ocd = (ObjectClassDefinition) ociEntry.getValue();
if (filter == null) {
Map<String, Object> metatype = new HashMap<String, Object>();
metatype.put(MAP_ENTRY_ID, pid);
metatype.put(MAP_ENTRY_NAME, ocd.getName());
AttributeDefinition[] defs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
metatype.put(MAP_ENTRY_METATYPE, createMetatypeMap(defs));
metatypeList.add(metatype);
} else {
final Dictionary props = new Hashtable();
props.put(type, pid);
if (filter.match(props)) {
Map<String, Object> metatype = new HashMap<String, Object>();
metatype.put(MAP_ENTRY_ID, pid);
metatype.put(MAP_ENTRY_NAME, ocd.getName());
AttributeDefinition[] defs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
metatype.put(MAP_ENTRY_METATYPE, createMetatypeMap(defs));
metatypeList.add(metatype);
}
}
}
return metatypeList;
}
Aggregations