Search in sources :

Example 16 with BeanMetadata

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

the class AbstractParserProxy method traverseComponent.

/**
	   * Traverse {@link ComponentMetadata} instances to find all nested {@link ComponentMetadata} instances
	   * @param component
	   * @param output
	   */
private void traverseComponent(ComponentMetadata component, Set<ComponentMetadata> output) {
    if (!!!output.add(component))
        return;
    if (component instanceof BeanMetadata) {
        BeanMetadata bean = (BeanMetadata) component;
        traverse(bean.getFactoryComponent(), output);
        for (BeanArgument argument : bean.getArguments()) {
            traverse(argument.getValue(), output);
        }
        for (BeanProperty property : bean.getProperties()) {
            traverse(property.getValue(), output);
        }
    } else if (component instanceof ServiceMetadata) {
        ServiceMetadata service = (ServiceMetadata) component;
        traverse(service.getServiceComponent(), output);
        for (RegistrationListener listener : service.getRegistrationListeners()) {
            traverse(listener.getListenerComponent(), output);
        }
        for (MapEntry e : service.getServiceProperties()) {
            traverse(e.getKey(), output);
            traverse(e.getValue(), output);
        }
    } else if (component instanceof ServiceReferenceMetadata) {
        ServiceReferenceMetadata reference = (ServiceReferenceMetadata) component;
        for (ReferenceListener listener : reference.getReferenceListeners()) {
            traverse(listener.getListenerComponent(), output);
        }
    }
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 17 with BeanMetadata

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

the class BlueprintRepository method createInstances.

private Map<String, Object> createInstances(Collection<String> names) {
    // Instance creation is synchronized inside each create method (via the use of futures), so that 
    // a recipe will only created once where appropriate
    DependencyGraph graph = new DependencyGraph(this);
    HashMap<String, Object> objects = new LinkedHashMap<String, Object>();
    for (Map.Entry<String, Recipe> entry : graph.getSortedRecipes(names).entrySet()) {
        String name = entry.getKey();
        ComponentMetadata component = blueprintContainer.getComponentDefinitionRegistry().getComponentDefinition(name);
        boolean prototype = (component instanceof BeanMetadata) && MetadataUtil.isPrototypeScope((BeanMetadata) component);
        if (!prototype || names.contains(name)) {
            objects.put(name, entry.getValue().create());
        }
    }
    return objects;
}
Also used : IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) Recipe(org.apache.aries.blueprint.di.Recipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe) RefRecipe(org.apache.aries.blueprint.di.RefRecipe) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 18 with BeanMetadata

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

the class AbstractPropertyPlaceholder method processMetadata.

protected Metadata processMetadata(Metadata metadata) {
    try {
        if (metadata instanceof BeanMetadata) {
            BeanMetadata bmd = (BeanMetadata) metadata;
            processingStack.add("Bean named " + bmd.getId() + "->");
            return processBeanMetadata(bmd);
        } else if (metadata instanceof CollectionMetadata) {
            CollectionMetadata cmd = (CollectionMetadata) metadata;
            processingStack.add("Collection of type " + cmd.getCollectionClass() + "->");
            return processCollectionMetadata(cmd);
        } else if (metadata instanceof MapMetadata) {
            processingStack.add("Map->");
            return processMapMetadata((MapMetadata) metadata);
        } else if (metadata instanceof PropsMetadata) {
            processingStack.add("Properties->");
            return processPropsMetadata((PropsMetadata) metadata);
        } else if (metadata instanceof ValueMetadata) {
            processingStack.add("Value->");
            return processValueMetadata((ValueMetadata) metadata);
        } else {
            processingStack.add("Unknown Metadata " + metadata + "->");
            return metadata;
        }
    } finally {
        processingStack.removeLast();
    }
}
Also used : MutablePropsMetadata(org.apache.aries.blueprint.mutable.MutablePropsMetadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata)

Example 19 with BeanMetadata

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

the class NSHandlerThree method decorate.

public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
    if (node.getLocalName().equals(ATTRIB_ONE)) {
        if (component instanceof BeanMetadata) {
            if (context.getComponentDefinitionRegistry().getComponentDefinition(NSURI + "/BeanProcessor") == null) {
                BeanMetadata bm = context.createMetadata(BeanMetadata.class);
                MutableBeanMetadata mbm = (MutableBeanMetadata) bm;
                mbm.setProcessor(true);
                mbm.setRuntimeClass(BeanProcessorTest.class);
                mbm.setScope(BeanMetadata.SCOPE_SINGLETON);
                mbm.setId(NSURI + "/BeanProcessor");
                context.getComponentDefinitionRegistry().registerComponentDefinition(mbm);
            }
        }
    }
    return component;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata)

Example 20 with BeanMetadata

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

the class AnnotationEnablingNameSpaceHandlerTest method testAnnotationEnabled.

@Test
public void testAnnotationEnabled() throws Exception {
    ComponentDefinitionRegistry cdr = parseCDR("enable-annotations.xml");
    checkCompTop(cdr);
    BeanMetadata pmd = (BeanMetadata) cdr.getComponentDefinition(TxNamespaceHandler.ANNOTATION_PARSER_BEAN_NAME);
    assertNotNull(pmd);
    assertEquals(3, pmd.getArguments().size());
    assertEquals(cdr, ((PassThroughMetadata) pmd.getArguments().get(0).getValue()).getObject());
//      assertEquals(tm, ((PassThroughMetadata) pmd.getArguments().get(2).getValue()).getObject());
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) Test(org.junit.Test)

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