Search in sources :

Example 66 with MutableBeanMetadata

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

the class TxNamespaceHandler method parseElement.

private void parseElement(Element elt, ParserContext pc) {
    LOGGER.debug("parser asked to parse element {} ", elt.getNodeName());
    ComponentDefinitionRegistry cdr = pc.getComponentDefinitionRegistry();
    if ("enable".equals(elt.getLocalName())) {
        Node n = elt.getChildNodes().item(0);
        if ((n == null || Boolean.parseBoolean(n.getNodeValue())) && !cdr.containsComponentDefinition(ANNOTATION_PARSER_BEAN_NAME)) {
            LOGGER.debug("Enabling annotation based transactions");
            MutableBeanMetadata meta = createAnnotationParserBean(pc, cdr);
            cdr.registerComponentDefinition(meta);
        }
    }
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) Node(org.w3c.dom.Node)

Example 67 with MutableBeanMetadata

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

the class ExtNamespaceHandler method parsePropertyPlaceholder.

private Metadata parsePropertyPlaceholder(ParserContext context, Element element) {
    MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
    metadata.setProcessor(true);
    metadata.setId(getId(context, element));
    metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    metadata.setRuntimeClass(PropertyPlaceholder.class);
    metadata.setInitMethod("init");
    String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) : "${";
    metadata.addProperty("placeholderPrefix", createValue(context, prefix));
    String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) : "}";
    metadata.addProperty("placeholderSuffix", createValue(context, suffix));
    metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    String nullValue = element.hasAttribute(PLACEHOLDER_NULL_VALUE_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_NULL_VALUE_ATTRIBUTE) : null;
    if (nullValue != null) {
        metadata.addProperty("nullValue", createValue(context, nullValue));
    }
    String defaultsRef = element.hasAttribute(DEFAULTS_REF_ATTRIBUTE) ? element.getAttribute(DEFAULTS_REF_ATTRIBUTE) : null;
    if (defaultsRef != null) {
        metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
    }
    String ignoreMissingLocations = element.hasAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE) ? element.getAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE) : null;
    if (ignoreMissingLocations != null) {
        metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
    }
    String systemProperties = element.hasAttribute(SYSTEM_PROPERTIES_ATTRIBUTE) ? element.getAttribute(SYSTEM_PROPERTIES_ATTRIBUTE) : null;
    if (systemProperties != null) {
        metadata.addProperty("systemProperties", createValue(context, systemProperties));
    }
    String evaluator = element.hasAttribute(EVALUATOR_ATTRIBUTE) ? element.getAttribute(EVALUATOR_ATTRIBUTE) : null;
    if (evaluator != null) {
        throw new IllegalStateException("Evaluators are not supported outside OSGi");
    }
    // Parse elements
    List<String> locations = new ArrayList<String>();
    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, DEFAULT_PROPERTIES_ELEMENT)) {
                    if (defaultsRef != null) {
                        throw new ComponentDefinitionException("Only one of " + DEFAULTS_REF_ATTRIBUTE + " attribute or " + DEFAULT_PROPERTIES_ELEMENT + " element is allowed");
                    }
                    Metadata props = parseDefaultProperties(context, metadata, e);
                    metadata.addProperty("defaultProperties", props);
                } else if (nodeNameEquals(e, LOCATION_ELEMENT)) {
                    locations.add(getTextValue(e));
                }
            }
        }
    }
    if (!locations.isEmpty()) {
        metadata.addProperty("locations", createList(context, locations));
    }
    validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) MutableReferenceMetadata(org.apache.aries.blueprint.mutable.MutableReferenceMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) MutableServiceReferenceMetadata(org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata) MutableIdRefMetadata(org.apache.aries.blueprint.mutable.MutableIdRefMetadata) MutableComponentMetadata(org.apache.aries.blueprint.mutable.MutableComponentMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) org.apache.aries.blueprint(org.apache.aries.blueprint)

Example 68 with MutableBeanMetadata

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

the class ExtNamespaceHandler method parseBeanArgument.

