Search in sources :

Example 21 with BlueprintContainer

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());
    }
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer)

Example 22 with BlueprintContainer

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;
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) NoSuchComponentException(org.osgi.service.blueprint.container.NoSuchComponentException)

Example 23 with BlueprintContainer

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();
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) BPMetadata(org.apache.aries.jmx.blueprint.codec.BPMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 24 with BlueprintContainer

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
    }
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) InterfaceC(org.apache.aries.blueprint.testbundlea.multi.InterfaceC) InterfaceD(org.apache.aries.blueprint.testbundlea.multi.InterfaceD) InterfaceB(org.apache.aries.blueprint.testbundlea.multi.InterfaceB) Test(org.junit.Test)

Example 25 with BlueprintContainer

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());
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultRunnable(org.apache.aries.blueprint.sample.DefaultRunnable) DefaultRunnable(org.apache.aries.blueprint.sample.DefaultRunnable) ServiceRegistration(org.osgi.framework.ServiceRegistration) DestroyTest(org.apache.aries.blueprint.sample.DestroyTest) Test(org.junit.Test)

Aggregations

BlueprintContainer (org.osgi.service.blueprint.container.BlueprintContainer)29 Test (org.junit.Test)14 Bundle (org.osgi.framework.Bundle)11 ServiceReference (org.osgi.framework.ServiceReference)6 Helper.mvnBundle (org.apache.aries.blueprint.itests.Helper.mvnBundle)5 List (java.util.List)4 BundleContext (org.osgi.framework.BundleContext)4 DestroyTest (org.apache.aries.blueprint.sample.DestroyTest)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)3 URL (java.net.URL)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 Hashtable (java.util.Hashtable)2 Map (java.util.Map)2 BindingListener (org.apache.aries.blueprint.sample.BindingListener)2 Foo (org.apache.aries.blueprint.sample.Foo)2 InterfaceA (org.apache.aries.blueprint.sample.InterfaceA)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)2