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.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.java

private String[] getMappingResources() {
    List<String> mappingResources = this.properties.getMappingResources();
    return (!ObjectUtils.isEmpty(mappingResources) ? StringUtils.toStringArray(mappingResources) : null);
}

From source file:org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration.java

private UserDetails getUserDetails(SecurityProperties.User user, String password) {
    List<String> roles = user.getRoles();
    return User.withUsername(user.getName()).password(password).roles(StringUtils.toStringArray(roles)).build();
}

From source file:org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration.java

@Bean
@ConditionalOnMissingBean(type = "org.springframework.security.oauth2.client.registration.ClientRegistrationRepository")
@Lazy//ww  w .  j a  v a  2  s  .c  om
public InMemoryUserDetailsManager inMemoryUserDetailsManager(SecurityProperties properties,
        ObjectProvider<PasswordEncoder> passwordEncoder) {
    SecurityProperties.User user = properties.getUser();
    List<String> roles = user.getRoles();
    return new InMemoryUserDetailsManager(User.withUsername(user.getName())
            .password(getOrDeducePassword(user, passwordEncoder.getIfAvailable()))
            .roles(StringUtils.toStringArray(roles)).build());
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListener.java

private Map<String, String[]> getGroups() {
    Map<String, String[]> groups = new LinkedHashMap<>();
    DEFAULT_GROUP_LOGGERS.forEach((name, loggers) -> groups.put(name, StringUtils.toStringArray(loggers)));
    return groups;
}

From source file:org.springframework.core.env.AbstractEnvironment.java

@Override
public String[] getActiveProfiles() {
    return StringUtils.toStringArray(doGetActiveProfiles());
}

From source file:org.springframework.core.env.AbstractEnvironment.java

@Override
public String[] getDefaultProfiles() {
    return StringUtils.toStringArray(doGetDefaultProfiles());
}

From source file:org.springframework.core.SimpleAliasRegistry.java

@Override
public String[] getAliases(String name) {
    List<String> result = new ArrayList<>();
    synchronized (this.aliasMap) {
        retrieveAliases(name, result);/*  w  ww.j ava 2  s.co  m*/
    }
    return StringUtils.toStringArray(result);
}

From source file:org.springframework.messaging.simp.SimpAttributes.java

/**
 * Retrieve the names of all attributes.
 * @return the attribute names as String array, never {@code null}
 *///from  w w w  .  j a va 2 s  .  co m
public String[] getAttributeNames() {
    return StringUtils.toStringArray(this.attributes.keySet());
}

From source file:org.springframework.test.context.ContextLoaderUtils.java

/**
 * Resolve <em>active bean definition profiles</em> for the supplied {@link Class}.
 *
 * <p>Note that the {@link ActiveProfiles#inheritProfiles inheritProfiles} flag of
 * {@link ActiveProfiles @ActiveProfiles} will be taken into consideration.
 * Specifically, if the {@code inheritProfiles} flag is set to {@code true}, profiles
 * defined in the test class will be merged with those defined in superclasses.
 *
 * @param testClass the class for which to resolve the active profiles (must not be
 * {@code null})/*from  w w w .j a v a2s  . c o m*/
 * @return the set of active profiles for the specified class, including active
 * profiles from superclasses if appropriate (never {@code null})
 * @see ActiveProfiles
 * @see org.springframework.context.annotation.Profile
 */
static String[] resolveActiveProfiles(Class<?> testClass) {
    Assert.notNull(testClass, "Class must not be null");

    Class<ActiveProfiles> annotationType = ActiveProfiles.class;
    Class<?> declaringClass = findAnnotationDeclaringClass(annotationType, testClass);

    if (declaringClass == null && logger.isDebugEnabled()) {
        logger.debug(String.format(
                "Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]",
                annotationType.getName(), testClass.getName()));
    }

    final Set<String> activeProfiles = new HashSet<String>();

    while (declaringClass != null) {
        ActiveProfiles annotation = declaringClass.getAnnotation(annotationType);

        if (logger.isTraceEnabled()) {
            logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].", annotation,
                    declaringClass.getName()));
        }

        String[] profiles = annotation.profiles();
        String[] valueProfiles = annotation.value();

        if (!ObjectUtils.isEmpty(valueProfiles) && !ObjectUtils.isEmpty(profiles)) {
            String msg = String.format(
                    "Test class [%s] has been configured with @ActiveProfiles' 'value' [%s] "
                            + "and 'profiles' [%s] attributes. Only one declaration of active bean "
                            + "definition profiles is permitted per @ActiveProfiles annotation.",
                    declaringClass.getName(), ObjectUtils.nullSafeToString(valueProfiles),
                    ObjectUtils.nullSafeToString(profiles));
            logger.error(msg);
            throw new IllegalStateException(msg);
        } else if (!ObjectUtils.isEmpty(valueProfiles)) {
            profiles = valueProfiles;
        }

        for (String profile : profiles) {
            if (StringUtils.hasText(profile)) {
                activeProfiles.add(profile.trim());
            }
        }

        declaringClass = annotation.inheritProfiles()
                ? findAnnotationDeclaringClass(annotationType, declaringClass.getSuperclass())
                : null;
    }

    return StringUtils.toStringArray(activeProfiles);
}

