Search in sources :

Example 11 with Repository

use of org.apache.aries.blueprint.di.Repository in project aries by apache.

the class WiringTest method testFieldInjection.

public void testFieldInjection() throws Exception {
    ComponentDefinitionRegistryImpl registry = parse("/test-wiring.xml");
    Repository repository = new TestBlueprintContainer(registry).getRepository();
    Object fiTestBean = repository.create("FITestBean");
    assertNotNull(fiTestBean);
    assertTrue(fiTestBean instanceof FITestBean);
    FITestBean bean = (FITestBean) fiTestBean;
    // single field injection
    assertEquals("value", bean.getAttr());
    // prefer setter injection to field injection
    assertEquals("IS_LOWER", bean.getUpperCaseAttr());
    // support cascaded injection 'bean.name' via fields
    assertEquals("aName", bean.getBeanName());
    // fail if field-injection is not specified
    try {
        repository.create("FIFailureTestBean");
        Assert.fail("Expected exception");
    } catch (ComponentDefinitionException cde) {
    }
    // fail if field-injection is false
    try {
        repository.create("FIFailureTest2Bean");
        Assert.fail("Expected exception");
    } catch (ComponentDefinitionException cde) {
    }
}
Also used : Repository(org.apache.aries.blueprint.di.Repository) BlueprintRepository(org.apache.aries.blueprint.container.BlueprintRepository) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) FITestBean(org.apache.aries.blueprint.pojos.FITestBean) MyObject(org.apache.aries.blueprint.pojos.PojoGenerics2.MyObject) ComponentDefinitionRegistryImpl(org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)

Example 12 with Repository

use of org.apache.aries.blueprint.di.Repository in project aries by apache.

the class BeanLoadingTest method testLoadSimpleBeanNested.

public void testLoadSimpleBeanNested() throws Exception {
    ComponentDefinitionRegistryImpl registry = parse("/test-bean-classes.xml");
    Repository repository = new TestBlueprintContainer(registry).getRepository();
    Object obj = repository.create("simpleBeanNested");
    assertNotNull(obj);
    assertTrue(obj instanceof SimpleBean.Nested);
}
Also used : Repository(org.apache.aries.blueprint.di.Repository) SimpleBean(org.apache.aries.blueprint.pojos.SimpleBean) ComponentDefinitionRegistryImpl(org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)

Example 13 with Repository

use of org.apache.aries.blueprint.di.Repository in project aries by apache.

the class BeanLoadingTest method testLoadSimpleBean.

public void testLoadSimpleBean() throws Exception {
    ComponentDefinitionRegistryImpl registry = parse("/test-bean-classes.xml");
    Repository repository = new TestBlueprintContainer(registry).getRepository();
    Object obj = repository.create("simpleBean");
    assertNotNull(obj);
    assertTrue(obj instanceof SimpleBean);
}
Also used : Repository(org.apache.aries.blueprint.di.Repository) SimpleBean(org.apache.aries.blueprint.pojos.SimpleBean) ComponentDefinitionRegistryImpl(org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)

Example 14 with Repository

use of org.apache.aries.blueprint.di.Repository in project aries by apache.

the class ServiceRecipe method createRecipe.

private Object createRecipe(Recipe recipe) {
    String name = recipe.getName();
    Repository repo = blueprintContainer.getRepository();
    if (repo.getRecipe(name) != recipe) {
        repo.putRecipe(name, recipe);
    }
    return repo.create(name);
}
Also used : Repository(org.apache.aries.blueprint.di.Repository)

Aggregations

Repository (org.apache.aries.blueprint.di.Repository)14 ComponentDefinitionRegistryImpl (org.apache.aries.blueprint.parser.ComponentDefinitionRegistryImpl)12 BlueprintRepository (org.apache.aries.blueprint.container.BlueprintRepository)8 MyObject (org.apache.aries.blueprint.pojos.PojoGenerics2.MyObject)6 HashMap (java.util.HashMap)4 BigInteger (java.math.BigInteger)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 Recipe (org.apache.aries.blueprint.di.Recipe)2 BeanD (org.apache.aries.blueprint.pojos.BeanD)2 PojoA (org.apache.aries.blueprint.pojos.PojoA)2 PojoB (org.apache.aries.blueprint.pojos.PojoB)2 SimpleBean (org.apache.aries.blueprint.pojos.SimpleBean)2 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)2 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1 List (java.util.List)1