Search in sources :

Example 6 with ObjectClassDefinition

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;
}
Also used : HashMap(java.util.HashMap) AttributeDefinition(org.osgi.service.metatype.AttributeDefinition) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition)

Example 7 with ObjectClassDefinition

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;
}
Also used : Locale(java.util.Locale) MetaTypeService(org.osgi.service.metatype.MetaTypeService) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation) HashMap(java.util.HashMap) Map(java.util.Map) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition)

Example 8 with ObjectClassDefinition

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;
}
Also used : Dictionary(java.util.Dictionary) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) AttributeDefinition(org.osgi.service.metatype.AttributeDefinition) Entry(java.util.Map.Entry) Filter(org.osgi.framework.Filter) Iterator(java.util.Iterator) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectClassDefinition(org.osgi.service.metatype.ObjectClassDefinition)

Aggregations

ObjectClassDefinition (org.osgi.service.metatype.ObjectClassDefinition)8 HashMap (java.util.HashMap)6 AttributeDefinition (org.osgi.service.metatype.AttributeDefinition)6 ArrayList (java.util.ArrayList)5 Dictionary (java.util.Dictionary)4 Hashtable (java.util.Hashtable)4 Map (java.util.Map)4 Bundle (org.osgi.framework.Bundle)4 MetaTypeInformation (org.osgi.service.metatype.MetaTypeInformation)4 MetaTypeService (org.osgi.service.metatype.MetaTypeService)4 Iterator (java.util.Iterator)3 Locale (java.util.Locale)3 Entry (java.util.Map.Entry)3 BundleContext (org.osgi.framework.BundleContext)3 Filter (org.osgi.framework.Filter)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 ServiceReference (org.osgi.framework.ServiceReference)3 Sets (com.google.common.collect.Sets)2 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)2 KeyValuePermission (ddf.security.permission.KeyValuePermission)2