Search in sources :

Example 1 with XmlMetadataAnnotations

use of org.mule.runtime.config.internal.parsers.XmlMetadataAnnotations in project mule by mulesoft.

the class XmlApplicationParser method configLineFromElement.

private Optional<ConfigLine> configLineFromElement(Node node, ConfigLineProvider parentProvider) {
    if (!isValidType(node)) {
        return Optional.empty();
    }
    String identifier = parseIdentifier(node);
    String namespace = parseNamespace(node);
    ConfigLine.Builder builder = new ConfigLine.Builder().setIdentifier(identifier).setNamespace(namespace).setNode(node).setParent(parentProvider);
    XmlMetadataAnnotations userData = (XmlMetadataAnnotations) node.getUserData(XmlMetadataAnnotations.METADATA_ANNOTATIONS_KEY);
    int lineNumber = userData.getLineNumber();
    builder.setLineNumber(lineNumber);
    to(builder).addNode(node);
    Element element = (Element) node;
    NamedNodeMap attributes = element.getAttributes();
    if (element.hasAttributes()) {
        for (int i = 0; i < attributes.getLength(); i++) {
            Node attribute = attributes.item(i);
            Attr attributeNode = element.getAttributeNode(attribute.getNodeName());
            boolean isFromXsd = !attributeNode.getSpecified();
            builder.addConfigAttribute(attribute.getNodeName(), attribute.getNodeValue(), isFromXsd);
        }
    }
    if (node.hasChildNodes()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (isTextContent(child)) {
                builder.setTextContent(child.getNodeValue());
                if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
                    builder.addCustomAttribute(IS_CDATA, Boolean.TRUE);
                    break;
                }
            } else {
                configLineFromElement(child, builder::build).ifPresent(builder::addChild);
            }
        }
    }
    return Optional.of(builder.build());
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) CacheBuilder(com.google.common.cache.CacheBuilder) Builder(com.google.common.collect.ImmutableList.Builder) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) Attr(org.w3c.dom.Attr) XmlMetadataAnnotations(org.mule.runtime.config.internal.parsers.XmlMetadataAnnotations)

Example 2 with XmlMetadataAnnotations

use of org.mule.runtime.config.internal.parsers.XmlMetadataAnnotations in project mule by mulesoft.

the class CommonBeanDefinitionCreator method processMetadataAnnotationsHelper.

private Map<QName, Object> processMetadataAnnotationsHelper(Element element, String configFileIdentifier, BeanDefinitionBuilder builder) {
    Map<QName, Object> annotations = new HashMap<>();
    if (element == null) {
        return annotations;
    } else {
        if (Component.class.isAssignableFrom(builder.getBeanDefinition().getBeanClass())) {
            XmlMetadataAnnotations elementMetadata = (XmlMetadataAnnotations) element.getUserData("metadataAnnotations");
            addMetadataAnnotationsFromXml(annotations, elementMetadata.getElementString());
            builder.getBeanDefinition().getPropertyValues().addPropertyValue("annotations", annotations);
        }
        return annotations;
    }
}
Also used : XmlMetadataAnnotations(org.mule.runtime.config.internal.parsers.XmlMetadataAnnotations) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName)

Aggregations

XmlMetadataAnnotations (org.mule.runtime.config.internal.parsers.XmlMetadataAnnotations)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 Builder (com.google.common.collect.ImmutableList.Builder)1 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 ConfigLine (org.mule.runtime.config.api.dsl.processor.ConfigLine)1 Attr (org.w3c.dom.Attr)1 Element (org.w3c.dom.Element)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1