Example usage for org.springframework.util StringUtils toStringArray

List of usage examples for org.springframework.util StringUtils toStringArray

Introduction

In this page you can find the example usage for org.springframework.util StringUtils toStringArray.

Prototype

public static String[] toStringArray(@Nullable Enumeration<String> enumeration) 

Source Link

Document

Copy the given Enumeration into a String array.

Usage

From source file:org.springframework.beans.factory.support.AbstractBeanFactory.java

public void destroySingletons() {
    if (logger.isInfoEnabled()) {
        logger.info("Destroying singletons in factory {" + this + "}");
    }/*from   ww  w .  j a v a 2  s . c  om*/
    synchronized (this.singletonCache) {
        synchronized (this.disposableBeans) {
            String[] disposableBeanNames = StringUtils.toStringArray(this.disposableBeans.keySet());
            for (int i = 0; i < disposableBeanNames.length; i++) {
                destroyDisposableBean(disposableBeanNames[i]);
            }
        }
        this.singletonCache.clear();
    }
}

From source file:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.java

@Override
public String[] getSingletonNames() {
    synchronized (this.singletonObjects) {
        return StringUtils.toStringArray(this.registeredSingletons);
    }//from w ww .  ja v a 2 s  . c  om
}

From source file:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.java

/**
 * Return the names of all beans which depend on the specified bean, if any.
 * @param beanName the name of the bean/*from   ww w . j  a v a  2  s.  c  om*/
 * @return the array of dependent bean names, or an empty array if none
 */
public String[] getDependentBeans(String beanName) {
    Set<String> dependentBeans = this.dependentBeanMap.get(beanName);
    if (dependentBeans == null) {
        return new String[0];
    }
    return StringUtils.toStringArray(dependentBeans);
}

From source file:org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.java

public void destroySingletons() {
    if (logger.isDebugEnabled()) {
        logger.debug("Destroying singletons in " + this);
    }/*from w w  w.j av  a2  s . c o  m*/
    synchronized (this.singletonObjects) {
        this.singletonsCurrentlyInDestruction = true;
    }

    String[] disposableBeanNames;
    synchronized (this.disposableBeans) {
        disposableBeanNames = StringUtils.toStringArray(this.disposableBeans.keySet());
    }
    for (int i = disposableBeanNames.length - 1; i >= 0; i--) {
        destroySingleton(disposableBeanNames[i]);
    }

    this.containedBeanMap.clear();
    this.dependentBeanMap.clear();
    this.dependenciesForBeanMap.clear();

    synchronized (this.singletonObjects) {
        this.singletonObjects.clear();
        this.singletonFactories.clear();
        this.earlySingletonObjects.clear();
        this.registeredSingletons.clear();
        this.singletonsCurrentlyInDestruction = false;
    }
}

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

/**
 * Parses the supplied {@code <bean>} element. May return {@code null}
 * if there were errors during parse. Errors are reported to the
 * {@link org.springframework.beans.factory.parsing.ProblemReporter}.
 *///from w ww  . j a  v a 2s.  c  o  m
@Nullable
public BeanDefinitionHolder parseBeanDefinitionElement(Element ele, @Nullable BeanDefinition containingBean) {
    String id = ele.getAttribute(ID_ATTRIBUTE);
    String nameAttr = ele.getAttribute(NAME_ATTRIBUTE);

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

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

    if (containingBean == null) {
        checkNameUniqueness(beanName, aliases, ele);
    }

    AbstractBeanDefinition beanDefinition = parseBeanDefinitionElement(ele, beanName, containingBean);
    if (beanDefinition != null) {
        if (!StringUtils.hasText(beanName)) {
            try {
                if (containingBean != null) {
                    beanName = BeanDefinitionReaderUtils.generateBeanName(beanDefinition,
                            this.readerContext.getRegistry(), true);
                } else {
                    beanName = this.readerContext.generateBeanName(beanDefinition);
                    // 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.
                    String beanClassName = beanDefinition.getBeanClassName();
                    if (beanClassName != null && beanName.startsWith(beanClassName)
                            && beanName.length() > beanClassName.length()
                            && !this.readerContext.getRegistry().isBeanNameInUse(beanClassName)) {
                        aliases.add(beanClassName);
                    }
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("Neither XML 'id' nor 'name' specified - " + "using generated bean name ["
                            + beanName + "]");
                }
            } catch (Exception ex) {
                error(ex.getMessage(), ele);
                return null;
            }
        }
        String[] aliasesArray = StringUtils.toStringArray(aliases);
        return new BeanDefinitionHolder(beanDefinition, beanName, aliasesArray);
    }

    return null;
}

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

