Java 5 code style
This commit is contained in:
@@ -103,16 +103,16 @@ public class CachedIntrospectionResults {
|
||||
return;
|
||||
}
|
||||
synchronized (classCache) {
|
||||
for (Iterator it = classCache.keySet().iterator(); it.hasNext();) {
|
||||
Class beanClass = (Class) it.next();
|
||||
for (Iterator<Class> it = classCache.keySet().iterator(); it.hasNext();) {
|
||||
Class beanClass = it.next();
|
||||
if (isUnderneathClassLoader(beanClass.getClassLoader(), classLoader)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
synchronized (acceptedClassLoaders) {
|
||||
for (Iterator it = acceptedClassLoaders.iterator(); it.hasNext();) {
|
||||
ClassLoader registeredLoader = (ClassLoader) it.next();
|
||||
for (Iterator<ClassLoader> it = acceptedClassLoaders.iterator(); it.hasNext();) {
|
||||
ClassLoader registeredLoader = it.next();
|
||||
if (isUnderneathClassLoader(registeredLoader, classLoader)) {
|
||||
it.remove();
|
||||
}
|
||||
|
||||
@@ -79,15 +79,15 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
|
||||
private boolean configValueEditorsActive = false;
|
||||
|
||||
private boolean propertySpecificEditorsRegistered = false;
|
||||
private Map<Class, PropertyEditor> defaultEditors;
|
||||
|
||||
private Map defaultEditors;
|
||||
private Map<Class, PropertyEditor> customEditors;
|
||||
|
||||
private Map customEditors;
|
||||
private Map<String, CustomEditorHolder> customEditorsForPath;
|
||||
|
||||
private Set sharedEditors;
|
||||
private Set<PropertyEditor> sharedEditors;
|
||||
|
||||
private Map customEditorCache;
|
||||
private Map<Class, PropertyEditor> customEditorCache;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
@@ -127,7 +127,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
if (this.defaultEditors == null) {
|
||||
doRegisterDefaultEditors();
|
||||
}
|
||||
return (PropertyEditor) this.defaultEditors.get(requiredType);
|
||||
return this.defaultEditors.get(requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +152,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* @see org.springframework.beans.propertyeditors.URLEditor
|
||||
*/
|
||||
private void doRegisterDefaultEditors() {
|
||||
this.defaultEditors = new HashMap(64);
|
||||
this.defaultEditors = new HashMap<Class, PropertyEditor>(64);
|
||||
|
||||
// Simple editors, without parameterization capabilities.
|
||||
// The JDK does not contain a default editor for any of these target types.
|
||||
@@ -238,14 +238,16 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
if (requiredType == null && propertyPath == null) {
|
||||
throw new IllegalArgumentException("Either requiredType or propertyPath is required");
|
||||
}
|
||||
if (this.customEditors == null) {
|
||||
this.customEditors = new LinkedHashMap(16);
|
||||
}
|
||||
if (propertyPath != null) {
|
||||
this.customEditors.put(propertyPath, new CustomEditorHolder(propertyEditor, requiredType));
|
||||
this.propertySpecificEditorsRegistered = true;
|
||||
if (this.customEditorsForPath == null) {
|
||||
this.customEditorsForPath = new LinkedHashMap<String, CustomEditorHolder>(16);
|
||||
}
|
||||
this.customEditorsForPath.put(propertyPath, new CustomEditorHolder(propertyEditor, requiredType));
|
||||
}
|
||||
else {
|
||||
if (this.customEditors == null) {
|
||||
this.customEditors = new LinkedHashMap<Class, PropertyEditor>(16);
|
||||
}
|
||||
this.customEditors.put(requiredType, propertyEditor);
|
||||
this.customEditorCache = null;
|
||||
}
|
||||
@@ -261,7 +263,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
public void registerSharedEditor(Class requiredType, PropertyEditor propertyEditor) {
|
||||
registerCustomEditor(requiredType, null, propertyEditor);
|
||||
if (this.sharedEditors == null) {
|
||||
this.sharedEditors = new HashSet();
|
||||
this.sharedEditors = new HashSet<PropertyEditor>();
|
||||
}
|
||||
this.sharedEditors.add(propertyEditor);
|
||||
}
|
||||
@@ -277,19 +279,16 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
}
|
||||
|
||||
public PropertyEditor findCustomEditor(Class requiredType, String propertyPath) {
|
||||
if (this.customEditors == null) {
|
||||
return null;
|
||||
}
|
||||
Class requiredTypeToUse = requiredType;
|
||||
if (propertyPath != null) {
|
||||
if (this.propertySpecificEditorsRegistered) {
|
||||
if (this.customEditorsForPath != null) {
|
||||
// Check property-specific editor first.
|
||||
PropertyEditor editor = getCustomEditor(propertyPath, requiredType);
|
||||
if (editor == null) {
|
||||
List strippedPaths = new LinkedList();
|
||||
List<String> strippedPaths = new LinkedList<String>();
|
||||
addStrippedPropertyPaths(strippedPaths, "", propertyPath);
|
||||
for (Iterator it = strippedPaths.iterator(); it.hasNext() && editor == null;) {
|
||||
String strippedPath = (String) it.next();
|
||||
for (Iterator<String> it = strippedPaths.iterator(); it.hasNext() && editor == null;) {
|
||||
String strippedPath = it.next();
|
||||
editor = getCustomEditor(strippedPath, requiredType);
|
||||
}
|
||||
}
|
||||
@@ -315,25 +314,17 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* @return whether a matching custom editor has been found
|
||||
*/
|
||||
public boolean hasCustomEditorForElement(Class elementType, String propertyPath) {
|
||||
if (this.customEditors == null) {
|
||||
return false;
|
||||
}
|
||||
if (propertyPath != null && this.propertySpecificEditorsRegistered) {
|
||||
for (Iterator it = this.customEditors.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
if (entry.getKey() instanceof String) {
|
||||
String regPath = (String) entry.getKey();
|
||||
if (PropertyAccessorUtils.matchesProperty(regPath, propertyPath)) {
|
||||
CustomEditorHolder editorHolder = (CustomEditorHolder) entry.getValue();
|
||||
if (editorHolder.getPropertyEditor(elementType) != null) {
|
||||
return true;
|
||||
}
|
||||
if (propertyPath != null && this.customEditorsForPath != null) {
|
||||
for (Map.Entry<String, CustomEditorHolder> entry : this.customEditorsForPath.entrySet()) {
|
||||
if (PropertyAccessorUtils.matchesProperty(entry.getKey(), propertyPath)) {
|
||||
if (entry.getValue().getPropertyEditor(elementType) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// No property-specific editor -> check type-specific editor.
|
||||
return (elementType != null && this.customEditors.containsKey(elementType));
|
||||
return (elementType != null && this.customEditors != null && this.customEditors.containsKey(elementType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -358,7 +349,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* @return the custom editor, or <code>null</code> if none specific for this property
|
||||
*/
|
||||
private PropertyEditor getCustomEditor(String propertyName, Class requiredType) {
|
||||
CustomEditorHolder holder = (CustomEditorHolder) this.customEditors.get(propertyName);
|
||||
CustomEditorHolder holder = this.customEditorsForPath.get(propertyName);
|
||||
return (holder != null ? holder.getPropertyEditor(requiredType) : null);
|
||||
}
|
||||
|
||||
@@ -371,26 +362,26 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* @see java.beans.PropertyEditor#getAsText()
|
||||
*/
|
||||
private PropertyEditor getCustomEditor(Class requiredType) {
|
||||
if (requiredType == null) {
|
||||
if (requiredType == null || this.customEditors == null) {
|
||||
return null;
|
||||
}
|
||||
// Check directly registered editor for type.
|
||||
PropertyEditor editor = (PropertyEditor) this.customEditors.get(requiredType);
|
||||
PropertyEditor editor = this.customEditors.get(requiredType);
|
||||
if (editor == null) {
|
||||
// Check cached editor for type, registered for superclass or interface.
|
||||
if (this.customEditorCache != null) {
|
||||
editor = (PropertyEditor) this.customEditorCache.get(requiredType);
|
||||
editor = this.customEditorCache.get(requiredType);
|
||||
}
|
||||
if (editor == null) {
|
||||
// Find editor for superclass or interface.
|
||||
for (Iterator it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) {
|
||||
Object key = it.next();
|
||||
if (key instanceof Class && ((Class) key).isAssignableFrom(requiredType)) {
|
||||
editor = (PropertyEditor) this.customEditors.get(key);
|
||||
for (Iterator<Class> it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) {
|
||||
Class key = it.next();
|
||||
if (key.isAssignableFrom(requiredType)) {
|
||||
editor = this.customEditors.get(key);
|
||||
// Cache editor for search type, to avoid the overhead
|
||||
// of repeated assignable-from checks.
|
||||
if (this.customEditorCache == null) {
|
||||
this.customEditorCache = new HashMap();
|
||||
this.customEditorCache = new HashMap<Class, PropertyEditor>();
|
||||
}
|
||||
this.customEditorCache.put(requiredType, editor);
|
||||
}
|
||||
@@ -407,14 +398,14 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* @return the property type, or <code>null</code> if not determinable
|
||||
*/
|
||||
protected Class guessPropertyTypeFromEditors(String propertyName) {
|
||||
if (this.customEditors != null) {
|
||||
CustomEditorHolder editorHolder = (CustomEditorHolder) this.customEditors.get(propertyName);
|
||||
if (this.customEditorsForPath != null) {
|
||||
CustomEditorHolder editorHolder = this.customEditorsForPath.get(propertyName);
|
||||
if (editorHolder == null) {
|
||||
List strippedPaths = new LinkedList();
|
||||
List<String> strippedPaths = new LinkedList<String>();
|
||||
addStrippedPropertyPaths(strippedPaths, "", propertyName);
|
||||
for (Iterator it = strippedPaths.iterator(); it.hasNext() && editorHolder == null;) {
|
||||
String strippedName = (String) it.next();
|
||||
editorHolder = (CustomEditorHolder) this.customEditors.get(strippedName);
|
||||
for (Iterator<String> it = strippedPaths.iterator(); it.hasNext() && editorHolder == null;) {
|
||||
String strippedName = it.next();
|
||||
editorHolder = this.customEditorsForPath.get(strippedName);
|
||||
}
|
||||
}
|
||||
if (editorHolder != null) {
|
||||
@@ -435,31 +426,28 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
String actualPropertyName =
|
||||
(nestedProperty != null ? PropertyAccessorUtils.getPropertyName(nestedProperty) : null);
|
||||
if (this.customEditors != null) {
|
||||
for (Iterator it = this.customEditors.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
if (entry.getKey() instanceof Class) {
|
||||
Class requiredType = (Class) entry.getKey();
|
||||
PropertyEditor editor = (PropertyEditor) entry.getValue();
|
||||
target.registerCustomEditor(requiredType, editor);
|
||||
}
|
||||
else if (entry.getKey() instanceof String) {
|
||||
String editorPath = (String) entry.getKey();
|
||||
CustomEditorHolder editorHolder = (CustomEditorHolder) entry.getValue();
|
||||
if (nestedProperty != null) {
|
||||
int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(editorPath);
|
||||
if (pos != -1) {
|
||||
String editorNestedProperty = editorPath.substring(0, pos);
|
||||
String editorNestedPath = editorPath.substring(pos + 1);
|
||||
if (editorNestedProperty.equals(nestedProperty) || editorNestedProperty.equals(actualPropertyName)) {
|
||||
target.registerCustomEditor(
|
||||
editorHolder.getRegisteredType(), editorNestedPath, editorHolder.getPropertyEditor());
|
||||
}
|
||||
for (Map.Entry<Class, PropertyEditor> entry : this.customEditors.entrySet()) {
|
||||
target.registerCustomEditor(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
if (this.customEditorsForPath != null) {
|
||||
for (Map.Entry<String, CustomEditorHolder> entry : this.customEditorsForPath.entrySet()) {
|
||||
String editorPath = entry.getKey();
|
||||
CustomEditorHolder editorHolder = entry.getValue();
|
||||
if (nestedProperty != null) {
|
||||
int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(editorPath);
|
||||
if (pos != -1) {
|
||||
String editorNestedProperty = editorPath.substring(0, pos);
|
||||
String editorNestedPath = editorPath.substring(pos + 1);
|
||||
if (editorNestedProperty.equals(nestedProperty) || editorNestedProperty.equals(actualPropertyName)) {
|
||||
target.registerCustomEditor(
|
||||
editorHolder.getRegisteredType(), editorNestedPath, editorHolder.getPropertyEditor());
|
||||
}
|
||||
}
|
||||
else {
|
||||
target.registerCustomEditor(
|
||||
editorHolder.getRegisteredType(), editorPath, editorHolder.getPropertyEditor());
|
||||
}
|
||||
}
|
||||
else {
|
||||
target.registerCustomEditor(
|
||||
editorHolder.getRegisteredType(), editorPath, editorHolder.getPropertyEditor());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -473,7 +461,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||
* @param nestedPath the current nested path
|
||||
* @param propertyPath the property path to check for keys/indexes to strip
|
||||
*/
|
||||
private void addStrippedPropertyPaths(List strippedPaths, String nestedPath, String propertyPath) {
|
||||
private void addStrippedPropertyPaths(List<String> strippedPaths, String nestedPath, String propertyPath) {
|
||||
int startIndex = propertyPath.indexOf(PropertyAccessor.PROPERTY_KEY_PREFIX_CHAR);
|
||||
if (startIndex != -1) {
|
||||
int endIndex = propertyPath.indexOf(PropertyAccessor.PROPERTY_KEY_SUFFIX_CHAR);
|
||||
|
||||
@@ -214,10 +214,11 @@ class TypeConverterDelegate {
|
||||
msg.append("Cannot convert value of type [").append(ClassUtils.getDescriptiveType(newValue));
|
||||
msg.append("] to required type [").append(ClassUtils.getQualifiedName(requiredType)).append("]");
|
||||
if (propertyName != null) {
|
||||
msg.append(" for property '" + propertyName + "'");
|
||||
msg.append(" for property '").append(propertyName).append("'");
|
||||
}
|
||||
if (editor != null) {
|
||||
msg.append(": PropertyEditor [" + editor.getClass().getName() + "] returned inappropriate value");
|
||||
msg.append(": PropertyEditor [").append(editor.getClass().getName()).append(
|
||||
"] returned inappropriate value");
|
||||
}
|
||||
else {
|
||||
msg.append(": no matching editors or conversion strategy found");
|
||||
@@ -242,7 +243,7 @@ class TypeConverterDelegate {
|
||||
}
|
||||
if (editor == null && requiredType != null) {
|
||||
// No custom editor -> check BeanWrapperImpl's default editors.
|
||||
editor = (PropertyEditor) this.propertyEditorRegistry.getDefaultEditor(requiredType);
|
||||
editor = this.propertyEditorRegistry.getDefaultEditor(requiredType);
|
||||
if (editor == null && !String.class.equals(requiredType)) {
|
||||
// No BeanWrapper default editor -> check standard JavaBean editor.
|
||||
editor = BeanUtils.findEditorByConvention(requiredType);
|
||||
@@ -394,6 +395,7 @@ class TypeConverterDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Collection convertToTypedCollection(
|
||||
Collection original, String propertyName, MethodParameter methodParam) {
|
||||
|
||||
@@ -445,6 +447,7 @@ class TypeConverterDelegate {
|
||||
return (actuallyConverted ? convertedCopy : original);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map convertToTypedMap(Map original, String propertyName, MethodParameter methodParam) {
|
||||
Class keyType = null;
|
||||
Class valueType = null;
|
||||
@@ -466,6 +469,7 @@ class TypeConverterDelegate {
|
||||
logger.debug("Map of type [" + original.getClass().getName() +
|
||||
"] returned null Iterator - injecting original Map as-is");
|
||||
}
|
||||
return original;
|
||||
}
|
||||
convertedCopy = CollectionFactory.createApproximateMap(original, original.size());
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public abstract class BeanFactoryUtils {
|
||||
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
|
||||
*/
|
||||
public static boolean isGeneratedBeanName(String name) {
|
||||
return (name != null && name.indexOf(GENERATED_BEAN_NAME_SEPARATOR) != -1);
|
||||
return (name != null && name.contains(GENERATED_BEAN_NAME_SEPARATOR));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,10 +298,10 @@ public abstract class BeanFactoryUtils {
|
||||
* if 0 or more than 1 beans of the given type were found
|
||||
* @throws BeansException if the bean could not be created
|
||||
*/
|
||||
public static Object beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class type)
|
||||
public static <T> T beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type)
|
||||
throws BeansException {
|
||||
|
||||
Map beansOfType = beansOfTypeIncludingAncestors(lbf, type);
|
||||
Map<String, T> beansOfType = beansOfTypeIncludingAncestors(lbf, type);
|
||||
if (beansOfType.size() == 1) {
|
||||
return beansOfType.values().iterator().next();
|
||||
}
|
||||
@@ -335,11 +335,11 @@ public abstract class BeanFactoryUtils {
|
||||
* if 0 or more than 1 beans of the given type were found
|
||||
* @throws BeansException if the bean could not be created
|
||||
*/
|
||||
public static Object beanOfTypeIncludingAncestors(
|
||||
ListableBeanFactory lbf, Class type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
throws BeansException {
|
||||
public static <T> T beanOfTypeIncludingAncestors(
|
||||
ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
throws BeansException {
|
||||
|
||||
Map beansOfType = beansOfTypeIncludingAncestors(lbf, type, includeNonSingletons, allowEagerInit);
|
||||
Map<String, T> beansOfType = beansOfTypeIncludingAncestors(lbf, type, includeNonSingletons, allowEagerInit);
|
||||
if (beansOfType.size() == 1) {
|
||||
return beansOfType.values().iterator().next();
|
||||
}
|
||||
@@ -364,9 +364,9 @@ public abstract class BeanFactoryUtils {
|
||||
* if 0 or more than 1 beans of the given type were found
|
||||
* @throws BeansException if the bean could not be created
|
||||
*/
|
||||
public static Object beanOfType(ListableBeanFactory lbf, Class type) throws BeansException {
|
||||
public static <T> T beanOfType(ListableBeanFactory lbf, Class<T> type) throws BeansException {
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
Map beansOfType = lbf.getBeansOfType(type);
|
||||
Map<String, T> beansOfType = lbf.getBeansOfType(type);
|
||||
if (beansOfType.size() == 1) {
|
||||
return beansOfType.values().iterator().next();
|
||||
}
|
||||
@@ -399,12 +399,12 @@ public abstract class BeanFactoryUtils {
|
||||
* if 0 or more than 1 beans of the given type were found
|
||||
* @throws BeansException if the bean could not be created
|
||||
*/
|
||||
public static Object beanOfType(
|
||||
ListableBeanFactory lbf, Class type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
throws BeansException {
|
||||
public static <T> T beanOfType(
|
||||
ListableBeanFactory lbf, Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
throws BeansException {
|
||||
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
Map beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit);
|
||||
Map<String, T> beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit);
|
||||
if (beansOfType.size() == 1) {
|
||||
return beansOfType.values().iterator().next();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -137,8 +136,7 @@ public class BeanDefinitionVisitor {
|
||||
|
||||
protected void visitPropertyValues(MutablePropertyValues pvs) {
|
||||
PropertyValue[] pvArray = pvs.getPropertyValues();
|
||||
for (int i = 0; i < pvArray.length; i++) {
|
||||
PropertyValue pv = pvArray[i];
|
||||
for (PropertyValue pv : pvArray) {
|
||||
Object newVal = resolveValue(pv.getValue());
|
||||
if (!ObjectUtils.nullSafeEquals(newVal, pv.getValue())) {
|
||||
pvs.addPropertyValue(pv.getName(), newVal);
|
||||
@@ -146,10 +144,8 @@ public class BeanDefinitionVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitIndexedArgumentValues(Map ias) {
|
||||
for (Iterator it = ias.values().iterator(); it.hasNext();) {
|
||||
ConstructorArgumentValues.ValueHolder valueHolder =
|
||||
(ConstructorArgumentValues.ValueHolder) it.next();
|
||||
protected void visitIndexedArgumentValues(Map<Integer, ConstructorArgumentValues.ValueHolder> ias) {
|
||||
for (ConstructorArgumentValues.ValueHolder valueHolder : ias.values()) {
|
||||
Object newVal = resolveValue(valueHolder.getValue());
|
||||
if (!ObjectUtils.nullSafeEquals(newVal, valueHolder.getValue())) {
|
||||
valueHolder.setValue(newVal);
|
||||
@@ -157,10 +153,8 @@ public class BeanDefinitionVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitGenericArgumentValues(List gas) {
|
||||
for (Iterator it = gas.iterator(); it.hasNext();) {
|
||||
ConstructorArgumentValues.ValueHolder valueHolder =
|
||||
(ConstructorArgumentValues.ValueHolder) it.next();
|
||||
protected void visitGenericArgumentValues(List<ConstructorArgumentValues.ValueHolder> gas) {
|
||||
for (ConstructorArgumentValues.ValueHolder valueHolder : gas) {
|
||||
Object newVal = resolveValue(valueHolder.getValue());
|
||||
if (!ObjectUtils.nullSafeEquals(newVal, valueHolder.getValue())) {
|
||||
valueHolder.setValue(newVal);
|
||||
@@ -212,6 +206,7 @@ public class BeanDefinitionVisitor {
|
||||
return value;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void visitList(List listVal) {
|
||||
for (int i = 0; i < listVal.size(); i++) {
|
||||
Object elem = listVal.get(i);
|
||||
@@ -222,11 +217,11 @@ public class BeanDefinitionVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void visitSet(Set setVal) {
|
||||
Set newContent = new LinkedHashSet();
|
||||
boolean entriesModified = false;
|
||||
for (Iterator it = setVal.iterator(); it.hasNext();) {
|
||||
Object elem = it.next();
|
||||
for (Object elem : setVal) {
|
||||
int elemHash = (elem != null ? elem.hashCode() : 0);
|
||||
Object newVal = resolveValue(elem);
|
||||
int newValHash = (newVal != null ? newVal.hashCode() : 0);
|
||||
@@ -239,11 +234,11 @@ public class BeanDefinitionVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
protected void visitMap(Map mapVal) {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void visitMap(Map<?, ?> mapVal) {
|
||||
Map newContent = new LinkedHashMap();
|
||||
boolean entriesModified = false;
|
||||
for (Iterator it = mapVal.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
for (Map.Entry entry : mapVal.entrySet()) {
|
||||
Object key = entry.getKey();
|
||||
int keyHash = (key != null ? key.hashCode() : 0);
|
||||
Object newKey = resolveValue(key);
|
||||
|
||||
@@ -322,11 +322,11 @@ public class ConstructorArgumentValues {
|
||||
this.indexedArgumentValues.size() != that.indexedArgumentValues.size()) {
|
||||
return false;
|
||||
}
|
||||
Iterator it1 = this.genericArgumentValues.iterator();
|
||||
Iterator it2 = that.genericArgumentValues.iterator();
|
||||
Iterator<ValueHolder> it1 = this.genericArgumentValues.iterator();
|
||||
Iterator<ValueHolder> it2 = that.genericArgumentValues.iterator();
|
||||
while (it1.hasNext() && it2.hasNext()) {
|
||||
ValueHolder vh1 = (ValueHolder) it1.next();
|
||||
ValueHolder vh2 = (ValueHolder) it2.next();
|
||||
ValueHolder vh1 = it1.next();
|
||||
ValueHolder vh2 = it2.next();
|
||||
if (!vh1.contentEquals(vh2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -45,7 +44,7 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClassLoaderAware, Ordered {
|
||||
|
||||
private Map scopes;
|
||||
private Map<String, Object> scopes;
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
@@ -58,7 +57,7 @@ public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClas
|
||||
* is expected to be the corresponding custom {@link Scope} instance
|
||||
* or class name.
|
||||
*/
|
||||
public void setScopes(Map scopes) {
|
||||
public void setScopes(Map<String, Object> scopes) {
|
||||
this.scopes = scopes;
|
||||
}
|
||||
|
||||
@@ -77,31 +76,25 @@ public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClas
|
||||
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
if (this.scopes != null) {
|
||||
for (Iterator it = this.scopes.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Object key = entry.getKey();
|
||||
if (!(key instanceof String)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid scope key [" + key + "]: only Strings allowed");
|
||||
}
|
||||
String scopeName = (String) key;
|
||||
for (Map.Entry<String, Object> entry : this.scopes.entrySet()) {
|
||||
String scopeKey = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
if (value instanceof Scope) {
|
||||
beanFactory.registerScope(scopeName, (Scope) value);
|
||||
beanFactory.registerScope(scopeKey, (Scope) value);
|
||||
}
|
||||
else if (value instanceof Class) {
|
||||
Class scopeClass = (Class) value;
|
||||
Assert.isAssignable(Scope.class, scopeClass);
|
||||
beanFactory.registerScope(scopeName, (Scope) BeanUtils.instantiateClass(scopeClass));
|
||||
beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
Class scopeClass = ClassUtils.resolveClassName((String) value, this.beanClassLoader);
|
||||
Assert.isAssignable(Scope.class, scopeClass);
|
||||
beanFactory.registerScope(scopeName, (Scope) BeanUtils.instantiateClass(scopeClass));
|
||||
beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Mapped value [" + value + "] for scope key [" +
|
||||
key + "] is not an instance of required type [" + Scope.class.getName() +
|
||||
scopeKey + "] is not an instance of required type [" + Scope.class.getName() +
|
||||
"] or a corresponding Class or String value indicating a Scope implementation");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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.
|
||||
@@ -17,13 +17,11 @@
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.TypeConverter;
|
||||
import org.springframework.core.GenericCollectionTypeResolver;
|
||||
import org.springframework.core.JdkVersion;
|
||||
|
||||
/**
|
||||
* Simple factory for shared List instances. Allows for central setup
|
||||
@@ -71,6 +69,7 @@ public class ListFactoryBean extends AbstractFactoryBean {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object createInstance() {
|
||||
if (this.sourceList == null) {
|
||||
throw new IllegalArgumentException("'sourceList' is required");
|
||||
@@ -88,8 +87,8 @@ public class ListFactoryBean extends AbstractFactoryBean {
|
||||
}
|
||||
if (valueType != null) {
|
||||
TypeConverter converter = getBeanTypeConverter();
|
||||
for (Iterator it = this.sourceList.iterator(); it.hasNext();) {
|
||||
result.add(converter.convertIfNecessary(it.next(), valueType));
|
||||
for (Object elem : this.sourceList) {
|
||||
result.add(converter.convertIfNecessary(elem, valueType));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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,14 +16,12 @@
|
||||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.TypeConverter;
|
||||
import org.springframework.core.GenericCollectionTypeResolver;
|
||||
import org.springframework.core.JdkVersion;
|
||||
|
||||
/**
|
||||
* Simple factory for shared Map instances. Allows for central setup
|
||||
@@ -36,7 +34,7 @@ import org.springframework.core.JdkVersion;
|
||||
*/
|
||||
public class MapFactoryBean extends AbstractFactoryBean {
|
||||
|
||||
private Map sourceMap;
|
||||
private Map<?, ?> sourceMap;
|
||||
|
||||
private Class targetMapClass;
|
||||
|
||||
@@ -71,6 +69,7 @@ public class MapFactoryBean extends AbstractFactoryBean {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object createInstance() {
|
||||
if (this.sourceMap == null) {
|
||||
throw new IllegalArgumentException("'sourceMap' is required");
|
||||
@@ -90,8 +89,7 @@ public class MapFactoryBean extends AbstractFactoryBean {
|
||||
}
|
||||
if (keyType != null || valueType != null) {
|
||||
TypeConverter converter = getBeanTypeConverter();
|
||||
for (Iterator it = this.sourceMap.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
for (Map.Entry entry : this.sourceMap.entrySet()) {
|
||||
Object convertedKey = converter.convertIfNecessary(entry.getKey(), keyType);
|
||||
Object convertedValue = converter.convertIfNecessary(entry.getValue(), valueType);
|
||||
result.put(convertedKey, convertedValue);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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,7 +16,6 @@
|
||||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -70,6 +69,7 @@ public class SetFactoryBean extends AbstractFactoryBean {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object createInstance() {
|
||||
if (this.sourceSet == null) {
|
||||
throw new IllegalArgumentException("'sourceSet' is required");
|
||||
@@ -87,8 +87,8 @@ public class SetFactoryBean extends AbstractFactoryBean {
|
||||
}
|
||||
if (valueType != null) {
|
||||
TypeConverter converter = getBeanTypeConverter();
|
||||
for (Iterator it = this.sourceSet.iterator(); it.hasNext();) {
|
||||
result.add(converter.convertIfNecessary(it.next(), valueType));
|
||||
for (Object elem : this.sourceSet) {
|
||||
result.add(converter.convertIfNecessary(elem, valueType));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1124,8 +1124,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
if (filtered == null) {
|
||||
List<PropertyDescriptor> pds =
|
||||
new LinkedList<PropertyDescriptor>(Arrays.asList(bw.getPropertyDescriptors()));
|
||||
for (Iterator it = pds.iterator(); it.hasNext();) {
|
||||
PropertyDescriptor pd = (PropertyDescriptor) it.next();
|
||||
for (Iterator<PropertyDescriptor> it = pds.iterator(); it.hasNext();) {
|
||||
PropertyDescriptor pd = it.next();
|
||||
if (isExcludedFromDependencyCheck(pd)) {
|
||||
it.remove();
|
||||
}
|
||||
|
||||
@@ -500,9 +500,9 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
||||
|
||||
// Remove destroyed bean from other beans' dependencies.
|
||||
synchronized (this.dependentBeanMap) {
|
||||
for (Iterator it = this.dependentBeanMap.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Set dependenciesToClean = (Set) entry.getValue();
|
||||
for (Iterator<Map.Entry<String, Set<String>>> it = this.dependentBeanMap.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<String, Set<String>> entry = it.next();
|
||||
Set<String> dependenciesToClean = entry.getValue();
|
||||
dependenciesToClean.remove(beanName);
|
||||
if (dependenciesToClean.isEmpty()) {
|
||||
it.remove();
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -28,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -62,7 +62,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
|
||||
private final boolean enforceDestroyMethod;
|
||||
|
||||
private List beanPostProcessors;
|
||||
private List<DestructionAwareBeanPostProcessor> beanPostProcessors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -73,8 +73,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
* @param postProcessors the List of BeanPostProcessors
|
||||
* (potentially DestructionAwareBeanPostProcessor), if any
|
||||
*/
|
||||
public DisposableBeanAdapter(
|
||||
Object bean, String beanName, RootBeanDefinition beanDefinition, List postProcessors) {
|
||||
public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition beanDefinition,
|
||||
List<BeanPostProcessor> postProcessors) {
|
||||
|
||||
Assert.notNull(bean, "Bean must not be null");
|
||||
this.bean = bean;
|
||||
@@ -100,7 +100,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
* @param postProcessors the List of DestructionAwareBeanPostProcessors, if any
|
||||
*/
|
||||
private DisposableBeanAdapter(Object bean, String beanName, boolean invokeDisposableBean,
|
||||
String destroyMethodName, boolean enforceDestroyMethod, List postProcessors) {
|
||||
String destroyMethodName, boolean enforceDestroyMethod,
|
||||
List<DestructionAwareBeanPostProcessor> postProcessors) {
|
||||
|
||||
this.bean = bean;
|
||||
this.beanName = beanName;
|
||||
@@ -110,19 +111,19 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
this.beanPostProcessors = postProcessors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Search for all DestructionAwareBeanPostProcessors in the List.
|
||||
* @param postProcessors the List to search
|
||||
* @return the filtered List of DestructionAwareBeanPostProcessors
|
||||
*/
|
||||
private List filterPostProcessors(List postProcessors) {
|
||||
List filteredPostProcessors = null;
|
||||
private List<DestructionAwareBeanPostProcessor> filterPostProcessors(List<BeanPostProcessor> postProcessors) {
|
||||
List<DestructionAwareBeanPostProcessor> filteredPostProcessors = null;
|
||||
if (postProcessors != null && !postProcessors.isEmpty()) {
|
||||
filteredPostProcessors = new ArrayList(postProcessors.size());
|
||||
for (Iterator it = postProcessors.iterator(); it.hasNext();) {
|
||||
Object postProcessor = it.next();
|
||||
filteredPostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>(postProcessors.size());
|
||||
for (BeanPostProcessor postProcessor : postProcessors) {
|
||||
if (postProcessor instanceof DestructionAwareBeanPostProcessor) {
|
||||
filteredPostProcessors.add(postProcessor);
|
||||
filteredPostProcessors.add((DestructionAwareBeanPostProcessor) postProcessor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,8 +138,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
public void destroy() {
|
||||
if (this.beanPostProcessors != null && !this.beanPostProcessors.isEmpty()) {
|
||||
for (int i = this.beanPostProcessors.size() - 1; i >= 0; i--) {
|
||||
((DestructionAwareBeanPostProcessor) this.beanPostProcessors.get(i)).postProcessBeforeDestruction(
|
||||
this.bean, this.beanName);
|
||||
this.beanPostProcessors.get(i).postProcessBeforeDestruction(this.bean, this.beanName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,11 +237,10 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
* filtering out non-serializable BeanPostProcessors.
|
||||
*/
|
||||
protected Object writeReplace() {
|
||||
List serializablePostProcessors = null;
|
||||
List<DestructionAwareBeanPostProcessor> serializablePostProcessors = null;
|
||||
if (this.beanPostProcessors != null) {
|
||||
serializablePostProcessors = new ArrayList();
|
||||
for (Iterator it = this.beanPostProcessors.iterator(); it.hasNext();) {
|
||||
Object postProcessor = it.next();
|
||||
serializablePostProcessors = new ArrayList<DestructionAwareBeanPostProcessor>();
|
||||
for (DestructionAwareBeanPostProcessor postProcessor : this.beanPostProcessors) {
|
||||
if (postProcessor instanceof Serializable) {
|
||||
serializablePostProcessors.add(postProcessor);
|
||||
}
|
||||
|
||||
@@ -18,10 +18,8 @@ package org.springframework.beans.factory.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
@@ -56,7 +54,7 @@ import org.springframework.util.StringUtils;
|
||||
public class StaticListableBeanFactory implements ListableBeanFactory {
|
||||
|
||||
/** Map from bean name to bean instance */
|
||||
private final Map beans = new HashMap();
|
||||
private final Map<String, Object> beans = new HashMap<String, Object>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -99,13 +97,13 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object getBean(String name, Class requiredType) throws BeansException {
|
||||
|
||||
public <T> T getBean(String name, Class<T> requiredType) throws BeansException {
|
||||
Object bean = getBean(name);
|
||||
if (requiredType != null && !requiredType.isAssignableFrom(bean.getClass())) {
|
||||
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
|
||||
}
|
||||
return bean;
|
||||
return (T) bean;
|
||||
}
|
||||
|
||||
public Object getBean(String name, Object[] args) throws BeansException {
|
||||
@@ -181,22 +179,19 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
|
||||
|
||||
public String[] getBeanNamesForType(Class type, boolean includeNonSingletons, boolean includeFactoryBeans) {
|
||||
boolean isFactoryType = (type != null && FactoryBean.class.isAssignableFrom(type));
|
||||
List matches = new ArrayList();
|
||||
Set keys = this.beans.keySet();
|
||||
Iterator it = keys.iterator();
|
||||
while (it.hasNext()) {
|
||||
String name = (String) it.next();
|
||||
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.isAssignableFrom(objectType)) {
|
||||
if (objectType != null && (type == null || type.isAssignableFrom(objectType))) {
|
||||
matches.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (type.isInstance(beanInstance)) {
|
||||
if (type == null || type.isInstance(beanInstance)) {
|
||||
matches.add(name);
|
||||
}
|
||||
}
|
||||
@@ -204,22 +199,19 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
|
||||
return StringUtils.toStringArray(matches);
|
||||
}
|
||||
|
||||
public Map getBeansOfType(Class type) throws BeansException {
|
||||
public <T> Map<String, T> getBeansOfType(Class<T> type) throws BeansException {
|
||||
return getBeansOfType(type, true, true);
|
||||
}
|
||||
|
||||
public Map getBeansOfType(Class type, boolean includeNonSingletons, boolean includeFactoryBeans)
|
||||
public <T> Map<String, T> getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean includeFactoryBeans)
|
||||
throws BeansException {
|
||||
|
||||
boolean isFactoryType = (type != null && FactoryBean.class.isAssignableFrom(type));
|
||||
Map matches = new HashMap();
|
||||
Map<String, T> matches = new HashMap<String, T>();
|
||||
|
||||
Iterator it = this.beans.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
String beanName = (String) entry.getKey();
|
||||
for (Map.Entry<String, Object> entry : beans.entrySet()) {
|
||||
String beanName = entry.getKey();
|
||||
Object beanInstance = entry.getValue();
|
||||
|
||||
// Is bean a FactoryBean?
|
||||
if (beanInstance instanceof FactoryBean && !isFactoryType) {
|
||||
if (includeFactoryBeans) {
|
||||
@@ -227,19 +219,19 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
|
||||
FactoryBean factory = (FactoryBean) beanInstance;
|
||||
Class objectType = factory.getObjectType();
|
||||
if ((includeNonSingletons || factory.isSingleton()) &&
|
||||
objectType != null && type.isAssignableFrom(objectType)) {
|
||||
matches.put(beanName, getBean(beanName));
|
||||
objectType != null && (type == null || type.isAssignableFrom(objectType))) {
|
||||
matches.put(beanName, getBean(beanName, type));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (type.isInstance(beanInstance)) {
|
||||
if (type == null || type.isInstance(beanInstance)) {
|
||||
// If type to match is FactoryBean, return FactoryBean itself.
|
||||
// Else, return bean instance.
|
||||
if (isFactoryType) {
|
||||
beanName = FACTORY_BEAN_PREFIX + beanName;
|
||||
}
|
||||
matches.put(beanName, beanInstance);
|
||||
matches.put(beanName, (T) beanInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.beans.factory.xml;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -737,9 +736,8 @@ public class BeanDefinitionParserDelegate {
|
||||
String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE);
|
||||
ReplaceOverride replaceOverride = new ReplaceOverride(name, callback);
|
||||
// Look for arg-type match elements.
|
||||
List argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT);
|
||||
for (Iterator it = argTypeEles.iterator(); it.hasNext();) {
|
||||
Element argTypeEle = (Element) it.next();
|
||||
List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT);
|
||||
for (Element argTypeEle : argTypeEles) {
|
||||
replaceOverride.addTypeIdentifier(argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE));
|
||||
}
|
||||
replaceOverride.setSource(extractSource(replacedMethodEle));
|
||||
@@ -1109,17 +1107,15 @@ public class BeanDefinitionParserDelegate {
|
||||
String defaultKeyTypeClassName = mapEle.getAttribute(KEY_TYPE_ATTRIBUTE);
|
||||
String defaultValueTypeClassName = mapEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
|
||||
|
||||
List entryEles = DomUtils.getChildElementsByTagName(mapEle, ENTRY_ELEMENT);
|
||||
List<Element> entryEles = DomUtils.getChildElementsByTagName(mapEle, ENTRY_ELEMENT);
|
||||
ManagedMap map = new ManagedMap(entryEles.size());
|
||||
map.setMergeEnabled(parseMergeAttribute(mapEle));
|
||||
map.setSource(extractSource(mapEle));
|
||||
|
||||
for (Iterator it = entryEles.iterator(); it.hasNext();) {
|
||||
Element entryEle = (Element) it.next();
|
||||
for (Element entryEle : entryEles) {
|
||||
// Should only have one value child element: ref, value, list, etc.
|
||||
// Optionally, there might be a key child element.
|
||||
NodeList entrySubNodes = entryEle.getChildNodes();
|
||||
|
||||
Element keyEle = null;
|
||||
Element valueEle = null;
|
||||
for (int j = 0; j < entrySubNodes.getLength(); j++) {
|
||||
@@ -1254,14 +1250,12 @@ public class BeanDefinitionParserDelegate {
|
||||
props.setSource(extractSource(propsEle));
|
||||
props.setMergeEnabled(parseMergeAttribute(propsEle));
|
||||
|
||||
List propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT);
|
||||
for (Iterator it = propEles.iterator(); it.hasNext();) {
|
||||
Element propEle = (Element) it.next();
|
||||
List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT);
|
||||
for (Element propEle : propEles) {
|
||||
String key = propEle.getAttribute(KEY_ATTRIBUTE);
|
||||
// Trim the text value to avoid unwanted whitespace
|
||||
// caused by typical XML formatting.
|
||||
String value = DomUtils.getTextValue(propEle).trim();
|
||||
|
||||
TypedStringValue keyHolder = new TypedStringValue(key);
|
||||
keyHolder.setSource(extractSource(propEle));
|
||||
TypedStringValue valueHolder = new TypedStringValue(value);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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.
|
||||
@@ -117,8 +117,8 @@ public class CustomCollectionEditor extends PropertyEditorSupport {
|
||||
// Convert Collection elements.
|
||||
Collection source = (Collection) value;
|
||||
Collection target = createCollection(this.collectionType, source.size());
|
||||
for (Iterator it = source.iterator(); it.hasNext();) {
|
||||
target.add(convertElement(it.next()));
|
||||
for (Object elem : source) {
|
||||
target.add(convertElement(elem));
|
||||
}
|
||||
super.setValue(target);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 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.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.beans.propertyeditors;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
@@ -105,10 +104,9 @@ public class CustomMapEditor extends PropertyEditorSupport {
|
||||
}
|
||||
else if (value instanceof Map) {
|
||||
// Convert Map elements.
|
||||
Map source = (Map) value;
|
||||
Map<?, ?> source = (Map) value;
|
||||
Map target = createMap(this.mapType, source.size());
|
||||
for (Iterator it = source.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
for (Map.Entry entry : source.entrySet()) {
|
||||
target.put(convertKey(entry.getKey()), convertValue(entry.getValue()));
|
||||
}
|
||||
super.setValue(target);
|
||||
|
||||
Reference in New Issue
Block a user