Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.Factory


    empty2.dispose();
  }
 
  public void testLevelTwo4() {
    ServiceContext sc1 = Utils.getServiceContext(empty);   
    Factory fact = Utils.getFactoryByName(sc1, "composite.empty");
    Properties p = new Properties();
    p.put("instance.name","empty2");
    ComponentInstance empty2 = null;
    try {
      empty2 = fact.createComponentInstance(p);
    } catch(Exception e) {
      fail("Cannot instantiate empty2 instance : " + e.getMessage());
    }
   
    ServiceContext sc2 = Utils.getServiceContext(empty2);
   
    Factory fact1 = Utils.getFactoryByName(sc2, "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name","client");
    ComponentInstance client = null;
    try {
      client = fact1.createComponentInstance(props, sc2);
    } catch(Exception e) { fail("Cannot instantiate the client : " + e.getMessage()); }
   
    Factory fact2 = Utils.getFactoryByName(sc2, "COMPO-FooProviderType-1");
    Properties props2 = new Properties();
    props2.put("instance.name","provider");
    ComponentInstance provider = null;
    try {
      provider = fact2.createComponentInstance(props2, sc2);
    } catch(Exception e) {
      fail("Cannot instantiate the provider : " + e.getMessage());
    }
   
    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
View Full Code Here


    ServiceReference[] internalFactoryReferences = Utils.getServiceReferences(sc, Factory.class.getName(), null);

    assertEquals("Check the number of available factories", parentsFactoryReferences.length, internalFactoryReferences.length);

    for(int i = 0; i < parentsFactoryReferences.length; i++) {
      Factory factory = (Factory) getContext().getService(parentsFactoryReferences[i]);
      assertTrue("Check the avaibility of " + factory.getName(), isExposed(factory, internalFactoryReferences, sc));
    }
  }
View Full Code Here

  public void testTwoLevelExposition() {
    ServiceReference[] parentsFactoryReferences = Utils.getServiceReferences(getContext(), Factory.class.getName(), null);
    ServiceContext sc1 = Utils.getServiceContext(empty);
    ServiceReference[] Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);

    Factory fact = Utils.getFactoryByName(sc1, "composite.empty");
    Properties p = new Properties();
    p.put("instance.name","empty2");
    ComponentInstance empty2 = null;
    try {
      empty2 = fact.createComponentInstance(p);
    } catch (Exception e) {
      fail("Cannot instantiate empty2 instance : " + e.getMessage());
    }

    ServiceContext sc2 = Utils.getServiceContext(empty2);
    ServiceReference[] Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);

    assertEquals("Check the number of available factories - 1", parentsFactoryReferences.length, Level1FactoryReferences.length);
    assertEquals("Check the number of available factories - 2", parentsFactoryReferences.length, Level2FactoryReferences.length);
    assertEquals("Check the number of available factories - 3", Level1FactoryReferences.length, Level2FactoryReferences.length);

    for(int i = 0; i < Level1FactoryReferences.length; i++) {
      Factory factory = (Factory) getContext().getService(parentsFactoryReferences[i]);
      assertTrue("Check the avaibility of " + factory.getName(), isExposed(factory, Level2FactoryReferences, sc2));
    }

    empty2.dispose();
  }
