Example usage for org.springframework.util.xml DomUtils nodeNameEquals

List of usage examples for org.springframework.util.xml DomUtils nodeNameEquals

Introduction

In this page you can find the example usage for org.springframework.util.xml DomUtils nodeNameEquals.

Prototype

public static boolean nodeNameEquals(Node node, String desiredName) 

Source Link

Document

Namespace-aware equals comparison.

Usage

From source file:com.consol.citrus.admin.service.spring.filter.AddSpringBeanFilter.java

/**
 * {@inheritDoc}/*from   ww w. ja  va2  s.  c  om*/
 */
public short accept(Element element) {
    if (DomUtils.nodeNameEquals(element, "beans")) {
        element.appendChild(element.getOwnerDocument().createTextNode("\n    ")); //TODO make indentation configurable
        element.appendChild(element.getOwnerDocument().importNode(beanDefinition, true));
    }

    return NodeFilter.FILTER_ACCEPT;
}

From source file:com.consol.citrus.admin.service.spring.filter.GetSpringBeanFilter.java

/**
 * {@inheritDoc}/*from  w  w  w.  j a v a  2 s .  c o m*/
 */
public short accept(Element element) {
    if (DomUtils.nodeNameEquals(element, elementName) && isEqualByNamespace(element, elementNamespace)
            && (isEqualById(element, id) || isEqualByBeanName(element, id))) {
        beanDefinition = element;
    }

    return NodeFilter.FILTER_ACCEPT;
}

From source file:com.consol.citrus.admin.service.spring.filter.GetSpringImportsFilter.java

@Override
public short startElement(Element element) {
    if (DomUtils.nodeNameEquals(element, "import")) {
        String resourceLocation = element.getAttribute("resource");

        if (StringUtils.hasText(resourceLocation)) {
            if (resourceLocation.startsWith("classpath:")) {
                resourceLocation = resourceLocation.substring("classpath:".length());
            } else if (resourceLocation.startsWith("file:")) {
                resourceLocation = resourceLocation.substring("file:".length());
            }/*from   ww w.j a  v a 2 s . co  m*/

            try {
                File importedFile = new FileSystemResource(
                        parentConfigFile.getParentFile().getCanonicalPath() + File.separator + resourceLocation)
                                .getFile();

                if (importedFile.exists()) {
                    importedFiles.add(importedFile);
                }
            } catch (IOException e) {
                log.warn("Unable to resolve imported file resource location", e);
            }
        }
    }

    return NodeFilter.FILTER_ACCEPT;
}

From source file:com.consol.citrus.admin.service.spring.filter.GetSpringBeansFilter.java

/**
 * {@inheritDoc}/*from   ww w.j  av a  2 s .  c o m*/
 */
public short accept(Element element) {
    if (DomUtils.nodeNameEquals(element, elementName) && isEqualByNamespace(element, elementNamespace)
            && isEqualByBeanAttributes(element, attributes)) {
        beanDefinitions.add(element);
    }

    return NodeFilter.FILTER_ACCEPT;
}

From source file:org.blocks4j.feature.toggle.spring.scheme.FeatureToggleDefinitionParser.java

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext context) {
    AbstractBeanDefinition result = null;
    if (DomUtils.nodeNameEquals(element, TAG_TOGGLE_NAME)) {
        BeanDefinitionHolder holder = context.getDelegate().parseBeanDefinitionElement(element);
        result = (AbstractBeanDefinition) holder.getBeanDefinition();

        String feature = element.getAttribute(TAG_FEATURE_NAME);
        String commonInterfaceName = element.getAttribute(TAG_COMMON_INTERFACE_NAME);
        String onRefName = element.getAttribute(TAG_ON_REF_NAME);
        String offRefName = element.getAttribute(TAG_OFF_REF_NAME);

        if (StringUtils.isEmpty(onRefName)) {
            throw new FeatureToggleDefinitionParsingException("You must specify on-ref");
        }/*from   ww w .j  ava 2 s .  co  m*/
        if (StringUtils.isEmpty(offRefName)) {
            throw new FeatureToggleDefinitionParsingException("You must specify on-ref");
        }
        Class<?> commonInterface;
        try {
            commonInterface = Class.forName(commonInterfaceName);
        } catch (Exception e) {
            LOGGER.error("It was not possible to find interface of type '{}'", commonInterfaceName);
            throw new FeatureToggleDefinitionParsingException(
                    String.format("It was not possible to find interface of type '%s'", commonInterfaceName),
                    e);
        }
        String fbeanName = feature.concat("_" + this.randomUUID() + "_factory");
        this.buildNewFactoryBean(fbeanName, context, onRefName, offRefName, commonInterface, feature);
        result.setFactoryBeanName(fbeanName);
        result.setFactoryMethodName(TAG_TOGGLE_NAME);
        context.getRegistry()
                .registerBeanDefinition(TAG_TOGGLE_NAME.concat(Integer.toHexString(this.hashCode())), result);
    }
    return result;
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

/**
 * Parsers contructor arguments./*  w  w  w.j a  va 2  s  .  co m*/
 * 
 * @param ele
 * @param beanDefinition
 * @param parserContext
 */
private void parseConstructorArgElements(Element ele, AbstractBeanDefinition beanDefinition) {

    NodeList nl = ele.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element && DomUtils.nodeNameEquals(node, CONSTRUCTOR_ARG)) {
            parseConstructorArgElement((Element) node, beanDefinition);
        }
    }
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

/**
 * Parses property elements./*w ww  . j a v  a2 s. c o m*/
 * 
 * @param ele
 * @param beanDefinition
 * @param parserContext
 */
