Java Code Examples for org.springframework.util.StringUtils.toStringArray()

The following are Jave code examples for showing how to use toStringArray() of the org.springframework.util.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: DefaultMessageCodesResolver.java   View Source Code Vote up 6 votes
/**
 * Build the code list for the given code and field: an
 * object/field-specific code, a field-specific code, a plain error code.
 * <p>Arrays, Lists and Maps are resolved both for specific elements and
 * the whole collection.
 * <p>See the {@link DefaultMessageCodesResolver class level Javadoc} for
 * details on the generated codes.
 * @return the list of codes
 */
@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);
	return StringUtils.toStringArray(codeList);
}
 
Example 2
Project: lams   File: ServletRequestAttributes.java   View Source Code Vote up 6 votes
@Override
public String[] getAttributeNames(int scope) {
	if (scope == SCOPE_REQUEST) {
		if (!isRequestActive()) {
			throw new IllegalStateException(
					"Cannot ask for request attributes - request is not active anymore!");
		}
		return StringUtils.toStringArray(this.request.getAttributeNames());
	}
	else {
		HttpSession session = getSession(false);
		if (session != null) {
			try {
				return StringUtils.toStringArray(session.getAttributeNames());
			}
			catch (IllegalStateException ex) {
				// Session invalidated - shouldn't usually happen.
			}
		}
		return new String[0];
	}
}
 
Example 3
Project: lams   File: BeanWrapperImpl.java   View Source Code Vote up 6 votes
/**
 * Parse the given property name into the corresponding property name tokens.
 * @param propertyName the property name to parse
 * @return representation of the parsed property tokens
 */
private PropertyTokenHolder getPropertyNameTokens(String propertyName) {
	PropertyTokenHolder tokens = new PropertyTokenHolder();
	String actualName = null;
	List<String> keys = new ArrayList<String>(2);
	int searchIndex = 0;
	while (searchIndex != -1) {
		int keyStart = propertyName.indexOf(PROPERTY_KEY_PREFIX, searchIndex);
		searchIndex = -1;
		if (keyStart != -1) {
			int keyEnd = propertyName.indexOf(PROPERTY_KEY_SUFFIX, keyStart + PROPERTY_KEY_PREFIX.length());
			if (keyEnd != -1) {
				if (actualName == null) {
					actualName = propertyName.substring(0, keyStart);
				}
				String key = propertyName.substring(keyStart + PROPERTY_KEY_PREFIX.length(), keyEnd);
				if ((key.startsWith("'") && key.endsWith("'")) || (key.startsWith("\"") && key.endsWith("\""))) {
					key = key.substring(1, key.length() - 1);
				}
				keys.add(key);
				searchIndex = keyEnd + PROPERTY_KEY_SUFFIX.length();
			}
		}
	}
	tokens.actualName = (actualName != null ? actualName : propertyName);
	tokens.canonicalName = tokens.actualName;
	if (!keys.isEmpty()) {
		tokens.canonicalName +=
				PROPERTY_KEY_PREFIX +
				StringUtils.collectionToDelimitedString(keys, PROPERTY_KEY_SUFFIX + PROPERTY_KEY_PREFIX) +
				PROPERTY_KEY_SUFFIX;
		tokens.keys = StringUtils.toStringArray(keys);
	}
	return tokens;
}
 
