Search in sources :

Example 1 with BundleInfo

use of org.apache.felix.webconsole.bundleinfo.BundleInfo in project felix by apache.

the class BundlesServlet method bundleInfoDetails.

private final void bundleInfoDetails(List<Map<String, Object>> props, Bundle bundle, String appRoot, final Locale locale) {
    final Map<String, Object> val = new LinkedHashMap<String, Object>();
    val.put("key", "nfo");
    final Map<String, Object[]> value = new LinkedHashMap<String, Object[]>();
    final Object[] bundleInfoProviders = bundleInfoTracker.getServices();
    for (int i = 0; bundleInfoProviders != null && i < bundleInfoProviders.length; i++) {
        final BundleInfoProvider infoProvider = (BundleInfoProvider) bundleInfoProviders[i];
        final BundleInfo[] infos = infoProvider.getBundleInfo(bundle, appRoot, locale);
        if (null != infos && infos.length > 0) {
            final Object[] infoArray = new Object[infos.length];
            for (int j = 0; j < infos.length; j++) {
                infoArray[j] = bundleInfo(infos[j]);
            }
            value.put(infoProvider.getName(locale), infoArray);
        }
    }
    val.put("value", value);
    props.add(val);
}
Also used : BundleInfo(org.apache.felix.webconsole.bundleinfo.BundleInfo) LinkedHashMap(java.util.LinkedHashMap) BundleInfoProvider(org.apache.felix.webconsole.bundleinfo.BundleInfoProvider)

Example 2 with BundleInfo

use of org.apache.felix.webconsole.bundleinfo.BundleInfo in project felix by apache.

the class InfoProvider method getBundleInfo.

/**
 * @see org.apache.felix.webconsole.bundleinfo.BundleInfoProvider#getBundleInfo(org.osgi.framework.Bundle,
 *      java.lang.String, java.util.Locale)
 */
public BundleInfo[] getBundleInfo(Bundle bundle, String webConsoleRoot, Locale locale) {
    final List<ComponentDescriptionDTO> disabled = new ArrayList<ComponentDescriptionDTO>();
    final List<ComponentConfigurationDTO> configurations = new ArrayList<ComponentConfigurationDTO>();
    final Collection<ComponentDescriptionDTO> descs = scrService.getComponentDescriptionDTOs(bundle);
    for (final ComponentDescriptionDTO d : descs) {
        if (!scrService.isComponentEnabled(d)) {
            disabled.add(d);
        } else {
            final Collection<ComponentConfigurationDTO> configs = scrService.getComponentConfigurationDTOs(d);
            if (configs.isEmpty()) {
                disabled.add(d);
            } else {
                configurations.addAll(configs);
            }
        }
    }
    Collections.sort(configurations, Util.COMPONENT_COMPARATOR);
    if (configurations.isEmpty()) {
        return NO_INFO;
    }
    BundleInfo[] ret = new BundleInfo[configurations.size() + disabled.size()];
    int i = 0;
    for (final ComponentDescriptionDTO cfg : disabled) {
        ret[i] = toInfo(cfg, webConsoleRoot, locale);
        i++;
    }
    for (final ComponentConfigurationDTO cfg : configurations) {
        ret[i] = toInfo(cfg, webConsoleRoot, locale);
        i++;
    }
    return ret;
}
Also used : BundleInfo(org.apache.felix.webconsole.bundleinfo.BundleInfo) ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ArrayList(java.util.ArrayList) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)

Example 3 with BundleInfo

use of org.apache.felix.webconsole.bundleinfo.BundleInfo in project felix by apache.

the class InfoProvider method toInfo.

private BundleInfo toInfo(final ComponentConfigurationDTO cfg, String webConsoleRoot, Locale locale) {
    final ResourceBundle bundle = localization.getResourceBundle(locale);
    final String state = ComponentConfigurationPrinter.toStateString(cfg.state);
    final String name = cfg.description.name;
    // $NON-NLS-1$;
    final String descr = bundle.getString("info.descr");
    // $NON-NLS-1$;
    String key = bundle.getString("info.key");
    // Component #{0} {1}, state {2}
    key = MessageFormat.format(key, new Object[] { String.valueOf(cfg.id), name, state });
    return new // $NON-NLS-1$
    BundleInfo(// $NON-NLS-1$
    key, // $NON-NLS-1$
    (webConsoleRoot == null ? "" : webConsoleRoot) + "/components/" + cfg.id, BundleInfoType.LINK, descr);
}
Also used : BundleInfo(org.apache.felix.webconsole.bundleinfo.BundleInfo) ResourceBundle(java.util.ResourceBundle)

Example 4 with BundleInfo

use of org.apache.felix.webconsole.bundleinfo.BundleInfo in project felix by apache.

the class InfoProvider method toInfo.

private BundleInfo toInfo(final ComponentDescriptionDTO cfg, String webConsoleRoot, Locale locale) {
    final ResourceBundle bundle = localization.getResourceBundle(locale);
    final String state = "disabled";
    final String name = cfg.name;
    // $NON-NLS-1$;
    final String descr = bundle.getString("info.descr");
    // $NON-NLS-1$;
    String key = bundle.getString("info.key");
    // Component #{0} {1}, state {2}
    key = MessageFormat.format(key, new Object[] { // $NON-NLS-1$
    "", name, state });
    return new BundleInfo(key, // $NON-NLS-1$
    (webConsoleRoot == null ? "" : webConsoleRoot) + "/components", BundleInfoType.LINK, descr);
}
Also used : BundleInfo(org.apache.felix.webconsole.bundleinfo.BundleInfo) ResourceBundle(java.util.ResourceBundle)

Aggregations

BundleInfo (org.apache.felix.webconsole.bundleinfo.BundleInfo)4 ResourceBundle (java.util.ResourceBundle)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 BundleInfoProvider (org.apache.felix.webconsole.bundleinfo.BundleInfoProvider)1 ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)1 ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)1