use of org.osgi.service.blueprint.reflect.ComponentMetadata in project cxf by apache.
the class BlueprintBeanLocator method getBeanNamesOfType.
/**
* {@inheritDoc}
*/
public List<String> getBeanNamesOfType(Class<?> type) {
Set<String> names = new LinkedHashSet<String>();
for (String s : container.getComponentIds()) {
ComponentMetadata cmd = container.getComponentMetadata(s);
Class<?> cls = getClassForMetaData(cmd);
if (cls != null && type.isAssignableFrom(cls)) {
names.add(s);
}
}
names.addAll(orig.getBeanNamesOfType(type));
return new ArrayList<>(names);
}
use of org.osgi.service.blueprint.reflect.ComponentMetadata in project cxf by apache.
the class BlueprintBeanLocator method loadBeansOfType.
/**
* {@inheritDoc}
*/
public <T> boolean loadBeansOfType(Class<T> type, BeanLoaderListener<T> listener) {
List<String> names = new ArrayList<>();
boolean loaded = false;
for (String s : container.getComponentIds()) {
ComponentMetadata cmd = container.getComponentMetadata(s);
Class<?> cls = getClassForMetaData(cmd);
if (cls != null && type.isAssignableFrom(cls)) {
names.add(s);
}
}
Collections.reverse(names);
for (String s : names) {
ComponentMetadata cmd = container.getComponentMetadata(s);
Class<?> beanType = getClassForMetaData(cmd);
Class<? extends T> t = beanType.asSubclass(type);
if (listener.loadBean(s, t)) {
Object o = container.getComponentInstance(s);
if (listener.beanLoaded(s, type.cast(o))) {
return true;
}
loaded = true;
}
}
try {
if (context != null) {
ServiceReference<?>[] refs = context.getServiceReferences(type.getName(), null);
if (refs != null) {
for (ServiceReference<?> r : refs) {
Object o2 = context.getService(r);
Class<? extends T> t = o2.getClass().asSubclass(type);
if (listener.loadBean(t.getName(), t)) {
if (listener.beanLoaded(t.getName(), type.cast(o2))) {
return true;
}
loaded = true;
}
}
}
}
} catch (Exception ex) {
// ignore, just don't support the OSGi services
LOG.info("Try to find the Bean with type:" + type + " from OSGi services and get error: " + ex);
}
return orig.loadBeansOfType(type, listener) || loaded;
}
use of org.osgi.service.blueprint.reflect.ComponentMetadata in project cxf by apache.
the class BlueprintBeanLocator method getBeansOfType.
/**
* {@inheritDoc}
*/
public <T> Collection<? extends T> getBeansOfType(Class<T> type) {
List<T> list = new ArrayList<>();
for (String s : container.getComponentIds()) {
ComponentMetadata cmd = container.getComponentMetadata(s);
Class<?> cls = getClassForMetaData(cmd);
if (cls != null && type.isAssignableFrom(cls)) {
list.add(type.cast(container.getComponentInstance(s)));
}
}
if (list.isEmpty() && context != null) {
try {
ServiceReference<?>[] refs = context.getServiceReferences(type.getName(), null);
if (refs != null) {
for (ServiceReference<?> r : refs) {
list.add(type.cast(context.getService(r)));
}
}
} catch (Exception ex) {
// ignore, just don't support the OSGi services
LOG.info("Try to find the Bean with type:" + type + " from OSGi services and get error: " + ex);
}
}
list.addAll(orig.getBeansOfType(type));
return list;
}
use of org.osgi.service.blueprint.reflect.ComponentMetadata in project cxf by apache.
the class AbstractBPBeanDefinitionParser method getBus.
protected MutableBeanMetadata getBus(ParserContext context, String name) {
ComponentDefinitionRegistry cdr = context.getComponentDefinitionRegistry();
ComponentMetadata meta = cdr.getComponentDefinition("blueprintBundle");
if (!cdr.containsComponentDefinition(InterceptorTypeConverter.class.getName())) {
MutablePassThroughMetadata md = context.createMetadata(MutablePassThroughMetadata.class);
md.setObject(new InterceptorTypeConverter());
md.setId(InterceptorTypeConverter.class.getName());
context.getComponentDefinitionRegistry().registerTypeConverter(md);
}
if (!cdr.containsComponentDefinition(name)) {
// Create a bus
MutableBeanMetadata bus = context.createMetadata(MutableBeanMetadata.class);
bus.setId(name);
bus.setRuntimeClass(BlueprintBus.class);
if (meta != null) {
// blueprint-no-osgi does not provide a bundleContext
bus.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
}
bus.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
bus.setDestroyMethod("shutdown");
bus.setInitMethod("initialize");
context.getComponentDefinitionRegistry().registerComponentDefinition(bus);
return bus;
}
return (MutableBeanMetadata) cdr.getComponentDefinition(name);
}
Aggregations