Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -169,7 +169,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the converted value of the constructor argument,
|
||||
* Set the converted value of this property value,
|
||||
* after processed type conversion.
|
||||
*/
|
||||
public synchronized void setConvertedValue(@Nullable Object value) {
|
||||
@@ -178,7 +178,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the converted value of the constructor argument,
|
||||
* Return the converted value of this property value,
|
||||
* after processed type conversion.
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
@@ -180,7 +180,7 @@ public class InjectionPoint {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (getClass() != other.getClass()) {
|
||||
if (other == null || getClass() != other.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InjectionPoint otherPoint = (InjectionPoint) other;
|
||||
|
||||
@@ -234,7 +234,7 @@ public class BeanDefinitionVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
protected void visitList(List listVal) {
|
||||
for (int i = 0; i < listVal.size(); i++) {
|
||||
Object elem = listVal.get(i);
|
||||
@@ -245,7 +245,7 @@ public class BeanDefinitionVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
protected void visitSet(Set setVal) {
|
||||
Set newContent = new LinkedHashSet();
|
||||
boolean entriesModified = false;
|
||||
@@ -262,7 +262,7 @@ public class BeanDefinitionVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
protected void visitMap(Map<?, ?> mapVal) {
|
||||
Map newContent = new LinkedHashMap();
|
||||
boolean entriesModified = false;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -26,7 +26,7 @@ import org.springframework.util.Assert;
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @see BeanDefinition#getPropertyValues()
|
||||
* @see org.springframework.beans.factory.BeanFactory#getBean
|
||||
* @see org.springframework.beans.factory.BeanFactory#getBean(String)
|
||||
*/
|
||||
public class RuntimeBeanReference implements BeanReference {
|
||||
|
||||
@@ -39,9 +39,7 @@ public class RuntimeBeanReference implements BeanReference {
|
||||
|
||||
|
||||
/**
|
||||
* Create a new RuntimeBeanReference to the given bean name,
|
||||
* without explicitly marking it as reference to a bean in
|
||||
* the parent factory.
|
||||
* Create a new RuntimeBeanReference to the given bean name.
|
||||
* @param beanName name of the target bean
|
||||
*/
|
||||
public RuntimeBeanReference(String beanName) {
|
||||
@@ -50,11 +48,10 @@ public class RuntimeBeanReference implements BeanReference {
|
||||
|
||||
/**
|
||||
* Create a new RuntimeBeanReference to the given bean name,
|
||||
* with the option to mark it as reference to a bean in
|
||||
* the parent factory.
|
||||
* with the option to mark it as reference to a bean in the parent factory.
|
||||
* @param beanName name of the target bean
|
||||
* @param toParent whether this is an explicit reference to
|
||||
* a bean in the parent factory
|
||||
* @param toParent whether this is an explicit reference to a bean in the
|
||||
* parent factory
|
||||
*/
|
||||
public RuntimeBeanReference(String beanName, boolean toParent) {
|
||||
Assert.hasText(beanName, "'beanName' must not be empty");
|
||||
@@ -69,8 +66,7 @@ public class RuntimeBeanReference implements BeanReference {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this is an explicit reference to a bean
|
||||
* in the parent factory.
|
||||
* Return whether this is an explicit reference to a bean in the parent factory.
|
||||
*/
|
||||
public boolean isToParent() {
|
||||
return this.toParent;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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,7 +117,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean<Map
|
||||
* case of a shared singleton; else, on each {@link #getObject()} call.
|
||||
* <p>The default implementation returns the merged {@code Map} instance.
|
||||
* @return the object returned by this factory
|
||||
* @see #process(java.util.Map, MatchCallback)
|
||||
* @see #process(MatchCallback)
|
||||
*/
|
||||
protected Map<String, Object> createMap() {
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
@@ -125,7 +125,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean<Map
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
private void merge(Map<String, Object> output, Map<String, Object> map) {
|
||||
map.forEach((key, value) -> {
|
||||
Object existing = output.get(key);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -128,7 +128,7 @@ public class YamlPropertiesFactoryBean extends YamlProcessor implements FactoryB
|
||||
* <p>Invoked lazily the first time {@link #getObject()} is invoked in
|
||||
* case of a shared singleton; else, on each {@link #getObject()} call.
|
||||
* @return the object returned by this factory
|
||||
* @see #process(MatchCallback) ()
|
||||
* @see #process(MatchCallback)
|
||||
*/
|
||||
protected Properties createProperties() {
|
||||
Properties result = CollectionFactory.createStringAdaptingProperties();
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
public static final String SCOPE_DEFAULT = "";
|
||||
|
||||
/**
|
||||
* Constant that indicates no autowiring at all.
|
||||
* Constant that indicates no external autowiring at all.
|
||||
* @see #setAutowireMode
|
||||
*/
|
||||
public static final int AUTOWIRE_NO = AutowireCapableBeanFactory.AUTOWIRE_NO;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -1628,7 +1628,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
return beanInstance;
|
||||
}
|
||||
if (!(beanInstance instanceof FactoryBean)) {
|
||||
throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass());
|
||||
throw new BeanIsNotAFactoryException(beanName, beanInstance.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,6 +180,8 @@ public class BeanDefinitionBuilder {
|
||||
/**
|
||||
* Set the name of a non-static factory method to use for this definition,
|
||||
* including the bean name of the factory instance to call the method on.
|
||||
* @param factoryMethod the name of the factory method
|
||||
* @param factoryBean the name of the bean to call the specified factory method on
|
||||
* @since 4.3.6
|
||||
*/
|
||||
public BeanDefinitionBuilder setFactoryMethodOnBean(String factoryMethod, String factoryBean) {
|
||||
@@ -209,7 +211,7 @@ public class BeanDefinitionBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the supplied property value under the given name.
|
||||
* Add the supplied property value under the given property name.
|
||||
*/
|
||||
public BeanDefinitionBuilder addPropertyValue(String name, @Nullable Object value) {
|
||||
this.beanDefinition.getPropertyValues().add(name, value);
|
||||
@@ -278,7 +280,7 @@ public class BeanDefinitionBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the depency check mode for this definition.
|
||||
* Set the dependency check mode for this definition.
|
||||
*/
|
||||
public BeanDefinitionBuilder setDependencyCheck(int dependencyCheck) {
|
||||
this.beanDefinition.setDependencyCheck(dependencyCheck);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -281,6 +281,40 @@ class BeanDefinitionValueResolver {
|
||||
return value.resolveTargetType(this.beanFactory.getBeanClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a reference to another bean in the factory.
|
||||
*/
|
||||
@Nullable
|
||||
private Object resolveReference(Object argName, RuntimeBeanReference ref) {
|
||||
try {
|
||||
Object bean;
|
||||
String refName = ref.getBeanName();
|
||||
refName = String.valueOf(doEvaluate(refName));
|
||||
if (ref.isToParent()) {
|
||||
if (this.beanFactory.getParentBeanFactory() == null) {
|
||||
throw new BeanCreationException(
|
||||
this.beanDefinition.getResourceDescription(), this.beanName,
|
||||
"Can't resolve reference to bean '" + refName +
|
||||
"' in parent factory: no parent factory available");
|
||||
}
|
||||
bean = this.beanFactory.getParentBeanFactory().getBean(refName);
|
||||
}
|
||||
else {
|
||||
bean = this.beanFactory.getBean(refName);
|
||||
this.beanFactory.registerDependentBean(refName, this.beanName);
|
||||
}
|
||||
if (bean instanceof NullBean) {
|
||||
bean = null;
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
catch (BeansException ex) {
|
||||
throw new BeanCreationException(
|
||||
this.beanDefinition.getResourceDescription(), this.beanName,
|
||||
"Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an inner bean definition.
|
||||
* @param argName the name of the argument that the inner bean is defined for
|
||||
@@ -345,48 +379,13 @@ class BeanDefinitionValueResolver {
|
||||
return actualInnerBeanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a reference to another bean in the factory.
|
||||
*/
|
||||
@Nullable
|
||||
private Object resolveReference(Object argName, RuntimeBeanReference ref) {
|
||||
try {
|
||||
Object bean;
|
||||
String refName = ref.getBeanName();
|
||||
refName = String.valueOf(doEvaluate(refName));
|
||||
if (ref.isToParent()) {
|
||||
if (this.beanFactory.getParentBeanFactory() == null) {
|
||||
throw new BeanCreationException(
|
||||
this.beanDefinition.getResourceDescription(), this.beanName,
|
||||
"Can't resolve reference to bean '" + refName +
|
||||
"' in parent factory: no parent factory available");
|
||||
}
|
||||
bean = this.beanFactory.getParentBeanFactory().getBean(refName);
|
||||
}
|
||||
else {
|
||||
bean = this.beanFactory.getBean(refName);
|
||||
this.beanFactory.registerDependentBean(refName, this.beanName);
|
||||
}
|
||||
if (bean instanceof NullBean) {
|
||||
bean = null;
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
catch (BeansException ex) {
|
||||
throw new BeanCreationException(
|
||||
this.beanDefinition.getResourceDescription(), this.beanName,
|
||||
"Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For each element in the managed array, resolve reference if necessary.
|
||||
*/
|
||||
private Object resolveManagedArray(Object argName, List<?> ml, Class<?> elementType) {
|
||||
Object resolved = Array.newInstance(elementType, ml.size());
|
||||
for (int i = 0; i < ml.size(); i++) {
|
||||
Array.set(resolved, i,
|
||||
resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i)));
|
||||
Array.set(resolved, i, resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i)));
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
@@ -397,8 +396,7 @@ class BeanDefinitionValueResolver {
|
||||
private List<?> resolveManagedList(Object argName, List<?> ml) {
|
||||
List<Object> resolved = new ArrayList<>(ml.size());
|
||||
for (int i = 0; i < ml.size(); i++) {
|
||||
resolved.add(
|
||||
resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i)));
|
||||
resolved.add(resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i)));
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -176,7 +176,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return (getClass() == other.getClass() &&
|
||||
return (other != null && getClass() == other.getClass() &&
|
||||
this.beanDefinition.equals(((CglibIdentitySupport) other).beanDefinition));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -23,7 +23,9 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -36,9 +38,9 @@ public class BeanDefinitionBuilderTests {
|
||||
String[] dependsOn = new String[] { "A", "B", "C" };
|
||||
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
||||
bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
||||
bdb.addPropertyReference("age", "15");
|
||||
for (int i = 0; i < dependsOn.length; i++) {
|
||||
bdb.addDependsOn(dependsOn[i]);
|
||||
bdb.addPropertyValue("age", "15");
|
||||
for (String dependsOnEntry : dependsOn) {
|
||||
bdb.addDependsOn(dependsOnEntry);
|
||||
}
|
||||
|
||||
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -61,8 +61,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
|
||||
private ITestBean spouse;
|
||||
|
||||
protected ITestBean[] spouses;
|
||||
|
||||
private String touchy;
|
||||
|
||||
private String[] stringArray;
|
||||
|
||||
Reference in New Issue
Block a user