List of usage examples for org.springframework.util StringUtils arrayToCommaDelimitedString
public static String arrayToCommaDelimitedString(@Nullable Object[] arr)
From source file:org.springframework.beans.factory.support.SimpleInstantiationStrategy.java
public Object instantiate(RootBeanDefinition beanDefinition, String beanName, BeanFactory owner, Object factoryBean, Method factoryMethod, Object[] args) { try {//from w ww. ja v a2 s.c o m // It's a static method if the target is null. if (!Modifier.isPublic(factoryMethod.getModifiers()) || !Modifier.isPublic(factoryMethod.getDeclaringClass().getModifiers())) { factoryMethod.setAccessible(true); } return factoryMethod.invoke(factoryBean, args); } catch (IllegalArgumentException ex) { throw new BeanDefinitionStoreException("Illegal arguments to factory method [" + factoryMethod + "]; " + "args: " + StringUtils.arrayToCommaDelimitedString(args)); } catch (IllegalAccessException ex) { throw new BeanDefinitionStoreException( "Cannot access factory method [" + factoryMethod + "]; is it public?"); } catch (InvocationTargetException ex) { String msg = "Factory method [" + factoryMethod + "] threw exception"; // We want to log this one, as it may be a config error: // the method may match, but may have been given incorrect arguments. logger.warn(msg, ex.getTargetException()); throw new BeanDefinitionStoreException(msg, ex.getTargetException()); } }
From source file:org.springframework.beans.TypeConverterDelegate.java
/** * Convert the value to the required type (if necessary from a String), * using the given property editor./*from ww w . java2 s . com*/ * @param oldValue the previous value, if available (may be {@code null}) * @param newValue the proposed new value * @param requiredType the type we must convert to * (or {@code null} if not known, for example in case of a collection element) * @param editor the PropertyEditor to use * @return the new value, possibly the result of type conversion * @throws IllegalArgumentException if type conversion failed */ @Nullable private Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue, @Nullable Class<?> requiredType, @Nullable PropertyEditor editor) { Object convertedValue = newValue; if (editor != null && !(convertedValue instanceof String)) { // Not a String -> use PropertyEditor's setValue. // With standard PropertyEditors, this will return the very same object; // we just want to allow special PropertyEditors to override setValue // for type conversion from non-String values to the required type. try { editor.setValue(convertedValue); Object newConvertedValue = editor.getValue(); if (newConvertedValue != convertedValue) { convertedValue = newConvertedValue; // Reset PropertyEditor: It already did a proper conversion. // Don't use it again for a setAsText call. editor = null; } } catch (Exception ex) { if (logger.isDebugEnabled()) { logger.debug( "PropertyEditor [" + editor.getClass().getName() + "] does not support setValue call", ex); } // Swallow and proceed. } } Object returnValue = convertedValue; if (requiredType != null && !requiredType.isArray() && convertedValue instanceof String[]) { // Convert String array to a comma-separated String. // Only applies if no PropertyEditor converted the String array before. // The CSV String will be passed into a PropertyEditor's setAsText method, if any. if (logger.isTraceEnabled()) { logger.trace("Converting String array to comma-delimited String [" + convertedValue + "]"); } convertedValue = StringUtils.arrayToCommaDelimitedString((String[]) convertedValue); } if (convertedValue instanceof String) { if (editor != null) { // Use PropertyEditor's setAsText in case of a String value. if (logger.isTraceEnabled()) { logger.trace( "Converting String to [" + requiredType + "] using property editor [" + editor + "]"); } String newTextValue = (String) convertedValue; return doConvertTextValue(oldValue, newTextValue, editor); } else if (String.class == requiredType) { returnValue = convertedValue; } } return returnValue; }
From source file:org.springframework.benchmark.cmt.web.AbstractBenchmarkController.java
private Benchmark getBenchmark(String name) throws Exception { BenchmarkFactory bf = (BenchmarkFactory) benchmarkFactories.get(name); if (bf == null) throw new ServletException("No benchmark factory with name '" + name + "': " + "valid values are " + StringUtils.arrayToCommaDelimitedString(this.benchmarkNames)); return bf.getBenchmark(); }
From source file:org.springframework.boot.autoconfigure.condition.OnNotWebApplicationCondition.java
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String checking = ConditionLogUtils.getPrefix(logger, metadata); if (!ClassUtils.isPresent("org.springframework.web.context.support.GenericWebApplicationContext", null)) { if (logger.isDebugEnabled()) { logger.debug(checking + "Web application classes not found"); }/*w w w . ja v a 2 s .c o m*/ return true; } boolean result = !StringUtils .arrayToCommaDelimitedString(context.getBeanFactory().getRegisteredScopeNames()) .contains("session"); if (logger.isDebugEnabled()) { logger.debug(checking + "Web application context found: " + !result); } return result; }
From source file:org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition.java
@Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { String checking = ConditionLogUtils.getPrefix(logger, metadata); if (!ClassUtils.isPresent("org.springframework.web.context.support.GenericWebApplicationContext", null)) { if (logger.isDebugEnabled()) { logger.debug(checking + "Web application classes not found"); }//from w w w. j av a 2s . c o m return false; } boolean result = StringUtils.arrayToCommaDelimitedString(context.getBeanFactory().getRegisteredScopeNames()) .contains("session") || context.getEnvironment() instanceof StandardServletEnvironment; if (logger.isDebugEnabled()) { logger.debug(checking + "Web application context found: " + result); } return result; }
From source file:org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.java
/** * Returns the {@link EmbeddedServletContainerFactory} that should be used to create * the embedded servlet container. By default this method searches for a suitable bean * in the context itself./* w w w.j a v a 2 s . c o m*/ * @return a {@link EmbeddedServletContainerFactory} (never {@code null}) */ protected EmbeddedServletContainerFactory getEmbeddedServletContainerFactory() { // Use bean names so that we don't consider the hierarchy String[] beanNames = getBeanFactory().getBeanNamesForType(EmbeddedServletContainerFactory.class); if (beanNames.length == 0) { throw new ApplicationContextException("Unable to start EmbeddedWebApplicationContext due to missing " + "EmbeddedServletContainerFactory bean."); } if (beanNames.length > 1) { throw new ApplicationContextException("Unable to start EmbeddedWebApplicationContext due to multiple " + "EmbeddedServletContainerFactory beans : " + StringUtils.arrayToCommaDelimitedString(beanNames)); } return getBeanFactory().getBean(beanNames[0], EmbeddedServletContainerFactory.class); }
From source file:org.springframework.boot.SpringApplication.java
/** * Called to log active profile information. * @param context the application context *//* w ww . j ava 2 s . com*/ protected void logStartupProfileInfo(ConfigurableApplicationContext context) { Log log = getApplicationLog(); if (log.isInfoEnabled()) { String[] activeProfiles = context.getEnvironment().getActiveProfiles(); if (ObjectUtils.isEmpty(activeProfiles)) { log.info("No profiles are active"); } else { log.info("The following profiles are active: " + StringUtils.arrayToCommaDelimitedString(activeProfiles)); } } }
From source file:org.springframework.boot.SpringApplication.java
/** * Load beans into the application context. * @param context the context to load beans into * @param sources the sources to load//from w w w . ja v a2 s. c o m */ protected void load(ApplicationContext context, Object[] sources) { if (this.log.isDebugEnabled()) { this.log.debug("Loading source " + StringUtils.arrayToCommaDelimitedString(sources)); } BeanDefinitionLoader loader = createBeanDefinitionLoader(getBeanDefinitionRegistry(context), sources); if (this.beanNameGenerator != null) { loader.setBeanNameGenerator(this.beanNameGenerator); } if (this.resourceLoader != null) { loader.setResourceLoader(this.resourceLoader); } if (this.environment != null) { loader.setEnvironment(this.environment); } loader.load(); }
From source file:org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.java
/** * Returns the {@link ServletWebServerFactory} that should be used to create the * embedded {@link WebServer}. By default this method searches for a suitable bean in * the context itself.//ww w . j a v a 2 s .co m * @return a {@link ServletWebServerFactory} (never {@code null}) */ protected ServletWebServerFactory getWebServerFactory() { // Use bean names so that we don't consider the hierarchy String[] beanNames = getBeanFactory().getBeanNamesForType(ServletWebServerFactory.class); if (beanNames.length == 0) { throw new ApplicationContextException( "Unable to start ServletWebServerApplicationContext due to missing " + "ServletWebServerFactory bean."); } if (beanNames.length > 1) { throw new ApplicationContextException( "Unable to start ServletWebServerApplicationContext due to multiple " + "ServletWebServerFactory beans : " + StringUtils.arrayToCommaDelimitedString(beanNames)); } return getBeanFactory().getBean(beanNames[0], ServletWebServerFactory.class); }
From source file:org.springframework.cloud.bootstrap.config.ConfigServiceBootstrapConfiguration.java
@Bean public ConfigServicePropertySourceLocator configServicePropertySource(ConfigurableEnvironment environment) { ConfigServicePropertySourceLocator locator = new ConfigServicePropertySourceLocator(); String[] profiles = environment.getActiveProfiles(); if (profiles.length == 0) { profiles = environment.getDefaultProfiles(); }/*from w ww. ja v a 2 s .co m*/ locator.setEnv(StringUtils.arrayToCommaDelimitedString(profiles)); return locator; }