Example usage for org.springframework.beans.factory.xml BeanDefinitionParserDelegate MULTI_VALUE_ATTRIBUTE_DELIMITERS

List of usage examples for org.springframework.beans.factory.xml BeanDefinitionParserDelegate MULTI_VALUE_ATTRIBUTE_DELIMITERS

Introduction

In this page you can find the example usage for org.springframework.beans.factory.xml BeanDefinitionParserDelegate MULTI_VALUE_ATTRIBUTE_DELIMITERS.

Prototype

String MULTI_VALUE_ATTRIBUTE_DELIMITERS

To view the source code for org.springframework.beans.factory.xml BeanDefinitionParserDelegate MULTI_VALUE_ATTRIBUTE_DELIMITERS.

Click Source Link

Usage

From source file:org.solmix.runtime.support.spring.AbstractBeanDefinitionParser.java

/**id ?*/
protected String getIdOrName(Element elem) {
    String id = elem.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
    //ID,name/*from w w  w  . java2  s . co  m*/
    if (null == id || "".equals(id)) {
        String names = elem.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);
        if (null != names) {
            StringTokenizer st = new StringTokenizer(names,
                    BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
            //?
            if (st.countTokens() > 0) {
                id = st.nextToken();
            }
        }
    }
    return id;
}

From source file:org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.java

/**
 * Register each bean definition within the given root {@code <beans/>} element.
 *//*from   w w  w. j a va  2 s  .  co  m*/
protected void doRegisterBeanDefinitions(Element root) {
    // Any nested <beans> elements will cause recursion in this method. In
    // order to propagate and preserve <beans> default-* attributes correctly,
    // keep track of the current (parent) delegate, which may be null. Create
    // the new (child) delegate with a reference to the parent for fallback purposes,
    // then ultimately reset this.delegate back to its original (parent) reference.
    // this behavior emulates a stack of delegates without actually necessitating one.
    BeanDefinitionParserDelegate parent = this.delegate;
    this.delegate = createDelegate(getReaderContext(), root, parent);

    if (this.delegate.isDefaultNamespace(root)) {
        String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE);
        if (StringUtils.hasText(profileSpec)) {
            String[] specifiedProfiles = StringUtils.tokenizeToStringArray(profileSpec,
                    BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
            if (!getReaderContext().getEnvironment().acceptsProfiles(specifiedProfiles)) {
                if (logger.isInfoEnabled()) {
                    logger.info("Skipped XML bean definition file due to specified profiles [" + profileSpec
                            + "] not matching: " + getReaderContext().getResource());
                }
                return;
            }
        }
    }

    preProcessXml(root);
    parseBeanDefinitions(root, this.delegate);
    postProcessXml(root);

    this.delegate = parent;
}

From source file:org.springframework.ide.eclipse.osgi.blueprint.internal.BlueprintParser.java

/**
 * Parses the supplied <code>&lt;bean&gt;</code> element. May return
 * <code>null</code> if there were errors during parse. Errors are reported
 * to the {@link org.springframework.beans.factory.parsing.ProblemReporter}.
 *///from   w w  w. j a  v  a  2  s. c o m
private BeanDefinitionHolder parseComponentDefinitionElement(Element ele, BeanDefinition containingBean) {

    // extract bean name
    String id = ele.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
    String nameAttr = ele.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);

    List<String> aliases = new ArrayList<String>(4);
    if (StringUtils.hasLength(nameAttr)) {
        String[] nameArr = StringUtils.tokenizeToStringArray(nameAttr,
                BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
        aliases.addAll(Arrays.asList(nameArr));
    }

    String beanName = id;

    if (!StringUtils.hasText(beanName) && !aliases.isEmpty()) {
        beanName = (String) aliases.remove(0);
        if (log.isDebugEnabled()) {
            log.debug("No XML 'id' specified - using '" + beanName + "' as bean name and " + aliases
                    + " as aliases");
        }
    }

    if (containingBean == null) {

        if (checkNameUniqueness(beanName, aliases, usedNames)) {
            error("Bean name '" + beanName + "' is already used in this file", ele);
        }

        if (ParsingUtils.isReservedName(beanName, ele, parserContext)) {
            error("Blueprint reserved name '" + beanName + "' cannot be used", ele);
        }
    }

    AbstractBeanDefinition beanDefinition = parseBeanDefinitionElement(ele, beanName, containingBean);
    if (beanDefinition != null) {
        if (!StringUtils.hasText(beanName)) {
            try {
                if (containingBean != null) {
                    beanName = ParsingUtils.generateBlueprintBeanName(beanDefinition,
                            parserContext.getRegistry(), true);
                } else {
                    beanName = ParsingUtils.generateBlueprintBeanName(beanDefinition,
                            parserContext.getRegistry(), false);
                    // TODO: should we support 2.0 behaviour (see below):
                    //
                    // Register an alias for the plain bean class name, if
                    // still possible,
                    // if the generator returned the class name plus a
                    // suffix.
                    // This is expected for Spring 1.2/2.0 backwards
                    // compatibility.
                }
                if (log.isDebugEnabled()) {
                    log.debug("Neither XML 'id' nor 'name' specified - " + "using generated bean name ["
                            + beanName + "]");
                }
            } catch (Exception ex) {
                error(ex.getMessage(), ele, ex);
                return null;
            }
        }
        return new BeanDefinitionHolder(beanDefinition, beanName);
    }

    return null;
}