private void parsePropertyElements(Element ele, AbstractBeanDefinition beanDefinition) {

    NodeList nl = ele.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element
                && DomUtils.nodeNameEquals(node, BeanDefinitionParserDelegate.PROPERTY_ELEMENT)) {
            parsePropertyElement((Element) node, beanDefinition);
        }
    }
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

private Object parsePropertyValue(Element ele, BeanDefinition bd, String propertyName) {
    String elementName = (propertyName != null) ? "<property> element for property '" + propertyName + "'"
            : "<constructor-arg> element";

    // Should only have one child element: ref, value, list, etc.
    NodeList nl = ele.getChildNodes();
    Element subElement = null;//  w  w w.  jav  a 2  s.co  m
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element
                && !DomUtils.nodeNameEquals(node, BeanDefinitionParserDelegate.DESCRIPTION_ELEMENT)) {
            // Child element is what we're looking for.
            if (subElement != null) {
                error(elementName + " must not contain more than one sub-element", ele);
            } else {
                subElement = (Element) node;
            }
        }
    }

    boolean hasRefAttribute = ele.hasAttribute(BeanDefinitionParserDelegate.REF_ATTRIBUTE);
    boolean hasValueAttribute = ele.hasAttribute(BeanDefinitionParserDelegate.VALUE_ATTRIBUTE);
    if ((hasRefAttribute && hasValueAttribute)
            || ((hasRefAttribute || hasValueAttribute) && subElement != null)) {
        error(elementName
                + " is only allowed to contain either 'ref' attribute OR 'value' attribute OR sub-element",
                ele);
    }

    if (hasRefAttribute) {
        String refName = ele.getAttribute(BeanDefinitionParserDelegate.REF_ATTRIBUTE);
        if (!StringUtils.hasText(refName)) {
            error(elementName + " contains empty 'ref' attribute", ele);
        }
        RuntimeBeanReference ref = new RuntimeBeanReference(refName);
        ref.setSource(parserContext.extractSource(ele));
        return ref;
    } else if (hasValueAttribute) {
        TypedStringValue valueHolder = new TypedStringValue(
                ele.getAttribute(BeanDefinitionParserDelegate.VALUE_ATTRIBUTE));
        valueHolder.setSource(parserContext.extractSource(ele));
        return valueHolder;
    } else if (subElement != null) {
        return parsePropertySubElement(subElement, bd, null);
    } else {
        // Neither child element nor "ref" or "value" attribute found.
        error(elementName + " must specify a ref or value", ele);
        return null;
    }
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

/**
 * Parse a value, ref or collection sub-element of a property or constructor-arg element. This method is called from
 * several places to handle reusable elements such as idref, ref, null, value and so on.
 * /*from w w w.  j a v a  2  s.c o m*/
 * In fact, this method is the main reason why the BeanDefinitionParserDelegate is not used in full since the
 * element namespace becomes important as mixed rfc124/bean content can coexist.
 * 
 * @param ele subelement of property element; we don't know which yet
 * @param defaultValueType the default type (class name) for any <code>&lt;value&gt;</code> tag that might be
 * created
 */
private Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultValueType) {
    // skip other namespace
    String namespaceUri = ele.getNamespaceURI();

    // check Spring own namespace
    if (parserContext.getDelegate().isDefaultNamespace(namespaceUri)) {
        return parserContext.getDelegate().parsePropertySubElement(ele, bd);
    }
    // let the delegate handle other ns
    else if (!NAMESPACE_URI.equals(namespaceUri)) {
        return parserContext.getDelegate().parseCustomElement(ele);
    }

    // 
    else {
        if (DomUtils.nodeNameEquals(ele, BEAN)) {
            BeanDefinitionHolder bdHolder = parseComponentDefinitionElement(ele, bd);
            if (bdHolder != null) {
                bdHolder = ParsingUtils.decorateBeanDefinitionIfRequired(ele, bdHolder, parserContext);
            }
            return bdHolder;
        }

        if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.REF_ELEMENT)) {
            return parseRefElement(ele);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.IDREF_ELEMENT)) {
            return parseIdRefElement(ele);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.VALUE_ELEMENT)) {
            return parseValueElement(ele, defaultValueType);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.NULL_ELEMENT)) {
            // It's a distinguished null value. Let's wrap it in a TypedStringValue
            // object in order to preserve the source location.
            TypedStringValue nullHolder = new TypedStringValue(null);
            nullHolder.setSource(parserContext.extractSource(ele));
            return nullHolder;
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.ARRAY_ELEMENT)) {
            return parseArrayElement(ele, bd);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.LIST_ELEMENT)) {
            return parseListElement(ele, bd);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.SET_ELEMENT)) {
            return parseSetElement(ele, bd);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.MAP_ELEMENT)) {
            return parseMapElement(ele, bd);
        } else if (DomUtils.nodeNameEquals(ele, BeanDefinitionParserDelegate.PROPS_ELEMENT)) {
            return parsePropsElement(ele);
        }

        // maybe it's a nested service/reference/ref-list/ref-set
        return parserContext.getDelegate().parseCustomElement(ele, bd);
    }
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

protected void parseCollectionElements(NodeList elementNodes, Collection<Object> target, BeanDefinition bd,
        String defaultElementType) {

    for (int i = 0; i < elementNodes.getLength(); i++) {
        Node node = elementNodes.item(i);
        if (node instanceof Element
                && !DomUtils.nodeNameEquals(node, BeanDefinitionParserDelegate.DESCRIPTION_ELEMENT)) {
            target.add(parsePropertySubElement((Element) node, bd, defaultElementType));
        }//w w  w  .  j  av  a2 s .com
    }
}