/**
 * Parse a standard bean definition into a BeanDefinitionHolder,
 * including bean name and aliases.//w ww  .j  a  va2s .  c om
 * <p>Bean elements specify their canonical name as "id" attribute
 * and their aliases as a delimited "name" attribute.
 * <p>If no "id" specified, uses the first name in the "name" attribute
 * as canonical name, registering all others as aliases.
 * <p>Callers should specify whether this element represents an inner bean
 * definition or not by setting the <code>isInnerBean</code> argument appropriately
 */
protected BeanDefinitionHolder parseBeanDefinitionElement(Element ele, boolean isInnerBean)
        throws BeanDefinitionStoreException {

    String id = ele.getAttribute(ID_ATTRIBUTE);
    String nameAttr = ele.getAttribute(NAME_ATTRIBUTE);

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

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

    BeanDefinition beanDefinition = parseBeanDefinitionElement(ele, beanName);

    if (!StringUtils.hasText(beanName) && beanDefinition instanceof AbstractBeanDefinition) {
        beanName = BeanDefinitionReaderUtils.generateBeanName((AbstractBeanDefinition) beanDefinition,
                this.beanDefinitionReader.getBeanFactory(), isInnerBean);
        if (logger.isDebugEnabled()) {
            logger.debug("Neither XML 'id' nor 'name' specified - " + "using generated bean name [" + beanName
                    + "]");
        }
    }

    String[] aliasesArray = StringUtils.toStringArray(aliases);
    return new BeanDefinitionHolder(beanDefinition, beanName, aliasesArray);
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.java

@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {
    if (!isEnabled(annotationMetadata)) {
        return NO_IMPORTS;
    }//from w ww .  j  a va 2s  .  c om
    AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader
            .loadMetadata(this.beanClassLoader);
    AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(autoConfigurationMetadata,
            annotationMetadata);
    return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.java

private List<String> filter(List<String> configurations, AutoConfigurationMetadata autoConfigurationMetadata) {
    long startTime = System.nanoTime();
    String[] candidates = StringUtils.toStringArray(configurations);
    boolean[] skip = new boolean[candidates.length];
    boolean skipped = false;
    for (AutoConfigurationImportFilter filter : getAutoConfigurationImportFilters()) {
        invokeAwareMethods(filter);//from   w w w. java2 s  .  c o m
        boolean[] match = filter.match(candidates, autoConfigurationMetadata);
        for (int i = 0; i < match.length; i++) {
            if (!match[i]) {
                skip[i] = true;
                skipped = true;
            }
        }
    }
    if (!skipped) {
        return configurations;
    }
    List<String> result = new ArrayList<>(candidates.length);
    for (int i = 0; i < candidates.length; i++) {
        if (!skip[i]) {
            result.add(candidates[i]);
        }
    }
    if (logger.isTraceEnabled()) {
        int numberFiltered = configurations.size() - result.size();
        logger.trace("Filtered " + numberFiltered + " auto configuration class in "
                + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) + " ms");
    }
    return new ArrayList<>(result);
}

From source file:org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration.java

private String[] getPackagesToScan(ApplicationContext applicationContext) {
    List<String> packages = EntityScanPackages.get(applicationContext).getPackageNames();
    if (packages.isEmpty() && AutoConfigurationPackages.has(applicationContext)) {
        packages = AutoConfigurationPackages.get(applicationContext);
    }/*w  w w .ja v a 2s  .  c o m*/
    return StringUtils.toStringArray(packages);
}

From source file:org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.java

protected String[] getPackagesToScan() {
    List<String> packages = EntityScanPackages.get(this.beanFactory).getPackageNames();
    if (packages.isEmpty() && AutoConfigurationPackages.has(this.beanFactory)) {
        packages = AutoConfigurationPackages.get(this.beanFactory);
    }/*w ww  .  j  av  a  2 s . c o  m*/
    return StringUtils.toStringArray(packages);
}