View Full Code Here

  public void testDynamism() {
    ServiceReference[] parentsFactoryReferences = Utils.getServiceReferences(getContext(), Factory.class.getName(), null);
    ServiceContext sc1 = Utils.getServiceContext(empty);
    ServiceReference[] Level1FactoryReferences = Utils.getServiceReferences(sc1, Factory.class.getName(), null);

    Factory fact = Utils.getFactoryByName(sc1, "composite.empty");
    Properties p = new Properties();
    p.put("instance.name","empty2");
    ComponentInstance empty2 = null;
    try {
      empty2 = fact.createComponentInstance(p);
    } catch (Exception e) {
      fail("Cannot instantiate empty2 instance : " + e.getMessage());
    }

    ServiceContext sc2 = Utils.getServiceContext(empty2);
    ServiceReference[] Level2FactoryReferences = Utils.getServiceReferences(sc2, Factory.class.getName(), null);

    assertEquals("Check the number of available factories - 1", parentsFactoryReferences.length, Level1FactoryReferences.length);
    assertEquals("Check the number of available factories - 2", parentsFactoryReferences.length, Level2FactoryReferences.length);
    assertEquals("Check the number of available factories - 3", Level1FactoryReferences.length, Level2FactoryReferences.length);

    for(int i = 0; i < Level1FactoryReferences.length; i++) {
      Factory factory = (Factory) getContext().getService(parentsFactoryReferences[i]);
      assertTrue("Check the avaibility of " + factory.getName(), isExposed(factory, Level2FactoryReferences, sc2));
    }

    // Publish fake1
    ServiceRegistration reg1 = getContext().registerService(Factory.class.getName(), fake1, null);
View Full Code Here

    empty2.dispose();
  }

  public void testInvocation() {
    ServiceContext sc1 = Utils.getServiceContext(empty);
    Factory fact = Utils.getFactoryByName(sc1, "composite.empty");
    Properties p = new Properties();
    p.put("instance.name","empty2");
    ComponentInstance empty2 = null;
    try {
      empty2 = fact.createComponentInstance(p);
    } catch (Exception e) {
      fail("Cannot instantiate empty2 instance : " + e.getMessage());
    }

    ServiceContext sc2 = Utils.getServiceContext(empty2);

    Factory fact1 = Utils.getFactoryByName(sc2, "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name","client");
    ComponentInstance client = null;
    try {
      client = fact1.createComponentInstance(props);
    } catch (Exception e) { e.printStackTrace(); fail("Cannot instantiate the client : " + e.getMessage()); }

    Factory fact2 = Utils.getFactoryByName(sc2, "COMPO-FooProviderType-1");
    Properties props2 = new Properties();
    props2.put("instance.name","provider");
    ComponentInstance provider = null;
    try {
      provider = fact2.createComponentInstance(props2);
    } catch (Exception e) {
      fail("Cannot instantiate the provider : " + e.getMessage());
    }

    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
View Full Code Here



  private boolean isExposed(Factory fact, ServiceReference[] refs, ServiceContext sc) {
    for(int i = 0; i < refs.length; i++) {
      Factory f = (Factory) sc.getService(refs[i]);
      if(fact.getName().equals(f.getName())) {
        sc.ungetService(refs[i]);
        return true;
      }
      sc.ungetService(refs[i]);
    }
View Full Code Here

    }
   
    foo1.stop();
    foo2.stop();
   
    Factory factory = Utils.getFactoryByName(getContext(), "composite.export.5");
    Properties props = new Properties();
    props.put("instance.name","export");
    try {
      export1 = factory.createComponentInstance(props);
    } catch(Exception e) {
      fail("Fail to instantiate exporter " + e.getMessage());
    }
  }
View Full Code Here

        }
       
        totoProv.stop();
        totoProv2.stop();
       
        Factory factory = Utils.getFactoryByName(getContext(), "comp-1");
        Properties props2 = new Properties();
        try {
            under = factory.createComponentInstance(props2);
        } catch(Exception e) {
            fail("Cannot create the instance : " + e.getMessage());
        }
        
    }
View Full Code Here

    }
   
    foo1.stop();
    foo2.stop();
   
    Factory factory = Utils.getFactoryByName(getContext(), "composite.export.1");
    Properties props = new Properties();
    props.put("instance.name","export");
    try {
      export1 = factory.createComponentInstance(props);
    } catch(Exception e) {
      fail("Fail to instantiate exporter " + e.getMessage());
    }
  }
View Full Code Here

    }
   
    foo1.stop();
    foo2.stop();
   
    Factory factory = Utils.getFactoryByName(getContext(), "composite.export.3");
    Properties props = new Properties();
    props.put("instance.name","export");
    try {
      export3 = factory.createComponentInstance(props);
    } catch(Exception e) {
      fail("Fail to instantiate exporter " + e.getMessage());
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.Factory

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.