Search in sources :

Example 1 with BeanProperty

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

the class ExtNamespaceHandler method parseDefaultProperties.

private Metadata parseDefaultProperties(ParserContext context, MutableBeanMetadata enclosingComponent, Element element) {
    MutableMapMetadata props = context.createMetadata(MutableMapMetadata.class);
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            if (isExtNamespace(e.getNamespaceURI())) {
                if (nodeNameEquals(e, PROPERTY_ELEMENT)) {
                    BeanProperty prop = context.parseElement(BeanProperty.class, enclosingComponent, e);
                    props.addEntry(createValue(context, prop.getName(), String.class.getName()), prop.getValue());
                }
            }
        }
    }
    return props;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 2 with BeanProperty

use of org.osgi.service.blueprint.reflect.BeanProperty 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 3 with BeanProperty

use of org.osgi.service.blueprint.reflect.BeanProperty 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 4 with BeanProperty

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

the class AbstractPropertyPlaceholder method processBeanMetadata.

protected Metadata processBeanMetadata(BeanMetadata component) {
    for (BeanArgument arg : component.getArguments()) {
        try {
            processingStack.add("Argument index " + arg.getIndex() + " and value type " + arg.getValueType() + "->");
            if (arg instanceof MutableBeanArgument) {
                ((MutableBeanArgument) arg).setValue(processMetadata(arg.getValue()));
            } else {
                //Say that we can't change this argument, but continue processing
                //If the value is mutable then we may be ok!
                printWarning(arg, "Constructor Argument");
                processMetadata(arg.getValue());
            }
        } finally {
            processingStack.removeLast();
        }
    }
    for (BeanProperty prop : component.getProperties()) {
        try {
            processingStack.add("Property named " + prop.getName() + "->");
            if (prop instanceof MutableBeanProperty) {
                ((MutableBeanProperty) prop).setValue(processMetadata(prop.getValue()));
            } else {
                //Say that we can't change this property, but continue processing
                //If the value is mutable then we may be ok!
                printWarning(prop, "Injection Property");
                processMetadata(prop.getValue());
            }
        } finally {
            processingStack.removeLast();
        }
    }
    Target factoryComponent = component.getFactoryComponent();
    if (factoryComponent != null) {
        try {
            if (component instanceof MutableBeanMetadata) {
                processingStack.add("Factory Component->");
                ((MutableBeanMetadata) component).setFactoryComponent((Target) processMetadata(factoryComponent));
            } else {
                printWarning(component, "Factory Component");
                processingStack.add("Factory Component->");
                processMetadata(factoryComponent);
            }
        } finally {
            processingStack.removeLast();
        }
    }
    return component;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableBeanArgument(org.apache.aries.blueprint.mutable.MutableBeanArgument) BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) Target(org.osgi.service.blueprint.reflect.Target) MutableBeanArgument(org.apache.aries.blueprint.mutable.MutableBeanArgument) MutableBeanProperty(org.apache.aries.blueprint.mutable.MutableBeanProperty) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty) MutableBeanProperty(org.apache.aries.blueprint.mutable.MutableBeanProperty)

Example 5 with BeanProperty

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

the class CmNamespaceHandler method parseDefaultProperties.

private Metadata parseDefaultProperties(ParserContext context, MutableBeanMetadata enclosingComponent, Element element) {
    MutableMapMetadata props = context.createMetadata(MutableMapMetadata.class);
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            if (isCmNamespace(e.getNamespaceURI())) {
                if (nodeNameEquals(e, PROPERTY_ELEMENT)) {
                    BeanProperty prop = context.parseElement(BeanProperty.class, enclosingComponent, e);
                    props.addEntry(createValue(context, prop.getName(), String.class.getName()), prop.getValue());
                }
            }
        }
    }
    return props;
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Aggregations

BeanProperty (org.osgi.service.blueprint.reflect.BeanProperty)8 BeanArgument (org.osgi.service.blueprint.reflect.BeanArgument)4 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)3 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)2 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)2 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)2 MapEntry (org.osgi.service.blueprint.reflect.MapEntry)2 Metadata (org.osgi.service.blueprint.reflect.Metadata)2 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)2 ReferenceListener (org.osgi.service.blueprint.reflect.ReferenceListener)2 RegistrationListener (org.osgi.service.blueprint.reflect.RegistrationListener)2 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)2 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 ArrayList (java.util.ArrayList)1 WrappedServiceMetadata (org.apache.aries.application.modelling.WrappedServiceMetadata)1 ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)1 ArrayRecipe (org.apache.aries.blueprint.di.ArrayRecipe)1