From source file:org.springframework.test.context.ContextLoaderUtils.java

/**
 * Build the {@link MergedContextConfiguration merged context configuration} for the
 * supplied {@link Class testClass}, context configuration attributes,
 * {@code defaultContextLoaderClassName}, and parent context configuration.
 *
 * @param testClass the test class for which the {@code MergedContextConfiguration}
 * should be built (must not be {@code null})
 * @param configAttributesList the list of context configuration attributes for the
 * specified test class, ordered <em>bottom-up</em> (i.e., as if we were
 * traversing up the class hierarchy); never {@code null} or empty
 * @param defaultContextLoaderClassName the name of the default {@code ContextLoader}
 * class to use (may be {@code null})//w  w  w. ja va 2s. c o  m
 * @param parentConfig the merged context configuration for the parent application
 * context in a context hierarchy, or {@code null} if there is no parent
 * @param cacheAwareContextLoaderDelegate the cache-aware context loader delegate to
 * be passed to the {@code MergedContextConfiguration} constructor
 * @return the merged context configuration
 * @see #resolveContextLoader
 * @see #resolveContextConfigurationAttributes
 * @see SmartContextLoader#processContextConfiguration
 * @see ContextLoader#processLocations
 * @see #resolveActiveProfiles
 * @see MergedContextConfiguration
 */
private static MergedContextConfiguration buildMergedContextConfiguration(final Class<?> testClass,
        final List<ContextConfigurationAttributes> configAttributesList,
        final String defaultContextLoaderClassName, MergedContextConfiguration parentConfig,
        CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) {

    final ContextLoader contextLoader = resolveContextLoader(testClass, configAttributesList,
            defaultContextLoaderClassName);
    final List<String> locationsList = new ArrayList<String>();
    final List<Class<?>> classesList = new ArrayList<Class<?>>();

    for (ContextConfigurationAttributes configAttributes : configAttributesList) {
        if (logger.isTraceEnabled()) {
            logger.trace(
                    String.format("Processing locations and classes for context configuration attributes %s",
                            configAttributes));
        }

        if (contextLoader instanceof SmartContextLoader) {
            SmartContextLoader smartContextLoader = (SmartContextLoader) contextLoader;
            smartContextLoader.processContextConfiguration(configAttributes);
            locationsList.addAll(0, Arrays.asList(configAttributes.getLocations()));
            classesList.addAll(0, Arrays.asList(configAttributes.getClasses()));
        } else {
            String[] processedLocations = contextLoader.processLocations(configAttributes.getDeclaringClass(),
                    configAttributes.getLocations());
            locationsList.addAll(0, Arrays.asList(processedLocations));
            // Legacy ContextLoaders don't know how to process classes
        }

        if (!configAttributes.isInheritLocations()) {
            break;
        }
    }

    String[] locations = StringUtils.toStringArray(locationsList);
    Class<?>[] classes = ClassUtils.toClassArray(classesList);
    Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> initializerClasses = resolveInitializerClasses(
            configAttributesList);
    String[] activeProfiles = resolveActiveProfiles(testClass);

    MergedContextConfiguration mergedConfig = buildWebMergedContextConfiguration(testClass, locations, classes,
            initializerClasses, activeProfiles, contextLoader, cacheAwareContextLoaderDelegate, parentConfig);

    if (mergedConfig == null) {
        mergedConfig = new MergedContextConfiguration(testClass, locations, classes, initializerClasses,
                activeProfiles, contextLoader, cacheAwareContextLoaderDelegate, parentConfig);
    }

    return mergedConfig;
}