Search in sources :

Example 6 with BeanMetadata

use of org.osgi.service.blueprint.reflect.BeanMetadata in project aries by apache.

the class ParserTest method testCustomNodes.

public void testCustomNodes() throws Exception {
    ComponentDefinitionRegistry registry = parse("/test-custom-nodes.xml", new TestNamespaceHandlerSet());
    ComponentMetadata metadata;
    metadata = registry.getComponentDefinition("fooService");
    assertNotNull(metadata);
    assertTrue(metadata instanceof MyLocalComponentMetadata);
    MyLocalComponentMetadata comp1 = (MyLocalComponentMetadata) metadata;
    assertEquals(true, comp1.getCacheReturnValues());
    assertEquals("getVolatile", comp1.getOperation());
    metadata = registry.getComponentDefinition("barService");
    assertNotNull(metadata);
    assertTrue(metadata instanceof BeanMetadata);
    BeanMetadata comp2 = (BeanMetadata) metadata;
    assertEquals(1, comp2.getProperties().size());
    BeanProperty propertyMetadata = comp2.getProperties().get(0);
    assertEquals("localCache", propertyMetadata.getName());
    Metadata propertyValue = propertyMetadata.getValue();
    assertTrue(propertyValue instanceof BeanMetadata);
    BeanMetadata innerComp = (BeanMetadata) propertyValue;
    assertEquals("org.apache.aries.CacheProperty", innerComp.getClassName());
    metadata = registry.getComponentDefinition("myCache");
    assertNotNull(metadata);
    assertTrue(metadata instanceof BeanMetadata);
    BeanMetadata comp3 = (BeanMetadata) metadata;
    assertEquals("org.apache.aries.Cache", comp3.getClassName());
}
Also used : BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 7 with BeanMetadata

use of org.osgi.service.blueprint.reflect.BeanMetadata in project aries by apache.

the class ParserTest method testScopes.

public void testScopes() throws Exception {
    ComponentDefinitionRegistry registry = parse("/test-scopes.xml", new TestNamespaceHandlerSet());
    ComponentMetadata metadata = registry.getComponentDefinition("fooService");
    assertNotNull(metadata);
    assertTrue(metadata instanceof BeanMetadata);
    BeanMetadata bm = (BeanMetadata) metadata;
    assertNull(bm.getScope());
    metadata = registry.getComponentDefinition("barService");
    assertNotNull(metadata);
    assertTrue(metadata instanceof BeanMetadata);
    bm = (BeanMetadata) metadata;
    assertEquals("prototype", bm.getScope());
    metadata = registry.getComponentDefinition("bazService");
    assertNotNull(metadata);
    assertTrue(metadata instanceof BeanMetadata);
    bm = (BeanMetadata) metadata;
    assertEquals("singleton", bm.getScope());
    metadata = registry.getComponentDefinition("booService");
    assertNotNull(metadata);
    assertTrue(metadata instanceof BeanMetadata);
    bm = (BeanMetadata) metadata;
    assertEquals("{http://test.org}boo", bm.getScope());
}
Also used : BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 8 with BeanMetadata

use of org.osgi.service.blueprint.reflect.BeanMetadata in project aries by apache.

the class BeanRecipe method runBeanProcPreInit.

private Object runBeanProcPreInit(Object obj) {
    String beanName = getName();
    BeanMetadata beanData = (BeanMetadata) blueprintContainer.getComponentDefinitionRegistry().getComponentDefinition(beanName);
    List<BeanProcessor> processors = blueprintContainer.getProcessors(BeanProcessor.class);
    //The start link of the chain, that provides the 
    //original, unprocessed bean to the head of the chain.
    BeanProcessor.BeanCreator initialBeanCreator = new BeanProcessor.BeanCreator() {

        public Object getBean() {
            Object obj = getInstance();
            //getinit, getdestroy, addpartial object don't need calling again.
            //however, property injection does.
            setProperties(obj);
            return obj;
        }
    };
    BeanProcessor.BeanCreator currentCreator = initialBeanCreator;
    for (BeanProcessor processor : processors) {
        obj = processor.beforeInit(obj, getName(), currentCreator, beanData);
        currentCreator = new BeanCreatorChain(currentCreator, processor, beanData, beanName, BeanCreatorChain.ChainType.Before);
    }
    return obj;
}
Also used : BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) BeanProcessor(org.apache.aries.blueprint.BeanProcessor)

