Search in sources :

Example 11 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project aries by apache.

the class NSHandlerHeight method parse.

//process elements
public Metadata parse(Element element, ParserContext context) {
    Metadata retval = null;
    if (element.getLocalName().equals(ELT_NAME)) {
        final String id = element.getAttributeNS(NSURI, ATTRIB_ID);
        MutableBeanMetadata bm = context.createMetadata(MutableBeanMetadata.class);
        bm.setId(id);
        bm.setScope("PROTOTYPE");
        bm.setClassName(TestBean.class.getName());
        retval = bm;
    }
    return retval;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 12 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project aries by apache.

the class TxNamespaceHandler method createAnnotationParserBean.

private MutableBeanMetadata createAnnotationParserBean(ParserContext pc, ComponentDefinitionRegistry cdr) {
    MutableBeanMetadata meta = pc.createMetadata(MutableBeanMetadata.class);
    meta.setId(ANNOTATION_PARSER_BEAN_NAME);
    meta.setRuntimeClass(AnnotationProcessor.class);
    meta.setProcessor(true);
    meta.addArgument(passThrough(pc, cdr), ComponentDefinitionRegistry.class.getName(), 0);
    meta.addArgument(passThrough(pc, tm), TransactionManager.class.getName(), 1);
    meta.addArgument(passThrough(pc, coordinator), Coordinator.class.getName(), 1);
    return meta;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) TransactionManager(javax.transaction.TransactionManager) Coordinator(org.osgi.service.coordinator.Coordinator)

Example 13 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project aries by apache.

the class CmNamespaceHandler method decorateCmProperties.

private ComponentMetadata decorateCmProperties(ParserContext context, Element element, ComponentMetadata component) {
    generateIdIfNeeded(context, ((MutableComponentMetadata) component));
    MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
    metadata.setProcessor(true);
    metadata.setId(getId(context, element));
    metadata.setRuntimeClass(CmProperties.class);
    String persistentId = element.getAttribute(PERSISTENT_ID_ATTRIBUTE);
    // ManagedService if the persistentId is not an empty string.
    if (persistentId.length() > 0) {
        metadata.setInitMethod("init");
        metadata.setDestroyMethod("destroy");
    }
    metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    metadata.addProperty("configAdmin", createConfigurationAdminRef(context));
    metadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
    metadata.addProperty("persistentId", createValue(context, persistentId));
    if (element.hasAttribute(UPDATE_ATTRIBUTE)) {
        metadata.addProperty("update", createValue(context, element.getAttribute(UPDATE_ATTRIBUTE)));
    }
    metadata.addProperty("serviceId", createIdRef(context, component.getId()));
    context.getComponentDefinitionRegistry().registerComponentDefinition(metadata);
    return component;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableComponentMetadata(org.apache.aries.blueprint.mutable.MutableComponentMetadata)

Example 14 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project aries by apache.

the class CmNamespaceHandler method parseCmProperties.

private ComponentMetadata parseCmProperties(ParserContext context, Element element) {
    String id = getId(context, element);
    MutableBeanMetadata factoryMetadata = context.createMetadata(MutableBeanMetadata.class);
    generateIdIfNeeded(context, factoryMetadata);
    factoryMetadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    factoryMetadata.setRuntimeClass(CmProperties.class);
    factoryMetadata.setInitMethod("init");
    factoryMetadata.setDestroyMethod("destroy");
    factoryMetadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    factoryMetadata.addProperty("configAdmin", createConfigurationAdminRef(context));
    factoryMetadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
    String persistentId = element.getAttribute(PERSISTENT_ID_ATTRIBUTE);
    factoryMetadata.addProperty("persistentId", createValue(context, persistentId));
    context.getComponentDefinitionRegistry().registerComponentDefinition(factoryMetadata);
    MutableBeanMetadata propertiesMetadata = context.createMetadata(MutableBeanMetadata.class);
    propertiesMetadata.setId(id);
    propertiesMetadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    propertiesMetadata.setRuntimeClass(Properties.class);
    propertiesMetadata.setFactoryComponent(createRef(context, factoryMetadata.getId()));
    propertiesMetadata.setFactoryComponent(factoryMetadata);
    propertiesMetadata.setFactoryMethod("getProperties");
    // Work around ARIES-877
    propertiesMetadata.setDependsOn(Arrays.asList(factoryMetadata.getId()));
    return propertiesMetadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 15 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata 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)

Aggregations

MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)43 Node (org.w3c.dom.Node)13 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)12 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)10 Element (org.w3c.dom.Element)10 Metadata (org.osgi.service.blueprint.reflect.Metadata)9 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)8 JAXBException (javax.xml.bind.JAXBException)7 ExpressionNode (org.apache.camel.model.ExpressionNode)7 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)7 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)7 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)6 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)6 NodeList (org.w3c.dom.NodeList)6 Attr (org.w3c.dom.Attr)5 List (java.util.List)4 MutableServiceMetadata (org.apache.aries.blueprint.mutable.MutableServiceMetadata)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)4 ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)3 MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)3