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