Example 4
Project: lams   File: StaticListableBeanFactory.java   View Source Code Vote up 6 votes
@Override
public String[] getBeanNamesForType(Class<?> type, boolean includeNonSingletons, boolean includeFactoryBeans) {
	boolean isFactoryType = (type != null && FactoryBean.class.isAssignableFrom(type));
	List<String> matches = new ArrayList<String>();
	for (String name : this.beans.keySet()) {
		Object beanInstance = this.beans.get(name);
		if (beanInstance instanceof FactoryBean && !isFactoryType) {
			if (includeFactoryBeans) {
				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 5
Project: configx   File: RefreshBeanDependencyFactory.java   View Source Code Vote up 5 votes
/**
 * Return the names of all property that the specified bean depends on, if any.
 *
 * @param beanName the name of the bean
 * @return the array of dependent property names, or an empty array if none
 */
public String[] getDependentPropertyNames(String beanName) {
    beanName = ProxyUtils.getOriginalBeanName(beanName);
    Set<String> dependentPropertyNames = this.dependentPropertyMap.get(beanName);
    if (dependentPropertyNames == null) {
        return new String[0];
    }
    return StringUtils.toStringArray(dependentPropertyNames);
}
 
Example 6
Project: lams   File: FacesRequestAttributes.java   View Source Code Vote up 5 votes
@Override
public String[] getAttributeNames(int scope) {
	if (scope == SCOPE_GLOBAL_SESSION && portletApiPresent) {
		return PortletSessionAccessor.getAttributeNames(getExternalContext());
	}
	else {
		return StringUtils.toStringArray(getAttributeMap(scope).keySet());
	}
}
 
Example 7
Project: lams   File: FacesRequestAttributes.java   View Source Code Vote up 5 votes
public static String[] getAttributeNames(ExternalContext externalContext) {
	Object session = externalContext.getSession(false);
	if (session instanceof PortletSession) {
		return StringUtils.toStringArray(
				((PortletSession) session).getAttributeNames(PortletSession.APPLICATION_SCOPE));
	}
	else if (session != null) {
		return StringUtils.toStringArray(externalContext.getSessionMap().keySet());
	}
	else {
		return new String[0];
	}
}
 
Example 8
Project: lams   File: PropertyMatches.java   View Source Code Vote up 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 propertyDescriptors the JavaBeans property descriptors to search
 * @param maxDistance the maximum distance to accept
 */
private String[] calculateMatches(PropertyDescriptor[] propertyDescriptors, int maxDistance) {
	List<String> candidates = new ArrayList<String>();
	for (PropertyDescriptor pd : propertyDescriptors) {
		if (pd.getWriteMethod() != null) {
			String possibleAlternative = pd.getName();
			if (calculateStringDistance(this.propertyName, possibleAlternative) <= maxDistance) {
				candidates.add(possibleAlternative);
			}
		}
	}
	Collections.sort(candidates);
	return StringUtils.toStringArray(candidates);
}
 
Example 9
Project: lams   File: DefaultListableBeanFactory.java   View Source Code Vote up 5 votes
@Override
public void freezeConfiguration() {
	this.configurationFrozen = true;
	synchronized (this.beanDefinitionMap) {
		this.frozenBeanDefinitionNames = StringUtils.toStringArray(this.beanDefinitionNames);
	}
}
 
Example 10
Project: lams   File: DefaultListableBeanFactory.java   View Source Code Vote up 5 votes
@Override
public String[] getBeanDefinitionNames() {
	synchronized (this.beanDefinitionMap) {
		if (this.frozenBeanDefinitionNames != null) {
			return this.frozenBeanDefinitionNames;
		}
		else {
			return StringUtils.toStringArray(this.beanDefinitionNames);
		}
	}
}
 
Example 11
Project: lams   File: AbstractAutowireCapableBeanFactory.java   View Source Code Vote up 5 votes
/**
 * Return an array of non-simple bean properties that are unsatisfied.
 * These are probably unsatisfied references to other beans in the
 * factory. Does not include simple properties like primitives or Strings.
 * @param mbd the merged bean definition the bean was created with
 * @param bw the BeanWrapper the bean was created with
 * @return an array of bean property names
 * @see org.springframework.beans.BeanUtils#isSimpleProperty
 */
protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {
	Set<String> result = new TreeSet<String>();
	PropertyValues pvs = mbd.getPropertyValues();
	PropertyDescriptor[] pds = bw.getPropertyDescriptors();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) &&
				!BeanUtils.isSimpleProperty(pd.getPropertyType())) {
			result.add(pd.getName());
		}
	}
	return StringUtils.toStringArray(result);
}
 
Example 12
Project: lams   File: DefaultSingletonBeanRegistry.java   View Source Code Vote up 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 13
Project: configx   File: ConfigPropertySource.java   View Source Code Vote up 4 votes
@Override
public String[] getPropertyNames() {
    return StringUtils.toStringArray(this.source.keys());
}
 
Example 14
Project: lams   File: ServletWebRequest.java   View Source Code Vote up 4 votes
@Override
public String[] getHeaderValues(String headerName) {
	String[] headerValues = StringUtils.toStringArray(getRequest().getHeaders(headerName));
	return (!ObjectUtils.isEmpty(headerValues) ? headerValues : null);
}
 
Example 15
Project: lams   File: StaticListableBeanFactory.java   View Source Code Vote up 4 votes
@Override
public String[] getBeanDefinitionNames() {
	return StringUtils.toStringArray(this.beans.keySet());
}
 
Example 16
Project: lams   File: AbstractBeanFactory.java   View Source Code Vote up 4 votes
@Override
public String[] getRegisteredScopeNames() {
	return StringUtils.toStringArray(this.scopes.keySet());
}
 
Example 17
Project: lams   File: SimpleBeanDefinitionRegistry.java   View Source Code Vote up 4 votes
@Override
public String[] getBeanDefinitionNames() {
	return StringUtils.toStringArray(this.beanDefinitionMap.keySet());
}
 
Example 18
Project: lams   File: DefaultSingletonBeanRegistry.java   View Source Code Vote up 4 votes
@Override
public String[] getSingletonNames() {
	synchronized (this.singletonObjects) {
		return StringUtils.toStringArray(this.registeredSingletons);
	}
}
 
Example 19
Project: lams   File: BeanDefinitionParserDelegate.java   View Source Code Vote up 4 votes
/**
 * Parses the supplied {@code &lt;bean&gt;} element. May return {@code null}
 * if there were errors during parse. Errors are reported to the
 * {@link org.springframework.beans.factory.parsing.ProblemReporter}.
 */
public BeanDefinitionHolder parseBeanDefinitionElement(Element ele, BeanDefinition containingBean) {
	String id = ele.getAttribute(ID_ATTRIBUTE);
	String nameAttr = ele.getAttribute(NAME_ATTRIBUTE);

	List<String> aliases = new ArrayList<String>();
	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;
}
 
Example 20
Project: lams   File: AbstractBindingResult.java   View Source Code Vote up 2 votes
/**
 * Return the list of fields that were suppressed during the bind process.
 * <p>Can be used to determine whether any field values were targetting
 * disallowed fields.
 * @see DataBinder#setAllowedFields
 */
@Override
public String[] getSuppressedFields() {
	return StringUtils.toStringArray(this.suppressedFields);
}