Search in sources :

Example 6 with MetaTypeInformation

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;
}
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)

Aggregations

MetaTypeInformation (org.osgi.service.metatype.MetaTypeInformation)6 Bundle (org.osgi.framework.Bundle)5 ArrayList (java.util.ArrayList)4 MetaTypeService (org.osgi.service.metatype.MetaTypeService)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HashSet (java.util.HashSet)2 BundleInfo (org.apache.karaf.features.BundleInfo)2 BundleContext (org.osgi.framework.BundleContext)2 ObjectClassDefinition (org.osgi.service.metatype.ObjectClassDefinition)2 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Locale (java.util.Locale)1 Application (org.codice.ddf.admin.application.service.Application)1 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)1 TYPE (org.codice.ddf.ui.admin.api.ConfigurationAdmin.TYPE)1 Test (org.junit.Test)1 Mockito.anyString (org.mockito.Mockito.anyString)1 ServiceReference (org.osgi.framework.ServiceReference)1