Example 9 with BeanMetadata

use of org.osgi.service.blueprint.reflect.BeanMetadata in project aries by apache.

the class BlueprintContainerImpl method getMetadata.

private <T extends ComponentMetadata> void getMetadata(Class<T> clazz, Metadata component, Collection<T> metadatas) {
    if (component == null) {
        return;
    }
    if (clazz.isInstance(component)) {
        metadatas.add(clazz.cast(component));
    }
    if (component instanceof BeanMetadata) {
        getMetadata(clazz, ((BeanMetadata) component).getFactoryComponent(), metadatas);
        for (BeanArgument arg : ((BeanMetadata) component).getArguments()) {
            getMetadata(clazz, arg.getValue(), metadatas);
        }
        for (BeanProperty prop : ((BeanMetadata) component).getProperties()) {
            getMetadata(clazz, prop.getValue(), metadatas);
        }
    }
    if (component instanceof CollectionMetadata) {
        for (Metadata m : ((CollectionMetadata) component).getValues()) {
            getMetadata(clazz, m, metadatas);
        }
    }
    if (component instanceof MapMetadata) {
        for (MapEntry m : ((MapMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof PropsMetadata) {
        for (MapEntry m : ((PropsMetadata) component).getEntries()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
    }
    if (component instanceof ServiceReferenceMetadata) {
        for (ReferenceListener l : ((ServiceReferenceMetadata) component).getReferenceListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
    if (component instanceof ServiceMetadata) {
        getMetadata(clazz, ((ServiceMetadata) component).getServiceComponent(), metadatas);
        for (MapEntry m : ((ServiceMetadata) component).getServiceProperties()) {
            getMetadata(clazz, m.getKey(), metadatas);
            getMetadata(clazz, m.getValue(), metadatas);
        }
        for (RegistrationListener l : ((ServiceMetadata) component).getRegistrationListeners()) {
            getMetadata(clazz, l.getListenerComponent(), metadatas);
        }
    }
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 10 with BeanMetadata

use of org.osgi.service.blueprint.reflect.BeanMetadata in project aries by apache.

the class BlueprintContainerImpl method processProcessors.

private void processProcessors() throws Exception {
    // Instantiate ComponentDefinitionRegistryProcessor and BeanProcessor
    for (BeanMetadata bean : getMetadata(BeanMetadata.class)) {
        if (bean instanceof ExtendedBeanMetadata && !((ExtendedBeanMetadata) bean).isProcessor()) {
            continue;
        }
        Class clazz = null;
        if (bean instanceof ExtendedBeanMetadata) {
            clazz = ((ExtendedBeanMetadata) bean).getRuntimeClass();
        }
        if (clazz == null && bean.getClassName() != null) {
            clazz = loadClass(bean.getClassName());
        }
        if (clazz == null) {
            continue;
        }
        if (ComponentDefinitionRegistryProcessor.class.isAssignableFrom(clazz)) {
            Object obj = repository.create(bean.getId(), Arrays.<Class<?>>asList(ComponentDefinitionRegistryProcessor.class));
            ((ComponentDefinitionRegistryProcessor) obj).process(componentDefinitionRegistry);
        } else if (Processor.class.isAssignableFrom(clazz)) {
            Object obj = repository.create(bean.getId(), Arrays.<Class<?>>asList(Processor.class));
            this.processors.add((Processor) obj);
        } else {
            continue;
        }
        updateUninstantiatedRecipes();
    }
}
Also used : ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) Processor(org.apache.aries.blueprint.Processor) ComponentDefinitionRegistryProcessor(org.apache.aries.blueprint.ComponentDefinitionRegistryProcessor) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ComponentDefinitionRegistryProcessor(org.apache.aries.blueprint.ComponentDefinitionRegistryProcessor)

Aggregations

BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)20 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)9 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)5 ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)4 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)4 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)4 ArrayList (java.util.ArrayList)3 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)3 BeanArgument (org.osgi.service.blueprint.reflect.BeanArgument)3 BeanProperty (org.osgi.service.blueprint.reflect.BeanProperty)3 MapEntry (org.osgi.service.blueprint.reflect.MapEntry)3 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)3 Metadata (org.osgi.service.blueprint.reflect.Metadata)3 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)3 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 WrappedServiceMetadata (org.apache.aries.application.modelling.WrappedServiceMetadata)2 BeanProcessor (org.apache.aries.blueprint.BeanProcessor)2 ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)2