Java Code Examples for org.springframework.util.StringUtils#toStringArray()
The following examples show how to use
org.springframework.util.StringUtils#toStringArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanFactoryUtils.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Get all bean names for the given type, including those defined in ancestor * factories. Will return unique names in case of overridden bean definitions. * <p>Does consider objects created by FactoryBeans, which means that FactoryBeans * will get initialized. If the object created by the FactoryBean doesn't match, * the raw FactoryBean itself will be matched against the type. * <p>This version of {@code beanNamesForTypeIncludingAncestors} automatically * includes prototypes and FactoryBeans. * @param lbf the bean factory * @param type the type that beans must match (as a {@code Class}) * @return the array of matching bean names, or an empty array if none */ public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lbf, Class<?> type) { Assert.notNull(lbf, "ListableBeanFactory must not be null"); String[] result = lbf.getBeanNamesForType(type); if (lbf instanceof HierarchicalBeanFactory) { HierarchicalBeanFactory hbf = (HierarchicalBeanFactory) lbf; if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) { String[] parentResult = beanNamesForTypeIncludingAncestors( (ListableBeanFactory) hbf.getParentBeanFactory(), type); List<String> resultList = new ArrayList<String>(); resultList.addAll(Arrays.asList(result)); for (String beanName : parentResult) { if (!resultList.contains(beanName) && !hbf.containsLocalBean(beanName)) { resultList.add(beanName); } } result = StringUtils.toStringArray(resultList); } } return result; }
Example 2
Source File: EntandoMessageCodesResolver.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
@Override public String[] resolveMessageCodes(String errorCode, String objectName, String field, Class<?> fieldType) { Set<String> codeList = new LinkedHashSet<String>(); List<String> fieldList = new ArrayList<String>(); buildFieldList(field, fieldList); addCodes(codeList, errorCode, objectName, fieldList); int dotIndex = field.lastIndexOf('.'); if (dotIndex != -1) { buildFieldList(field.substring(dotIndex + 1), fieldList); } addCodes(codeList, errorCode, null, fieldList); if (fieldType != null) { addCode(codeList, errorCode, null, fieldType.getName()); } addCode(codeList, errorCode, null, null); if (this.getValidationErrorCodeMapping().containsKey(errorCode)) { addCode(codeList, this.getValidationErrorCodeMapping().get(errorCode), null, null); } return StringUtils.toStringArray(codeList); }
Example 3
Source File: StaticListableBeanFactory.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public String[] getBeanNamesForType(ResolvableType type) { boolean isFactoryType = false; if (type != null) { Class<?> resolved = type.resolve(); if (resolved != null && FactoryBean.class.isAssignableFrom(resolved)) { isFactoryType = true; } } List<String> matches = new ArrayList<String>(); for (Map.Entry<String, Object> entry : this.beans.entrySet()) { String name = entry.getKey(); Object beanInstance = entry.getValue(); if (beanInstance instanceof FactoryBean && !isFactoryType) { Class<?> objectType = ((FactoryBean<?>) beanInstance).getObjectType(); if (objectType != null && (type == null || type.isAssignableFrom(objectType))) { matches.add(name); } } else { if (type == null || type.isInstance(beanInstance)) { matches.add(name); } } } return StringUtils.toStringArray(matches); }
Example 4
Source File: DefaultActiveProfilesResolver.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Resolve the <em>bean definition profiles</em> for the given {@linkplain * Class test class} based on profiles configured declaratively via * {@link ActiveProfiles#profiles} or {@link ActiveProfiles#value}. * @param testClass the test class for which the profiles should be resolved; * never {@code null} * @return the list of bean definition profiles to use when loading the * {@code ApplicationContext}; never {@code null} */ @Override public String[] resolve(Class<?> testClass) { Assert.notNull(testClass, "Class must not be null"); final Set<String> activeProfiles = new LinkedHashSet<String>(); Class<ActiveProfiles> annotationType = ActiveProfiles.class; AnnotationDescriptor<ActiveProfiles> descriptor = findAnnotationDescriptor(testClass, annotationType); if (descriptor == null) { if (logger.isDebugEnabled()) { logger.debug(String.format( "Could not find an 'annotation declaring class' for annotation type [%s] and class [%s]", annotationType.getName(), testClass.getName())); } } else { Class<?> declaringClass = descriptor.getDeclaringClass(); ActiveProfiles annotation = descriptor.synthesizeAnnotation(); if (logger.isTraceEnabled()) { logger.trace(String.format("Retrieved @ActiveProfiles [%s] for declaring class [%s].", annotation, declaringClass.getName())); } for (String profile : annotation.profiles()) { if (StringUtils.hasText(profile)) { activeProfiles.add(profile.trim()); } } } return StringUtils.toStringArray(activeProfiles); }
Example 5
Source File: AbstractBeanFactory.java From blog_demos with Apache License 2.0 | 5 votes |
@Override public String[] getAliases(String name) { String beanName = transformedBeanName(name); List<String> aliases = new ArrayList<String>(); boolean factoryPrefix = name.startsWith(FACTORY_BEAN_PREFIX); String fullBeanName = beanName; if (factoryPrefix) { fullBeanName = FACTORY_BEAN_PREFIX + beanName; } if (!fullBeanName.equals(name)) { aliases.add(fullBeanName); } String[] retrievedAliases = super.getAliases(beanName); for (String retrievedAlias : retrievedAliases) { String alias = (factoryPrefix ? FACTORY_BEAN_PREFIX : "") + retrievedAlias; if (!alias.equals(name)) { aliases.add(alias); } } if (!containsSingleton(beanName) && !containsBeanDefinition(beanName)) { BeanFactory parentBeanFactory = getParentBeanFactory(); if (parentBeanFactory != null) { aliases.addAll(Arrays.asList(parentBeanFactory.getAliases(fullBeanName))); } } return StringUtils.toStringArray(aliases); }
Example 6
Source File: DefaultSingletonBeanRegistry.java From blog_demos with Apache License 2.0 | 5 votes |
public void destroySingletons() { if (logger.isDebugEnabled()) { logger.debug("Destroying singletons in " + this); } 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; } }
Example 7
Source File: BeanFactoryUtils.java From java-technology-stack with MIT License | 5 votes |
/** * Merge the given bean names result with the given parent result. * @param result the local bean name result * @param parentResult the parent bean name result (possibly empty) * @param hbf the local bean factory * @return the merged result (possibly the local result as-is) * @since 4.3.15 */ private static String[] mergeNamesWithParent(String[] result, String[] parentResult, HierarchicalBeanFactory hbf) { if (parentResult.length == 0) { return result; } List<String> merged = new ArrayList<>(result.length + parentResult.length); merged.addAll(Arrays.asList(result)); for (String beanName : parentResult) { if (!merged.contains(beanName) && !hbf.containsLocalBean(beanName)) { merged.add(beanName); } } return StringUtils.toStringArray(merged); }
Example 8
Source File: PropertyMatches.java From spring-analysis-note with MIT License | 5 votes |
/** * Generate possible property alternatives for the given property and class. * Internally uses the {@code getStringDistance} method, which in turn uses * the Levenshtein algorithm to determine the distance between two Strings. * @param descriptors the JavaBeans property descriptors to search * @param maxDistance the maximum distance to accept */ private static String[] calculateMatches(String name, PropertyDescriptor[] descriptors, int maxDistance) { List<String> candidates = new ArrayList<>(); for (PropertyDescriptor pd : descriptors) { if (pd.getWriteMethod() != null) { String possibleAlternative = pd.getName(); if (calculateStringDistance(name, possibleAlternative) <= maxDistance) { candidates.add(possibleAlternative); } } } Collections.sort(candidates); return StringUtils.toStringArray(candidates); }
Example 9
Source File: DefaultListableBeanFactory.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void freezeConfiguration() { this.configurationFrozen = true; this.frozenBeanDefinitionNames = StringUtils.toStringArray(this.beanDefinitionNames); }
Example 10
Source File: StaticListableBeanFactory.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public String[] getBeanDefinitionNames() { return StringUtils.toStringArray(this.beans.keySet()); }
Example 11
Source File: FacesRequestAttributes.java From java-technology-stack with MIT License | 4 votes |
@Override public String[] getAttributeNames(int scope) { return StringUtils.toStringArray(getAttributeMap(scope).keySet()); }
Example 12
Source File: DefaultAnnotationHandlerMapping.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Checks for presence of the {@link org.springframework.web.bind.annotation.RequestMapping} * annotation on the handler class and on any of its methods. */ @Override protected String[] determineUrlsForHandler(String beanName) { ApplicationContext context = getApplicationContext(); Class<?> handlerType = context.getType(beanName); RequestMapping mapping = context.findAnnotationOnBean(beanName, RequestMapping.class); if (mapping != null) { // @RequestMapping found at type level this.cachedMappings.put(handlerType, mapping); Set<String> urls = new LinkedHashSet<String>(); String[] typeLevelPatterns = mapping.value(); if (typeLevelPatterns.length > 0) { // @RequestMapping specifies paths at type level String[] methodLevelPatterns = determineUrlsForHandlerMethods(handlerType, true); for (String typeLevelPattern : typeLevelPatterns) { if (!typeLevelPattern.startsWith("/")) { typeLevelPattern = "/" + typeLevelPattern; } boolean hasEmptyMethodLevelMappings = false; for (String methodLevelPattern : methodLevelPatterns) { if (methodLevelPattern == null) { hasEmptyMethodLevelMappings = true; } else { String combinedPattern = getPathMatcher().combine(typeLevelPattern, methodLevelPattern); addUrlsForPath(urls, combinedPattern); } } if (hasEmptyMethodLevelMappings || org.springframework.web.servlet.mvc.Controller.class.isAssignableFrom(handlerType)) { addUrlsForPath(urls, typeLevelPattern); } } return StringUtils.toStringArray(urls); } else { // actual paths specified by @RequestMapping at method level return determineUrlsForHandlerMethods(handlerType, false); } } else if (AnnotationUtils.findAnnotation(handlerType, Controller.class) != null) { // @RequestMapping to be introspected at method level return determineUrlsForHandlerMethods(handlerType, false); } else { return null; } }
Example 13
Source File: MapPropertySource.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public String[] getPropertyNames() { return StringUtils.toStringArray(this.source.keySet()); }
Example 14
Source File: ServletConfigPropertySource.java From java-technology-stack with MIT License | 4 votes |
@Override public String[] getPropertyNames() { return StringUtils.toStringArray(this.source.getInitParameterNames()); }
Example 15
Source File: FacesRequestAttributes.java From spring-analysis-note with MIT License | 4 votes |
@Override public String[] getAttributeNames(int scope) { return StringUtils.toStringArray(getAttributeMap(scope).keySet()); }
Example 16
Source File: SimpleBeanDefinitionRegistry.java From blog_demos with Apache License 2.0 | 4 votes |
@Override public String[] getBeanDefinitionNames() { return StringUtils.toStringArray(this.beanDefinitionMap.keySet()); }
Example 17
Source File: PropertyResourceConfigurerTests.java From java-technology-stack with MIT License | 4 votes |
@Override protected String[] childrenNamesSpi() throws BackingStoreException { return StringUtils.toStringArray(children.keySet()); }
Example 18
Source File: AttributeAccessorSupport.java From java-technology-stack with MIT License | 4 votes |
@Override public String[] attributeNames() { return StringUtils.toStringArray(this.attributes.keySet()); }
Example 19
Source File: ServletConfigPropertySource.java From spring-analysis-note with MIT License | 4 votes |
@Override public String[] getPropertyNames() { return StringUtils.toStringArray(this.source.getInitParameterNames()); }
Example 20
Source File: HttpRequestMethodNotSupportedException.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Create a new HttpRequestMethodNotSupportedException. * @param method the unsupported HTTP request method * @param supportedMethods the actually supported HTTP methods (may be {@code null}) */ public HttpRequestMethodNotSupportedException(String method, Collection<String> supportedMethods) { this(method, StringUtils.toStringArray(supportedMethods)); }