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

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

Introduction

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

Prototype

String ID_ATTRIBUTE

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

Click Source Link

Usage

From source file:org.globus.security.authorization.xml.AbstractBeanDefinitionParser.java

protected String getIdOrName(Element elem) {
    String id = elem.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);

    if (null == id || "".equals(id)) {
        String names = elem.getAttribute("name");
        if (null != names) {
            StringTokenizer st = new StringTokenizer(names, BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
            if (st.countTokens() > 0) {
                id = st.nextToken();//from ww  w .j  a v  a2  s  .  co m
            }
        }
    }
    return id;
}

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  ww .ja  v  a2s  .c om
    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.eclipse.gemini.blueprint.blueprint.config.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  ww  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.BEAN_NAME_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;
}

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}.
 *///  w w w  . j av  a2 s  .c  om
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;
}