use of org.osgi.service.blueprint.container.BlueprintContainer in project cxf by apache.
the class CXFBlueprintServlet method loadBus.
@Override
protected void loadBus(ServletConfig servletConfig) {
BlueprintContainer container = (BlueprintContainer) servletConfig.getServletContext().getAttribute(CONTAINER_ATTRIBUTE);
if (container != null) {
Object busComponent = container.getComponentInstance("cxf");
setBus((Bus) busComponent);
} else {
busCreated = true;
setBus(BusFactory.newInstance().createBus());
}
}
use of org.osgi.service.blueprint.container.BlueprintContainer in project aries by apache.
the class BlueprintURLContext method lookup.
@Override
public Object lookup(Name name) throws NamingException, ServiceUnavailableException {
ServiceReference<BlueprintContainer> blueprintContainerRef = getBlueprintContainerRef(_callersBundle);
Object result;
try {
BlueprintContainer blueprintContainer = _callersBundle.getBundleContext().getService(blueprintContainerRef);
BlueprintName bpName;
if (name instanceof BlueprintName) {
bpName = (BlueprintName) name;
} else if (_parentName != null) {
bpName = new BlueprintName(_parentName.toString() + "/" + name.toString());
} else {
bpName = (BlueprintName) _parser.parse(name.toString());
}
if (bpName.hasComponent()) {
String componentId = bpName.getComponentId();
try {
result = blueprintContainer.getComponentInstance(componentId);
} catch (NoSuchComponentException nsce) {
throw new NameNotFoundException(nsce.getMessage());
}
} else {
result = new BlueprintURLContext(_callersBundle, bpName, _env);
}
} finally {
_callersBundle.getBundleContext().ungetService(blueprintContainerRef);
}
return result;
}
use of org.osgi.service.blueprint.container.BlueprintContainer in project aries by apache.
the class BlueprintMetadata method getComponentMetadata.
public CompositeData getComponentMetadata(long containerServiceId, String componentId) throws IOException {
BlueprintContainer container = getBlueprintContainer(containerServiceId);
ComponentMetadata componentMetadata = container.getComponentMetadata(componentId);
BPMetadata metadata = Util.metadata2BPMetadata(componentMetadata);
return metadata.asCompositeData();
}
use of org.osgi.service.blueprint.container.BlueprintContainer in project aries by apache.
the class MultiInterfacesTest method testMultiInterfaceReferences.
@Test
public void testMultiInterfaceReferences() throws Exception {
// bundlea provides the ns handlers, bean processors, interceptors etc for this test.
startBundleBlueprint("org.apache.aries.blueprint.testbundlea");
// bundleb makes use of the extensions provided by bundlea
// bundleb's container will hold the beans we need to query to check the function
// provided by bundlea functioned as expected
BlueprintContainer beanContainer = startBundleBlueprint("org.apache.aries.blueprint.testbundleb");
Object obj1 = beanContainer.getComponentInstance("OnlyA");
Object obj2 = beanContainer.getComponentInstance("AandB");
Object obj3 = beanContainer.getComponentInstance("AandBandC");
Object obj4 = beanContainer.getComponentInstance("AandBandCandD");
assertEquals("A", ((InterfaceA) obj1).methodA());
assertEquals("A", ((InterfaceA) obj2).methodA());
assertEquals("A", ((InterfaceA) obj3).methodA());
assertEquals("B", ((InterfaceB) obj2).methodB());
assertEquals("C", ((InterfaceC) obj3).methodC());
assertFalse(obj1 instanceof InterfaceC);
assertFalse(obj2 instanceof InterfaceC);
assertFalse(obj1 instanceof InterfaceB);
assertTrue(obj4 instanceof InterfaceD);
try {
((InterfaceD) obj4).methodD();
fail("This should not work");
} catch (org.osgi.service.blueprint.container.ServiceUnavailableException t) {
// expected
}
}
use of org.osgi.service.blueprint.container.BlueprintContainer in project aries by apache.
the class TestReferences method testDefaultReference.
@SuppressWarnings("rawtypes")
@Test
public void testDefaultReference() throws Exception {
BlueprintContainer blueprintContainer = Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.blueprint.sample");
assertNotNull(blueprintContainer);
Runnable refRunnable = (Runnable) blueprintContainer.getComponentInstance("refWithDefault");
DefaultRunnable defaultRunnable = (DefaultRunnable) blueprintContainer.getComponentInstance("defaultRunnable");
refRunnable.run();
waitForAsynchronousHandling();
Thread.sleep(2000);
assertEquals("The default runnable was not called", 1, defaultRunnable.getCount());
final AtomicBoolean called = new AtomicBoolean(false);
Runnable mockService = new Runnable() {
public void run() {
called.set(true);
}
};
ServiceRegistration reg = bundleContext.registerService(Runnable.class.getName(), mockService, null);
waitForAsynchronousHandling();
Thread.sleep(2000);
refRunnable.run();
assertEquals("The default runnable was called when a service was bound", 1, defaultRunnable.getCount());
Assert.assertTrue("Service should have been called", called.get());
reg.unregister();
waitForAsynchronousHandling();
Thread.sleep(2000);
refRunnable.run();
assertEquals("The default runnable was not called", 2, defaultRunnable.getCount());
}
Aggregations