Polishing
This commit is contained in:
@@ -389,7 +389,8 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
||||
if (pd.getReadMethod() != null || pd.getWriteMethod() != null) {
|
||||
return TypeDescriptor.nested(property(pd), tokens.keys.length);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (pd.getReadMethod() != null || pd.getWriteMethod() != null) {
|
||||
return new TypeDescriptor(property(pd));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,7 +49,7 @@ final class PropertyMatches {
|
||||
* @param propertyName the name of the property to find possible matches for
|
||||
* @param beanClass the bean class to search for matches
|
||||
*/
|
||||
public static PropertyMatches forProperty(String propertyName, Class beanClass) {
|
||||
public static PropertyMatches forProperty(String propertyName, Class<?> beanClass) {
|
||||
return forProperty(propertyName, beanClass, DEFAULT_MAX_DISTANCE);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ final class PropertyMatches {
|
||||
* @param beanClass the bean class to search for matches
|
||||
* @param maxDistance the maximum property distance allowed for matches
|
||||
*/
|
||||
public static PropertyMatches forProperty(String propertyName, Class beanClass, int maxDistance) {
|
||||
public static PropertyMatches forProperty(String propertyName, Class<?> beanClass, int maxDistance) {
|
||||
return new PropertyMatches(propertyName, beanClass, maxDistance);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ final class PropertyMatches {
|
||||
/**
|
||||
* Create a new PropertyMatches instance for the given property.
|
||||
*/
|
||||
private PropertyMatches(String propertyName, Class beanClass, int maxDistance) {
|
||||
private PropertyMatches(String propertyName, Class<?> beanClass, int maxDistance) {
|
||||
this.propertyName = propertyName;
|
||||
this.possibleMatches = calculateMatches(BeanUtils.getPropertyDescriptors(beanClass), maxDistance);
|
||||
}
|
||||
@@ -172,7 +172,8 @@ final class PropertyMatches {
|
||||
char t_j = s2.charAt(j - 1);
|
||||
if (s_i == t_j) {
|
||||
cost = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
cost = 1;
|
||||
}
|
||||
d[i][j] = Math.min(Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1),
|
||||
|
||||
@@ -200,13 +200,13 @@ class TypeConverterDelegate {
|
||||
else if (convertedValue instanceof Collection) {
|
||||
// Convert elements to target type, if determined.
|
||||
convertedValue = convertToTypedCollection(
|
||||
(Collection) convertedValue, propertyName, requiredType, typeDescriptor);
|
||||
(Collection<?>) convertedValue, propertyName, requiredType, typeDescriptor);
|
||||
standardConversion = true;
|
||||
}
|
||||
else if (convertedValue instanceof Map) {
|
||||
// Convert keys and values to respective target type, if determined.
|
||||
convertedValue = convertToTypedMap(
|
||||
(Map) convertedValue, propertyName, requiredType, typeDescriptor);
|
||||
(Map<?, ?>) convertedValue, propertyName, requiredType, typeDescriptor);
|
||||
standardConversion = true;
|
||||
}
|
||||
if (convertedValue.getClass().isArray() && Array.getLength(convertedValue) == 1) {
|
||||
@@ -296,12 +296,12 @@ class TypeConverterDelegate {
|
||||
convertedValue = enumField.get(null);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Enum class [" + enumType + "] cannot be loaded", ex);
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if(logger.isTraceEnabled()) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Field [" + fieldName + "] isn't an enum value for type [" + enumType + "]", ex);
|
||||
}
|
||||
}
|
||||
@@ -459,10 +459,10 @@ class TypeConverterDelegate {
|
||||
private Object convertToTypedArray(Object input, String propertyName, Class<?> componentType) {
|
||||
if (input instanceof Collection) {
|
||||
// Convert Collection elements to array elements.
|
||||
Collection coll = (Collection) input;
|
||||
Collection<?> coll = (Collection<?>) input;
|
||||
Object result = Array.newInstance(componentType, coll.size());
|
||||
int i = 0;
|
||||
for (Iterator it = coll.iterator(); it.hasNext(); i++) {
|
||||
for (Iterator<?> it = coll.iterator(); it.hasNext(); i++) {
|
||||
Object value = convertIfNecessary(
|
||||
buildIndexedPropertyName(propertyName, i), null, it.next(), componentType);
|
||||
Array.set(result, i, value);
|
||||
@@ -495,8 +495,8 @@ class TypeConverterDelegate {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection convertToTypedCollection(
|
||||
Collection original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
||||
private Collection<?> convertToTypedCollection(
|
||||
Collection<?> original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
||||
|
||||
if (!Collection.class.isAssignableFrom(requiredType)) {
|
||||
return original;
|
||||
@@ -519,7 +519,7 @@ class TypeConverterDelegate {
|
||||
return original;
|
||||
}
|
||||
|
||||
Iterator it;
|
||||
Iterator<?> it;
|
||||
try {
|
||||
it = original.iterator();
|
||||
if (it == null) {
|
||||
@@ -538,13 +538,13 @@ class TypeConverterDelegate {
|
||||
return original;
|
||||
}
|
||||
|
||||
Collection convertedCopy;
|
||||
Collection<Object> convertedCopy;
|
||||
try {
|
||||
if (approximable) {
|
||||
convertedCopy = CollectionFactory.createApproximateCollection(original, original.size());
|
||||
}
|
||||
else {
|
||||
convertedCopy = (Collection) requiredType.newInstance();
|
||||
convertedCopy = (Collection<Object>) requiredType.newInstance();
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
@@ -577,8 +577,8 @@ class TypeConverterDelegate {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map convertToTypedMap(
|
||||
Map original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
||||
private Map<?, ?> convertToTypedMap(
|
||||
Map<?, ?> original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
||||
|
||||
if (!Map.class.isAssignableFrom(requiredType)) {
|
||||
return original;
|
||||
@@ -602,7 +602,7 @@ class TypeConverterDelegate {
|
||||
return original;
|
||||
}
|
||||
|
||||
Iterator it;
|
||||
Iterator<?> it;
|
||||
try {
|
||||
it = original.entrySet().iterator();
|
||||
if (it == null) {
|
||||
@@ -621,13 +621,13 @@ class TypeConverterDelegate {
|
||||
return original;
|
||||
}
|
||||
|
||||
Map convertedCopy;
|
||||
Map<Object, Object> convertedCopy;
|
||||
try {
|
||||
if (approximable) {
|
||||
convertedCopy = CollectionFactory.createApproximateMap(original, original.size());
|
||||
}
|
||||
else {
|
||||
convertedCopy = (Map) requiredType.newInstance();
|
||||
convertedCopy = (Map<Object, Object>) requiredType.newInstance();
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
@@ -639,7 +639,7 @@ class TypeConverterDelegate {
|
||||
}
|
||||
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>) it.next();
|
||||
Object key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
String keyedPropertyName = buildKeyedPropertyName(propertyName, key);
|
||||
|
||||
@@ -149,7 +149,7 @@ public abstract class AbstractSimpleBeanDefinitionParser extends AbstractSingleB
|
||||
*/
|
||||
protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) {
|
||||
boolean eligible = isEligibleAttribute(attribute);
|
||||
if(!eligible) {
|
||||
if (!eligible) {
|
||||
String fullName = attribute.getName();
|
||||
eligible = (!fullName.equals("xmlns") && !fullName.startsWith("xmlns:") &&
|
||||
isEligibleAttribute(parserContext.getDelegate().getLocalName(attribute)));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,29 +13,30 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans.factory.xml;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
|
||||
import org.springframework.core.Conventions;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.core.Conventions;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Simple {@code NamespaceHandler} implementation that maps custom
|
||||
* attributes directly through to bean properties. An important point to note is
|
||||
* that this {@code NamespaceHandler} does not have a corresponding schema
|
||||
* since there is no way to know in advance all possible attribute names.
|
||||
*
|
||||
* <p>
|
||||
* An example of the usage of this {@code NamespaceHandler} is shown below:
|
||||
* <p>An example of the usage of this {@code NamespaceHandler} is shown below:
|
||||
*
|
||||
* <pre class="code">
|
||||
* <bean id="author" class="..TestBean" c:name="Enescu" c:work-ref="compositions"/>
|
||||
@@ -51,14 +52,17 @@ import org.w3c.dom.Node;
|
||||
* support for indexes or types. Further more, the names are used as hints by
|
||||
* the container which, by default, does type introspection.
|
||||
*
|
||||
* @see SimplePropertyNamespaceHandler
|
||||
* @author Costin Leau
|
||||
* @since 3.1
|
||||
* @see SimplePropertyNamespaceHandler
|
||||
*/
|
||||
public class SimpleConstructorNamespaceHandler implements NamespaceHandler {
|
||||
|
||||
private static final String REF_SUFFIX = "-ref";
|
||||
|
||||
private static final String DELIMITER_PREFIX = "_";
|
||||
|
||||
|
||||
public void init() {
|
||||
}
|
||||
|
||||
@@ -99,7 +103,8 @@ public class SimpleConstructorNamespaceHandler implements NamespaceHandler {
|
||||
int index = -1;
|
||||
try {
|
||||
index = Integer.parseInt(arg);
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
parserContext.getReaderContext().error(
|
||||
"Constructor argument '" + argName + "' specifies an invalid integer", attr);
|
||||
}
|
||||
@@ -133,11 +138,8 @@ public class SimpleConstructorNamespaceHandler implements NamespaceHandler {
|
||||
}
|
||||
|
||||
private boolean containsArgWithName(String name, ConstructorArgumentValues cvs) {
|
||||
if (!checkName(name, cvs.getGenericArgumentValues())) {
|
||||
return checkName(name, cvs.getIndexedArgumentValues().values());
|
||||
}
|
||||
|
||||
return true;
|
||||
return (checkName(name, cvs.getGenericArgumentValues()) ||
|
||||
checkName(name, cvs.getIndexedArgumentValues().values()));
|
||||
}
|
||||
|
||||
private boolean checkName(String name, Collection<ValueHolder> values) {
|
||||
@@ -148,4 +150,5 @@ public class SimpleConstructorNamespaceHandler implements NamespaceHandler {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.springframework.beans.propertyeditors;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link java.beans.PropertyEditor} implementation for
|
||||
* {@link java.util.ResourceBundle ResourceBundles}.
|
||||
@@ -87,7 +87,8 @@ public class ResourceBundleEditor extends PropertyEditorSupport {
|
||||
int indexOfBaseNameSeparator = rawBaseName.indexOf(BASE_NAME_SEPARATOR);
|
||||
if (indexOfBaseNameSeparator == -1) {
|
||||
bundle = ResourceBundle.getBundle(rawBaseName);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// it potentially has locale information
|
||||
String baseName = rawBaseName.substring(0, indexOfBaseNameSeparator);
|
||||
if (!StringUtils.hasText(baseName)) {
|
||||
|
||||
Reference in New Issue
Block a user