Package org.osgi.service.blueprint.container

Examples of org.osgi.service.blueprint.container.BlueprintContainer


  public Object lookup(Name name) throws NamingException, ServiceUnavailableException
  {
    ServiceReference blueprintContainerRef = getBlueprintContainerRef(_callersBundle);
    Object result;
    try {
      BlueprintContainer 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);
View Full Code Here


   
    public BlueprintComponentNamingEnumeration (Bundle callersBundle, ComponentProcessor<T> p) throws ServiceUnavailableException
    {
      ServiceReference blueprintContainerRef = getBlueprintContainerRef(callersBundle);
      try {
        BlueprintContainer blueprintContainer = (BlueprintContainer) callersBundle.getBundleContext().getService(blueprintContainerRef);
        @SuppressWarnings("unchecked")
        Set<String> componentIds = blueprintContainer.getComponentIds();
        blueprintIdToComponentBindings = new Binding[componentIds.size()];
        Iterator<String> idIterator= componentIds.iterator();
        for (int i=0; i < blueprintIdToComponentBindings.length; i++) {
          String id = idIterator.next();
          Object o = blueprintContainer.getComponentInstance(id);
          blueprintIdToComponentBindings[i] = new Binding (id, o);
        }
        processor = p;
      } finally {
        callersBundle.getBundleContext().ungetService(blueprintContainerRef);
View Full Code Here

    }
   
    private BlueprintContainer getBlueprintContainer(String bundleName)
    {      
       BlueprintContainer container = null;
       try {
       container = getOsgiService(BlueprintContainer.class, "(osgi.blueprint.container.symbolicname=" + bundleName + ")", 500);
       } catch (RuntimeException e)
       {
          // Just return null if we couldn't get the container
View Full Code Here

    bundleContext.installBundle("fragment", fragmentJar.getInputStream());
    bundleContext.installBundle("host", hostJar.getInputStream()).start();
   
    Runnable r = context().getService(Runnable.class);
    assertNotNull("Could not find blueprint registered service", r);
    BlueprintContainer bc = Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.test.host");
    assertNotNull("Could not find blueprint container for bundle", bc);
  }
View Full Code Here

    bundleContext.installBundle("fragment", fragmentJar.getInputStream());
    bundleContext.installBundle("host", hostJar.getInputStream()).start();
   
    Runnable r = context().getService(Runnable.class);
    assertNotNull("Could not find blueprint registered service", r);
    BlueprintContainer bc = Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.test.host");
    assertNotNull("Could not find blueprint container for bundle", bc);
  }
View Full Code Here

        assertNotNull(bundleb);
        bundleb.start();
       
        //bundleb's container will hold the beans we need to query to check the function
        //provided by bundlea functioned as expected
        BlueprintContainer beanContainer =
            Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.blueprint.testbundleb");
        assertNotNull(beanContainer);

        //TestBeanA should have the values below, no interference should be present from other sources.
        Object obj1 = beanContainer.getComponentInstance("TestBeanA");
        assertTrue(obj1 instanceof TestBean);
        TestBean testBeanA = (TestBean)obj1;
        org.junit.Assert.assertEquals("RED", testBeanA.getRed());
        org.junit.Assert.assertEquals("GREEN", testBeanA.getGreen());
        org.junit.Assert.assertEquals("BLUE", testBeanA.getBlue());

        //TestBeanB tests that a custom ns handler is able to inject custom components to the blueprint,
        //and modify existing components, and use injected components as modifications.
        Object obj2 = beanContainer.getComponentInstance("TestBeanB");
        assertTrue(obj2 instanceof TestBean);
        TestBean testBeanB = (TestBean)obj2;
        //value should be set in via the added passthroughmetadata via the nshandler.
        org.junit.Assert.assertEquals("ONE_VALUE", testBeanB.getRed());
        org.junit.Assert.assertEquals("GREEN", testBeanB.getGreen());
        org.junit.Assert.assertEquals("BLUE", testBeanB.getBlue());       
       
        //TestBeanC tests that custom ns handlers can add interceptors to beans.
        Object obj3 = beanContainer.getComponentInstance("TestBeanC");
        assertTrue(obj3 instanceof TestBean);
        TestBean testBeanC = (TestBean)obj3;
      
        //handlers are in bundlea, with its own container.
        BlueprintContainer handlerContainer =
            Helper.getBlueprintContainerForBundle( context(), "org.apache.aries.blueprint.testbundlea");
        assertNotNull(handlerContainer);
       
        Object ns1 = handlerContainer.getComponentInstance("NSHandlerOne");
        assertTrue(ns1 instanceof NSHandlerOne);
       
        Object ns2 = handlerContainer.getComponentInstance("NSHandlerTwo");
        assertTrue(ns2 instanceof NSHandlerTwo);
        NSHandlerTwo nstwo = (NSHandlerTwo)ns2;
       
        //now we have a handle to the nshandler2, we can query what it 'saw', and ensure
        //that the interceptors are functioning as expected.
View Full Code Here

public class TestRegistrationListener extends AbstractIntegrationTest {

    @Test
    public void testWithAutoExportEnabled() throws Exception {

        BlueprintContainer blueprintContainer =
            Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.blueprint.sample");
       
        assertNotNull(blueprintContainer);

        Foo foo = context().getService(Foo.class, "(" + BlueprintConstants.COMPONENT_NAME_PROPERTY + "=foo)");
        assertEquals(5, foo.getA());

        FooRegistrationListener listener =
            (FooRegistrationListener) blueprintContainer.getComponentInstance("fooRegistrationListener");

        // If registration listener works fine, the registration method should
        // have already been called and properties that were passed to this
        // method should have been not null
View Full Code Here

        Bundle bundle = context().getBundleByName("org.apache.aries.blueprint.sample");
        assertNotNull(bundle);
        bundle.start();

        BlueprintContainer blueprintContainer = Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.blueprint.sample");
        assertNotNull(blueprintContainer);

        Foo foo = (Foo) blueprintContainer.getComponentInstance("none-managed");
        assertNotNull(foo);

        assertEquals(5, foo.getA());
        assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
View Full Code Here

        Bundle bundle = context().getBundleByName("org.apache.aries.blueprint.sample");
        assertNotNull(bundle);
        bundle.start();

        BlueprintContainer blueprintContainer = Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.blueprint.sample");
        assertNotNull(blueprintContainer);

        Foo foo = (Foo) blueprintContainer.getComponentInstance("container-managed");
        assertNotNull(foo);

        assertEquals(5, foo.getA());
        assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
View Full Code Here

        Bundle bundle = context().getBundleByName("org.apache.aries.blueprint.sample");
        assertNotNull(bundle);
        bundle.start();

        BlueprintContainer blueprintContainer = Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.blueprint.sample");
        assertNotNull(blueprintContainer);

        Foo foo = (Foo) blueprintContainer.getComponentInstance("component-managed");
        assertNotNull(foo);

        assertEquals(5, foo.getA());
        assertEquals(Currency.getInstance("PLN"), foo.getCurrency());
View Full Code Here

TOP

Related Classes of org.osgi.service.blueprint.container.BlueprintContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.