Search in sources :

Example 1 with ReferenceMetadata

use of org.osgi.service.blueprint.reflect.ReferenceMetadata in project camel by apache.

the class BlueprintContainerRegistry method lookupByType.

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<String, T>();
    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;
                    }
                }
                cl = bundle.loadClass(beanMetadata.getClassName());
            } 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;
}
Also used : BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) Bundle(org.osgi.framework.Bundle) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ReferenceMetadata

use of org.osgi.service.blueprint.reflect.ReferenceMetadata in project admin-console-beta by connexta.

the class BundleUtils method populateServices.

private void populateServices(Bundle bundle, BundleField toPopulate) {
    Optional<BlueprintContainer> blueprintContainer = getBlueprintContainer(bundle);
    if (blueprintContainer.isPresent()) {
        List<ComponentMetadata> cmpMetas = blueprintContainer.get().getComponentIds().stream().map(id -> blueprintContainer.get().getComponentMetadata(id)).collect(Collectors.toList());
        for (ComponentMetadata meta : cmpMetas) {
            if (meta instanceof ReferenceListMetadata) {
                populateServiceRefLists((ReferenceListMetadata) meta, bundle, toPopulate);
            } else if (meta instanceof ReferenceMetadata) {
                populateServiceRef((ReferenceMetadata) meta, bundle, toPopulate);
            } else if (meta instanceof BeanMetadata || meta instanceof ServiceMetadata || meta instanceof PassThroughMetadata) {
                continue;
            } else {
                LOGGER.warn("Unable to handle blueprint metadata of type {} for bundle {}.", meta.getClass(), bundle.getSymbolicName());
            }
        }
        getRegisteredServices(bundle).forEach(ref -> toPopulate.addService(createServiceField(ref)));
    }
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) ServiceReferenceField(org.codice.ddf.admin.query.dev.system.fields.ServiceReferenceField) ServiceReferenceListField(org.codice.ddf.admin.query.dev.system.fields.ServiceReferenceListField) BundleService(org.apache.karaf.bundle.core.BundleService) LoggerFactory(org.slf4j.LoggerFactory) PackageField(org.codice.ddf.admin.query.dev.system.fields.PackageField) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) ArrayList(java.util.ArrayList) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) Parser(org.apache.felix.utils.manifest.Parser) ServiceField(org.codice.ddf.admin.query.dev.system.fields.ServiceField) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) Clause(org.apache.felix.utils.manifest.Clause) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) GetBundles(org.codice.ddf.admin.query.dev.system.discover.GetBundles) Bundle(org.osgi.framework.Bundle) BundleField(org.codice.ddf.admin.query.dev.system.fields.BundleField) ServiceReference(org.osgi.framework.ServiceReference) Logger(org.slf4j.Logger) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) List(java.util.List) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata)

Example 3 with ReferenceMetadata

use of org.osgi.service.blueprint.reflect.ReferenceMetadata in project geronimo-xbean by apache.

the class XBeanNamespaceHandler method equals.

private boolean equals(NonNullMetadata key1, NonNullMetadata key2) {
    if (key1 == key2)
        return true;
    if (key1.getClass() != key2.getClass())
        return false;
    if (key1 instanceof RefMetadata)
        return ((RefMetadata) key1).getComponentId().equals(((RefMetadata) key2).getComponentId());
    if (key1 instanceof ReferenceMetadata) {
        if (((ReferenceMetadata) key1).getTimeout() != ((ReferenceMetadata) key2).getTimeout())
            return false;
    }
    if (key1 instanceof ServiceReferenceMetadata) {
        ServiceReferenceMetadata sr1 = (ServiceReferenceMetadata) key1;
        ServiceReferenceMetadata sr2 = (ServiceReferenceMetadata) key2;
        return sr1.getAvailability() == sr2.getAvailability() && sr1.getInterface().equals(sr2.getInterface()) && sr1.getComponentName().equals(sr2.getComponentName()) && sr1.getFilter().equals(sr2.getFilter()) && sr1.getReferenceListeners().equals(sr2.getReferenceListeners()) && sr1.getId().equals(sr2.getId()) && sr1.getActivation() == sr2.getActivation() && sr1.getDependsOn().equals(sr2.getDependsOn());
    }
    if (key1 instanceof ValueMetadata) {
        ValueMetadata v1 = (ValueMetadata) key1;
        ValueMetadata v2 = (ValueMetadata) key2;
        if (v1.getStringValue() != null ? v1.getStringValue().equals(v2.getStringValue()) : v2.getStringValue() == null && v1.getType() != null ? v1.getType().equals(v2.getType()) : v2.getType() == null) {
            return true;
        }
    }
    return false;
}
Also used : RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata)

Aggregations

ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)3 Bundle (org.osgi.framework.Bundle)2 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)2 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)1 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)1 MutableValueMetadata (org.apache.aries.blueprint.mutable.MutableValueMetadata)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang.StringUtils)1 Clause (org.apache.felix.utils.manifest.Clause)1 Parser (org.apache.felix.utils.manifest.Parser)1