private ComponentMetadata parseBeanArgument(ParserContext context, Element element) {
    MutableBeanMetadata mbm = (MutableBeanMetadata) context.getEnclosingComponent();
    BeanArgument arg = context.parseElement(BeanArgument.class, mbm, element);
    int index = 0;
    for (Node node = element.getPreviousSibling(); node != null; node = node.getPreviousSibling()) {
        if (nodeNameEquals(node, ARGUMENT)) {
            index++;
        }
    }
    List<BeanArgument> args = new ArrayList<BeanArgument>(mbm.getArguments());
    if (index == args.size()) {
        mbm.addArgument(arg);
    } else {
        for (BeanArgument ba : args) {
            mbm.removeArgument(ba);
        }
        args.add(index, arg);
        for (BeanArgument ba : args) {
            mbm.addArgument(ba);
        }
    }
    return mbm;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) Node(org.w3c.dom.Node) org.apache.aries.blueprint(org.apache.aries.blueprint)

Example 69 with MutableBeanMetadata

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

the class ExtNamespaceHandler method mergeList.

private void mergeList(ExtendedBeanMetadata bean1, MutableBeanMetadata bean2, String name) {
    Metadata m1 = getProperty(bean1, name);
    Metadata m2 = getProperty(bean2, name);
    if (m1 == null && m2 != null) {
        ((MutableBeanMetadata) bean1).addProperty(name, m2);
    } else if (m1 != null && m2 != null) {
        if (!(m1 instanceof MutableCollectionMetadata) || !(m2 instanceof MutableCollectionMetadata)) {
            throw new ComponentDefinitionException("Unable to merge " + name + " list properties");
        }
        MutableCollectionMetadata c1 = (MutableCollectionMetadata) m1;
        MutableCollectionMetadata c2 = (MutableCollectionMetadata) m2;
        for (Metadata v : c2.getValues()) {
            c1.addValue(v);
        }
    }
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) MutableReferenceMetadata(org.apache.aries.blueprint.mutable.MutableReferenceMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) MutableServiceReferenceMetadata(org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata) MutableIdRefMetadata(org.apache.aries.blueprint.mutable.MutableIdRefMetadata) MutableComponentMetadata(org.apache.aries.blueprint.mutable.MutableComponentMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

Example 70 with MutableBeanMetadata

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

the class ExtNamespaceHandler method mergeMap.

private void mergeMap(ExtendedBeanMetadata bean1, MutableBeanMetadata bean2, String name) {
    Metadata m1 = getProperty(bean1, name);
    Metadata m2 = getProperty(bean2, name);
    if (m1 == null && m2 != null) {
        ((MutableBeanMetadata) bean1).addProperty(name, m2);
    } else if (m1 != null && m2 != null) {
        if (!(m1 instanceof MutableMapMetadata) || !(m2 instanceof MutableMapMetadata)) {
            throw new ComponentDefinitionException("Unable to merge " + name + " list properties");
        }
        MutableMapMetadata c1 = (MutableMapMetadata) m1;
        MutableMapMetadata c2 = (MutableMapMetadata) m2;
        for (MapEntry e : c2.getEntries()) {
            c1.addEntry(e);
        }
    }
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) MutableReferenceMetadata(org.apache.aries.blueprint.mutable.MutableReferenceMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) MutableServiceReferenceMetadata(org.apache.aries.blueprint.mutable.MutableServiceReferenceMetadata) MutableIdRefMetadata(org.apache.aries.blueprint.mutable.MutableIdRefMetadata) MutableComponentMetadata(org.apache.aries.blueprint.mutable.MutableComponentMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata)

Aggregations

MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)96 Element (org.w3c.dom.Element)23 Node (org.w3c.dom.Node)20 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)19 Metadata (org.osgi.service.blueprint.reflect.Metadata)19 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)18 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)18 MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)17 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)16 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)15 MutableValueMetadata (org.apache.aries.blueprint.mutable.MutableValueMetadata)13 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)12 NodeList (org.w3c.dom.NodeList)11 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)10 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)9 JAXBException (javax.xml.bind.JAXBException)8 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)8 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)8 ExpressionNode (org.apache.camel.model.ExpressionNode)7 Attr (org.w3c.dom.Attr)7