public static Map lookupByType()

in components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintContainerBeanRepository.java [103:137]


    public static <T> Map<String, T> lookupByType(BlueprintContainer blueprintContainer, Class<T> type, boolean includeNonSingletons) {
        Bundle bundle = (Bundle) blueprintContainer.getComponentInstance("blueprintBundle");
        Map<String, T> objects = new LinkedHashMap<>();
        Set<String> ids = blueprintContainer.getComponentIds();
        for (String id : ids) {
            try {
                ComponentMetadata metadata = blueprintContainer.getComponentMetadata(id);
                Class<?> cl = null;
                if (metadata instanceof BeanMetadata) {
                    BeanMetadata beanMetadata = (BeanMetadata)metadata;
                    // should we skip the bean if its prototype and we are only looking for singletons?
                    if (!includeNonSingletons) {
                        String scope = beanMetadata.getScope();
                        if (BeanMetadata.SCOPE_PROTOTYPE.equals(scope)) {
                            continue;
                        }
                    }
                    String clazz = beanMetadata.getClassName();
                    if (clazz != null) {
                        cl = bundle.loadClass(clazz);
                    }
                } else if (metadata instanceof ReferenceMetadata) {
                    ReferenceMetadata referenceMetadata = (ReferenceMetadata)metadata;
                    cl = bundle.loadClass(referenceMetadata.getInterface());
                }
                if (cl != null && type.isAssignableFrom(cl)) {
                    Object o = blueprintContainer.getComponentInstance(metadata.getId());
                    objects.put(metadata.getId(), type.cast(o));
                }
            } catch (Throwable t) {
                // ignore
            }
        }
        return objects;
    }