Consistent use of @Nullable across the codebase (even for internals)
Beyond just formally declaring the current behavior, this revision actually enforces non-null behavior in selected signatures now, not tolerating null values anymore when not explicitly documented. It also changes some utility methods with historic null-in/null-out tolerance towards enforced non-null return values, making them a proper citizen in non-null assignments. Some issues are left as to-do: in particular a thorough revision of spring-test, and a few tests with unclear failures (ignored as "TODO: NULLABLE") to be sorted out in a follow-up commit. Issue: SPR-15540
This commit is contained in:
parent
ffc3f6d87d
commit
f813712f5b
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*<
|
/*<
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -31,14 +31,14 @@ import org.springframework.lang.Nullable;
|
||||||
* {@code TargetSources} directly: this is an AOP framework interface.
|
* {@code TargetSources} directly: this is an AOP framework interface.
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public interface TargetSource extends TargetClassAware {
|
public interface TargetSource extends TargetClassAware {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the type of targets returned by this {@link TargetSource}.
|
* Return the type of targets returned by this {@link TargetSource}.
|
||||||
* <p>Can return {@code null}, although certain usages of a
|
* <p>Can return {@code null}, although certain usages of a {@code TargetSource}
|
||||||
* {@code TargetSource} might just work with a predetermined
|
* might just work with a predetermined target class.
|
||||||
* target class.
|
|
||||||
* @return the type of targets returned by this {@link TargetSource}
|
* @return the type of targets returned by this {@link TargetSource}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -46,9 +46,8 @@ public interface TargetSource extends TargetClassAware {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will all calls to {@link #getTarget()} return the same object?
|
* Will all calls to {@link #getTarget()} return the same object?
|
||||||
* <p>In that case, there will be no need to invoke
|
* <p>In that case, there will be no need to invoke {@link #releaseTarget(Object)},
|
||||||
* {@link #releaseTarget(Object)}, and the AOP framework can cache
|
* and the AOP framework can cache the return value of {@link #getTarget()}.
|
||||||
* the return value of {@link #getTarget()}.
|
|
||||||
* @return {@code true} if the target is immutable
|
* @return {@code true} if the target is immutable
|
||||||
* @see #getTarget
|
* @see #getTarget
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -208,6 +208,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||||
/**
|
/**
|
||||||
* Return the ClassLoader for aspect instances.
|
* Return the ClassLoader for aspect instances.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public final ClassLoader getAspectClassLoader() {
|
public final ClassLoader getAspectClassLoader() {
|
||||||
return this.aspectInstanceFactory.getAspectClassLoader();
|
return this.aspectInstanceFactory.getAspectClassLoader();
|
||||||
}
|
}
|
||||||
|
@ -296,8 +297,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
throw new IllegalArgumentException("Returning name '" + name +
|
throw new IllegalArgumentException("Returning name '" + name +
|
||||||
"' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
|
"' is neither a valid argument name nor the fully-qualified " +
|
||||||
"Root cause: " + ex);
|
"name of a Java type on the classpath. Root cause: " + ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,6 +307,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||||
return this.discoveredReturningType;
|
return this.discoveredReturningType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected Type getDiscoveredReturningGenericType() {
|
protected Type getDiscoveredReturningGenericType() {
|
||||||
return this.discoveredReturningGenericType;
|
return this.discoveredReturningGenericType;
|
||||||
}
|
}
|
||||||
|
@ -330,8 +332,8 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
throw new IllegalArgumentException("Throwing name '" + name +
|
throw new IllegalArgumentException("Throwing name '" + name +
|
||||||
"' is neither a valid argument name nor the fully-qualified name of a Java type on the classpath. " +
|
"' is neither a valid argument name nor the fully-qualified " +
|
||||||
"Root cause: " + ex);
|
"name of a Java type on the classpath. Root cause: " + ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -549,7 +551,9 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||||
* @param ex the exception thrown by the method execution (may be null)
|
* @param ex the exception thrown by the method execution (may be null)
|
||||||
* @return the empty array if there are no arguments
|
* @return the empty array if there are no arguments
|
||||||
*/
|
*/
|
||||||
protected Object[] argBinding(JoinPoint jp, JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) {
|
protected Object[] argBinding(JoinPoint jp, @Nullable JoinPointMatch jpMatch,
|
||||||
|
@Nullable Object returnValue, @Nullable Throwable ex) {
|
||||||
|
|
||||||
calculateArgumentBindings();
|
calculateArgumentBindings();
|
||||||
|
|
||||||
// AMC start
|
// AMC start
|
||||||
|
@ -608,13 +612,16 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||||
* @return the invocation result
|
* @return the invocation result
|
||||||
* @throws Throwable in case of invocation failure
|
* @throws Throwable in case of invocation failure
|
||||||
*/
|
*/
|
||||||
protected Object invokeAdviceMethod(JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex) throws Throwable {
|
protected Object invokeAdviceMethod(
|
||||||
|
@Nullable JoinPointMatch jpMatch, @Nullable Object returnValue, @Nullable Throwable ex)
|
||||||
|
throws Throwable {
|
||||||
|
|
||||||
return invokeAdviceMethodWithGivenArgs(argBinding(getJoinPoint(), jpMatch, returnValue, ex));
|
return invokeAdviceMethodWithGivenArgs(argBinding(getJoinPoint(), jpMatch, returnValue, ex));
|
||||||
}
|
}
|
||||||
|
|
||||||
// As above, but in this case we are given the join point.
|
// As above, but in this case we are given the join point.
|
||||||
protected Object invokeAdviceMethod(JoinPoint jp, JoinPointMatch jpMatch, Object returnValue, Throwable t)
|
protected Object invokeAdviceMethod(JoinPoint jp, @Nullable JoinPointMatch jpMatch,
|
||||||
throws Throwable {
|
@Nullable Object returnValue, @Nullable Throwable t) throws Throwable {
|
||||||
|
|
||||||
return invokeAdviceMethodWithGivenArgs(argBinding(jp, jpMatch, returnValue, t));
|
return invokeAdviceMethodWithGivenArgs(argBinding(jp, jpMatch, returnValue, t));
|
||||||
}
|
}
|
||||||
|
@ -649,6 +656,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||||
/**
|
/**
|
||||||
* Get the current join point match at the join point we are being dispatched on.
|
* Get the current join point match at the join point we are being dispatched on.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
protected JoinPointMatch getJoinPointMatch() {
|
protected JoinPointMatch getJoinPointMatch() {
|
||||||
MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
|
MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation();
|
||||||
if (!(mi instanceof ProxyMethodInvocation)) {
|
if (!(mi instanceof ProxyMethodInvocation)) {
|
||||||
|
@ -663,8 +671,10 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||||
// 'last man wins' which is not what we want at all.
|
// 'last man wins' which is not what we want at all.
|
||||||
// Using the expression is guaranteed to be safe, since 2 identical expressions
|
// Using the expression is guaranteed to be safe, since 2 identical expressions
|
||||||
// are guaranteed to bind in exactly the same way.
|
// are guaranteed to bind in exactly the same way.
|
||||||
|
@Nullable
|
||||||
protected JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi) {
|
protected JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi) {
|
||||||
return (JoinPointMatch) pmi.getUserAttribute(this.pointcut.getExpression());
|
String expression = this.pointcut.getExpression();
|
||||||
|
return (expression != null ? (JoinPointMatch) pmi.getUserAttribute(expression) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface implemented to provide an instance of an AspectJ aspect.
|
* Interface implemented to provide an instance of an AspectJ aspect.
|
||||||
|
@ -40,8 +41,10 @@ public interface AspectInstanceFactory extends Ordered {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose the aspect class loader that this factory uses.
|
* Expose the aspect class loader that this factory uses.
|
||||||
* @return the aspect class loader (never {@code null})
|
* @return the aspect class loader (or {@code null} for the bootstrap loader)
|
||||||
|
* @see org.springframework.util.ClassUtils#getDefaultClassLoader()
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
ClassLoader getAspectClassLoader();
|
ClassLoader getAspectClassLoader();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -183,10 +183,11 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||||
* Create a new discoverer that attempts to discover parameter names
|
* Create a new discoverer that attempts to discover parameter names
|
||||||
* from the given pointcut expression.
|
* from the given pointcut expression.
|
||||||
*/
|
*/
|
||||||
public AspectJAdviceParameterNameDiscoverer(String pointcutExpression) {
|
public AspectJAdviceParameterNameDiscoverer(@Nullable String pointcutExpression) {
|
||||||
this.pointcutExpression = pointcutExpression;
|
this.pointcutExpression = pointcutExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicate whether {@link IllegalArgumentException} and {@link AmbiguousBindingException}
|
* Indicate whether {@link IllegalArgumentException} and {@link AmbiguousBindingException}
|
||||||
* must be thrown as appropriate in the case of failing to deduce advice parameter names.
|
* must be thrown as appropriate in the case of failing to deduce advice parameter names.
|
||||||
|
@ -214,6 +215,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||||
this.throwingName = throwingName;
|
this.throwingName = throwingName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deduce the parameter names for an advice method.
|
* Deduce the parameter names for an advice method.
|
||||||
* <p>See the {@link AspectJAdviceParameterNameDiscoverer class level javadoc}
|
* <p>See the {@link AspectJAdviceParameterNameDiscoverer class level javadoc}
|
||||||
|
@ -475,8 +477,8 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||||
* If the token starts meets Java identifier conventions, it's in.
|
* If the token starts meets Java identifier conventions, it's in.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private String maybeExtractVariableName(String candidateToken) {
|
private String maybeExtractVariableName(@Nullable String candidateToken) {
|
||||||
if (candidateToken == null || candidateToken.equals("")) {
|
if (!StringUtils.hasLength(candidateToken)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&
|
if (Character.isJavaIdentifierStart(candidateToken.charAt(0)) &&
|
||||||
|
@ -498,7 +500,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||||
* Given an args pointcut body (could be {@code args} or {@code at_args}),
|
* Given an args pointcut body (could be {@code args} or {@code at_args}),
|
||||||
* add any candidate variable names to the given list.
|
* add any candidate variable names to the given list.
|
||||||
*/
|
*/
|
||||||
private void maybeExtractVariableNamesFromArgs(String argsSpec, List<String> varNames) {
|
private void maybeExtractVariableNamesFromArgs(@Nullable String argsSpec, List<String> varNames) {
|
||||||
if (argsSpec == null) {
|
if (argsSpec == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -781,7 +783,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
public PointcutBody(int tokens, String text) {
|
public PointcutBody(int tokens, @Nullable String text) {
|
||||||
this.numTokensConsumed = tokens;
|
this.numTokensConsumed = tokens;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -57,6 +57,7 @@ import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
|
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
@ -196,6 +197,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||||
/**
|
/**
|
||||||
* Determine the ClassLoader to use for pointcut evaluation.
|
* Determine the ClassLoader to use for pointcut evaluation.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
private ClassLoader determinePointcutClassLoader() {
|
private ClassLoader determinePointcutClassLoader() {
|
||||||
if (this.beanFactory instanceof ConfigurableBeanFactory) {
|
if (this.beanFactory instanceof ConfigurableBeanFactory) {
|
||||||
return ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader();
|
return ((ConfigurableBeanFactory) this.beanFactory).getBeanClassLoader();
|
||||||
|
@ -209,21 +211,27 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||||
/**
|
/**
|
||||||
* Build the underlying AspectJ pointcut expression.
|
* Build the underlying AspectJ pointcut expression.
|
||||||
*/
|
*/
|
||||||
private PointcutExpression buildPointcutExpression(ClassLoader classLoader) {
|
private PointcutExpression buildPointcutExpression(@Nullable ClassLoader classLoader) {
|
||||||
PointcutParser parser = initializePointcutParser(classLoader);
|
PointcutParser parser = initializePointcutParser(classLoader);
|
||||||
PointcutParameter[] pointcutParameters = new PointcutParameter[this.pointcutParameterNames.length];
|
PointcutParameter[] pointcutParameters = new PointcutParameter[this.pointcutParameterNames.length];
|
||||||
for (int i = 0; i < pointcutParameters.length; i++) {
|
for (int i = 0; i < pointcutParameters.length; i++) {
|
||||||
pointcutParameters[i] = parser.createPointcutParameter(
|
pointcutParameters[i] = parser.createPointcutParameter(
|
||||||
this.pointcutParameterNames[i], this.pointcutParameterTypes[i]);
|
this.pointcutParameterNames[i], this.pointcutParameterTypes[i]);
|
||||||
}
|
}
|
||||||
return parser.parsePointcutExpression(replaceBooleanOperators(getExpression()),
|
return parser.parsePointcutExpression(replaceBooleanOperators(resolveExpression()),
|
||||||
this.pointcutDeclarationScope, pointcutParameters);
|
this.pointcutDeclarationScope, pointcutParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String resolveExpression() {
|
||||||
|
String expression = getExpression();
|
||||||
|
Assert.state(expression != null, "No expression set");
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the underlying AspectJ pointcut parser.
|
* Initialize the underlying AspectJ pointcut parser.
|
||||||
*/
|
*/
|
||||||
private PointcutParser initializePointcutParser(ClassLoader classLoader) {
|
private PointcutParser initializePointcutParser(@Nullable ClassLoader classLoader) {
|
||||||
PointcutParser parser = PointcutParser
|
PointcutParser parser = PointcutParser
|
||||||
.getPointcutParserSupportingSpecifiedPrimitivesAndUsingSpecifiedClassLoaderForResolution(
|
.getPointcutParserSupportingSpecifiedPrimitivesAndUsingSpecifiedClassLoaderForResolution(
|
||||||
SUPPORTED_PRIMITIVES, classLoader);
|
SUPPORTED_PRIMITIVES, classLoader);
|
||||||
|
@ -301,7 +309,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||||
// we say this is not a match as in Spring there will never be a different
|
// we say this is not a match as in Spring there will never be a different
|
||||||
// runtime subtype.
|
// runtime subtype.
|
||||||
RuntimeTestWalker walker = getRuntimeTestWalker(shadowMatch);
|
RuntimeTestWalker walker = getRuntimeTestWalker(shadowMatch);
|
||||||
return (!walker.testsSubtypeSensitiveVars() || walker.testTargetInstanceOfResidue(targetClass));
|
return (!walker.testsSubtypeSensitiveVars() ||
|
||||||
|
(targetClass != null && walker.testTargetInstanceOfResidue(targetClass)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +363,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||||
* type but not 'this' (as would be the case of JDK dynamic proxies).
|
* type but not 'this' (as would be the case of JDK dynamic proxies).
|
||||||
* <p>See SPR-2979 for the original bug.
|
* <p>See SPR-2979 for the original bug.
|
||||||
*/
|
*/
|
||||||
if (pmi != null) { // there is a current invocation
|
if (pmi != null && thisObject != null) { // there is a current invocation
|
||||||
RuntimeTestWalker originalMethodResidueTest = getRuntimeTestWalker(originalShadowMatch);
|
RuntimeTestWalker originalMethodResidueTest = getRuntimeTestWalker(originalShadowMatch);
|
||||||
if (!originalMethodResidueTest.testThisInstanceOfResidue(thisObject.getClass())) {
|
if (!originalMethodResidueTest.testThisInstanceOfResidue(thisObject.getClass())) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -375,6 +384,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected String getCurrentProxiedBeanName() {
|
protected String getCurrentProxiedBeanName() {
|
||||||
return ProxyCreationContext.getCurrentProxiedBeanName();
|
return ProxyCreationContext.getCurrentProxiedBeanName();
|
||||||
}
|
}
|
||||||
|
@ -411,7 +421,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||||
// 'last man wins' which is not what we want at all.
|
// 'last man wins' which is not what we want at all.
|
||||||
// Using the expression is guaranteed to be safe, since 2 identical expressions
|
// Using the expression is guaranteed to be safe, since 2 identical expressions
|
||||||
// are guaranteed to bind in exactly the same way.
|
// are guaranteed to bind in exactly the same way.
|
||||||
invocation.setUserAttribute(getExpression(), jpm);
|
invocation.setUserAttribute(resolveExpression(), jpm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
|
private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
|
||||||
|
@ -600,7 +610,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FuzzyBoolean contextMatch(Class<?> targetType) {
|
private FuzzyBoolean contextMatch(@Nullable Class<?> targetType) {
|
||||||
String advisedBeanName = getCurrentProxiedBeanName();
|
String advisedBeanName = getCurrentProxiedBeanName();
|
||||||
if (advisedBeanName == null) { // no proxy creation in progress
|
if (advisedBeanName == null) { // no proxy creation in progress
|
||||||
// abstain; can't return YES, since that will make pointcut with negation fail
|
// abstain; can't return YES, since that will make pointcut with negation fail
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -20,6 +20,7 @@ import org.springframework.aop.Pointcut;
|
||||||
import org.springframework.aop.support.AbstractGenericPointcutAdvisor;
|
import org.springframework.aop.support.AbstractGenericPointcutAdvisor;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.BeanFactoryAware;
|
import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spring AOP Advisor that can be used for any AspectJ pointcut expression.
|
* Spring AOP Advisor that can be used for any AspectJ pointcut expression.
|
||||||
|
@ -37,6 +38,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv
|
||||||
this.pointcut.setExpression(expression);
|
this.pointcut.setExpression(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getExpression() {
|
public String getExpression() {
|
||||||
return this.pointcut.getExpression();
|
return this.pointcut.getExpression();
|
||||||
}
|
}
|
||||||
|
@ -45,6 +47,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv
|
||||||
this.pointcut.setLocation(location);
|
this.pointcut.setLocation(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getLocation() {
|
public String getLocation() {
|
||||||
return this.pointcut.getLocation();
|
return this.pointcut.getLocation();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -212,6 +212,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||||
throw new IllegalStateException("Unknown annotation type: " + annotation.toString());
|
throw new IllegalStateException("Unknown annotation type: " + annotation.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private String resolveExpression(A annotation) throws Exception {
|
private String resolveExpression(A annotation) throws Exception {
|
||||||
String expression = null;
|
String expression = null;
|
||||||
for (String methodName : EXPRESSION_PROPERTIES) {
|
for (String methodName : EXPRESSION_PROPERTIES) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -119,7 +119,9 @@ public class AspectJProxyFactory extends ProxyCreatorSupport {
|
||||||
*/
|
*/
|
||||||
private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) {
|
private void addAdvisorsFromAspectInstanceFactory(MetadataAwareAspectInstanceFactory instanceFactory) {
|
||||||
List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory);
|
List<Advisor> advisors = this.aspectFactory.getAdvisors(instanceFactory);
|
||||||
advisors = AopUtils.findAdvisorsThatCanApply(advisors, getTargetClass());
|
Class<?> targetClass = getTargetClass();
|
||||||
|
Assert.state(targetClass != null, "Unresolvable target class");
|
||||||
|
advisors = AopUtils.findAdvisorsThatCanApply(advisors, targetClass);
|
||||||
AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors);
|
AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(advisors);
|
||||||
AnnotationAwareOrderComparator.sort(advisors);
|
AnnotationAwareOrderComparator.sort(advisors);
|
||||||
addAdvisors(advisors);
|
addAdvisors(advisors);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -22,6 +22,7 @@ import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.annotation.OrderUtils;
|
import org.springframework.core.annotation.OrderUtils;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
|
||||||
* @param name name of the bean
|
* @param name name of the bean
|
||||||
*/
|
*/
|
||||||
public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name) {
|
public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name) {
|
||||||
this(beanFactory, name, beanFactory.getType(name));
|
this(beanFactory, name, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,13 +69,19 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst
|
||||||
* @param beanFactory BeanFactory to obtain instance(s) from
|
* @param beanFactory BeanFactory to obtain instance(s) from
|
||||||
* @param name the name of the bean
|
* @param name the name of the bean
|
||||||
* @param type the type that should be introspected by AspectJ
|
* @param type the type that should be introspected by AspectJ
|
||||||
|
* ({@code null} indicates resolution through {@link BeanFactory#getType} via the bean name)
|
||||||
*/
|
*/
|
||||||
public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, Class<?> type) {
|
public BeanFactoryAspectInstanceFactory(BeanFactory beanFactory, String name, @Nullable Class<?> type) {
|
||||||
Assert.notNull(beanFactory, "BeanFactory must not be null");
|
Assert.notNull(beanFactory, "BeanFactory must not be null");
|
||||||
Assert.notNull(name, "Bean name must not be null");
|
Assert.notNull(name, "Bean name must not be null");
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.aspectMetadata = new AspectMetadata(type, name);
|
Class<?> resolvedType = type;
|
||||||
|
if (type == null) {
|
||||||
|
resolvedType = beanFactory.getType(name);
|
||||||
|
Assert.notNull(resolvedType, "Unresolvable bean type - explicitly specify the aspect class");
|
||||||
|
}
|
||||||
|
this.aspectMetadata = new AspectMetadata(resolvedType, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -45,6 +45,9 @@ import org.springframework.lang.Nullable;
|
||||||
class InstantiationModelAwarePointcutAdvisorImpl
|
class InstantiationModelAwarePointcutAdvisorImpl
|
||||||
implements InstantiationModelAwarePointcutAdvisor, AspectJPrecedenceInformation, Serializable {
|
implements InstantiationModelAwarePointcutAdvisor, AspectJPrecedenceInformation, Serializable {
|
||||||
|
|
||||||
|
private static Advice EMPTY_ADVICE = new Advice() {};
|
||||||
|
|
||||||
|
|
||||||
private final AspectJExpressionPointcut declaredPointcut;
|
private final AspectJExpressionPointcut declaredPointcut;
|
||||||
|
|
||||||
private final Class<?> declaringClass;
|
private final Class<?> declaringClass;
|
||||||
|
@ -157,9 +160,10 @@ class InstantiationModelAwarePointcutAdvisorImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Advice instantiateAdvice(AspectJExpressionPointcut pcut) {
|
private Advice instantiateAdvice(AspectJExpressionPointcut pointcut) {
|
||||||
return this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pcut,
|
Advice advice = this.aspectJAdvisorFactory.getAdvice(this.aspectJAdviceMethod, pointcut,
|
||||||
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
|
this.aspectInstanceFactory, this.declarationOrder, this.aspectName);
|
||||||
|
return (advice != null ? advice : EMPTY_ADVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory() {
|
public MetadataAwareAspectInstanceFactory getAspectInstanceFactory() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -132,7 +132,9 @@ class AspectJPrecedenceComparator implements Comparator<Advisor> {
|
||||||
|
|
||||||
// pre-condition is that hasAspectName returned true
|
// pre-condition is that hasAspectName returned true
|
||||||
private String getAspectName(Advisor anAdvisor) {
|
private String getAspectName(Advisor anAdvisor) {
|
||||||
return AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor).getAspectName();
|
AspectJPrecedenceInformation pi = AspectJAopUtils.getAspectJPrecedenceInformationFor(anAdvisor);
|
||||||
|
Assert.state(pi != null, "Unresolvable precedence information");
|
||||||
|
return pi.getAspectName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAspectDeclarationOrder(Advisor anAdvisor) {
|
private int getAspectDeclarationOrder(Advisor anAdvisor) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -30,6 +30,7 @@ import org.springframework.beans.factory.support.ManagedList;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
|
import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
@ -105,8 +106,8 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void addInterceptorNameToList(String interceptorName, BeanDefinition beanDefinition) {
|
private void addInterceptorNameToList(String interceptorName, BeanDefinition beanDefinition) {
|
||||||
List<String> list = (List<String>)
|
List<String> list = (List<String>) beanDefinition.getPropertyValues().get("interceptorNames");
|
||||||
beanDefinition.getPropertyValues().getPropertyValue("interceptorNames").getValue();
|
Assert.state(list != null, "Missing 'interceptorNames' property");
|
||||||
list.add(interceptorName);
|
list.add(interceptorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +116,9 @@ public abstract class AbstractInterceptorDrivenBeanDefinitionDecorator implement
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
|
protected String getInterceptorNameSuffix(BeanDefinition interceptorDefinition) {
|
||||||
return StringUtils.uncapitalize(ClassUtils.getShortName(interceptorDefinition.getBeanClassName()));
|
String beanClassName = interceptorDefinition.getBeanClassName();
|
||||||
|
return (StringUtils.hasLength(beanClassName) ?
|
||||||
|
StringUtils.uncapitalize(ClassUtils.getShortName(beanClassName)) : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -20,6 +20,7 @@ import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.config.BeanReference;
|
import org.springframework.beans.factory.config.BeanReference;
|
||||||
import org.springframework.beans.factory.parsing.AbstractComponentDefinition;
|
import org.springframework.beans.factory.parsing.AbstractComponentDefinition;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,7 +51,7 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdvisorComponentDefinition(
|
public AdvisorComponentDefinition(
|
||||||
String advisorBeanName, BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) {
|
String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {
|
||||||
|
|
||||||
Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null");
|
Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null");
|
||||||
Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null");
|
Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null");
|
||||||
|
@ -60,9 +61,10 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void unwrapDefinitions(BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) {
|
private void unwrapDefinitions(BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) {
|
||||||
MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
|
MutablePropertyValues pvs = advisorDefinition.getPropertyValues();
|
||||||
BeanReference adviceReference = (BeanReference) pvs.getPropertyValue("adviceBeanName").getValue();
|
BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName");
|
||||||
|
Assert.state(adviceReference != null, "Missing 'adviceBeanName' property");
|
||||||
|
|
||||||
if (pointcutDefinition != null) {
|
if (pointcutDefinition != null) {
|
||||||
this.beanReferences = new BeanReference[] {adviceReference};
|
this.beanReferences = new BeanReference[] {adviceReference};
|
||||||
|
@ -70,7 +72,8 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
||||||
this.description = buildDescription(adviceReference, pointcutDefinition);
|
this.description = buildDescription(adviceReference, pointcutDefinition);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BeanReference pointcutReference = (BeanReference) pvs.getPropertyValue("pointcut").getValue();
|
BeanReference pointcutReference = (BeanReference) pvs.get("pointcut");
|
||||||
|
Assert.state(pointcutReference != null, "Missing 'pointcut' property");
|
||||||
this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
|
this.beanReferences = new BeanReference[] {adviceReference, pointcutReference};
|
||||||
this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
|
this.beanDefinitions = new BeanDefinition[] {advisorDefinition};
|
||||||
this.description = buildDescription(adviceReference, pointcutReference);
|
this.description = buildDescription(adviceReference, pointcutReference);
|
||||||
|
@ -78,16 +81,15 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildDescription(BeanReference adviceReference, BeanDefinition pointcutDefinition) {
|
private String buildDescription(BeanReference adviceReference, BeanDefinition pointcutDefinition) {
|
||||||
return new StringBuilder("Advisor <advice(ref)='").
|
return "Advisor <advice(ref)='" +
|
||||||
append(adviceReference.getBeanName()).append("', pointcut(expression)=[").
|
adviceReference.getBeanName() + "', pointcut(expression)=[" +
|
||||||
append(pointcutDefinition.getPropertyValues().getPropertyValue("expression").getValue()).
|
pointcutDefinition.getPropertyValues().get("expression") + "]>";
|
||||||
append("]>").toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildDescription(BeanReference adviceReference, BeanReference pointcutReference) {
|
private String buildDescription(BeanReference adviceReference, BeanReference pointcutReference) {
|
||||||
return new StringBuilder("Advisor <advice(ref)='").
|
return "Advisor <advice(ref)='" +
|
||||||
append(adviceReference.getBeanName()).append("', pointcut(ref)='").
|
adviceReference.getBeanName() + "', pointcut(ref)='" +
|
||||||
append(pointcutReference.getBeanName()).append("'>").toString();
|
pointcutReference.getBeanName() + "'>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -67,27 +67,39 @@ public abstract class AopConfigUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
|
public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
|
||||||
return registerAutoProxyCreatorIfNecessary(registry, null);
|
return registerAutoProxyCreatorIfNecessary(registry, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
|
@Nullable
|
||||||
|
public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
|
||||||
|
@Nullable Object source) {
|
||||||
|
|
||||||
return registerOrEscalateApcAsRequired(InfrastructureAdvisorAutoProxyCreator.class, registry, source);
|
return registerOrEscalateApcAsRequired(InfrastructureAdvisorAutoProxyCreator.class, registry, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
|
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
|
||||||
return registerAspectJAutoProxyCreatorIfNecessary(registry, null);
|
return registerAspectJAutoProxyCreatorIfNecessary(registry, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
|
@Nullable
|
||||||
|
public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
|
||||||
|
@Nullable Object source) {
|
||||||
|
|
||||||
return registerOrEscalateApcAsRequired(AspectJAwareAdvisorAutoProxyCreator.class, registry, source);
|
return registerOrEscalateApcAsRequired(AspectJAwareAdvisorAutoProxyCreator.class, registry, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
|
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) {
|
||||||
return registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry, null);
|
return registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry, Object source) {
|
@Nullable
|
||||||
|
public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry,
|
||||||
|
@Nullable Object source) {
|
||||||
|
|
||||||
return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source);
|
return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,8 +118,11 @@ public abstract class AopConfigUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static BeanDefinition registerOrEscalateApcAsRequired(Class<?> cls, BeanDefinitionRegistry registry, Object source) {
|
private static BeanDefinition registerOrEscalateApcAsRequired(Class<?> cls, BeanDefinitionRegistry registry,
|
||||||
|
@Nullable Object source) {
|
||||||
|
|
||||||
Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
|
Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
|
||||||
|
|
||||||
if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
|
if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
|
||||||
BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
|
BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||||
if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
|
if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
|
||||||
|
@ -119,6 +134,7 @@ public abstract class AopConfigUtils {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
|
||||||
beanDefinition.setSource(source);
|
beanDefinition.setSource(source);
|
||||||
beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
|
beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
|
||||||
|
@ -131,7 +147,7 @@ public abstract class AopConfigUtils {
|
||||||
return APC_PRIORITY_LIST.indexOf(clazz);
|
return APC_PRIORITY_LIST.indexOf(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int findPriorityForClass(String className) {
|
private static int findPriorityForClass(@Nullable String className) {
|
||||||
for (int i = 0; i < APC_PRIORITY_LIST.size(); i++) {
|
for (int i = 0; i < APC_PRIORITY_LIST.size(); i++) {
|
||||||
Class<?> clazz = APC_PRIORITY_LIST.get(i);
|
Class<?> clazz = APC_PRIORITY_LIST.get(i);
|
||||||
if (clazz.getName().equals(className)) {
|
if (clazz.getName().equals(className)) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -22,6 +22,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for handling registration of auto-proxy creators used internally
|
* Utility class for handling registration of auto-proxy creators used internally
|
||||||
|
@ -79,7 +80,7 @@ public abstract class AopNamespaceUtils {
|
||||||
registerComponentIfNecessary(beanDefinition, parserContext);
|
registerComponentIfNecessary(beanDefinition, parserContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, Element sourceElement) {
|
private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, @Nullable Element sourceElement) {
|
||||||
if (sourceElement != null) {
|
if (sourceElement != null) {
|
||||||
boolean proxyTargetClass = Boolean.valueOf(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
|
boolean proxyTargetClass = Boolean.valueOf(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
|
||||||
if (proxyTargetClass) {
|
if (proxyTargetClass) {
|
||||||
|
@ -92,7 +93,7 @@ public abstract class AopNamespaceUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerComponentIfNecessary(BeanDefinition beanDefinition, ParserContext parserContext) {
|
private static void registerComponentIfNecessary(@Nullable BeanDefinition beanDefinition, ParserContext parserContext) {
|
||||||
if (beanDefinition != null) {
|
if (beanDefinition != null) {
|
||||||
BeanComponentDefinition componentDefinition =
|
BeanComponentDefinition componentDefinition =
|
||||||
new BeanComponentDefinition(beanDefinition, AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
|
new BeanComponentDefinition(beanDefinition, AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2007 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -19,6 +19,7 @@ package org.springframework.aop.config;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.config.BeanReference;
|
import org.springframework.beans.factory.config.BeanReference;
|
||||||
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.beans.factory.parsing.ComponentDefinition}
|
* {@link org.springframework.beans.factory.parsing.ComponentDefinition}
|
||||||
|
@ -37,8 +38,8 @@ public class AspectComponentDefinition extends CompositeComponentDefinition {
|
||||||
private final BeanReference[] beanReferences;
|
private final BeanReference[] beanReferences;
|
||||||
|
|
||||||
|
|
||||||
public AspectComponentDefinition(
|
public AspectComponentDefinition(String aspectName, @Nullable BeanDefinition[] beanDefinitions,
|
||||||
String aspectName, BeanDefinition[] beanDefinitions, BeanReference[] beanReferences, Object source) {
|
@Nullable BeanReference[] beanReferences, @Nullable Object source) {
|
||||||
|
|
||||||
super(aspectName, source);
|
super(aspectName, source);
|
||||||
this.beanDefinitions = (beanDefinitions != null ? beanDefinitions : new BeanDefinition[0]);
|
this.beanDefinitions = (beanDefinitions != null ? beanDefinitions : new BeanDefinition[0]);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -124,7 +124,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||||
if (this.proxyClassLoader == null) {
|
if (this.proxyClassLoader == null) {
|
||||||
this.proxyClassLoader = classLoader;
|
this.proxyClassLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
@ -170,8 +170,10 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
|
||||||
}
|
}
|
||||||
else if (!isProxyTargetClass()) {
|
else if (!isProxyTargetClass()) {
|
||||||
// Rely on AOP infrastructure to tell us what interfaces to proxy.
|
// Rely on AOP infrastructure to tell us what interfaces to proxy.
|
||||||
proxyFactory.setInterfaces(
|
Class<?> targetClass = targetSource.getTargetClass();
|
||||||
ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), this.proxyClassLoader));
|
if (targetClass != null) {
|
||||||
|
proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
postProcessProxyFactory(proxyFactory);
|
postProcessProxyFactory(proxyFactory);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -38,6 +38,7 @@ import org.springframework.aop.support.DefaultIntroductionAdvisor;
|
||||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||||
import org.springframework.aop.target.EmptyTargetSource;
|
import org.springframework.aop.target.EmptyTargetSource;
|
||||||
import org.springframework.aop.target.SingletonTargetSource;
|
import org.springframework.aop.target.SingletonTargetSource;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
@ -137,7 +138,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTargetSource(TargetSource targetSource) {
|
public void setTargetSource(@Nullable TargetSource targetSource) {
|
||||||
this.targetSource = (targetSource != null ? targetSource : EMPTY_TARGET_SOURCE);
|
this.targetSource = (targetSource != null ? targetSource : EMPTY_TARGET_SOURCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,7 +447,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||||
* @param advice the advice to check inclusion of
|
* @param advice the advice to check inclusion of
|
||||||
* @return whether this advice instance is included
|
* @return whether this advice instance is included
|
||||||
*/
|
*/
|
||||||
public boolean adviceIncluded(Advice advice) {
|
public boolean adviceIncluded(@Nullable Advice advice) {
|
||||||
if (advice != null) {
|
if (advice != null) {
|
||||||
for (Advisor advisor : this.advisors) {
|
for (Advisor advisor : this.advisors) {
|
||||||
if (advisor.getAdvice() == advice) {
|
if (advisor.getAdvice() == advice) {
|
||||||
|
@ -462,7 +463,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||||
* @param adviceClass the advice class to check
|
* @param adviceClass the advice class to check
|
||||||
* @return the count of the interceptors of this class or subclasses
|
* @return the count of the interceptors of this class or subclasses
|
||||||
*/
|
*/
|
||||||
public int countAdvicesOfType(Class<?> adviceClass) {
|
public int countAdvicesOfType(@Nullable Class<?> adviceClass) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (adviceClass != null) {
|
if (adviceClass != null) {
|
||||||
for (Advisor advisor : this.advisors) {
|
for (Advisor advisor : this.advisors) {
|
||||||
|
@ -482,7 +483,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||||
* @param targetClass the target class
|
* @param targetClass the target class
|
||||||
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
|
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
|
||||||
*/
|
*/
|
||||||
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, Class<?> targetClass) {
|
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) {
|
||||||
MethodCacheKey cacheKey = new MethodCacheKey(method);
|
MethodCacheKey cacheKey = new MethodCacheKey(method);
|
||||||
List<Object> cached = this.methodCache.get(cacheKey);
|
List<Object> cached = this.methodCache.get(cacheKey);
|
||||||
if (cached == null) {
|
if (cached == null) {
|
||||||
|
|
|
@ -134,7 +134,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
* @param constructorArgs the constructor argument values
|
* @param constructorArgs the constructor argument values
|
||||||
* @param constructorArgTypes the constructor argument types
|
* @param constructorArgTypes the constructor argument types
|
||||||
*/
|
*/
|
||||||
public void setConstructorArguments(Object[] constructorArgs, Class<?>[] constructorArgTypes) {
|
public void setConstructorArguments(@Nullable Object[] constructorArgs, @Nullable Class<?>[] constructorArgTypes) {
|
||||||
if (constructorArgs == null || constructorArgTypes == null) {
|
if (constructorArgs == null || constructorArgTypes == null) {
|
||||||
throw new IllegalArgumentException("Both 'constructorArgs' and 'constructorArgTypes' need to be specified");
|
throw new IllegalArgumentException("Both 'constructorArgs' and 'constructorArgTypes' need to be specified");
|
||||||
}
|
}
|
||||||
|
@ -233,7 +233,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
* Checks to see whether the supplied {@code Class} has already been validated and
|
* Checks to see whether the supplied {@code Class} has already been validated and
|
||||||
* validates it if not.
|
* validates it if not.
|
||||||
*/
|
*/
|
||||||
private void validateClassIfNecessary(Class<?> proxySuperClass, ClassLoader proxyClassLoader) {
|
private void validateClassIfNecessary(Class<?> proxySuperClass, @Nullable ClassLoader proxyClassLoader) {
|
||||||
if (logger.isWarnEnabled()) {
|
if (logger.isWarnEnabled()) {
|
||||||
synchronized (validatedClasses) {
|
synchronized (validatedClasses) {
|
||||||
if (!validatedClasses.containsKey(proxySuperClass)) {
|
if (!validatedClasses.containsKey(proxySuperClass)) {
|
||||||
|
@ -249,7 +249,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
* Checks for final methods on the given {@code Class}, as well as package-visible
|
* Checks for final methods on the given {@code Class}, as well as package-visible
|
||||||
* methods across ClassLoaders, and writes warnings to the log for each one found.
|
* methods across ClassLoaders, and writes warnings to the log for each one found.
|
||||||
*/
|
*/
|
||||||
private void doValidateClass(Class<?> proxySuperClass, ClassLoader proxyClassLoader, Set<Class<?>> ifcs) {
|
private void doValidateClass(Class<?> proxySuperClass, @Nullable ClassLoader proxyClassLoader, Set<Class<?>> ifcs) {
|
||||||
if (proxySuperClass != Object.class) {
|
if (proxySuperClass != Object.class) {
|
||||||
Method[] methods = proxySuperClass.getDeclaredMethods();
|
Method[] methods = proxySuperClass.getDeclaredMethods();
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
|
@ -374,7 +374,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
|
* {@code proxy} and also verifies that {@code null} is not returned as a primitive.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private static Object processReturnType(Object proxy, Object target, Method method, @Nullable Object retVal) {
|
private static Object processReturnType(Object proxy, @Nullable Object target, Method method, @Nullable Object retVal) {
|
||||||
// Massage return value if necessary
|
// Massage return value if necessary
|
||||||
if (retVal != null && retVal == target &&
|
if (retVal != null && retVal == target &&
|
||||||
!RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
|
!RawTargetAccess.class.isAssignableFrom(method.getDeclaringClass())) {
|
||||||
|
@ -409,11 +409,12 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
|
|
||||||
private final Object target;
|
private final Object target;
|
||||||
|
|
||||||
public StaticUnadvisedInterceptor(Object target) {
|
public StaticUnadvisedInterceptor(@Nullable Object target) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||||
Object retVal = methodProxy.invoke(this.target, args);
|
Object retVal = methodProxy.invoke(this.target, args);
|
||||||
return processReturnType(proxy, this.target, method, retVal);
|
return processReturnType(proxy, this.target, method, retVal);
|
||||||
|
@ -429,11 +430,12 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
|
|
||||||
private final Object target;
|
private final Object target;
|
||||||
|
|
||||||
public StaticUnadvisedExposedInterceptor(Object target) {
|
public StaticUnadvisedExposedInterceptor(@Nullable Object target) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||||
Object oldProxy = null;
|
Object oldProxy = null;
|
||||||
try {
|
try {
|
||||||
|
@ -462,6 +464,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||||
Object target = this.targetSource.getTarget();
|
Object target = this.targetSource.getTarget();
|
||||||
try {
|
try {
|
||||||
|
@ -469,7 +472,9 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
return processReturnType(proxy, target, method, retVal);
|
return processReturnType(proxy, target, method, retVal);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
this.targetSource.releaseTarget(target);
|
if (target != null) {
|
||||||
|
this.targetSource.releaseTarget(target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -487,6 +492,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||||
Object oldProxy = null;
|
Object oldProxy = null;
|
||||||
Object target = this.targetSource.getTarget();
|
Object target = this.targetSource.getTarget();
|
||||||
|
@ -497,7 +503,9 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
AopContext.setCurrentProxy(oldProxy);
|
AopContext.setCurrentProxy(oldProxy);
|
||||||
this.targetSource.releaseTarget(target);
|
if (target != null) {
|
||||||
|
this.targetSource.releaseTarget(target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,7 +520,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
|
|
||||||
private Object target;
|
private Object target;
|
||||||
|
|
||||||
public StaticDispatcher(Object target) {
|
public StaticDispatcher(@Nullable Object target) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,13 +612,16 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
|
|
||||||
private final Class<?> targetClass;
|
private final Class<?> targetClass;
|
||||||
|
|
||||||
public FixedChainStaticTargetInterceptor(List<Object> adviceChain, Object target, Class<?> targetClass) {
|
public FixedChainStaticTargetInterceptor(
|
||||||
|
List<Object> adviceChain, @Nullable Object target, @Nullable Class<?> targetClass) {
|
||||||
|
|
||||||
this.adviceChain = adviceChain;
|
this.adviceChain = adviceChain;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.targetClass = targetClass;
|
this.targetClass = targetClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||||
MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args,
|
MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args,
|
||||||
this.targetClass, this.adviceChain, methodProxy);
|
this.targetClass, this.adviceChain, methodProxy);
|
||||||
|
@ -635,6 +646,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
|
||||||
Object oldProxy = null;
|
Object oldProxy = null;
|
||||||
boolean setProxyContext = false;
|
boolean setProxyContext = false;
|
||||||
|
@ -697,6 +709,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
return this.advised.hashCode();
|
return this.advised.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected Object getTarget() throws Exception {
|
protected Object getTarget() throws Exception {
|
||||||
return this.advised.getTargetSource().getTarget();
|
return this.advised.getTargetSource().getTarget();
|
||||||
}
|
}
|
||||||
|
@ -716,8 +729,9 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
|
|
||||||
private final boolean publicMethod;
|
private final boolean publicMethod;
|
||||||
|
|
||||||
public CglibMethodInvocation(Object proxy, Object target, Method method, Object[] arguments,
|
public CglibMethodInvocation(Object proxy, @Nullable Object target, Method method,
|
||||||
Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
|
Object[] arguments, @Nullable Class<?> targetClass,
|
||||||
|
List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
|
||||||
|
|
||||||
super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers);
|
super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers);
|
||||||
this.methodProxy = methodProxy;
|
this.methodProxy = methodProxy;
|
||||||
|
@ -751,7 +765,9 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
|
|
||||||
private final int fixedInterceptorOffset;
|
private final int fixedInterceptorOffset;
|
||||||
|
|
||||||
public ProxyCallbackFilter(AdvisedSupport advised, Map<String, Integer> fixedInterceptorMap, int fixedInterceptorOffset) {
|
public ProxyCallbackFilter(
|
||||||
|
AdvisedSupport advised, Map<String, Integer> fixedInterceptorMap, int fixedInterceptorOffset) {
|
||||||
|
|
||||||
this.advised = advised;
|
this.advised = advised;
|
||||||
this.fixedInterceptorMap = fixedInterceptorMap;
|
this.fixedInterceptorMap = fixedInterceptorMap;
|
||||||
this.fixedInterceptorOffset = fixedInterceptorOffset;
|
this.fixedInterceptorOffset = fixedInterceptorOffset;
|
||||||
|
@ -859,7 +875,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
return INVOKE_TARGET;
|
return INVOKE_TARGET;
|
||||||
}
|
}
|
||||||
Class<?> returnType = method.getReturnType();
|
Class<?> returnType = method.getReturnType();
|
||||||
if (returnType.isAssignableFrom(targetClass)) {
|
if (targetClass != null && returnType.isAssignableFrom(targetClass)) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Method return type is assignable from target type and " +
|
logger.debug("Method return type is assignable from target type and " +
|
||||||
"may therefore return 'this' - using INVOKE_TARGET: " + method);
|
"may therefore return 'this' - using INVOKE_TARGET: " + method);
|
||||||
|
@ -886,9 +902,6 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
}
|
}
|
||||||
ProxyCallbackFilter otherCallbackFilter = (ProxyCallbackFilter) other;
|
ProxyCallbackFilter otherCallbackFilter = (ProxyCallbackFilter) other;
|
||||||
AdvisedSupport otherAdvised = otherCallbackFilter.advised;
|
AdvisedSupport otherAdvised = otherCallbackFilter.advised;
|
||||||
if (this.advised == null || otherAdvised == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (this.advised.isFrozen() != otherAdvised.isFrozen()) {
|
if (this.advised.isFrozen() != otherAdvised.isFrozen()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -922,12 +935,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean equalsAdviceClasses(Advisor a, Advisor b) {
|
private boolean equalsAdviceClasses(Advisor a, Advisor b) {
|
||||||
Advice aa = a.getAdvice();
|
return (a.getAdvice().getClass() == b.getAdvice().getClass());
|
||||||
Advice ba = b.getAdvice();
|
|
||||||
if (aa == null || ba == null) {
|
|
||||||
return (aa == ba);
|
|
||||||
}
|
|
||||||
return (aa.getClass() == ba.getClass());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean equalsPointcuts(Advisor a, Advisor b) {
|
private boolean equalsPointcuts(Advisor a, Advisor b) {
|
||||||
|
@ -944,9 +952,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
Advisor[] advisors = this.advised.getAdvisors();
|
Advisor[] advisors = this.advised.getAdvisors();
|
||||||
for (Advisor advisor : advisors) {
|
for (Advisor advisor : advisors) {
|
||||||
Advice advice = advisor.getAdvice();
|
Advice advice = advisor.getAdvice();
|
||||||
if (advice != null) {
|
hashCode = 13 * hashCode + advice.getClass().hashCode();
|
||||||
hashCode = 13 * hashCode + advice.getClass().hashCode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
hashCode = 13 * hashCode + (this.advised.isFrozen() ? 1 : 0);
|
hashCode = 13 * hashCode + (this.advised.isFrozen() ? 1 : 0);
|
||||||
hashCode = 13 * hashCode + (this.advised.isExposeProxy() ? 1 : 0);
|
hashCode = 13 * hashCode + (this.advised.isExposeProxy() ? 1 : 0);
|
||||||
|
@ -966,7 +972,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||||
|
|
||||||
private final ClassLoader classLoader;
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
public ClassLoaderAwareUndeclaredThrowableStrategy(ClassLoader classLoader) {
|
public ClassLoaderAwareUndeclaredThrowableStrategy(@Nullable ClassLoader classLoader) {
|
||||||
super(UndeclaredThrowableException.class);
|
super(UndeclaredThrowableException.class);
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -152,6 +152,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
||||||
* unless a hook method throws an exception.
|
* unless a hook method throws an exception.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
MethodInvocation invocation;
|
MethodInvocation invocation;
|
||||||
Object oldProxy = null;
|
Object oldProxy = null;
|
||||||
|
@ -249,7 +250,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
||||||
* or a dynamic proxy wrapping a JdkDynamicAopProxy instance.
|
* or a dynamic proxy wrapping a JdkDynamicAopProxy instance.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(@Nullable Object other) {
|
||||||
if (other == this) {
|
if (other == this) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -220,7 +220,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||||
if (!this.classLoaderConfigured) {
|
if (!this.classLoaderConfigured) {
|
||||||
this.proxyClassLoader = classLoader;
|
this.proxyClassLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
@ -345,8 +345,10 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||||
copy.copyConfigurationFrom(this, targetSource, freshAdvisorChain());
|
copy.copyConfigurationFrom(this, targetSource, freshAdvisorChain());
|
||||||
if (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) {
|
if (this.autodetectInterfaces && getProxiedInterfaces().length == 0 && !isProxyTargetClass()) {
|
||||||
// Rely on AOP infrastructure to tell us what interfaces to proxy.
|
// Rely on AOP infrastructure to tell us what interfaces to proxy.
|
||||||
copy.setInterfaces(
|
Class<?> targetClass = targetSource.getTargetClass();
|
||||||
ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), this.proxyClassLoader));
|
if (targetClass != null) {
|
||||||
|
copy.setInterfaces(ClassUtils.getAllInterfacesForClass(targetClass, this.proxyClassLoader));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
copy.setFrozen(this.freezeProxy);
|
copy.setFrozen(this.freezeProxy);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -69,7 +69,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC
|
||||||
* {@link org.springframework.beans.factory.BeanFactory} for loading all bean classes.
|
* {@link org.springframework.beans.factory.BeanFactory} for loading all bean classes.
|
||||||
* This can be overridden here for specific proxies.
|
* This can be overridden here for specific proxies.
|
||||||
*/
|
*/
|
||||||
public void setProxyClassLoader(ClassLoader classLoader) {
|
public void setProxyClassLoader(@Nullable ClassLoader classLoader) {
|
||||||
this.proxyClassLoader = classLoader;
|
this.proxyClassLoader = classLoader;
|
||||||
this.classLoaderConfigured = (classLoader != null);
|
this.classLoaderConfigured = (classLoader != null);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||||
if (!this.classLoaderConfigured) {
|
if (!this.classLoaderConfigured) {
|
||||||
this.proxyClassLoader = classLoader;
|
this.proxyClassLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -103,8 +103,8 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||||
* but would complicate the code. And it would work only for static pointcuts.
|
* but would complicate the code. And it would work only for static pointcuts.
|
||||||
*/
|
*/
|
||||||
protected ReflectiveMethodInvocation(
|
protected ReflectiveMethodInvocation(
|
||||||
Object proxy, Object target, Method method, Object[] arguments,
|
Object proxy, @Nullable Object target, Method method, Object[] arguments,
|
||||||
Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers) {
|
@Nullable Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers) {
|
||||||
|
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
@ -152,6 +152,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object proceed() throws Throwable {
|
public Object proceed() throws Throwable {
|
||||||
// We start with an index of -1 and increment early.
|
// We start with an index of -1 and increment early.
|
||||||
if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) {
|
if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) {
|
||||||
|
@ -187,6 +188,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||||
* @return the return value of the joinpoint
|
* @return the return value of the joinpoint
|
||||||
* @throws Throwable if invoking the joinpoint resulted in an exception
|
* @throws Throwable if invoking the joinpoint resulted in an exception
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
protected Object invokeJoinpoint() throws Throwable {
|
protected Object invokeJoinpoint() throws Throwable {
|
||||||
return AopUtils.invokeJoinpointUsingReflection(this.target, this.method, this.arguments);
|
return AopUtils.invokeJoinpointUsingReflection(this.target, this.method, this.arguments);
|
||||||
}
|
}
|
||||||
|
@ -220,7 +222,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
|
||||||
* @see java.lang.Object#clone()
|
* @see java.lang.Object#clone()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MethodInvocation invocableClone(Object... arguments) {
|
public MethodInvocation invocableClone(@Nullable Object... arguments) {
|
||||||
// Force initialization of the user attributes Map,
|
// Force initialization of the user attributes Map,
|
||||||
// for having a shared Map reference in the clone.
|
// for having a shared Map reference in the clone.
|
||||||
if (this.userAttributes == null) {
|
if (this.userAttributes == null) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -27,6 +27,7 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.aop.AfterAdvice;
|
import org.springframework.aop.AfterAdvice;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,6 +104,7 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
|
||||||
* @param exception the exception thrown
|
* @param exception the exception thrown
|
||||||
* @return a handler for the given exception type
|
* @return a handler for the given exception type
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
private Method getExceptionHandler(Throwable exception) {
|
private Method getExceptionHandler(Throwable exception) {
|
||||||
Class<?> exceptionClass = exception.getClass();
|
Class<?> exceptionClass = exception.getClass();
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -238,7 +238,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
|
public Object postProcessBeforeInstantiation(Class<?> beanClass, @Nullable String beanName) throws BeansException {
|
||||||
Object cacheKey = getCacheKey(beanClass, beanName);
|
Object cacheKey = getCacheKey(beanClass, beanName);
|
||||||
|
|
||||||
if (beanName == null || !this.targetSourcedBeans.contains(beanName)) {
|
if (beanName == null || !this.targetSourcedBeans.contains(beanName)) {
|
||||||
|
@ -291,7 +291,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
* @see #getAdvicesAndAdvisorsForBean
|
* @see #getAdvicesAndAdvisorsForBean
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
public Object postProcessAfterInitialization(@Nullable Object bean, String beanName) throws BeansException {
|
||||||
if (bean != null) {
|
if (bean != null) {
|
||||||
Object cacheKey = getCacheKey(bean.getClass(), beanName);
|
Object cacheKey = getCacheKey(bean.getClass(), beanName);
|
||||||
if (!this.earlyProxyReferences.contains(cacheKey)) {
|
if (!this.earlyProxyReferences.contains(cacheKey)) {
|
||||||
|
@ -313,7 +313,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
* @param beanName the bean name
|
* @param beanName the bean name
|
||||||
* @return the cache key for the given class and name
|
* @return the cache key for the given class and name
|
||||||
*/
|
*/
|
||||||
protected Object getCacheKey(Class<?> beanClass, String beanName) {
|
protected Object getCacheKey(Class<?> beanClass, @Nullable String beanName) {
|
||||||
if (StringUtils.hasLength(beanName)) {
|
if (StringUtils.hasLength(beanName)) {
|
||||||
return (FactoryBean.class.isAssignableFrom(beanClass) ?
|
return (FactoryBean.class.isAssignableFrom(beanClass) ?
|
||||||
BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName);
|
BeanFactory.FACTORY_BEAN_PREFIX + beanName : beanName);
|
||||||
|
@ -330,7 +330,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
* @param cacheKey the cache key for metadata access
|
* @param cacheKey the cache key for metadata access
|
||||||
* @return a proxy wrapping the bean, or the raw bean instance as-is
|
* @return a proxy wrapping the bean, or the raw bean instance as-is
|
||||||
*/
|
*/
|
||||||
protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
|
protected Object wrapIfNecessary(Object bean, @Nullable String beanName, Object cacheKey) {
|
||||||
if (beanName != null && this.targetSourcedBeans.contains(beanName)) {
|
if (beanName != null && this.targetSourcedBeans.contains(beanName)) {
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
* @param beanName the name of the bean
|
* @param beanName the name of the bean
|
||||||
* @return whether to skip the given bean
|
* @return whether to skip the given bean
|
||||||
*/
|
*/
|
||||||
protected boolean shouldSkip(Class<?> beanClass, String beanName) {
|
protected boolean shouldSkip(Class<?> beanClass, @Nullable String beanName) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,8 +435,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
* @return the AOP proxy for the bean
|
* @return the AOP proxy for the bean
|
||||||
* @see #buildAdvisors
|
* @see #buildAdvisors
|
||||||
*/
|
*/
|
||||||
protected Object createProxy(
|
protected Object createProxy(Class<?> beanClass, @Nullable String beanName,
|
||||||
Class<?> beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource) {
|
@Nullable Object[] specificInterceptors, TargetSource targetSource) {
|
||||||
|
|
||||||
if (this.beanFactory instanceof ConfigurableListableBeanFactory) {
|
if (this.beanFactory instanceof ConfigurableListableBeanFactory) {
|
||||||
AutoProxyUtils.exposeTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName, beanClass);
|
AutoProxyUtils.exposeTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName, beanClass);
|
||||||
|
@ -479,7 +479,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
* @return whether the given bean should be proxied with its target class
|
* @return whether the given bean should be proxied with its target class
|
||||||
* @see AutoProxyUtils#shouldProxyTargetClass
|
* @see AutoProxyUtils#shouldProxyTargetClass
|
||||||
*/
|
*/
|
||||||
protected boolean shouldProxyTargetClass(Class<?> beanClass, String beanName) {
|
protected boolean shouldProxyTargetClass(Class<?> beanClass, @Nullable String beanName) {
|
||||||
return (this.beanFactory instanceof ConfigurableListableBeanFactory &&
|
return (this.beanFactory instanceof ConfigurableListableBeanFactory &&
|
||||||
AutoProxyUtils.shouldProxyTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName));
|
AutoProxyUtils.shouldProxyTargetClass((ConfigurableListableBeanFactory) this.beanFactory, beanName));
|
||||||
}
|
}
|
||||||
|
@ -506,7 +506,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
* specific to this bean (may be empty, but not null)
|
* specific to this bean (may be empty, but not null)
|
||||||
* @return the list of Advisors for the given bean
|
* @return the list of Advisors for the given bean
|
||||||
*/
|
*/
|
||||||
protected Advisor[] buildAdvisors(String beanName, Object[] specificInterceptors) {
|
protected Advisor[] buildAdvisors(@Nullable String beanName, @Nullable Object[] specificInterceptors) {
|
||||||
// Handle prototypes correctly...
|
// Handle prototypes correctly...
|
||||||
Advisor[] commonInterceptors = resolveInterceptorNames();
|
Advisor[] commonInterceptors = resolveInterceptorNames();
|
||||||
|
|
||||||
|
@ -582,7 +582,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
* @see #PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
|
* @see #PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected abstract Object[] getAdvicesAndAdvisorsForBean(
|
protected abstract Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass,
|
||||||
Class<?> beanClass, String beanName, @Nullable TargetSource customTargetSource) throws BeansException;
|
@Nullable String beanName, @Nullable TargetSource customTargetSource)
|
||||||
|
throws BeansException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -63,7 +63,7 @@ public abstract class AutoProxyUtils {
|
||||||
* @param beanName the name of the bean
|
* @param beanName the name of the bean
|
||||||
* @return whether the given bean should be proxied with its target class
|
* @return whether the given bean should be proxied with its target class
|
||||||
*/
|
*/
|
||||||
public static boolean shouldProxyTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
|
public static boolean shouldProxyTargetClass(ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {
|
||||||
if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
|
if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
|
||||||
BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
|
BeanDefinition bd = beanFactory.getBeanDefinition(beanName);
|
||||||
return Boolean.TRUE.equals(bd.getAttribute(PRESERVE_TARGET_CLASS_ATTRIBUTE));
|
return Boolean.TRUE.equals(bd.getAttribute(PRESERVE_TARGET_CLASS_ATTRIBUTE));
|
||||||
|
@ -81,7 +81,7 @@ public abstract class AutoProxyUtils {
|
||||||
* @see org.springframework.beans.factory.BeanFactory#getType(String)
|
* @see org.springframework.beans.factory.BeanFactory#getType(String)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Class<?> determineTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName) {
|
public static Class<?> determineTargetClass(ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) {
|
||||||
if (beanName == null) {
|
if (beanName == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,9 @@ public abstract class AutoProxyUtils {
|
||||||
* @param targetClass the corresponding target class
|
* @param targetClass the corresponding target class
|
||||||
* @since 4.2.3
|
* @since 4.2.3
|
||||||
*/
|
*/
|
||||||
static void exposeTargetClass(ConfigurableListableBeanFactory beanFactory, String beanName, Class<?> targetClass) {
|
static void exposeTargetClass(ConfigurableListableBeanFactory beanFactory, @Nullable String beanName,
|
||||||
|
Class<?> targetClass) {
|
||||||
|
|
||||||
if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
|
if (beanName != null && beanFactory.containsBeanDefinition(beanName)) {
|
||||||
beanFactory.getMergedBeanDefinition(beanName).setAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE, targetClass);
|
beanFactory.getMergedBeanDefinition(beanName).setAttribute(ORIGINAL_TARGET_CLASS_ATTRIBUTE, targetClass);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -20,6 +20,8 @@ import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for monitoring interceptors, such as performance monitors.
|
* Base class for monitoring interceptors, such as performance monitors.
|
||||||
* Provides {@code prefix} and {@code suffix} properties
|
* Provides {@code prefix} and {@code suffix} properties
|
||||||
|
@ -50,7 +52,7 @@ public abstract class AbstractMonitoringInterceptor extends AbstractTraceInterce
|
||||||
* Set the text that will get appended to the trace data.
|
* Set the text that will get appended to the trace data.
|
||||||
* <p>Default is none.
|
* <p>Default is none.
|
||||||
*/
|
*/
|
||||||
public void setPrefix(String prefix) {
|
public void setPrefix(@Nullable String prefix) {
|
||||||
this.prefix = (prefix != null ? prefix : "");
|
this.prefix = (prefix != null ? prefix : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +67,7 @@ public abstract class AbstractMonitoringInterceptor extends AbstractTraceInterce
|
||||||
* Set the text that will get prepended to the trace data.
|
* Set the text that will get prepended to the trace data.
|
||||||
* <p>Default is none.
|
* <p>Default is none.
|
||||||
*/
|
*/
|
||||||
public void setSuffix(String suffix) {
|
public void setSuffix(@Nullable String suffix) {
|
||||||
this.suffix = (suffix != null ? suffix : "");
|
this.suffix = (suffix != null ? suffix : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
||||||
* executor has been requested via a qualifier on the async method, in which case the
|
* executor has been requested via a qualifier on the async method, in which case the
|
||||||
* executor will be looked up at invocation time against the enclosing bean factory
|
* executor will be looked up at invocation time against the enclosing bean factory
|
||||||
*/
|
*/
|
||||||
public AsyncExecutionAspectSupport(Executor defaultExecutor) {
|
public AsyncExecutionAspectSupport(@Nullable Executor defaultExecutor) {
|
||||||
this(defaultExecutor, new SimpleAsyncUncaughtExceptionHandler());
|
this(defaultExecutor, new SimpleAsyncUncaughtExceptionHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
||||||
* executor will be looked up at invocation time against the enclosing bean factory
|
* executor will be looked up at invocation time against the enclosing bean factory
|
||||||
* @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use
|
* @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use
|
||||||
*/
|
*/
|
||||||
public AsyncExecutionAspectSupport(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
|
public AsyncExecutionAspectSupport(@Nullable Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
|
||||||
this.defaultExecutor = defaultExecutor;
|
this.defaultExecutor = defaultExecutor;
|
||||||
this.exceptionHandler = exceptionHandler;
|
this.exceptionHandler = exceptionHandler;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
||||||
* @see #getExecutorQualifier(Method)
|
* @see #getExecutorQualifier(Method)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected Executor findQualifiedExecutor(BeanFactory beanFactory, String qualifier) {
|
protected Executor findQualifiedExecutor(@Nullable BeanFactory beanFactory, String qualifier) {
|
||||||
if (beanFactory == null) {
|
if (beanFactory == null) {
|
||||||
throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
|
throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() +
|
||||||
" to access qualified executor '" + qualifier + "'");
|
" to access qualified executor '" + qualifier + "'");
|
||||||
|
@ -217,7 +217,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware {
|
||||||
* @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME
|
* @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected Executor getDefaultExecutor(BeanFactory beanFactory) {
|
protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) {
|
||||||
if (beanFactory != null) {
|
if (beanFactory != null) {
|
||||||
try {
|
try {
|
||||||
// Search for TaskExecutor bean... not plain Executor since that would
|
// Search for TaskExecutor bean... not plain Executor since that would
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -31,6 +31,7 @@ import org.springframework.core.BridgeMethodResolver;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.task.AsyncTaskExecutor;
|
import org.springframework.core.task.AsyncTaskExecutor;
|
||||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +74,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
|
||||||
* or {@link java.util.concurrent.ExecutorService}) to delegate to;
|
* or {@link java.util.concurrent.ExecutorService}) to delegate to;
|
||||||
* as of 4.2.6, a local executor for this interceptor will be built otherwise
|
* as of 4.2.6, a local executor for this interceptor will be built otherwise
|
||||||
*/
|
*/
|
||||||
public AsyncExecutionInterceptor(Executor defaultExecutor) {
|
public AsyncExecutionInterceptor(@Nullable Executor defaultExecutor) {
|
||||||
super(defaultExecutor);
|
super(defaultExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple
|
||||||
* as of 4.2.6, a local executor for this interceptor will be built otherwise
|
* as of 4.2.6, a local executor for this interceptor will be built otherwise
|
||||||
* @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use
|
* @param exceptionHandler the {@link AsyncUncaughtExceptionHandler} to use
|
||||||
*/
|
*/
|
||||||
public AsyncExecutionInterceptor(Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
|
public AsyncExecutionInterceptor(@Nullable Executor defaultExecutor, AsyncUncaughtExceptionHandler exceptionHandler) {
|
||||||
super(defaultExecutor, exceptionHandler);
|
super(defaultExecutor, exceptionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -292,7 +292,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
|
||||||
* at {@code TRACE} level. Sub-classes can override this method
|
* at {@code TRACE} level. Sub-classes can override this method
|
||||||
* to control which level the message is written at.
|
* to control which level the message is written at.
|
||||||
*/
|
*/
|
||||||
protected void writeToLog(Log logger, String message, Throwable ex) {
|
protected void writeToLog(Log logger, String message, @Nullable Throwable ex) {
|
||||||
if (ex != null) {
|
if (ex != null) {
|
||||||
logger.trace(message, ex);
|
logger.trace(message, ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -22,6 +22,7 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for creating a scoped proxy.
|
* Utility class for creating a scoped proxy.
|
||||||
|
@ -102,7 +103,7 @@ public abstract class ScopedProxyUtils {
|
||||||
* bean within a scoped proxy.
|
* bean within a scoped proxy.
|
||||||
* @since 4.1.4
|
* @since 4.1.4
|
||||||
*/
|
*/
|
||||||
public static boolean isScopedTarget(String beanName) {
|
public static boolean isScopedTarget(@Nullable String beanName) {
|
||||||
return (beanName != null && beanName.startsWith(TARGET_NAME_PREFIX));
|
return (beanName != null && beanName.startsWith(TARGET_NAME_PREFIX));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -101,11 +101,13 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu
|
||||||
@Override
|
@Override
|
||||||
public Advice getAdvice() {
|
public Advice getAdvice() {
|
||||||
Advice advice = this.advice;
|
Advice advice = this.advice;
|
||||||
if (advice != null || this.adviceBeanName == null) {
|
if (advice != null) {
|
||||||
return advice;
|
return advice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Assert.state(this.adviceBeanName != null, "'adviceBeanName' must be specified");
|
||||||
Assert.state(this.beanFactory != null, "BeanFactory must be set to resolve 'adviceBeanName'");
|
Assert.state(this.beanFactory != null, "BeanFactory must be set to resolve 'adviceBeanName'");
|
||||||
|
|
||||||
if (this.beanFactory.isSingleton(this.adviceBeanName)) {
|
if (this.beanFactory.isSingleton(this.adviceBeanName)) {
|
||||||
// Rely on singleton semantics provided by the factory.
|
// Rely on singleton semantics provided by the factory.
|
||||||
advice = this.beanFactory.getBean(this.adviceBeanName, Advice.class);
|
advice = this.beanFactory.getBean(this.adviceBeanName, Advice.class);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -127,7 +127,10 @@ public abstract class AopUtils {
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
* @see MethodIntrospector#selectInvocableMethod(Method, Class)
|
* @see MethodIntrospector#selectInvocableMethod(Method, Class)
|
||||||
*/
|
*/
|
||||||
public static Method selectInvocableMethod(Method method, Class<?> targetType) {
|
public static Method selectInvocableMethod(Method method, @Nullable Class<?> targetType) {
|
||||||
|
if (targetType == null) {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
Method methodToUse = MethodIntrospector.selectInvocableMethod(method, targetType);
|
Method methodToUse = MethodIntrospector.selectInvocableMethod(method, targetType);
|
||||||
if (Modifier.isPrivate(methodToUse.getModifiers()) && !Modifier.isStatic(methodToUse.getModifiers()) &&
|
if (Modifier.isPrivate(methodToUse.getModifiers()) && !Modifier.isStatic(methodToUse.getModifiers()) &&
|
||||||
SpringProxy.class.isAssignableFrom(targetType)) {
|
SpringProxy.class.isAssignableFrom(targetType)) {
|
||||||
|
@ -143,7 +146,7 @@ public abstract class AopUtils {
|
||||||
* Determine whether the given method is an "equals" method.
|
* Determine whether the given method is an "equals" method.
|
||||||
* @see java.lang.Object#equals
|
* @see java.lang.Object#equals
|
||||||
*/
|
*/
|
||||||
public static boolean isEqualsMethod(Method method) {
|
public static boolean isEqualsMethod(@Nullable Method method) {
|
||||||
return ReflectionUtils.isEqualsMethod(method);
|
return ReflectionUtils.isEqualsMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +154,7 @@ public abstract class AopUtils {
|
||||||
* Determine whether the given method is a "hashCode" method.
|
* Determine whether the given method is a "hashCode" method.
|
||||||
* @see java.lang.Object#hashCode
|
* @see java.lang.Object#hashCode
|
||||||
*/
|
*/
|
||||||
public static boolean isHashCodeMethod(Method method) {
|
public static boolean isHashCodeMethod(@Nullable Method method) {
|
||||||
return ReflectionUtils.isHashCodeMethod(method);
|
return ReflectionUtils.isHashCodeMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +162,7 @@ public abstract class AopUtils {
|
||||||
* Determine whether the given method is a "toString" method.
|
* Determine whether the given method is a "toString" method.
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
public static boolean isToStringMethod(Method method) {
|
public static boolean isToStringMethod(@Nullable Method method) {
|
||||||
return ReflectionUtils.isToStringMethod(method);
|
return ReflectionUtils.isToStringMethod(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +170,7 @@ public abstract class AopUtils {
|
||||||
* Determine whether the given method is a "finalize" method.
|
* Determine whether the given method is a "finalize" method.
|
||||||
* @see java.lang.Object#finalize()
|
* @see java.lang.Object#finalize()
|
||||||
*/
|
*/
|
||||||
public static boolean isFinalizeMethod(Method method) {
|
public static boolean isFinalizeMethod(@Nullable Method method) {
|
||||||
return (method != null && method.getName().equals("finalize") &&
|
return (method != null && method.getName().equals("finalize") &&
|
||||||
method.getParameterCount() == 0);
|
method.getParameterCount() == 0);
|
||||||
}
|
}
|
||||||
|
@ -326,7 +329,7 @@ public abstract class AopUtils {
|
||||||
* @throws org.springframework.aop.AopInvocationException in case of a reflection error
|
* @throws org.springframework.aop.AopInvocationException in case of a reflection error
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Object invokeJoinpointUsingReflection(Object target, Method method, Object[] args)
|
public static Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, Object[] args)
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
|
|
||||||
// Use reflection to invoke the method.
|
// Use reflection to invoke the method.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.aop.support;
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
import org.springframework.aop.Pointcut;
|
import org.springframework.aop.Pointcut;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Concrete BeanFactory-based PointcutAdvisor that allows for any Advice
|
* Concrete BeanFactory-based PointcutAdvisor that allows for any Advice
|
||||||
|
@ -43,7 +44,7 @@ public class DefaultBeanFactoryPointcutAdvisor extends AbstractBeanFactoryPointc
|
||||||
* <p>Default is {@code Pointcut.TRUE}.
|
* <p>Default is {@code Pointcut.TRUE}.
|
||||||
* @see #setAdviceBeanName
|
* @see #setAdviceBeanName
|
||||||
*/
|
*/
|
||||||
public void setPointcut(Pointcut pointcut) {
|
public void setPointcut(@Nullable Pointcut pointcut) {
|
||||||
this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
|
this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -21,6 +21,7 @@ import java.io.Serializable;
|
||||||
import org.aopalliance.aop.Advice;
|
import org.aopalliance.aop.Advice;
|
||||||
|
|
||||||
import org.springframework.aop.Pointcut;
|
import org.springframework.aop.Pointcut;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenient Pointcut-driven Advisor implementation.
|
* Convenient Pointcut-driven Advisor implementation.
|
||||||
|
@ -73,7 +74,7 @@ public class DefaultPointcutAdvisor extends AbstractGenericPointcutAdvisor imple
|
||||||
* <p>Default is {@code Pointcut.TRUE}.
|
* <p>Default is {@code Pointcut.TRUE}.
|
||||||
* @see #setAdvice
|
* @see #setAdvice
|
||||||
*/
|
*/
|
||||||
public void setPointcut(Pointcut pointcut) {
|
public void setPointcut(@Nullable Pointcut pointcut) {
|
||||||
this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
|
this.pointcut = (pointcut != null ? pointcut : Pointcut.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.aop.support;
|
package org.springframework.aop.support;
|
||||||
|
|
||||||
import org.springframework.aop.Pointcut;
|
import org.springframework.aop.Pointcut;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to be implemented by pointcuts that use String expressions.
|
* Interface to be implemented by pointcuts that use String expressions.
|
||||||
|
@ -29,6 +30,7 @@ public interface ExpressionPointcut extends Pointcut {
|
||||||
/**
|
/**
|
||||||
* Return the String expression for this pointcut.
|
* Return the String expression for this pointcut.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
String getExpression();
|
String getExpression();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -125,11 +125,11 @@ public abstract class MethodMatchers {
|
||||||
(matchesClass2(targetClass) && this.mm2.matches(method, targetClass));
|
(matchesClass2(targetClass) && this.mm2.matches(method, targetClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean matchesClass1(Class<?> targetClass) {
|
protected boolean matchesClass1(@Nullable Class<?> targetClass) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean matchesClass2(Class<?> targetClass) {
|
protected boolean matchesClass2(@Nullable Class<?> targetClass) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,13 +183,13 @@ public abstract class MethodMatchers {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesClass1(Class<?> targetClass) {
|
protected boolean matchesClass1(@Nullable Class<?> targetClass) {
|
||||||
return this.cf1.matches(targetClass);
|
return (targetClass != null && this.cf1.matches(targetClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean matchesClass2(Class<?> targetClass) {
|
protected boolean matchesClass2(@Nullable Class<?> targetClass) {
|
||||||
return this.cf2.matches(targetClass);
|
return (targetClass != null && this.cf2.matches(targetClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -56,7 +56,7 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
|
||||||
* Matching will be the union of all these; if any match,
|
* Matching will be the union of all these; if any match,
|
||||||
* the pointcut matches.
|
* the pointcut matches.
|
||||||
*/
|
*/
|
||||||
public void setMappedNames(String... mappedNames) {
|
public void setMappedNames(@Nullable String... mappedNames) {
|
||||||
this.mappedNames = new LinkedList<>();
|
this.mappedNames = new LinkedList<>();
|
||||||
if (mappedNames != null) {
|
if (mappedNames != null) {
|
||||||
this.mappedNames.addAll(Arrays.asList(mappedNames));
|
this.mappedNames.addAll(Arrays.asList(mappedNames));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -21,7 +21,6 @@ import java.io.Serializable;
|
||||||
import org.aopalliance.aop.Advice;
|
import org.aopalliance.aop.Advice;
|
||||||
|
|
||||||
import org.springframework.aop.Pointcut;
|
import org.springframework.aop.Pointcut;
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,7 +132,6 @@ public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor
|
||||||
* will be used.
|
* will be used.
|
||||||
* @return the Pointcut instance (never {@code null})
|
* @return the Pointcut instance (never {@code null})
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
protected AbstractRegexpMethodPointcut createPointcut() {
|
protected AbstractRegexpMethodPointcut createPointcut() {
|
||||||
return new JdkRegexpMethodPointcut();
|
return new JdkRegexpMethodPointcut();
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,8 @@ public class AnnotationMatchingPointcut implements Pointcut {
|
||||||
* @param methodAnnotationType the annotation type to look for at the method level
|
* @param methodAnnotationType the annotation type to look for at the method level
|
||||||
* (can be {@code null})
|
* (can be {@code null})
|
||||||
*/
|
*/
|
||||||
public AnnotationMatchingPointcut(
|
public AnnotationMatchingPointcut(@Nullable Class<? extends Annotation> classAnnotationType,
|
||||||
@Nullable Class<? extends Annotation> classAnnotationType, @Nullable Class<? extends Annotation> methodAnnotationType) {
|
@Nullable Class<? extends Annotation> methodAnnotationType) {
|
||||||
|
|
||||||
this(classAnnotationType, methodAnnotationType, false);
|
this(classAnnotationType, methodAnnotationType, false);
|
||||||
}
|
}
|
||||||
|
@ -87,8 +87,8 @@ public class AnnotationMatchingPointcut implements Pointcut {
|
||||||
* @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
|
* @see AnnotationClassFilter#AnnotationClassFilter(Class, boolean)
|
||||||
* @see AnnotationMethodMatcher#AnnotationMethodMatcher(Class, boolean)
|
* @see AnnotationMethodMatcher#AnnotationMethodMatcher(Class, boolean)
|
||||||
*/
|
*/
|
||||||
public AnnotationMatchingPointcut(Class<? extends Annotation> classAnnotationType,
|
public AnnotationMatchingPointcut(@Nullable Class<? extends Annotation> classAnnotationType,
|
||||||
Class<? extends Annotation> methodAnnotationType, boolean checkInherited) {
|
@Nullable Class<? extends Annotation> methodAnnotationType, boolean checkInherited) {
|
||||||
|
|
||||||
Assert.isTrue((classAnnotationType != null || methodAnnotationType != null),
|
Assert.isTrue((classAnnotationType != null || methodAnnotationType != null),
|
||||||
"Either Class annotation type or Method annotation type needs to be specified (or both)");
|
"Either Class annotation type or Method annotation type needs to be specified (or both)");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.aop.TargetSource;
|
import org.springframework.aop.TargetSource;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.BeanFactoryAware;
|
import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,9 +130,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
|
||||||
logger.trace("Getting bean with name '" + this.targetBeanName + "' in order to determine type");
|
logger.trace("Getting bean with name '" + this.targetBeanName + "' in order to determine type");
|
||||||
}
|
}
|
||||||
Object beanInstance = this.beanFactory.getBean(this.targetBeanName);
|
Object beanInstance = this.beanFactory.getBean(this.targetBeanName);
|
||||||
if (beanInstance != null) {
|
this.targetClass = beanInstance.getClass();
|
||||||
this.targetClass = beanInstance.getClass();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.targetClass;
|
return this.targetClass;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
<cache:annotation-driven mode="aspectj" key-generator="keyGenerator"/>
|
<cache:annotation-driven mode="aspectj" key-generator="keyGenerator"/>
|
||||||
|
|
||||||
<bean id="keyGenerator" class="org.springframework.cache.config.SomeKeyGenerator" />
|
<bean id="keyGenerator" class="org.springframework.cache.config.SomeKeyGenerator"/>
|
||||||
|
|
||||||
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
|
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
|
||||||
<property name="caches">
|
<property name="caches">
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="customKeyGenerator" class="org.springframework.cache.config.SomeCustomKeyGenerator" />
|
<bean id="customKeyGenerator" class="org.springframework.cache.config.SomeCustomKeyGenerator"/>
|
||||||
|
|
||||||
<bean id="customCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
|
<bean id="customCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
|
||||||
<property name="caches">
|
<property name="caches">
|
||||||
|
@ -55,6 +55,7 @@
|
||||||
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor"/>
|
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor"/>
|
||||||
|
|
||||||
<bean id="service" class="org.springframework.cache.config.DefaultCacheableService"/>
|
<bean id="service" class="org.springframework.cache.config.DefaultCacheableService"/>
|
||||||
|
|
||||||
<bean id="classService" class="org.springframework.cache.config.AnnotatedClassCacheableService"/>
|
<bean id="classService" class="org.springframework.cache.config.AnnotatedClassCacheableService"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -257,7 +257,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||||
|
|
||||||
int countBefore = getRegistry().getBeanDefinitionCount();
|
int countBefore = getRegistry().getBeanDefinitionCount();
|
||||||
try {
|
try {
|
||||||
GroovyShell shell = new GroovyShell(getResourceLoader().getClassLoader(), binding);
|
GroovyShell shell = new GroovyShell(getBeanClassLoader(), binding);
|
||||||
shell.evaluate(encodedResource.getReader(), "beans");
|
shell.evaluate(encodedResource.getReader(), "beans");
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -56,10 +56,10 @@ import org.springframework.util.StringUtils;
|
||||||
* as String arrays are converted in such a format if the array itself is not
|
* as String arrays are converted in such a format if the array itself is not
|
||||||
* assignable.
|
* assignable.
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Rob Harrop
|
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Rod Johnson
|
||||||
|
* @author Rob Harrop
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
* @see #registerCustomEditor
|
* @see #registerCustomEditor
|
||||||
* @see #setPropertyValues
|
* @see #setPropertyValues
|
||||||
|
@ -189,7 +189,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
* @param nestedPath the nested path of the object
|
* @param nestedPath the nested path of the object
|
||||||
* @param rootObject the root object at the top of the path
|
* @param rootObject the root object at the top of the path
|
||||||
*/
|
*/
|
||||||
public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
|
public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject) {
|
||||||
this.wrappedObject = ObjectUtils.unwrapOptional(object);
|
this.wrappedObject = ObjectUtils.unwrapOptional(object);
|
||||||
Assert.notNull(this.wrappedObject, "Target object must not be null");
|
Assert.notNull(this.wrappedObject, "Target object must not be null");
|
||||||
this.nestedPath = (nestedPath != null ? nestedPath : "");
|
this.nestedPath = (nestedPath != null ? nestedPath : "");
|
||||||
|
@ -199,11 +199,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Object getWrappedInstance() {
|
public final Object getWrappedInstance() {
|
||||||
|
Assert.state(this.wrappedObject != null, "No wrapped instance");
|
||||||
return this.wrappedObject;
|
return this.wrappedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Class<?> getWrappedClass() {
|
public final Class<?> getWrappedClass() {
|
||||||
return (this.wrappedObject != null ? this.wrappedObject.getClass() : null);
|
return getWrappedInstance().getClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -217,6 +218,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
* Return the root object at the top of the path of this accessor.
|
* Return the root object at the top of the path of this accessor.
|
||||||
* @see #getNestedPath
|
* @see #getNestedPath
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public final Object getRootInstance() {
|
public final Object getRootInstance() {
|
||||||
return this.rootObject;
|
return this.rootObject;
|
||||||
}
|
}
|
||||||
|
@ -226,11 +228,12 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
* @see #getNestedPath
|
* @see #getNestedPath
|
||||||
*/
|
*/
|
||||||
public final Class<?> getRootClass() {
|
public final Class<?> getRootClass() {
|
||||||
return (this.rootObject != null ? this.rootObject.getClass() : null);
|
Assert.state(this.wrappedObject != null, "No root object");
|
||||||
|
return this.rootObject.getClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPropertyValue(String propertyName, Object value) throws BeansException {
|
public void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException {
|
||||||
AbstractNestablePropertyAccessor nestedPa;
|
AbstractNestablePropertyAccessor nestedPa;
|
||||||
try {
|
try {
|
||||||
nestedPa = getPropertyAccessorForPropertyPath(propertyName);
|
nestedPa = getPropertyAccessorForPropertyPath(propertyName);
|
||||||
|
@ -279,10 +282,14 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void processKeyedProperty(PropertyTokenHolder tokens, PropertyValue pv) {
|
private void processKeyedProperty(PropertyTokenHolder tokens, PropertyValue pv) {
|
||||||
Object propValue = getPropertyHoldingValue(tokens);
|
Object propValue = getPropertyHoldingValue(tokens);
|
||||||
|
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
|
||||||
|
if (ph == null) {
|
||||||
|
throw new InvalidPropertyException(
|
||||||
|
getRootClass(), this.nestedPath + tokens.actualName, "No property handler found");
|
||||||
|
}
|
||||||
String lastKey = tokens.keys[tokens.keys.length - 1];
|
String lastKey = tokens.keys[tokens.keys.length - 1];
|
||||||
|
|
||||||
if (propValue.getClass().isArray()) {
|
if (propValue.getClass().isArray()) {
|
||||||
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
|
|
||||||
Class<?> requiredType = propValue.getClass().getComponentType();
|
Class<?> requiredType = propValue.getClass().getComponentType();
|
||||||
int arrayIndex = Integer.parseInt(lastKey);
|
int arrayIndex = Integer.parseInt(lastKey);
|
||||||
Object oldValue = null;
|
Object oldValue = null;
|
||||||
|
@ -309,7 +316,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (propValue instanceof List) {
|
else if (propValue instanceof List) {
|
||||||
PropertyHandler ph = getPropertyHandler(tokens.actualName);
|
|
||||||
Class<?> requiredType = ph.getCollectionType(tokens.keys.length);
|
Class<?> requiredType = ph.getCollectionType(tokens.keys.length);
|
||||||
List<Object> list = (List<Object>) propValue;
|
List<Object> list = (List<Object>) propValue;
|
||||||
int index = Integer.parseInt(lastKey);
|
int index = Integer.parseInt(lastKey);
|
||||||
|
@ -346,7 +352,6 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (propValue instanceof Map) {
|
else if (propValue instanceof Map) {
|
||||||
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
|
|
||||||
Class<?> mapKeyType = ph.getMapKeyType(tokens.keys.length);
|
Class<?> mapKeyType = ph.getMapKeyType(tokens.keys.length);
|
||||||
Class<?> mapValueType = ph.getMapValueType(tokens.keys.length);
|
Class<?> mapValueType = ph.getMapValueType(tokens.keys.length);
|
||||||
Map<Object, Object> map = (Map<Object, Object>) propValue;
|
Map<Object, Object> map = (Map<Object, Object>) propValue;
|
||||||
|
@ -449,7 +454,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
}
|
}
|
||||||
pv.getOriginalPropertyValue().conversionNecessary = (valueToApply != originalValue);
|
pv.getOriginalPropertyValue().conversionNecessary = (valueToApply != originalValue);
|
||||||
}
|
}
|
||||||
ph.setValue(this.wrappedObject, valueToApply);
|
ph.setValue(valueToApply);
|
||||||
}
|
}
|
||||||
catch (TypeMismatchException ex) {
|
catch (TypeMismatchException ex) {
|
||||||
throw ex;
|
throw ex;
|
||||||
|
@ -567,34 +572,29 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue, Class<?> requiredType,
|
@Nullable
|
||||||
TypeDescriptor td) throws TypeMismatchException {
|
private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
|
||||||
|
@Nullable Object newValue, @Nullable Class<?> requiredType, @Nullable TypeDescriptor td)
|
||||||
|
throws TypeMismatchException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, newValue, requiredType, td);
|
return this.typeConverterDelegate.convertIfNecessary(propertyName, oldValue, newValue, requiredType, td);
|
||||||
}
|
}
|
||||||
catch (ConverterNotFoundException ex) {
|
catch (ConverterNotFoundException | IllegalStateException ex) {
|
||||||
PropertyChangeEvent pce =
|
|
||||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
|
||||||
throw new ConversionNotSupportedException(pce, td.getType(), ex);
|
|
||||||
}
|
|
||||||
catch (ConversionException ex) {
|
|
||||||
PropertyChangeEvent pce =
|
|
||||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
|
||||||
throw new TypeMismatchException(pce, requiredType, ex);
|
|
||||||
}
|
|
||||||
catch (IllegalStateException ex) {
|
|
||||||
PropertyChangeEvent pce =
|
PropertyChangeEvent pce =
|
||||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||||
throw new ConversionNotSupportedException(pce, requiredType, ex);
|
throw new ConversionNotSupportedException(pce, requiredType, ex);
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException ex) {
|
catch (ConversionException | IllegalArgumentException ex) {
|
||||||
PropertyChangeEvent pce =
|
PropertyChangeEvent pce =
|
||||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, newValue);
|
||||||
throw new TypeMismatchException(pce, requiredType, ex);
|
throw new TypeMismatchException(pce, requiredType, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object convertForProperty(String propertyName, @Nullable Object oldValue, Object newValue, TypeDescriptor td)
|
@Nullable
|
||||||
|
protected Object convertForProperty(
|
||||||
|
String propertyName, @Nullable Object oldValue, @Nullable Object newValue, TypeDescriptor td)
|
||||||
throws TypeMismatchException {
|
throws TypeMismatchException {
|
||||||
|
|
||||||
return convertIfNecessary(propertyName, oldValue, newValue, td.getType(), td);
|
return convertIfNecessary(propertyName, oldValue, newValue, td.getType(), td);
|
||||||
|
@ -608,6 +608,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@Nullable
|
||||||
protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
|
protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
|
||||||
String propertyName = tokens.canonicalName;
|
String propertyName = tokens.canonicalName;
|
||||||
String actualName = tokens.actualName;
|
String actualName = tokens.actualName;
|
||||||
|
@ -724,10 +725,10 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a {@link PropertyHandler} for the specified local {@code propertyName}. Only
|
* Return a {@link PropertyHandler} for the specified local {@code propertyName}.
|
||||||
* used to reach a property available in the current context.
|
* Only used to reach a property available in the current context.
|
||||||
* @param propertyName the name of a local property
|
* @param propertyName the name of a local property
|
||||||
* @return the handler for that property or {@code null} if it has not been found
|
* @return the handler for that property, or {@code null} if it has not been found
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected abstract PropertyHandler getLocalPropertyHandler(String propertyName);
|
protected abstract PropertyHandler getLocalPropertyHandler(String propertyName);
|
||||||
|
@ -760,7 +761,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
Array.set(newArray, i, newValue(componentType, null, name));
|
Array.set(newArray, i, newValue(componentType, null, name));
|
||||||
}
|
}
|
||||||
setPropertyValue(name, newArray);
|
setPropertyValue(name, newArray);
|
||||||
return getPropertyValue(name);
|
Object defaultValue = getPropertyValue(name);
|
||||||
|
Assert.state(defaultValue != null, "Default value must not be null");
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return array;
|
return array;
|
||||||
|
@ -872,17 +875,18 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
private Object setDefaultValue(PropertyTokenHolder tokens) {
|
private Object setDefaultValue(PropertyTokenHolder tokens) {
|
||||||
PropertyValue pv = createDefaultPropertyValue(tokens);
|
PropertyValue pv = createDefaultPropertyValue(tokens);
|
||||||
setPropertyValue(tokens, pv);
|
setPropertyValue(tokens, pv);
|
||||||
return getPropertyValue(tokens);
|
Object defaultValue = getPropertyValue(tokens);
|
||||||
|
Assert.state(defaultValue != null, "Default value must not be null");
|
||||||
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PropertyValue createDefaultPropertyValue(PropertyTokenHolder tokens) {
|
private PropertyValue createDefaultPropertyValue(PropertyTokenHolder tokens) {
|
||||||
TypeDescriptor desc = getPropertyTypeDescriptor(tokens.canonicalName);
|
TypeDescriptor desc = getPropertyTypeDescriptor(tokens.canonicalName);
|
||||||
Class<?> type = desc.getType();
|
if (desc == null) {
|
||||||
if (type == null) {
|
|
||||||
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + tokens.canonicalName,
|
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + tokens.canonicalName,
|
||||||
"Could not determine property type for auto-growing a default value");
|
"Could not determine property type for auto-growing a default value");
|
||||||
}
|
}
|
||||||
Object defaultValue = newValue(type, desc, tokens.canonicalName);
|
Object defaultValue = newValue(desc.getType(), desc, tokens.canonicalName);
|
||||||
return new PropertyValue(tokens.canonicalName, defaultValue);
|
return new PropertyValue(tokens.canonicalName, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1005,24 +1009,28 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
||||||
|
|
||||||
public abstract ResolvableType getResolvableType();
|
public abstract ResolvableType getResolvableType();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Class<?> getMapKeyType(int nestingLevel) {
|
public Class<?> getMapKeyType(int nestingLevel) {
|
||||||
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(0);
|
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Class<?> getMapValueType(int nestingLevel) {
|
public Class<?> getMapValueType(int nestingLevel) {
|
||||||
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(1);
|
return getResolvableType().getNested(nestingLevel).asMap().resolveGeneric(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Class<?> getCollectionType(int nestingLevel) {
|
public Class<?> getCollectionType(int nestingLevel) {
|
||||||
return getResolvableType().getNested(nestingLevel).asCollection().resolveGeneric();
|
return getResolvableType().getNested(nestingLevel).asCollection().resolveGeneric();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public abstract TypeDescriptor nested(int level);
|
public abstract TypeDescriptor nested(int level);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract Object getValue() throws Exception;
|
public abstract Object getValue() throws Exception;
|
||||||
|
|
||||||
public abstract void setValue(Object object, Object value) throws Exception;
|
public abstract void setValue(@Nullable Object value) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -21,6 +21,8 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract implementation of the {@link PropertyAccessor} interface.
|
* Abstract implementation of the {@link PropertyAccessor} interface.
|
||||||
* Provides base implementations of all convenience methods, with the
|
* Provides base implementations of all convenience methods, with the
|
||||||
|
@ -151,6 +153,6 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
|
||||||
* accessor method failed or a type mismatch occurred
|
* accessor method failed or a type mismatch occurred
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public abstract void setPropertyValue(String propertyName, Object value) throws BeansException;
|
public abstract void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -53,7 +53,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
||||||
* @param msg the detail message
|
* @param msg the detail message
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
*/
|
*/
|
||||||
public BeanInstantiationException(Class<?> beanClass, String msg, Throwable cause) {
|
public BeanInstantiationException(Class<?> beanClass, String msg, @Nullable Throwable cause) {
|
||||||
super("Failed to instantiate [" + beanClass.getName() + "]: " + msg, cause);
|
super("Failed to instantiate [" + beanClass.getName() + "]: " + msg, cause);
|
||||||
this.beanClass = beanClass;
|
this.beanClass = beanClass;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
public BeanInstantiationException(Constructor<?> constructor, String msg, Throwable cause) {
|
public BeanInstantiationException(Constructor<?> constructor, String msg, @Nullable Throwable cause) {
|
||||||
super("Failed to instantiate [" + constructor.getDeclaringClass().getName() + "]: " + msg, cause);
|
super("Failed to instantiate [" + constructor.getDeclaringClass().getName() + "]: " + msg, cause);
|
||||||
this.beanClass = constructor.getDeclaringClass();
|
this.beanClass = constructor.getDeclaringClass();
|
||||||
this.constructor = constructor;
|
this.constructor = constructor;
|
||||||
|
@ -79,7 +79,7 @@ public class BeanInstantiationException extends FatalBeanException {
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
public BeanInstantiationException(Method constructingMethod, String msg, Throwable cause) {
|
public BeanInstantiationException(Method constructingMethod, String msg, @Nullable Throwable cause) {
|
||||||
super("Failed to instantiate [" + constructingMethod.getReturnType().getName() + "]: " + msg, cause);
|
super("Failed to instantiate [" + constructingMethod.getReturnType().getName() + "]: " + msg, cause);
|
||||||
this.beanClass = constructingMethod.getReturnType();
|
this.beanClass = constructingMethod.getReturnType();
|
||||||
this.constructingMethod = constructingMethod;
|
this.constructingMethod = constructingMethod;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.beans;
|
package org.springframework.beans;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
|
||||||
* @param name the name of the attribute (never {@code null})
|
* @param name the name of the attribute (never {@code null})
|
||||||
* @param value the value of the attribute (possibly before type conversion)
|
* @param value the value of the attribute (possibly before type conversion)
|
||||||
*/
|
*/
|
||||||
public BeanMetadataAttribute(String name, Object value) {
|
public BeanMetadataAttribute(String name, @Nullable Object value) {
|
||||||
Assert.notNull(name, "Name must not be null");
|
Assert.notNull(name, "Name must not be null");
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -65,7 +66,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
|
||||||
* Set the configuration source {@code Object} for this metadata element.
|
* Set the configuration source {@code Object} for this metadata element.
|
||||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||||
*/
|
*/
|
||||||
public void setSource(Object source) {
|
public void setSource(@Nullable Object source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
|
||||||
* Set the configuration source {@code Object} for this metadata element.
|
* Set the configuration source {@code Object} for this metadata element.
|
||||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||||
*/
|
*/
|
||||||
public void setSource(Object source) {
|
public void setSource(@Nullable Object source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -426,7 +426,7 @@ public abstract class BeanUtils {
|
||||||
* @return the corresponding editor, or {@code null} if none found
|
* @return the corresponding editor, or {@code null} if none found
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static PropertyEditor findEditorByConvention(Class<?> targetType) {
|
public static PropertyEditor findEditorByConvention(@Nullable Class<?> targetType) {
|
||||||
if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) {
|
if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -476,7 +476,7 @@ public abstract class BeanUtils {
|
||||||
* @param beanClasses the classes to check against
|
* @param beanClasses the classes to check against
|
||||||
* @return the property type, or {@code Object.class} as fallback
|
* @return the property type, or {@code Object.class} as fallback
|
||||||
*/
|
*/
|
||||||
public static Class<?> findPropertyType(String propertyName, Class<?>... beanClasses) {
|
public static Class<?> findPropertyType(String propertyName, @Nullable Class<?>... beanClasses) {
|
||||||
if (beanClasses != null) {
|
if (beanClasses != null) {
|
||||||
for (Class<?> beanClass : beanClasses) {
|
for (Class<?> beanClass : beanClasses) {
|
||||||
PropertyDescriptor pd = getPropertyDescriptor(beanClass, propertyName);
|
PropertyDescriptor pd = getPropertyDescriptor(beanClass, propertyName);
|
||||||
|
@ -599,8 +599,8 @@ public abstract class BeanUtils {
|
||||||
* @throws BeansException if the copying failed
|
* @throws BeansException if the copying failed
|
||||||
* @see BeanWrapper
|
* @see BeanWrapper
|
||||||
*/
|
*/
|
||||||
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable, String... ignoreProperties)
|
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable,
|
||||||
throws BeansException {
|
@Nullable String... ignoreProperties) throws BeansException {
|
||||||
|
|
||||||
Assert.notNull(source, "Source must not be null");
|
Assert.notNull(source, "Source must not be null");
|
||||||
Assert.notNull(target, "Target must not be null");
|
Assert.notNull(target, "Target must not be null");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -18,8 +18,6 @@ package org.springframework.beans;
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The central interface of Spring's low-level JavaBeans infrastructure.
|
* The central interface of Spring's low-level JavaBeans infrastructure.
|
||||||
*
|
*
|
||||||
|
@ -64,18 +62,13 @@ public interface BeanWrapper extends ConfigurablePropertyAccessor {
|
||||||
int getAutoGrowCollectionLimit();
|
int getAutoGrowCollectionLimit();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the bean instance wrapped by this object, if any.
|
* Return the bean instance wrapped by this object.
|
||||||
* @return the bean instance, or {@code null} if none set
|
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
Object getWrappedInstance();
|
Object getWrappedInstance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the type of the wrapped JavaBean object.
|
* Return the type of the wrapped bean instance.
|
||||||
* @return the type of the wrapped bean instance,
|
|
||||||
* or {@code null} if no wrapped object has been set
|
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
Class<?> getWrappedClass();
|
Class<?> getWrappedClass();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -18,7 +18,6 @@ package org.springframework.beans;
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.security.AccessControlContext;
|
import java.security.AccessControlContext;
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
|
@ -29,7 +28,7 @@ import org.springframework.core.ResolvableType;
|
||||||
import org.springframework.core.convert.Property;
|
import org.springframework.core.convert.Property;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default {@link BeanWrapper} implementation that should be sufficient
|
* Default {@link BeanWrapper} implementation that should be sufficient
|
||||||
|
@ -148,7 +147,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setWrappedInstance(Object object, String nestedPath, @Nullable Object rootObject) {
|
public void setWrappedInstance(Object object, @Nullable String nestedPath, @Nullable Object rootObject) {
|
||||||
super.setWrappedInstance(object, nestedPath, rootObject);
|
super.setWrappedInstance(object, nestedPath, rootObject);
|
||||||
setIntrospectionClass(getWrappedClass());
|
setIntrospectionClass(getWrappedClass());
|
||||||
}
|
}
|
||||||
|
@ -169,7 +168,6 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
||||||
* for the wrapped object.
|
* for the wrapped object.
|
||||||
*/
|
*/
|
||||||
private CachedIntrospectionResults getCachedIntrospectionResults() {
|
private CachedIntrospectionResults getCachedIntrospectionResults() {
|
||||||
Assert.state(getWrappedInstance() != null, "BeanWrapper does not hold a bean instance");
|
|
||||||
if (this.cachedIntrospectionResults == null) {
|
if (this.cachedIntrospectionResults == null) {
|
||||||
this.cachedIntrospectionResults = CachedIntrospectionResults.forClass(getWrappedClass());
|
this.cachedIntrospectionResults = CachedIntrospectionResults.forClass(getWrappedClass());
|
||||||
}
|
}
|
||||||
|
@ -203,6 +201,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
||||||
* @return the new value, possibly the result of type conversion
|
* @return the new value, possibly the result of type conversion
|
||||||
* @throws TypeMismatchException if type conversion failed
|
* @throws TypeMismatchException if type conversion failed
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Object convertForProperty(Object value, String propertyName) throws TypeMismatchException {
|
public Object convertForProperty(Object value, String propertyName) throws TypeMismatchException {
|
||||||
CachedIntrospectionResults cachedIntrospectionResults = getCachedIntrospectionResults();
|
CachedIntrospectionResults cachedIntrospectionResults = getCachedIntrospectionResults();
|
||||||
PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName);
|
PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName);
|
||||||
|
@ -289,73 +288,45 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
|
||||||
@Override
|
@Override
|
||||||
public Object getValue() throws Exception {
|
public Object getValue() throws Exception {
|
||||||
final Method readMethod = this.pd.getReadMethod();
|
final Method readMethod = this.pd.getReadMethod();
|
||||||
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers()) && !readMethod.isAccessible()) {
|
|
||||||
if (System.getSecurityManager() != null) {
|
|
||||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
|
||||||
@Override
|
|
||||||
public Object run() {
|
|
||||||
readMethod.setAccessible(true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
readMethod.setAccessible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (System.getSecurityManager() != null) {
|
if (System.getSecurityManager() != null) {
|
||||||
|
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||||
|
ReflectionUtils.makeAccessible(readMethod);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
try {
|
try {
|
||||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
return AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
|
||||||
@Override
|
readMethod.invoke(getWrappedInstance(), (Object[]) null), acc);
|
||||||
public Object run() throws Exception {
|
|
||||||
return readMethod.invoke(getWrappedInstance(), (Object[]) null);
|
|
||||||
}
|
|
||||||
}, acc);
|
|
||||||
}
|
}
|
||||||
catch (PrivilegedActionException pae) {
|
catch (PrivilegedActionException pae) {
|
||||||
throw pae.getException();
|
throw pae.getException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
ReflectionUtils.makeAccessible(readMethod);
|
||||||
return readMethod.invoke(getWrappedInstance(), (Object[]) null);
|
return readMethod.invoke(getWrappedInstance(), (Object[]) null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(final Object object, Object valueToApply) throws Exception {
|
public void setValue(final @Nullable Object value) throws Exception {
|
||||||
final Method writeMethod = (this.pd instanceof GenericTypeAwarePropertyDescriptor ?
|
final Method writeMethod = (this.pd instanceof GenericTypeAwarePropertyDescriptor ?
|
||||||
((GenericTypeAwarePropertyDescriptor) this.pd).getWriteMethodForActualAccess() :
|
((GenericTypeAwarePropertyDescriptor) this.pd).getWriteMethodForActualAccess() :
|
||||||
this.pd.getWriteMethod());
|
this.pd.getWriteMethod());
|
||||||
if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers()) && !writeMethod.isAccessible()) {
|
|
||||||
if (System.getSecurityManager() != null) {
|
|
||||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
|
||||||
@Override
|
|
||||||
public Object run() {
|
|
||||||
writeMethod.setAccessible(true);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
writeMethod.setAccessible(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final Object value = valueToApply;
|
|
||||||
if (System.getSecurityManager() != null) {
|
if (System.getSecurityManager() != null) {
|
||||||
|
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
|
||||||
|
ReflectionUtils.makeAccessible(writeMethod);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
try {
|
try {
|
||||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () ->
|
||||||
@Override
|
writeMethod.invoke(getWrappedInstance(), value), acc);
|
||||||
public Object run() throws Exception {
|
|
||||||
writeMethod.invoke(object, value);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, acc);
|
|
||||||
}
|
}
|
||||||
catch (PrivilegedActionException ex) {
|
catch (PrivilegedActionException ex) {
|
||||||
throw ex.getException();
|
throw ex.getException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
ReflectionUtils.makeAccessible(writeMethod);
|
||||||
writeMethod.invoke(getWrappedInstance(), value);
|
writeMethod.invoke(getWrappedInstance(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
package org.springframework.beans;
|
package org.springframework.beans;
|
||||||
|
|
||||||
import org.springframework.core.NestedRuntimeException;
|
import org.springframework.core.NestedRuntimeException;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract superclass for all exceptions thrown in the beans package
|
* Abstract superclass for all exceptions thrown in the beans package
|
||||||
|
@ -46,27 +46,8 @@ public abstract class BeansException extends NestedRuntimeException {
|
||||||
* @param msg the detail message
|
* @param msg the detail message
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
*/
|
*/
|
||||||
public BeansException(String msg, Throwable cause) {
|
public BeansException(@Nullable String msg, @Nullable Throwable cause) {
|
||||||
super(msg, cause);
|
super(msg, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
if (this == other) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!(other instanceof BeansException)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
BeansException otherBe = (BeansException) other;
|
|
||||||
return (getMessage().equals(otherBe.getMessage()) &&
|
|
||||||
ObjectUtils.nullSafeEquals(getCause(), otherBe.getCause()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return getMessage().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.core.SpringProperties;
|
import org.springframework.core.SpringProperties;
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
@ -136,7 +137,7 @@ public class CachedIntrospectionResults {
|
||||||
* be paired with a {@link #clearClassLoader} call at application shutdown.
|
* be paired with a {@link #clearClassLoader} call at application shutdown.
|
||||||
* @param classLoader the ClassLoader to accept
|
* @param classLoader the ClassLoader to accept
|
||||||
*/
|
*/
|
||||||
public static void acceptClassLoader(ClassLoader classLoader) {
|
public static void acceptClassLoader(@Nullable ClassLoader classLoader) {
|
||||||
if (classLoader != null) {
|
if (classLoader != null) {
|
||||||
acceptedClassLoaders.add(classLoader);
|
acceptedClassLoaders.add(classLoader);
|
||||||
}
|
}
|
||||||
|
@ -148,7 +149,7 @@ public class CachedIntrospectionResults {
|
||||||
* removing the ClassLoader (and its children) from the acceptance list.
|
* removing the ClassLoader (and its children) from the acceptance list.
|
||||||
* @param classLoader the ClassLoader to clear the cache for
|
* @param classLoader the ClassLoader to clear the cache for
|
||||||
*/
|
*/
|
||||||
public static void clearClassLoader(ClassLoader classLoader) {
|
public static void clearClassLoader(@Nullable ClassLoader classLoader) {
|
||||||
for (Iterator<ClassLoader> it = acceptedClassLoaders.iterator(); it.hasNext();) {
|
for (Iterator<ClassLoader> it = acceptedClassLoaders.iterator(); it.hasNext();) {
|
||||||
ClassLoader registeredLoader = it.next();
|
ClassLoader registeredLoader = it.next();
|
||||||
if (isUnderneathClassLoader(registeredLoader, classLoader)) {
|
if (isUnderneathClassLoader(registeredLoader, classLoader)) {
|
||||||
|
@ -226,7 +227,7 @@ public class CachedIntrospectionResults {
|
||||||
* @param candidate the candidate ClassLoader to check
|
* @param candidate the candidate ClassLoader to check
|
||||||
* @param parent the parent ClassLoader to check for
|
* @param parent the parent ClassLoader to check for
|
||||||
*/
|
*/
|
||||||
private static boolean isUnderneathClassLoader(ClassLoader candidate, ClassLoader parent) {
|
private static boolean isUnderneathClassLoader(@Nullable ClassLoader candidate, @Nullable ClassLoader parent) {
|
||||||
if (candidate == parent) {
|
if (candidate == parent) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -336,6 +337,7 @@ public class CachedIntrospectionResults {
|
||||||
return this.beanInfo.getBeanDescriptor().getBeanClass();
|
return this.beanInfo.getBeanDescriptor().getBeanClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
PropertyDescriptor getPropertyDescriptor(String name) {
|
PropertyDescriptor getPropertyDescriptor(String name) {
|
||||||
PropertyDescriptor pd = this.propertyDescriptorCache.get(name);
|
PropertyDescriptor pd = this.propertyDescriptorCache.get(name);
|
||||||
if (pd == null && StringUtils.hasLength(name)) {
|
if (pd == null && StringUtils.hasLength(name)) {
|
||||||
|
@ -375,6 +377,7 @@ public class CachedIntrospectionResults {
|
||||||
return (existing != null ? existing : td);
|
return (existing != null ? existing : td);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
TypeDescriptor getTypeDescriptor(PropertyDescriptor pd) {
|
TypeDescriptor getTypeDescriptor(PropertyDescriptor pd) {
|
||||||
return this.typeDescriptorCache.get(pd);
|
return this.typeDescriptorCache.get(pd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -37,7 +37,7 @@ public interface ConfigurablePropertyAccessor extends PropertyAccessor, Property
|
||||||
* Specify a Spring 3.0 ConversionService to use for converting
|
* Specify a Spring 3.0 ConversionService to use for converting
|
||||||
* property values, as an alternative to JavaBeans PropertyEditors.
|
* property values, as an alternative to JavaBeans PropertyEditors.
|
||||||
*/
|
*/
|
||||||
void setConversionService(ConversionService conversionService);
|
void setConversionService(@Nullable ConversionService conversionService);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the associated ConversionService, if any.
|
* Return the associated ConversionService, if any.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -134,10 +134,10 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Object object, Object value) throws Exception {
|
public void setValue(Object value) throws Exception {
|
||||||
try {
|
try {
|
||||||
ReflectionUtils.makeAccessible(this.field);
|
ReflectionUtils.makeAccessible(this.field);
|
||||||
this.field.set(object, value);
|
this.field.set(getWrappedInstance(), value);
|
||||||
}
|
}
|
||||||
catch (IllegalAccessException ex) {
|
catch (IllegalAccessException ex) {
|
||||||
throw new InvalidPropertyException(getWrappedClass(), this.field.getName(),
|
throw new InvalidPropertyException(getWrappedClass(), this.field.getName(),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.beans;
|
package org.springframework.beans;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown on an unrecoverable problem encountered in the
|
* Thrown on an unrecoverable problem encountered in the
|
||||||
* beans packages or sub-packages, e.g. bad class or field.
|
* beans packages or sub-packages, e.g. bad class or field.
|
||||||
|
@ -39,7 +41,7 @@ public class FatalBeanException extends BeansException {
|
||||||
* @param msg the detail message
|
* @param msg the detail message
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
*/
|
*/
|
||||||
public FatalBeanException(String msg, Throwable cause) {
|
public FatalBeanException(String msg, @Nullable Throwable cause) {
|
||||||
super(msg, cause);
|
super(msg, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.core.BridgeMethodResolver;
|
import org.springframework.core.BridgeMethodResolver;
|
||||||
import org.springframework.core.GenericTypeResolver;
|
import org.springframework.core.GenericTypeResolver;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
@ -57,18 +58,14 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
|
||||||
|
|
||||||
|
|
||||||
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
|
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
|
||||||
Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
|
@Nullable Method readMethod, @Nullable Method writeMethod, Class<?> propertyEditorClass)
|
||||||
throws IntrospectionException {
|
throws IntrospectionException {
|
||||||
|
|
||||||
super(propertyName, null, null);
|
super(propertyName, null, null);
|
||||||
|
|
||||||
if (beanClass == null) {
|
|
||||||
throw new IntrospectionException("Bean class must not be null");
|
|
||||||
}
|
|
||||||
this.beanClass = beanClass;
|
this.beanClass = beanClass;
|
||||||
|
|
||||||
Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
|
Method readMethodToUse = (readMethod != null ? BridgeMethodResolver.findBridgedMethod(readMethod) : null);
|
||||||
Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
|
Method writeMethodToUse = (writeMethod != null ? BridgeMethodResolver.findBridgedMethod(writeMethod) : null);
|
||||||
if (writeMethodToUse == null && readMethodToUse != null) {
|
if (writeMethodToUse == null && readMethodToUse != null) {
|
||||||
// Fallback: Original JavaBeans introspection might not have found matching setter
|
// Fallback: Original JavaBeans introspection might not have found matching setter
|
||||||
// method due to lack of bridge method resolution, in case of the getter using a
|
// method due to lack of bridge method resolution, in case of the getter using a
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.beans;
|
package org.springframework.beans;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when referring to an invalid bean property.
|
* Exception thrown when referring to an invalid bean property.
|
||||||
* Carries the offending bean class and property name.
|
* Carries the offending bean class and property name.
|
||||||
|
@ -48,7 +50,7 @@ public class InvalidPropertyException extends FatalBeanException {
|
||||||
* @param msg the detail message
|
* @param msg the detail message
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
*/
|
*/
|
||||||
public InvalidPropertyException(Class<?> beanClass, String propertyName, String msg, Throwable cause) {
|
public InvalidPropertyException(Class<?> beanClass, String propertyName, String msg, @Nullable Throwable cause) {
|
||||||
super("Invalid property '" + propertyName + "' of bean class [" + beanClass.getName() + "]: " + msg, cause);
|
super("Invalid property '" + propertyName + "' of bean class [" + beanClass.getName() + "]: " + msg, cause);
|
||||||
this.beanClass = beanClass;
|
this.beanClass = beanClass;
|
||||||
this.propertyName = propertyName;
|
this.propertyName = propertyName;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -62,7 +62,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||||
* @param original the PropertyValues to copy
|
* @param original the PropertyValues to copy
|
||||||
* @see #addPropertyValues(PropertyValues)
|
* @see #addPropertyValues(PropertyValues)
|
||||||
*/
|
*/
|
||||||
public MutablePropertyValues(PropertyValues original) {
|
public MutablePropertyValues(@Nullable PropertyValues original) {
|
||||||
// We can optimize this because it's all new:
|
// We can optimize this because it's all new:
|
||||||
// There is no replacement of existing property values.
|
// There is no replacement of existing property values.
|
||||||
if (original != null) {
|
if (original != null) {
|
||||||
|
@ -82,7 +82,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||||
* @param original Map with property values keyed by property name Strings
|
* @param original Map with property values keyed by property name Strings
|
||||||
* @see #addPropertyValues(Map)
|
* @see #addPropertyValues(Map)
|
||||||
*/
|
*/
|
||||||
public MutablePropertyValues(Map<?, ?> original) {
|
public MutablePropertyValues(@Nullable Map<?, ?> original) {
|
||||||
// We can optimize this because it's all new:
|
// We can optimize this because it's all new:
|
||||||
// There is no replacement of existing property values.
|
// There is no replacement of existing property values.
|
||||||
if (original != null) {
|
if (original != null) {
|
||||||
|
@ -103,7 +103,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||||
* It is not intended for typical programmatic use.
|
* It is not intended for typical programmatic use.
|
||||||
* @param propertyValueList List of PropertyValue objects
|
* @param propertyValueList List of PropertyValue objects
|
||||||
*/
|
*/
|
||||||
public MutablePropertyValues(List<PropertyValue> propertyValueList) {
|
public MutablePropertyValues(@Nullable List<PropertyValue> propertyValueList) {
|
||||||
this.propertyValueList =
|
this.propertyValueList =
|
||||||
(propertyValueList != null ? propertyValueList : new ArrayList<>());
|
(propertyValueList != null ? propertyValueList : new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||||
* @param other the PropertyValues to copy
|
* @param other the PropertyValues to copy
|
||||||
* @return this in order to allow for adding multiple property values in a chain
|
* @return this in order to allow for adding multiple property values in a chain
|
||||||
*/
|
*/
|
||||||
public MutablePropertyValues addPropertyValues(PropertyValues other) {
|
public MutablePropertyValues addPropertyValues(@Nullable PropertyValues other) {
|
||||||
if (other != null) {
|
if (other != null) {
|
||||||
PropertyValue[] pvs = other.getPropertyValues();
|
PropertyValue[] pvs = other.getPropertyValues();
|
||||||
for (PropertyValue pv : pvs) {
|
for (PropertyValue pv : pvs) {
|
||||||
|
@ -149,7 +149,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||||
* which must be a String
|
* which must be a String
|
||||||
* @return this in order to allow for adding multiple property values in a chain
|
* @return this in order to allow for adding multiple property values in a chain
|
||||||
*/
|
*/
|
||||||
public MutablePropertyValues addPropertyValues(Map<?, ?> other) {
|
public MutablePropertyValues addPropertyValues(@Nullable Map<?, ?> other) {
|
||||||
if (other != null) {
|
if (other != null) {
|
||||||
for (Map.Entry<?, ?> entry : other.entrySet()) {
|
for (Map.Entry<?, ?> entry : other.entrySet()) {
|
||||||
addPropertyValue(new PropertyValue(entry.getKey().toString(), entry.getValue()));
|
addPropertyValue(new PropertyValue(entry.getKey().toString(), entry.getValue()));
|
||||||
|
@ -197,7 +197,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||||
* @param propertyValue value of the property
|
* @param propertyValue value of the property
|
||||||
* @return this in order to allow for adding multiple property values in a chain
|
* @return this in order to allow for adding multiple property values in a chain
|
||||||
*/
|
*/
|
||||||
public MutablePropertyValues add(String propertyName, Object propertyValue) {
|
public MutablePropertyValues add(String propertyName, @Nullable Object propertyValue) {
|
||||||
addPropertyValue(new PropertyValue(propertyName, propertyValue));
|
addPropertyValue(new PropertyValue(propertyName, propertyValue));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||||
/**
|
/**
|
||||||
* Get the raw property value, if any.
|
* Get the raw property value, if any.
|
||||||
* @param propertyName the name to search for
|
* @param propertyName the name to search for
|
||||||
* @return the raw property value, or {@code null}
|
* @return the raw property value, or {@code null} if none found
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
* @see #getPropertyValue(String)
|
* @see #getPropertyValue(String)
|
||||||
* @see PropertyValue#getValue()
|
* @see PropertyValue#getValue()
|
||||||
|
|
|
@ -39,7 +39,7 @@ public abstract class PropertyAccessException extends BeansException {
|
||||||
* @param msg the detail message
|
* @param msg the detail message
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
*/
|
*/
|
||||||
public PropertyAccessException(PropertyChangeEvent propertyChangeEvent, String msg, Throwable cause) {
|
public PropertyAccessException(PropertyChangeEvent propertyChangeEvent, String msg, @Nullable Throwable cause) {
|
||||||
super(msg, cause);
|
super(msg, cause);
|
||||||
this.propertyChangeEvent = propertyChangeEvent;
|
this.propertyChangeEvent = propertyChangeEvent;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public abstract class PropertyAccessException extends BeansException {
|
||||||
* @param msg the detail message
|
* @param msg the detail message
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
*/
|
*/
|
||||||
public PropertyAccessException(String msg, Throwable cause) {
|
public PropertyAccessException(String msg, @Nullable Throwable cause) {
|
||||||
super(msg, cause);
|
super(msg, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ public abstract class PropertyAccessException extends BeansException {
|
||||||
/**
|
/**
|
||||||
* Return the name of the affected property, if available.
|
* Return the name of the affected property, if available.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getPropertyName() {
|
public String getPropertyName() {
|
||||||
return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getPropertyName() : null);
|
return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getPropertyName() : null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -82,8 +82,6 @@ public interface PropertyAccessor {
|
||||||
* (may be a nested path and/or an indexed/mapped property)
|
* (may be a nested path and/or an indexed/mapped property)
|
||||||
* @return the property type for the particular property,
|
* @return the property type for the particular property,
|
||||||
* or {@code null} if not determinable
|
* or {@code null} if not determinable
|
||||||
* @throws InvalidPropertyException if there is no such property or
|
|
||||||
* if the property isn't readable
|
|
||||||
* @throws PropertyAccessException if the property was valid but the
|
* @throws PropertyAccessException if the property was valid but the
|
||||||
* accessor method failed
|
* accessor method failed
|
||||||
*/
|
*/
|
||||||
|
@ -97,8 +95,8 @@ public interface PropertyAccessor {
|
||||||
* (may be a nested path and/or an indexed/mapped property)
|
* (may be a nested path and/or an indexed/mapped property)
|
||||||
* @return the property type for the particular property,
|
* @return the property type for the particular property,
|
||||||
* or {@code null} if not determinable
|
* or {@code null} if not determinable
|
||||||
* @throws InvalidPropertyException if there is no such property or
|
* @throws PropertyAccessException if the property was valid but the
|
||||||
* if the property isn't readable
|
* accessor method failed
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;
|
TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;
|
||||||
|
@ -113,6 +111,7 @@ public interface PropertyAccessor {
|
||||||
* @throws PropertyAccessException if the property was valid but the
|
* @throws PropertyAccessException if the property was valid but the
|
||||||
* accessor method failed
|
* accessor method failed
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
Object getPropertyValue(String propertyName) throws BeansException;
|
Object getPropertyValue(String propertyName) throws BeansException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,7 +124,7 @@ public interface PropertyAccessor {
|
||||||
* @throws PropertyAccessException if the property was valid but the
|
* @throws PropertyAccessException if the property was valid but the
|
||||||
* accessor method failed or a type mismatch occurred
|
* accessor method failed or a type mismatch occurred
|
||||||
*/
|
*/
|
||||||
void setPropertyValue(String propertyName, Object value) throws BeansException;
|
void setPropertyValue(String propertyName, @Nullable Object value) throws BeansException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the specified value as current property value.
|
* Set the specified value as current property value.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.beans;
|
package org.springframework.beans;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for classes that perform bean property access
|
* Utility methods for classes that perform bean property access
|
||||||
* according to the {@link PropertyAccessor} interface.
|
* according to the {@link PropertyAccessor} interface.
|
||||||
|
@ -42,7 +44,7 @@ public abstract class PropertyAccessorUtils {
|
||||||
* @param propertyPath the property path to check
|
* @param propertyPath the property path to check
|
||||||
* @return whether the path indicates an indexed or nested property
|
* @return whether the path indicates an indexed or nested property
|
||||||
*/
|
*/
|
||||||
public static boolean isNestedOrIndexedProperty(String propertyPath) {
|
public static boolean isNestedOrIndexedProperty(@Nullable String propertyPath) {
|
||||||
if (propertyPath == null) {
|
if (propertyPath == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +139,7 @@ public abstract class PropertyAccessorUtils {
|
||||||
* @param propertyName the bean property path
|
* @param propertyName the bean property path
|
||||||
* @return the canonical representation of the property path
|
* @return the canonical representation of the property path
|
||||||
*/
|
*/
|
||||||
public static String canonicalPropertyName(String propertyName) {
|
public static String canonicalPropertyName(@Nullable String propertyName) {
|
||||||
if (propertyName == null) {
|
if (propertyName == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -171,7 +173,8 @@ public abstract class PropertyAccessorUtils {
|
||||||
* (as array of the same size)
|
* (as array of the same size)
|
||||||
* @see #canonicalPropertyName(String)
|
* @see #canonicalPropertyName(String)
|
||||||
*/
|
*/
|
||||||
public static String[] canonicalPropertyNames(String[] propertyNames) {
|
@Nullable
|
||||||
|
public static String[] canonicalPropertyNames(@Nullable String[] propertyNames) {
|
||||||
if (propertyNames == null) {
|
if (propertyNames == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -48,7 +48,7 @@ public class PropertyBatchUpdateException extends BeansException {
|
||||||
* @param propertyAccessExceptions the List of PropertyAccessExceptions
|
* @param propertyAccessExceptions the List of PropertyAccessExceptions
|
||||||
*/
|
*/
|
||||||
public PropertyBatchUpdateException(PropertyAccessException[] propertyAccessExceptions) {
|
public PropertyBatchUpdateException(PropertyAccessException[] propertyAccessExceptions) {
|
||||||
super(null);
|
super(null, null);
|
||||||
Assert.notEmpty(propertyAccessExceptions, "At least 1 PropertyAccessException required");
|
Assert.notEmpty(propertyAccessExceptions, "At least 1 PropertyAccessException required");
|
||||||
this.propertyAccessExceptions = propertyAccessExceptions;
|
this.propertyAccessExceptions = propertyAccessExceptions;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ public class PropertyBatchUpdateException extends BeansException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Class<?> exType) {
|
public boolean contains(@Nullable Class<?> exType) {
|
||||||
if (exType == null) {
|
if (exType == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -21,6 +21,7 @@ import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +61,10 @@ class PropertyDescriptorUtils {
|
||||||
/**
|
/**
|
||||||
* See {@link java.beans.PropertyDescriptor#findPropertyType}.
|
* See {@link java.beans.PropertyDescriptor#findPropertyType}.
|
||||||
*/
|
*/
|
||||||
public static Class<?> findPropertyType(Method readMethod, Method writeMethod) throws IntrospectionException {
|
@Nullable
|
||||||
|
public static Class<?> findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod)
|
||||||
|
throws IntrospectionException {
|
||||||
|
|
||||||
Class<?> propertyType = null;
|
Class<?> propertyType = null;
|
||||||
|
|
||||||
if (readMethod != null) {
|
if (readMethod != null) {
|
||||||
|
@ -103,8 +107,9 @@ class PropertyDescriptorUtils {
|
||||||
/**
|
/**
|
||||||
* See {@link java.beans.IndexedPropertyDescriptor#findIndexedPropertyType}.
|
* See {@link java.beans.IndexedPropertyDescriptor#findIndexedPropertyType}.
|
||||||
*/
|
*/
|
||||||
public static Class<?> findIndexedPropertyType(String name, Class<?> propertyType,
|
@Nullable
|
||||||
Method indexedReadMethod, Method indexedWriteMethod) throws IntrospectionException {
|
public static Class<?> findIndexedPropertyType(String name, @Nullable Class<?> propertyType,
|
||||||
|
@Nullable Method indexedReadMethod, @Nullable Method indexedWriteMethod) throws IntrospectionException {
|
||||||
|
|
||||||
Class<?> indexedPropertyType = null;
|
Class<?> indexedPropertyType = null;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -112,7 +112,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||||
* Specify a Spring 3.0 ConversionService to use for converting
|
* Specify a Spring 3.0 ConversionService to use for converting
|
||||||
* property values, as an alternative to JavaBeans PropertyEditors.
|
* property values, as an alternative to JavaBeans PropertyEditors.
|
||||||
*/
|
*/
|
||||||
public void setConversionService(ConversionService conversionService) {
|
public void setConversionService(@Nullable ConversionService conversionService) {
|
||||||
this.conversionService = conversionService;
|
this.conversionService = conversionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||||
* @return the custom editor, or {@code null} if none specific for this property
|
* @return the custom editor, or {@code null} if none specific for this property
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private PropertyEditor getCustomEditor(String propertyName, Class<?> requiredType) {
|
private PropertyEditor getCustomEditor(String propertyName, @Nullable Class<?> requiredType) {
|
||||||
CustomEditorHolder holder = this.customEditorsForPath.get(propertyName);
|
CustomEditorHolder holder = this.customEditorsForPath.get(propertyName);
|
||||||
return (holder != null ? holder.getPropertyEditor(requiredType) : null);
|
return (holder != null ? holder.getPropertyEditor(requiredType) : null);
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||||
* @see java.beans.PropertyEditor#getAsText()
|
* @see java.beans.PropertyEditor#getAsText()
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private PropertyEditor getCustomEditor(Class<?> requiredType) {
|
private PropertyEditor getCustomEditor(@Nullable Class<?> requiredType) {
|
||||||
if (requiredType == null || this.customEditors == null) {
|
if (requiredType == null || this.customEditors == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -521,7 +521,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||||
|
|
||||||
private final Class<?> registeredType;
|
private final Class<?> registeredType;
|
||||||
|
|
||||||
private CustomEditorHolder(PropertyEditor propertyEditor, Class<?> registeredType) {
|
private CustomEditorHolder(PropertyEditor propertyEditor, @Nullable Class<?> registeredType) {
|
||||||
this.propertyEditor = propertyEditor;
|
this.propertyEditor = propertyEditor;
|
||||||
this.registeredType = registeredType;
|
this.registeredType = registeredType;
|
||||||
}
|
}
|
||||||
|
@ -530,11 +530,12 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
||||||
return this.propertyEditor;
|
return this.propertyEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Class<?> getRegisteredType() {
|
private Class<?> getRegisteredType() {
|
||||||
return this.registeredType;
|
return this.registeredType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PropertyEditor getPropertyEditor(Class<?> requiredType) {
|
private PropertyEditor getPropertyEditor(@Nullable Class<?> requiredType) {
|
||||||
// Special case: If no required type specified, which usually only happens for
|
// Special case: If no required type specified, which usually only happens for
|
||||||
// Collection elements, or required type is not assignable to registered type,
|
// Collection elements, or required type is not assignable to registered type,
|
||||||
// which usually only happens for generic properties of type Object -
|
// which usually only happens for generic properties of type Object -
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -18,6 +18,7 @@ package org.springframework.beans;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
|
@ -63,7 +64,8 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||||
* @param name the name of the property (never {@code null})
|
* @param name the name of the property (never {@code null})
|
||||||
* @param value the value of the property (possibly before type conversion)
|
* @param value the value of the property (possibly before type conversion)
|
||||||
*/
|
*/
|
||||||
public PropertyValue(String name, Object value) {
|
public PropertyValue(String name, @Nullable Object value) {
|
||||||
|
Assert.notNull(name, "Name must not be null");
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
@ -116,6 +118,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||||
* It is the responsibility of the BeanWrapper implementation to
|
* It is the responsibility of the BeanWrapper implementation to
|
||||||
* perform type conversion.
|
* perform type conversion.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -37,7 +37,7 @@ public interface PropertyValues {
|
||||||
/**
|
/**
|
||||||
* Return the property value with the given name, if any.
|
* Return the property value with the given name, if any.
|
||||||
* @param propertyName the name to search for
|
* @param propertyName the name to search for
|
||||||
* @return the property value, or {@code null}
|
* @return the property value, or {@code null} if none
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
PropertyValue getPropertyValue(String propertyName);
|
PropertyValue getPropertyValue(String propertyName);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -50,7 +50,8 @@ public interface TypeConverter {
|
||||||
* @see org.springframework.core.convert.ConversionService
|
* @see org.springframework.core.convert.ConversionService
|
||||||
* @see org.springframework.core.convert.converter.Converter
|
* @see org.springframework.core.convert.converter.Converter
|
||||||
*/
|
*/
|
||||||
<T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType) throws TypeMismatchException;
|
@Nullable
|
||||||
|
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the value to the required type (if necessary from a String).
|
* Convert the value to the required type (if necessary from a String).
|
||||||
|
@ -68,8 +69,9 @@ public interface TypeConverter {
|
||||||
* @see org.springframework.core.convert.ConversionService
|
* @see org.springframework.core.convert.ConversionService
|
||||||
* @see org.springframework.core.convert.converter.Converter
|
* @see org.springframework.core.convert.converter.Converter
|
||||||
*/
|
*/
|
||||||
<T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
@Nullable
|
||||||
throws TypeMismatchException;
|
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
|
||||||
|
@Nullable MethodParameter methodParam) throws TypeMismatchException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the value to the required type (if necessary from a String).
|
* Convert the value to the required type (if necessary from a String).
|
||||||
|
@ -87,7 +89,8 @@ public interface TypeConverter {
|
||||||
* @see org.springframework.core.convert.ConversionService
|
* @see org.springframework.core.convert.ConversionService
|
||||||
* @see org.springframework.core.convert.converter.Converter
|
* @see org.springframework.core.convert.converter.Converter
|
||||||
*/
|
*/
|
||||||
<T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
@Nullable
|
||||||
|
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||||
throws TypeMismatchException;
|
throws TypeMismatchException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ class TypeConverterDelegate {
|
||||||
* @param propertyEditorRegistry the editor registry to use
|
* @param propertyEditorRegistry the editor registry to use
|
||||||
* @param targetObject the target object to work on (as context that can be passed to editors)
|
* @param targetObject the target object to work on (as context that can be passed to editors)
|
||||||
*/
|
*/
|
||||||
public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, Object targetObject) {
|
public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistry, @Nullable Object targetObject) {
|
||||||
this.propertyEditorRegistry = propertyEditorRegistry;
|
this.propertyEditorRegistry = propertyEditorRegistry;
|
||||||
this.targetObject = targetObject;
|
this.targetObject = targetObject;
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,9 @@ class TypeConverterDelegate {
|
||||||
* @return the new value, possibly the result of type conversion
|
* @return the new value, possibly the result of type conversion
|
||||||
* @throws IllegalArgumentException if type conversion failed
|
* @throws IllegalArgumentException if type conversion failed
|
||||||
*/
|
*/
|
||||||
public <T> T convertIfNecessary(Object newValue, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
@Nullable
|
||||||
throws IllegalArgumentException {
|
public <T> T convertIfNecessary(@Nullable Object newValue, @Nullable Class<T> requiredType,
|
||||||
|
@Nullable MethodParameter methodParam) throws IllegalArgumentException {
|
||||||
|
|
||||||
return convertIfNecessary(null, null, newValue, requiredType,
|
return convertIfNecessary(null, null, newValue, requiredType,
|
||||||
(methodParam != null ? new TypeDescriptor(methodParam) : TypeDescriptor.valueOf(requiredType)));
|
(methodParam != null ? new TypeDescriptor(methodParam) : TypeDescriptor.valueOf(requiredType)));
|
||||||
|
@ -108,7 +109,8 @@ class TypeConverterDelegate {
|
||||||
* @return the new value, possibly the result of type conversion
|
* @return the new value, possibly the result of type conversion
|
||||||
* @throws IllegalArgumentException if type conversion failed
|
* @throws IllegalArgumentException if type conversion failed
|
||||||
*/
|
*/
|
||||||
public <T> T convertIfNecessary(Object newValue, @Nullable Class<T> requiredType, @Nullable Field field)
|
@Nullable
|
||||||
|
public <T> T convertIfNecessary(@Nullable Object newValue, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
|
|
||||||
return convertIfNecessary(null, null, newValue, requiredType,
|
return convertIfNecessary(null, null, newValue, requiredType,
|
||||||
|
@ -125,9 +127,9 @@ class TypeConverterDelegate {
|
||||||
* @return the new value, possibly the result of type conversion
|
* @return the new value, possibly the result of type conversion
|
||||||
* @throws IllegalArgumentException if type conversion failed
|
* @throws IllegalArgumentException if type conversion failed
|
||||||
*/
|
*/
|
||||||
public <T> T convertIfNecessary(
|
@Nullable
|
||||||
String propertyName, @Nullable Object oldValue, Object newValue, @Nullable Class<T> requiredType)
|
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
|
||||||
throws IllegalArgumentException {
|
Object newValue, @Nullable Class<T> requiredType) throws IllegalArgumentException {
|
||||||
|
|
||||||
return convertIfNecessary(propertyName, oldValue, newValue, requiredType, TypeDescriptor.valueOf(requiredType));
|
return convertIfNecessary(propertyName, oldValue, newValue, requiredType, TypeDescriptor.valueOf(requiredType));
|
||||||
}
|
}
|
||||||
|
@ -145,8 +147,9 @@ class TypeConverterDelegate {
|
||||||
* @throws IllegalArgumentException if type conversion failed
|
* @throws IllegalArgumentException if type conversion failed
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue,
|
@Nullable
|
||||||
@Nullable Class<T> requiredType, TypeDescriptor typeDescriptor) throws IllegalArgumentException {
|
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue,
|
||||||
|
@Nullable Class<T> requiredType, @Nullable TypeDescriptor typeDescriptor) throws IllegalArgumentException {
|
||||||
|
|
||||||
// Custom editor for this type?
|
// Custom editor for this type?
|
||||||
PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName);
|
PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName);
|
||||||
|
@ -268,7 +271,7 @@ class TypeConverterDelegate {
|
||||||
// Original exception from former ConversionService call above...
|
// Original exception from former ConversionService call above...
|
||||||
throw conversionAttemptEx;
|
throw conversionAttemptEx;
|
||||||
}
|
}
|
||||||
else if (conversionService != null) {
|
else if (conversionService != null && typeDescriptor != null) {
|
||||||
// ConversionService not tried before, probably custom editor found
|
// ConversionService not tried before, probably custom editor found
|
||||||
// but editor couldn't produce the required type...
|
// but editor couldn't produce the required type...
|
||||||
TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(newValue);
|
TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(newValue);
|
||||||
|
@ -359,7 +362,7 @@ class TypeConverterDelegate {
|
||||||
* @return the corresponding editor, or {@code null} if none
|
* @return the corresponding editor, or {@code null} if none
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private PropertyEditor findDefaultEditor(Class<?> requiredType) {
|
private PropertyEditor findDefaultEditor(@Nullable Class<?> requiredType) {
|
||||||
PropertyEditor editor = null;
|
PropertyEditor editor = null;
|
||||||
if (requiredType != null) {
|
if (requiredType != null) {
|
||||||
// No custom editor -> check BeanWrapperImpl's default editors.
|
// No custom editor -> check BeanWrapperImpl's default editors.
|
||||||
|
@ -383,7 +386,10 @@ class TypeConverterDelegate {
|
||||||
* @return the new value, possibly the result of type conversion
|
* @return the new value, possibly the result of type conversion
|
||||||
* @throws IllegalArgumentException if type conversion failed
|
* @throws IllegalArgumentException if type conversion failed
|
||||||
*/
|
*/
|
||||||
private Object doConvertValue(@Nullable Object oldValue, Object newValue, @Nullable Class<?> requiredType, PropertyEditor editor) {
|
@Nullable
|
||||||
|
private Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue,
|
||||||
|
@Nullable Class<?> requiredType, @Nullable PropertyEditor editor) {
|
||||||
|
|
||||||
Object convertedValue = newValue;
|
Object convertedValue = newValue;
|
||||||
|
|
||||||
if (editor != null && !(convertedValue instanceof String)) {
|
if (editor != null && !(convertedValue instanceof String)) {
|
||||||
|
@ -459,7 +465,7 @@ class TypeConverterDelegate {
|
||||||
return editor.getValue();
|
return editor.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object convertToTypedArray(Object input, String propertyName, Class<?> componentType) {
|
private Object convertToTypedArray(Object input, @Nullable String propertyName, Class<?> componentType) {
|
||||||
if (input instanceof Collection) {
|
if (input instanceof Collection) {
|
||||||
// Convert Collection elements to array elements.
|
// Convert Collection elements to array elements.
|
||||||
Collection<?> coll = (Collection<?>) input;
|
Collection<?> coll = (Collection<?>) input;
|
||||||
|
@ -498,8 +504,8 @@ class TypeConverterDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Collection<?> convertToTypedCollection(
|
private Collection<?> convertToTypedCollection(Collection<?> original, @Nullable String propertyName,
|
||||||
Collection<?> original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
Class<?> requiredType, @Nullable TypeDescriptor typeDescriptor) {
|
||||||
|
|
||||||
if (!Collection.class.isAssignableFrom(requiredType)) {
|
if (!Collection.class.isAssignableFrom(requiredType)) {
|
||||||
return original;
|
return original;
|
||||||
|
@ -515,7 +521,7 @@ class TypeConverterDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean originalAllowed = requiredType.isInstance(original);
|
boolean originalAllowed = requiredType.isInstance(original);
|
||||||
TypeDescriptor elementType = typeDescriptor.getElementTypeDescriptor();
|
TypeDescriptor elementType = (typeDescriptor != null ? typeDescriptor.getElementTypeDescriptor() : null);
|
||||||
if (elementType == null && originalAllowed &&
|
if (elementType == null && originalAllowed &&
|
||||||
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
|
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
|
||||||
return original;
|
return original;
|
||||||
|
@ -524,13 +530,6 @@ class TypeConverterDelegate {
|
||||||
Iterator<?> it;
|
Iterator<?> it;
|
||||||
try {
|
try {
|
||||||
it = original.iterator();
|
it = original.iterator();
|
||||||
if (it == null) {
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Collection of type [" + original.getClass().getName() +
|
|
||||||
"] returned null Iterator - injecting original Collection as-is");
|
|
||||||
}
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
|
@ -580,8 +579,8 @@ class TypeConverterDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Map<?, ?> convertToTypedMap(
|
private Map<?, ?> convertToTypedMap(Map<?, ?> original, @Nullable String propertyName,
|
||||||
Map<?, ?> original, String propertyName, Class<?> requiredType, TypeDescriptor typeDescriptor) {
|
Class<?> requiredType, @Nullable TypeDescriptor typeDescriptor) {
|
||||||
|
|
||||||
if (!Map.class.isAssignableFrom(requiredType)) {
|
if (!Map.class.isAssignableFrom(requiredType)) {
|
||||||
return original;
|
return original;
|
||||||
|
@ -597,8 +596,8 @@ class TypeConverterDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean originalAllowed = requiredType.isInstance(original);
|
boolean originalAllowed = requiredType.isInstance(original);
|
||||||
TypeDescriptor keyType = typeDescriptor.getMapKeyTypeDescriptor();
|
TypeDescriptor keyType = (typeDescriptor != null ? typeDescriptor.getMapKeyTypeDescriptor() : null);
|
||||||
TypeDescriptor valueType = typeDescriptor.getMapValueTypeDescriptor();
|
TypeDescriptor valueType = (typeDescriptor != null ? typeDescriptor.getMapValueTypeDescriptor() : null);
|
||||||
if (keyType == null && valueType == null && originalAllowed &&
|
if (keyType == null && valueType == null && originalAllowed &&
|
||||||
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
|
!this.propertyEditorRegistry.hasCustomEditorForElement(null, propertyName)) {
|
||||||
return original;
|
return original;
|
||||||
|
@ -607,13 +606,6 @@ class TypeConverterDelegate {
|
||||||
Iterator<?> it;
|
Iterator<?> it;
|
||||||
try {
|
try {
|
||||||
it = original.entrySet().iterator();
|
it = original.entrySet().iterator();
|
||||||
if (it == null) {
|
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Map of type [" + original.getClass().getName() +
|
|
||||||
"] returned null Iterator - injecting original Map as-is");
|
|
||||||
}
|
|
||||||
return original;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
|
@ -665,13 +657,15 @@ class TypeConverterDelegate {
|
||||||
return (originalAllowed ? original : convertedCopy);
|
return (originalAllowed ? original : convertedCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildIndexedPropertyName(String propertyName, int index) {
|
@Nullable
|
||||||
|
private String buildIndexedPropertyName(@Nullable String propertyName, int index) {
|
||||||
return (propertyName != null ?
|
return (propertyName != null ?
|
||||||
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + index + PropertyAccessor.PROPERTY_KEY_SUFFIX :
|
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + index + PropertyAccessor.PROPERTY_KEY_SUFFIX :
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildKeyedPropertyName(String propertyName, Object key) {
|
@Nullable
|
||||||
|
private String buildKeyedPropertyName(@Nullable String propertyName, Object key) {
|
||||||
return (propertyName != null ?
|
return (propertyName != null ?
|
||||||
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + key + PropertyAccessor.PROPERTY_KEY_SUFFIX :
|
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + key + PropertyAccessor.PROPERTY_KEY_SUFFIX :
|
||||||
null);
|
null);
|
||||||
|
|
|
@ -37,26 +37,28 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType) throws TypeMismatchException {
|
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException {
|
||||||
return doConvert(value, requiredType, null, null);
|
return doConvert(value, requiredType, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable MethodParameter methodParam)
|
||||||
throws TypeMismatchException {
|
throws TypeMismatchException {
|
||||||
|
|
||||||
return doConvert(value, requiredType, methodParam, null);
|
return doConvert(value, requiredType, methodParam, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> T convertIfNecessary(Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
|
||||||
throws TypeMismatchException {
|
throws TypeMismatchException {
|
||||||
|
|
||||||
return doConvert(value, requiredType, null, field);
|
return doConvert(value, requiredType, null, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> T doConvert(Object value, Class<T> requiredType, @Nullable MethodParameter methodParam, @Nullable Field field)
|
@Nullable
|
||||||
throws TypeMismatchException {
|
private <T> T doConvert(@Nullable Object value,@Nullable Class<T> requiredType,
|
||||||
|
@Nullable MethodParameter methodParam, @Nullable Field field) throws TypeMismatchException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (field != null) {
|
if (field != null) {
|
||||||
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, field);
|
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, field);
|
||||||
|
@ -65,16 +67,10 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
|
||||||
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, methodParam);
|
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, methodParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ConverterNotFoundException ex) {
|
catch (ConverterNotFoundException | IllegalStateException ex) {
|
||||||
throw new ConversionNotSupportedException(value, requiredType, ex);
|
throw new ConversionNotSupportedException(value, requiredType, ex);
|
||||||
}
|
}
|
||||||
catch (ConversionException ex) {
|
catch (ConversionException | IllegalArgumentException ex) {
|
||||||
throw new TypeMismatchException(value, requiredType, ex);
|
|
||||||
}
|
|
||||||
catch (IllegalStateException ex) {
|
|
||||||
throw new ConversionNotSupportedException(value, requiredType, ex);
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex) {
|
|
||||||
throw new TypeMismatchException(value, requiredType, ex);
|
throw new TypeMismatchException(value, requiredType, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,9 @@ public class TypeMismatchException extends PropertyAccessException {
|
||||||
* @param requiredType the required target type (or {@code null} if not known)
|
* @param requiredType the required target type (or {@code null} if not known)
|
||||||
* @param cause the root cause (may be {@code null})
|
* @param cause the root cause (may be {@code null})
|
||||||
*/
|
*/
|
||||||
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class<?> requiredType, @Nullable Throwable cause) {
|
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class<?> requiredType,
|
||||||
|
@Nullable Throwable cause) {
|
||||||
|
|
||||||
super(propertyChangeEvent,
|
super(propertyChangeEvent,
|
||||||
"Failed to convert property value of type '" +
|
"Failed to convert property value of type '" +
|
||||||
ClassUtils.getDescriptiveType(propertyChangeEvent.getNewValue()) + "'" +
|
ClassUtils.getDescriptiveType(propertyChangeEvent.getNewValue()) + "'" +
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -45,7 +45,7 @@ public abstract class AnnotationBeanUtils {
|
||||||
* @param excludedProperties the names of excluded properties, if any
|
* @param excludedProperties the names of excluded properties, if any
|
||||||
* @see org.springframework.beans.BeanWrapper
|
* @see org.springframework.beans.BeanWrapper
|
||||||
*/
|
*/
|
||||||
public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable String... excludedProperties) {
|
public static void copyPropertiesToBean(Annotation ann, Object bean, String... excludedProperties) {
|
||||||
copyPropertiesToBean(ann, bean, null, excludedProperties);
|
copyPropertiesToBean(ann, bean, null, excludedProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,9 @@ public abstract class AnnotationBeanUtils {
|
||||||
* @param excludedProperties the names of excluded properties, if any
|
* @param excludedProperties the names of excluded properties, if any
|
||||||
* @see org.springframework.beans.BeanWrapper
|
* @see org.springframework.beans.BeanWrapper
|
||||||
*/
|
*/
|
||||||
public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver, @Nullable String... excludedProperties) {
|
public static void copyPropertiesToBean(Annotation ann, Object bean, @Nullable StringValueResolver valueResolver,
|
||||||
|
String... excludedProperties) {
|
||||||
|
|
||||||
Set<String> excluded = new HashSet<>(Arrays.asList(excludedProperties));
|
Set<String> excluded = new HashSet<>(Arrays.asList(excludedProperties));
|
||||||
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
|
Method[] annotationProperties = ann.annotationType().getDeclaredMethods();
|
||||||
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
|
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory;
|
package org.springframework.beans.factory;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback that allows a bean to be aware of the bean
|
* Callback that allows a bean to be aware of the bean
|
||||||
* {@link ClassLoader class loader}; that is, the class loader used by the
|
* {@link ClassLoader class loader}; that is, the class loader used by the
|
||||||
|
@ -47,11 +45,8 @@ public interface BeanClassLoaderAware extends Aware {
|
||||||
* {@link InitializingBean InitializingBean's}
|
* {@link InitializingBean InitializingBean's}
|
||||||
* {@link InitializingBean#afterPropertiesSet()}
|
* {@link InitializingBean#afterPropertiesSet()}
|
||||||
* method or a custom init-method.
|
* method or a custom init-method.
|
||||||
* @param classLoader the owning class loader; may be {@code null} in
|
* @param classLoader the owning class loader
|
||||||
* which case a default {@code ClassLoader} must be used, for example
|
|
||||||
* the {@code ClassLoader} obtained via
|
|
||||||
* {@link org.springframework.util.ClassUtils#getDefaultClassLoader()}
|
|
||||||
*/
|
*/
|
||||||
void setBeanClassLoader(@Nullable ClassLoader classLoader);
|
void setBeanClassLoader(ClassLoader classLoader);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -64,7 +64,7 @@ public class BeanCreationException extends FatalBeanException {
|
||||||
* @param msg the detail message
|
* @param msg the detail message
|
||||||
*/
|
*/
|
||||||
public BeanCreationException(String beanName, String msg) {
|
public BeanCreationException(String beanName, String msg) {
|
||||||
super("Error creating bean" + (beanName != null ? " with name '" + beanName + "'" : "") + ": " + msg);
|
super("Error creating bean with name '" + beanName + "': " + msg);
|
||||||
this.beanName = beanName;
|
this.beanName = beanName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ public class BeanCreationException extends FatalBeanException {
|
||||||
* @param beanName the name of the bean requested
|
* @param beanName the name of the bean requested
|
||||||
* @param msg the detail message
|
* @param msg the detail message
|
||||||
*/
|
*/
|
||||||
public BeanCreationException(String resourceDescription, String beanName, String msg) {
|
public BeanCreationException(@Nullable String resourceDescription, @Nullable String beanName, String msg) {
|
||||||
super("Error creating bean" + (beanName != null ? " with name '" + beanName + "'" : "") +
|
super("Error creating bean with name '" + beanName + "'" +
|
||||||
(resourceDescription != null ? " defined in " + resourceDescription : "") + ": " + msg);
|
(resourceDescription != null ? " defined in " + resourceDescription : "") + ": " + msg);
|
||||||
this.resourceDescription = resourceDescription;
|
this.resourceDescription = resourceDescription;
|
||||||
this.beanName = beanName;
|
this.beanName = beanName;
|
||||||
|
@ -101,20 +101,12 @@ public class BeanCreationException extends FatalBeanException {
|
||||||
* @param msg the detail message
|
* @param msg the detail message
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
*/
|
*/
|
||||||
public BeanCreationException(String resourceDescription, String beanName, String msg, Throwable cause) {
|
public BeanCreationException(@Nullable String resourceDescription, String beanName, String msg, Throwable cause) {
|
||||||
this(resourceDescription, beanName, msg);
|
this(resourceDescription, beanName, msg);
|
||||||
initCause(cause);
|
initCause(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the name of the bean requested, if any.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public String getBeanName() {
|
|
||||||
return this.beanName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the description of the resource that the bean
|
* Return the description of the resource that the bean
|
||||||
* definition came from, if any.
|
* definition came from, if any.
|
||||||
|
@ -124,6 +116,13 @@ public class BeanCreationException extends FatalBeanException {
|
||||||
return this.resourceDescription;
|
return this.resourceDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the name of the bean requested, if any.
|
||||||
|
*/
|
||||||
|
public String getBeanName() {
|
||||||
|
return this.beanName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a related cause to this bean creation exception,
|
* Add a related cause to this bean creation exception,
|
||||||
* not being a direct cause of the failure but having occurred
|
* not being a direct cause of the failure but having occurred
|
||||||
|
@ -189,7 +188,7 @@ public class BeanCreationException extends FatalBeanException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(Class<?> exClass) {
|
public boolean contains(@Nullable Class<?> exClass) {
|
||||||
if (super.contains(exClass)) {
|
if (super.contains(exClass)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -57,7 +57,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||||
* @param resourceDescription description of the resource that the bean definition came from
|
* @param resourceDescription description of the resource that the bean definition came from
|
||||||
* @param msg the detail message (used as exception message as-is)
|
* @param msg the detail message (used as exception message as-is)
|
||||||
*/
|
*/
|
||||||
public BeanDefinitionStoreException(String resourceDescription, String msg) {
|
public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
this.resourceDescription = resourceDescription;
|
this.resourceDescription = resourceDescription;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||||
* @param msg the detail message (used as exception message as-is)
|
* @param msg the detail message (used as exception message as-is)
|
||||||
* @param cause the root cause (may be {@code null})
|
* @param cause the root cause (may be {@code null})
|
||||||
*/
|
*/
|
||||||
public BeanDefinitionStoreException(String resourceDescription, String msg, @Nullable Throwable cause) {
|
public BeanDefinitionStoreException(@Nullable String resourceDescription, String msg, @Nullable Throwable cause) {
|
||||||
super(msg, cause);
|
super(msg, cause);
|
||||||
this.resourceDescription = resourceDescription;
|
this.resourceDescription = resourceDescription;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||||
* @param msg the detail message (appended to an introductory message that indicates
|
* @param msg the detail message (appended to an introductory message that indicates
|
||||||
* the resource and the name of the bean)
|
* the resource and the name of the bean)
|
||||||
*/
|
*/
|
||||||
public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg) {
|
public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg) {
|
||||||
this(resourceDescription, beanName, msg, null);
|
this(resourceDescription, beanName, msg, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public class BeanDefinitionStoreException extends FatalBeanException {
|
||||||
* the resource and the name of the bean)
|
* the resource and the name of the bean)
|
||||||
* @param cause the root cause (may be {@code null})
|
* @param cause the root cause (may be {@code null})
|
||||||
*/
|
*/
|
||||||
public BeanDefinitionStoreException(String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
|
public BeanDefinitionStoreException(@Nullable String resourceDescription, String beanName, String msg, @Nullable Throwable cause) {
|
||||||
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg, cause);
|
super("Invalid bean definition with name '" + beanName + "' defined in " + resourceDescription + ": " + msg, cause);
|
||||||
this.resourceDescription = resourceDescription;
|
this.resourceDescription = resourceDescription;
|
||||||
this.beanName = beanName;
|
this.beanName = beanName;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -159,6 +159,22 @@ public interface BeanFactory {
|
||||||
*/
|
*/
|
||||||
<T> T getBean(String name, @Nullable Class<T> requiredType) throws BeansException;
|
<T> T getBean(String name, @Nullable Class<T> requiredType) throws BeansException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an instance, which may be shared or independent, of the specified bean.
|
||||||
|
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
||||||
|
* overriding the specified default arguments (if any) in the bean definition.
|
||||||
|
* @param name the name of the bean to retrieve
|
||||||
|
* @param args arguments to use when creating a bean instance using explicit arguments
|
||||||
|
* (only applied when creating a new instance as opposed to retrieving an existing one)
|
||||||
|
* @return an instance of the bean
|
||||||
|
* @throws NoSuchBeanDefinitionException if there is no such bean definition
|
||||||
|
* @throws BeanDefinitionStoreException if arguments have been given but
|
||||||
|
* the affected bean isn't a prototype
|
||||||
|
* @throws BeansException if the bean could not be created
|
||||||
|
* @since 2.5
|
||||||
|
*/
|
||||||
|
Object getBean(String name, Object... args) throws BeansException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the bean instance that uniquely matches the given object type, if any.
|
* Return the bean instance that uniquely matches the given object type, if any.
|
||||||
* <p>This method goes into {@link ListableBeanFactory} by-type lookup territory
|
* <p>This method goes into {@link ListableBeanFactory} by-type lookup territory
|
||||||
|
@ -176,22 +192,6 @@ public interface BeanFactory {
|
||||||
*/
|
*/
|
||||||
<T> T getBean(Class<T> requiredType) throws BeansException;
|
<T> T getBean(Class<T> requiredType) throws BeansException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an instance, which may be shared or independent, of the specified bean.
|
|
||||||
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
|
||||||
* overriding the specified default arguments (if any) in the bean definition.
|
|
||||||
* @param name the name of the bean to retrieve
|
|
||||||
* @param args arguments to use when creating a bean instance using explicit arguments
|
|
||||||
* (only applied when creating a new instance as opposed to retrieving an existing one)
|
|
||||||
* @return an instance of the bean
|
|
||||||
* @throws NoSuchBeanDefinitionException if there is no such bean definition
|
|
||||||
* @throws BeanDefinitionStoreException if arguments have been given but
|
|
||||||
* the affected bean isn't a prototype
|
|
||||||
* @throws BeansException if the bean could not be created
|
|
||||||
* @since 2.5
|
|
||||||
*/
|
|
||||||
Object getBean(String name, Object... args) throws BeansException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an instance, which may be shared or independent, of the specified bean.
|
* Return an instance, which may be shared or independent, of the specified bean.
|
||||||
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
* <p>Allows for specifying explicit constructor arguments / factory method arguments,
|
||||||
|
@ -298,7 +298,7 @@ public interface BeanFactory {
|
||||||
* @see #getBean
|
* @see #getBean
|
||||||
* @see #getType
|
* @see #getType
|
||||||
*/
|
*/
|
||||||
boolean isTypeMatch(String name, Class<?> typeToMatch) throws NoSuchBeanDefinitionException;
|
boolean isTypeMatch(String name, @Nullable Class<?> typeToMatch) throws NoSuchBeanDefinitionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the type of the bean with the given name. More specifically,
|
* Determine the type of the bean with the given name. More specifically,
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.core.ResolvableType;
|
import org.springframework.core.ResolvableType;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ public abstract class BeanFactoryUtils {
|
||||||
* @return whether the given name is a factory dereference
|
* @return whether the given name is a factory dereference
|
||||||
* @see BeanFactory#FACTORY_BEAN_PREFIX
|
* @see BeanFactory#FACTORY_BEAN_PREFIX
|
||||||
*/
|
*/
|
||||||
public static boolean isFactoryDereference(String name) {
|
public static boolean isFactoryDereference(@Nullable String name) {
|
||||||
return (name != null && name.startsWith(BeanFactory.FACTORY_BEAN_PREFIX));
|
return (name != null && name.startsWith(BeanFactory.FACTORY_BEAN_PREFIX));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ public abstract class BeanFactoryUtils {
|
||||||
* @see org.springframework.beans.factory.support.BeanDefinitionReaderUtils#generateBeanName
|
* @see org.springframework.beans.factory.support.BeanDefinitionReaderUtils#generateBeanName
|
||||||
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
|
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
|
||||||
*/
|
*/
|
||||||
public static boolean isGeneratedBeanName(String name) {
|
public static boolean isGeneratedBeanName(@Nullable String name) {
|
||||||
return (name != null && name.contains(GENERATED_BEAN_NAME_SEPARATOR));
|
return (name != null && name.contains(GENERATED_BEAN_NAME_SEPARATOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.beans.factory;
|
package org.springframework.beans.factory;
|
||||||
|
|
||||||
import org.springframework.beans.FatalBeanException;
|
import org.springframework.beans.FatalBeanException;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when the BeanFactory cannot load the specified class
|
* Exception thrown when the BeanFactory cannot load the specified class
|
||||||
|
@ -44,10 +45,10 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
*/
|
*/
|
||||||
public CannotLoadBeanClassException(
|
public CannotLoadBeanClassException(
|
||||||
String resourceDescription, String beanName, String beanClassName, ClassNotFoundException cause) {
|
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, ClassNotFoundException cause) {
|
||||||
|
|
||||||
super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName +
|
super("Cannot find class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
|
||||||
"' defined in " + resourceDescription, cause);
|
(resourceDescription != null ? " defined in " + resourceDescription : ""), cause);
|
||||||
this.resourceDescription = resourceDescription;
|
this.resourceDescription = resourceDescription;
|
||||||
this.beanName = beanName;
|
this.beanName = beanName;
|
||||||
this.beanClassName = beanClassName;
|
this.beanClassName = beanClassName;
|
||||||
|
@ -62,10 +63,11 @@ public class CannotLoadBeanClassException extends FatalBeanException {
|
||||||
* @param cause the root cause
|
* @param cause the root cause
|
||||||
*/
|
*/
|
||||||
public CannotLoadBeanClassException(
|
public CannotLoadBeanClassException(
|
||||||
String resourceDescription, String beanName, String beanClassName, LinkageError cause) {
|
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, LinkageError cause) {
|
||||||
|
|
||||||
super("Error loading class [" + beanClassName + "] for bean with name '" + beanName +
|
super("Error loading class [" + String.valueOf(beanClassName) + "] for bean with name '" + beanName + "'" +
|
||||||
"' defined in " + resourceDescription + ": problem with class file or dependent class", cause);
|
(resourceDescription != null ? " defined in " + resourceDescription : "") +
|
||||||
|
": problem with class file or dependent class", cause);
|
||||||
this.resourceDescription = resourceDescription;
|
this.resourceDescription = resourceDescription;
|
||||||
this.beanName = beanName;
|
this.beanName = beanName;
|
||||||
this.beanClassName = beanClassName;
|
this.beanClassName = beanClassName;
|
||||||
|
|
|
@ -106,7 +106,7 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||||
* result will be the same as for {@code getBeanNamesForType(type, true, true)}.
|
* result will be the same as for {@code getBeanNamesForType(type, true, true)}.
|
||||||
* <p>Bean names returned by this method should always return bean names <i>in the
|
* <p>Bean names returned by this method should always return bean names <i>in the
|
||||||
* order of definition</i> in the backend configuration, as far as possible.
|
* order of definition</i> in the backend configuration, as far as possible.
|
||||||
* @param type the class or interface to match, or {@code null} for all bean names
|
* @param type the generically typed class or interface to match
|
||||||
* @return the names of beans (or objects created by FactoryBeans) matching
|
* @return the names of beans (or objects created by FactoryBeans) matching
|
||||||
* the given object type (including subclasses), or an empty array if none
|
* the given object type (including subclasses), or an empty array if none
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
|
@ -114,7 +114,7 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||||
* @see FactoryBean#getObjectType
|
* @see FactoryBean#getObjectType
|
||||||
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, ResolvableType)
|
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, ResolvableType)
|
||||||
*/
|
*/
|
||||||
String[] getBeanNamesForType(@Nullable ResolvableType type);
|
String[] getBeanNamesForType(ResolvableType type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the names of beans matching the given type (including subclasses),
|
* Return the names of beans matching the given type (including subclasses),
|
||||||
|
@ -268,7 +268,7 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||||
* found on the given class itself.
|
* found on the given class itself.
|
||||||
* @param beanName the name of the bean to look for annotations on
|
* @param beanName the name of the bean to look for annotations on
|
||||||
* @param annotationType the annotation class to look for
|
* @param annotationType the annotation class to look for
|
||||||
* @return the annotation of the given type if found, or {@code null}
|
* @return the annotation of the given type if found, or {@code null} otherwise
|
||||||
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.beans.factory;
|
package org.springframework.beans.factory;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines a factory which can return an Object instance
|
* Defines a factory which can return an Object instance
|
||||||
|
@ -41,9 +42,10 @@ public interface ObjectFactory<T> {
|
||||||
/**
|
/**
|
||||||
* Return an instance (possibly shared or independent)
|
* Return an instance (possibly shared or independent)
|
||||||
* of the object managed by this factory.
|
* of the object managed by this factory.
|
||||||
* @return an instance of the bean (should never be {@code null})
|
* @return the resulting instance
|
||||||
* @throws BeansException in case of creation errors
|
* @throws BeansException in case of creation errors
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
T getObject() throws BeansException;
|
T getObject() throws BeansException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ public interface ObjectProvider<T> extends ObjectFactory<T> {
|
||||||
* @throws BeansException in case of creation errors
|
* @throws BeansException in case of creation errors
|
||||||
* @see #getObject()
|
* @see #getObject()
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
T getObject(Object... args) throws BeansException;
|
T getObject(Object... args) throws BeansException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -228,10 +228,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
|
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
|
||||||
if (beanType != null) {
|
InjectionMetadata metadata = findAutowiringMetadata(beanName, beanType, null);
|
||||||
InjectionMetadata metadata = findAutowiringMetadata(beanName, beanType, null);
|
metadata.checkConfigMembers(beanDefinition);
|
||||||
metadata.checkConfigMembers(beanDefinition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -389,7 +387,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
|
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
|
||||||
// Fall back to class name as cache key, for backwards compatibility with custom callers.
|
// Fall back to class name as cache key, for backwards compatibility with custom callers.
|
||||||
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
|
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
|
||||||
// Quick check on the concurrent map first, with minimal locking.
|
// Quick check on the concurrent map first, with minimal locking.
|
||||||
|
@ -512,7 +510,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
/**
|
/**
|
||||||
* Register the specified bean as dependent on the autowired beans.
|
* Register the specified bean as dependent on the autowired beans.
|
||||||
*/
|
*/
|
||||||
private void registerDependentBeans(String beanName, Set<String> autowiredBeanNames) {
|
private void registerDependentBeans(@Nullable String beanName, Set<String> autowiredBeanNames) {
|
||||||
if (beanName != null) {
|
if (beanName != null) {
|
||||||
for (String autowiredBeanName : autowiredBeanNames) {
|
for (String autowiredBeanName : autowiredBeanNames) {
|
||||||
if (this.beanFactory.containsBean(autowiredBeanName)) {
|
if (this.beanFactory.containsBean(autowiredBeanName)) {
|
||||||
|
@ -529,7 +527,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
/**
|
/**
|
||||||
* Resolve the specified cached method argument or field value.
|
* Resolve the specified cached method argument or field value.
|
||||||
*/
|
*/
|
||||||
private Object resolvedCachedArgument(String beanName, Object cachedArgument) {
|
@Nullable
|
||||||
|
private Object resolvedCachedArgument(@Nullable String beanName, Object cachedArgument) {
|
||||||
if (cachedArgument instanceof DependencyDescriptor) {
|
if (cachedArgument instanceof DependencyDescriptor) {
|
||||||
DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
|
DependencyDescriptor descriptor = (DependencyDescriptor) cachedArgument;
|
||||||
return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
|
return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
|
||||||
|
@ -557,7 +556,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
|
protected void inject(Object bean, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
|
||||||
Field field = (Field) this.member;
|
Field field = (Field) this.member;
|
||||||
Object value;
|
Object value;
|
||||||
if (this.cached) {
|
if (this.cached) {
|
||||||
|
@ -615,13 +614,13 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
|
|
||||||
private volatile Object[] cachedMethodArguments;
|
private volatile Object[] cachedMethodArguments;
|
||||||
|
|
||||||
public AutowiredMethodElement(Method method, boolean required, PropertyDescriptor pd) {
|
public AutowiredMethodElement(Method method, boolean required, @Nullable PropertyDescriptor pd) {
|
||||||
super(method, pd);
|
super(method, pd);
|
||||||
this.required = required;
|
this.required = required;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
|
protected void inject(Object bean, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
|
||||||
if (checkPropertySkipping(pvs)) {
|
if (checkPropertySkipping(pvs)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -694,7 +693,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Object[] resolveCachedArguments(String beanName) {
|
private Object[] resolveCachedArguments(@Nullable String beanName) {
|
||||||
if (this.cachedMethodArguments == null) {
|
if (this.cachedMethodArguments == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||||
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,7 +121,9 @@ public abstract class BeanFactoryAnnotationUtils {
|
||||||
* qualifier value (through {@code <qualifier>} or {@code @Qualifier})
|
* qualifier value (through {@code <qualifier>} or {@code @Qualifier})
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
public static boolean isQualifierMatch(Predicate<String> qualifier, String beanName, BeanFactory beanFactory) {
|
public static boolean isQualifierMatch(Predicate<String> qualifier, String beanName,
|
||||||
|
@Nullable BeanFactory beanFactory) {
|
||||||
|
|
||||||
// Try quick bean name or alias match first...
|
// Try quick bean name or alias match first...
|
||||||
if (qualifier.test(beanName)) {
|
if (qualifier.test(beanName)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -121,10 +121,8 @@ public class InitDestroyAnnotationBeanPostProcessor
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
|
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
|
||||||
if (beanType != null) {
|
LifecycleMetadata metadata = findLifecycleMetadata(beanType);
|
||||||
LifecycleMetadata metadata = findLifecycleMetadata(beanType);
|
metadata.checkConfigMembers(beanDefinition);
|
||||||
metadata.checkConfigMembers(beanDefinition);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -77,7 +77,7 @@ public class InjectionMetadata {
|
||||||
this.checkedElements = checkedElements;
|
this.checkedElements = checkedElements;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inject(Object target, String beanName, PropertyValues pvs) throws Throwable {
|
public void inject(Object target, @Nullable String beanName, @Nullable PropertyValues pvs) throws Throwable {
|
||||||
Collection<InjectedElement> elementsToIterate =
|
Collection<InjectedElement> elementsToIterate =
|
||||||
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
|
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
|
||||||
if (!elementsToIterate.isEmpty()) {
|
if (!elementsToIterate.isEmpty()) {
|
||||||
|
@ -94,7 +94,7 @@ public class InjectionMetadata {
|
||||||
/**
|
/**
|
||||||
* @since 3.2.13
|
* @since 3.2.13
|
||||||
*/
|
*/
|
||||||
public void clear(PropertyValues pvs) {
|
public void clear(@Nullable PropertyValues pvs) {
|
||||||
Collection<InjectedElement> elementsToIterate =
|
Collection<InjectedElement> elementsToIterate =
|
||||||
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
|
(this.checkedElements != null ? this.checkedElements : this.injectedElements);
|
||||||
if (!elementsToIterate.isEmpty()) {
|
if (!elementsToIterate.isEmpty()) {
|
||||||
|
@ -105,7 +105,7 @@ public class InjectionMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean needsRefresh(InjectionMetadata metadata, Class<?> clazz) {
|
public static boolean needsRefresh(@Nullable InjectionMetadata metadata, Class<?> clazz) {
|
||||||
return (metadata == null || metadata.targetClass != clazz);
|
return (metadata == null || metadata.targetClass != clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ public class InjectionMetadata {
|
||||||
|
|
||||||
protected volatile Boolean skip;
|
protected volatile Boolean skip;
|
||||||
|
|
||||||
protected InjectedElement(Member member, PropertyDescriptor pd) {
|
protected InjectedElement(Member member, @Nullable PropertyDescriptor pd) {
|
||||||
this.member = member;
|
this.member = member;
|
||||||
this.isField = (member instanceof Field);
|
this.isField = (member instanceof Field);
|
||||||
this.pd = pd;
|
this.pd = pd;
|
||||||
|
@ -163,7 +163,9 @@ public class InjectionMetadata {
|
||||||
/**
|
/**
|
||||||
* Either this or {@link #getResourceToInject} needs to be overridden.
|
* Either this or {@link #getResourceToInject} needs to be overridden.
|
||||||
*/
|
*/
|
||||||
protected void inject(Object target, String requestingBeanName, PropertyValues pvs) throws Throwable {
|
protected void inject(Object target, @Nullable String requestingBeanName, @Nullable PropertyValues pvs)
|
||||||
|
throws Throwable {
|
||||||
|
|
||||||
if (this.isField) {
|
if (this.isField) {
|
||||||
Field field = (Field) this.member;
|
Field field = (Field) this.member;
|
||||||
ReflectionUtils.makeAccessible(field);
|
ReflectionUtils.makeAccessible(field);
|
||||||
|
@ -189,7 +191,7 @@ public class InjectionMetadata {
|
||||||
* an explicit property value having been specified. Also marks the
|
* an explicit property value having been specified. Also marks the
|
||||||
* affected property as processed for other processors to ignore it.
|
* affected property as processed for other processors to ignore it.
|
||||||
*/
|
*/
|
||||||
protected boolean checkPropertySkipping(PropertyValues pvs) {
|
protected boolean checkPropertySkipping(@Nullable PropertyValues pvs) {
|
||||||
if (this.skip != null) {
|
if (this.skip != null) {
|
||||||
return this.skip;
|
return this.skip;
|
||||||
}
|
}
|
||||||
|
@ -219,7 +221,7 @@ public class InjectionMetadata {
|
||||||
/**
|
/**
|
||||||
* @since 3.2.13
|
* @since 3.2.13
|
||||||
*/
|
*/
|
||||||
protected void clearPropertySkipping(PropertyValues pvs) {
|
protected void clearPropertySkipping(@Nullable PropertyValues pvs) {
|
||||||
if (pvs == null) {
|
if (pvs == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -234,7 +236,7 @@ public class InjectionMetadata {
|
||||||
* Either this or {@link #inject} needs to be overridden.
|
* Either this or {@link #inject} needs to be overridden.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected Object getResourceToInject(Object target, String requestingBeanName) {
|
protected Object getResourceToInject(Object target, @Nullable String requestingBeanName) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
||||||
@Override
|
@Override
|
||||||
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
|
public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
|
||||||
boolean match = super.isAutowireCandidate(bdHolder, descriptor);
|
boolean match = super.isAutowireCandidate(bdHolder, descriptor);
|
||||||
if (match && descriptor != null) {
|
if (match) {
|
||||||
match = checkQualifiers(bdHolder, descriptor.getAnnotations());
|
match = checkQualifiers(bdHolder, descriptor.getAnnotations());
|
||||||
if (match) {
|
if (match) {
|
||||||
MethodParameter methodParam = descriptor.getMethodParameter();
|
MethodParameter methodParam = descriptor.getMethodParameter();
|
||||||
|
@ -298,11 +298,13 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
|
protected Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
|
||||||
AnnotatedElement qualifiedElement = bd.getQualifiedElement();
|
AnnotatedElement qualifiedElement = bd.getQualifiedElement();
|
||||||
return (qualifiedElement != null ? AnnotationUtils.getAnnotation(qualifiedElement, type) : null);
|
return (qualifiedElement != null ? AnnotationUtils.getAnnotation(qualifiedElement, type) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
|
protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
|
||||||
Method resolvedFactoryMethod = bd.getResolvedFactoryMethod();
|
Method resolvedFactoryMethod = bd.getResolvedFactoryMethod();
|
||||||
return (resolvedFactoryMethod != null ? AnnotationUtils.getAnnotation(resolvedFactoryMethod, type) : null);
|
return (resolvedFactoryMethod != null ? AnnotationUtils.getAnnotation(resolvedFactoryMethod, type) : null);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -39,6 +39,7 @@ import org.springframework.core.Conventions;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.PriorityOrdered;
|
import org.springframework.core.PriorityOrdered;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
import org.springframework.core.annotation.AnnotationUtils;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,7 +171,7 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP
|
||||||
* @param beanName the name of the bean to check against
|
* @param beanName the name of the bean to check against
|
||||||
* @return {@code true} to skip the bean; {@code false} to process it
|
* @return {@code true} to skip the bean; {@code false} to process it
|
||||||
*/
|
*/
|
||||||
protected boolean shouldSkip(ConfigurableListableBeanFactory beanFactory, String beanName) {
|
protected boolean shouldSkip(@Nullable ConfigurableListableBeanFactory beanFactory, String beanName) {
|
||||||
if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
|
if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public abstract class AbstractFactoryBean<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
|
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||||
this.beanClassLoader = classLoader;
|
this.beanClassLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -268,6 +268,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
* @return the bean instance to use, either the original or a wrapped one
|
* @return the bean instance to use, either the original or a wrapped one
|
||||||
* @throws BeansException if the initialization failed
|
* @throws BeansException if the initialization failed
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
Object initializeBean(Object existingBean, String beanName) throws BeansException;
|
Object initializeBean(Object existingBean, String beanName) throws BeansException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -280,6 +281,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
* @throws BeansException if any post-processing failed
|
* @throws BeansException if any post-processing failed
|
||||||
* @see BeanPostProcessor#postProcessBeforeInitialization
|
* @see BeanPostProcessor#postProcessBeforeInitialization
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
|
Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
|
||||||
throws BeansException;
|
throws BeansException;
|
||||||
|
|
||||||
|
@ -293,6 +295,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
* @throws BeansException if any post-processing failed
|
* @throws BeansException if any post-processing failed
|
||||||
* @see BeanPostProcessor#postProcessAfterInitialization
|
* @see BeanPostProcessor#postProcessAfterInitialization
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
|
Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
|
||||||
throws BeansException;
|
throws BeansException;
|
||||||
|
|
||||||
|
@ -356,7 +359,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
* @see DependencyDescriptor
|
* @see DependencyDescriptor
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName,
|
Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
|
||||||
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException;
|
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -101,7 +101,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||||
* @see #setFactoryBeanName
|
* @see #setFactoryBeanName
|
||||||
* @see #setFactoryMethodName
|
* @see #setFactoryMethodName
|
||||||
*/
|
*/
|
||||||
void setBeanClassName(String beanClassName);
|
void setBeanClassName(@Nullable String beanClassName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current bean class name of this bean definition.
|
* Return the current bean class name of this bean definition.
|
||||||
|
@ -115,6 +115,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||||
* @see #getFactoryBeanName()
|
* @see #getFactoryBeanName()
|
||||||
* @see #getFactoryMethodName()
|
* @see #getFactoryMethodName()
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
String getBeanClassName();
|
String getBeanClassName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,11 +123,10 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||||
* @see #SCOPE_SINGLETON
|
* @see #SCOPE_SINGLETON
|
||||||
* @see #SCOPE_PROTOTYPE
|
* @see #SCOPE_PROTOTYPE
|
||||||
*/
|
*/
|
||||||
void setScope(String scope);
|
void setScope(@Nullable String scope);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the name of the current target scope for this bean,
|
* Return the name of the current target scope for this bean.
|
||||||
* or {@code null} if not known yet.
|
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
String getScope();
|
String getScope();
|
||||||
|
@ -153,6 +153,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||||
/**
|
/**
|
||||||
* Return the bean names that this bean depends on.
|
* Return the bean names that this bean depends on.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
String[] getDependsOn();
|
String[] getDependsOn();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,7 +187,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||||
* This the name of the bean to call the specified factory method on.
|
* This the name of the bean to call the specified factory method on.
|
||||||
* @see #setFactoryMethodName
|
* @see #setFactoryMethodName
|
||||||
*/
|
*/
|
||||||
void setFactoryBeanName(String factoryBeanName);
|
void setFactoryBeanName(@Nullable String factoryBeanName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the factory bean name, if any.
|
* Return the factory bean name, if any.
|
||||||
|
@ -202,7 +203,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||||
* @see #setFactoryBeanName
|
* @see #setFactoryBeanName
|
||||||
* @see #setBeanClassName
|
* @see #setBeanClassName
|
||||||
*/
|
*/
|
||||||
void setFactoryMethodName(String factoryMethodName);
|
void setFactoryMethodName(@Nullable String factoryMethodName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a factory method, if any.
|
* Return a factory method, if any.
|
||||||
|
@ -259,6 +260,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
|
||||||
/**
|
/**
|
||||||
* Return a human-readable description of this bean definition.
|
* Return a human-readable description of this bean definition.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
String getDescription();
|
String getDescription();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -120,7 +120,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
|
||||||
* Determine whether the given candidate name matches the bean name
|
* Determine whether the given candidate name matches the bean name
|
||||||
* or the aliases stored in this bean definition.
|
* or the aliases stored in this bean definition.
|
||||||
*/
|
*/
|
||||||
public boolean matchesName(String candidateName) {
|
public boolean matchesName(@Nullable String candidateName) {
|
||||||
return (candidateName != null && (candidateName.equals(this.beanName) ||
|
return (candidateName != null && (candidateName.equals(this.beanName) ||
|
||||||
candidateName.equals(BeanFactoryUtils.transformedBeanName(this.beanName)) ||
|
candidateName.equals(BeanFactoryUtils.transformedBeanName(this.beanName)) ||
|
||||||
ObjectUtils.containsElement(this.aliases, candidateName)));
|
ObjectUtils.containsElement(this.aliases, candidateName)));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2011 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -24,6 +24,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.PropertyValue;
|
import org.springframework.beans.PropertyValue;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringValueResolver;
|
import org.springframework.util.StringValueResolver;
|
||||||
|
@ -164,7 +165,8 @@ public class BeanDefinitionVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
protected Object resolveValue(Object value) {
|
@Nullable
|
||||||
|
protected Object resolveValue(@Nullable Object value) {
|
||||||
if (value instanceof BeanDefinition) {
|
if (value instanceof BeanDefinition) {
|
||||||
visitBeanDefinition((BeanDefinition) value);
|
visitBeanDefinition((BeanDefinition) value);
|
||||||
}
|
}
|
||||||
|
@ -174,6 +176,9 @@ public class BeanDefinitionVisitor {
|
||||||
else if (value instanceof RuntimeBeanReference) {
|
else if (value instanceof RuntimeBeanReference) {
|
||||||
RuntimeBeanReference ref = (RuntimeBeanReference) value;
|
RuntimeBeanReference ref = (RuntimeBeanReference) value;
|
||||||
String newBeanName = resolveStringValue(ref.getBeanName());
|
String newBeanName = resolveStringValue(ref.getBeanName());
|
||||||
|
if (newBeanName == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (!newBeanName.equals(ref.getBeanName())) {
|
if (!newBeanName.equals(ref.getBeanName())) {
|
||||||
return new RuntimeBeanReference(newBeanName);
|
return new RuntimeBeanReference(newBeanName);
|
||||||
}
|
}
|
||||||
|
@ -181,6 +186,9 @@ public class BeanDefinitionVisitor {
|
||||||
else if (value instanceof RuntimeBeanNameReference) {
|
else if (value instanceof RuntimeBeanNameReference) {
|
||||||
RuntimeBeanNameReference ref = (RuntimeBeanNameReference) value;
|
RuntimeBeanNameReference ref = (RuntimeBeanNameReference) value;
|
||||||
String newBeanName = resolveStringValue(ref.getBeanName());
|
String newBeanName = resolveStringValue(ref.getBeanName());
|
||||||
|
if (newBeanName == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (!newBeanName.equals(ref.getBeanName())) {
|
if (!newBeanName.equals(ref.getBeanName())) {
|
||||||
return new RuntimeBeanNameReference(newBeanName);
|
return new RuntimeBeanNameReference(newBeanName);
|
||||||
}
|
}
|
||||||
|
@ -274,6 +282,7 @@ public class BeanDefinitionVisitor {
|
||||||
* @param strVal the original String value
|
* @param strVal the original String value
|
||||||
* @return the resolved String value
|
* @return the resolved String value
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
protected String resolveStringValue(String strVal) {
|
protected String resolveStringValue(String strVal) {
|
||||||
if (this.valueResolver == null) {
|
if (this.valueResolver == null) {
|
||||||
throw new IllegalStateException("No StringValueResolver specified - pass a resolver " +
|
throw new IllegalStateException("No StringValueResolver specified - pass a resolver " +
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.beans.factory.config;
|
package org.springframework.beans.factory.config;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strategy interface for resolving a value through evaluating it
|
* Strategy interface for resolving a value through evaluating it
|
||||||
|
@ -40,6 +41,7 @@ public interface BeanExpressionResolver {
|
||||||
* @return the resolved value (potentially the given value as-is)
|
* @return the resolved value (potentially the given value as-is)
|
||||||
* @throws BeansException if evaluation failed
|
* @throws BeansException if evaluation failed
|
||||||
*/
|
*/
|
||||||
Object evaluate(String value, BeanExpressionContext evalContext) throws BeansException;
|
@Nullable
|
||||||
|
Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -134,12 +134,13 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
|
||||||
* here, supporting "#{...}" expressions in a Unified EL compatible style.
|
* here, supporting "#{...}" expressions in a Unified EL compatible style.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
void setBeanExpressionResolver(BeanExpressionResolver resolver);
|
void setBeanExpressionResolver(@Nullable BeanExpressionResolver resolver);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the resolution strategy for expressions in bean definition values.
|
* Return the resolution strategy for expressions in bean definition values.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
BeanExpressionResolver getBeanExpressionResolver();
|
BeanExpressionResolver getBeanExpressionResolver();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +148,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
|
||||||
* property values, as an alternative to JavaBeans PropertyEditors.
|
* property values, as an alternative to JavaBeans PropertyEditors.
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
void setConversionService(ConversionService conversionService);
|
void setConversionService(@Nullable ConversionService conversionService);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the associated ConversionService, if any.
|
* Return the associated ConversionService, if any.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -78,7 +78,7 @@ public interface ConfigurableListableBeanFactory
|
||||||
* implementation of the {@link org.springframework.beans.factory.ObjectFactory}
|
* implementation of the {@link org.springframework.beans.factory.ObjectFactory}
|
||||||
* interface, which allows for lazy resolution of the actual target value.
|
* interface, which allows for lazy resolution of the actual target value.
|
||||||
*/
|
*/
|
||||||
void registerResolvableDependency(Class<?> dependencyType, Object autowiredValue);
|
void registerResolvableDependency(Class<?> dependencyType, @Nullable Object autowiredValue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether the specified bean qualifies as an autowire candidate,
|
* Determine whether the specified bean qualifies as an autowire candidate,
|
||||||
|
@ -106,7 +106,7 @@ public interface ConfigurableListableBeanFactory
|
||||||
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
||||||
* defined in this factory
|
* defined in this factory
|
||||||
*/
|
*/
|
||||||
BeanDefinition getBeanDefinition(@Nullable String beanName) throws NoSuchBeanDefinitionException;
|
BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a unified view over all bean names managed by this factory.
|
* Return a unified view over all bean names managed by this factory.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -70,7 +70,7 @@ public class ConstructorArgumentValues {
|
||||||
* to allow for merging and re-merging of argument value definitions. Distinct
|
* to allow for merging and re-merging of argument value definitions. Distinct
|
||||||
* ValueHolder instances carrying the same content are of course allowed.
|
* ValueHolder instances carrying the same content are of course allowed.
|
||||||
*/
|
*/
|
||||||
public void addArgumentValues(ConstructorArgumentValues other) {
|
public void addArgumentValues(@Nullable ConstructorArgumentValues other) {
|
||||||
if (other != null) {
|
if (other != null) {
|
||||||
for (Map.Entry<Integer, ValueHolder> entry : other.indexedArgumentValues.entrySet()) {
|
for (Map.Entry<Integer, ValueHolder> entry : other.indexedArgumentValues.entrySet()) {
|
||||||
addOrMergeIndexedArgumentValue(entry.getKey(), entry.getValue().copy());
|
addOrMergeIndexedArgumentValue(entry.getKey(), entry.getValue().copy());
|
||||||
|
@ -89,7 +89,7 @@ public class ConstructorArgumentValues {
|
||||||
* @param index the index in the constructor argument list
|
* @param index the index in the constructor argument list
|
||||||
* @param value the argument value
|
* @param value the argument value
|
||||||
*/
|
*/
|
||||||
public void addIndexedArgumentValue(int index, Object value) {
|
public void addIndexedArgumentValue(int index, @Nullable Object value) {
|
||||||
addIndexedArgumentValue(index, new ValueHolder(value));
|
addIndexedArgumentValue(index, new ValueHolder(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ public class ConstructorArgumentValues {
|
||||||
* @param value the argument value
|
* @param value the argument value
|
||||||
* @param type the type of the constructor argument
|
* @param type the type of the constructor argument
|
||||||
*/
|
*/
|
||||||
public void addIndexedArgumentValue(int index, Object value, String type) {
|
public void addIndexedArgumentValue(int index, @Nullable Object value, String type) {
|
||||||
addIndexedArgumentValue(index, new ValueHolder(value, type));
|
addIndexedArgumentValue(index, new ValueHolder(value, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +453,7 @@ public class ConstructorArgumentValues {
|
||||||
* Create a new ValueHolder for the given value.
|
* Create a new ValueHolder for the given value.
|
||||||
* @param value the argument value
|
* @param value the argument value
|
||||||
*/
|
*/
|
||||||
public ValueHolder(Object value) {
|
public ValueHolder(@Nullable Object value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,7 +462,7 @@ public class ConstructorArgumentValues {
|
||||||
* @param value the argument value
|
* @param value the argument value
|
||||||
* @param type the type of the constructor argument
|
* @param type the type of the constructor argument
|
||||||
*/
|
*/
|
||||||
public ValueHolder(Object value, String type) {
|
public ValueHolder(@Nullable Object value, @Nullable String type) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +473,7 @@ public class ConstructorArgumentValues {
|
||||||
* @param type the type of the constructor argument
|
* @param type the type of the constructor argument
|
||||||
* @param name the name of the constructor argument
|
* @param name the name of the constructor argument
|
||||||
*/
|
*/
|
||||||
public ValueHolder(Object value, String type, String name) {
|
public ValueHolder(@Nullable Object value, @Nullable String type, @Nullable String name) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -483,13 +483,14 @@ public class ConstructorArgumentValues {
|
||||||
* Set the value for the constructor argument.
|
* Set the value for the constructor argument.
|
||||||
* @see PropertyPlaceholderConfigurer
|
* @see PropertyPlaceholderConfigurer
|
||||||
*/
|
*/
|
||||||
public void setValue(Object value) {
|
public void setValue(@Nullable Object value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the value for the constructor argument.
|
* Return the value for the constructor argument.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
@ -497,13 +498,14 @@ public class ConstructorArgumentValues {
|
||||||
/**
|
/**
|
||||||
* Set the type of the constructor argument.
|
* Set the type of the constructor argument.
|
||||||
*/
|
*/
|
||||||
public void setType(String type) {
|
public void setType(@Nullable String type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the type of the constructor argument.
|
* Return the type of the constructor argument.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return this.type;
|
return this.type;
|
||||||
}
|
}
|
||||||
|
@ -511,13 +513,14 @@ public class ConstructorArgumentValues {
|
||||||
/**
|
/**
|
||||||
* Set the name of the constructor argument.
|
* Set the name of the constructor argument.
|
||||||
*/
|
*/
|
||||||
public void setName(String name) {
|
public void setName(@Nullable String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the name of the constructor argument.
|
* Return the name of the constructor argument.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
@ -526,11 +529,12 @@ public class ConstructorArgumentValues {
|
||||||
* Set the configuration source {@code Object} for this metadata element.
|
* Set the configuration source {@code Object} for this metadata element.
|
||||||
* <p>The exact type of the object will depend on the configuration mechanism used.
|
* <p>The exact type of the object will depend on the configuration mechanism used.
|
||||||
*/
|
*/
|
||||||
public void setSource(Object source) {
|
public void setSource(@Nullable Object source) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Object getSource() {
|
public Object getSource() {
|
||||||
return this.source;
|
return this.source;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,12 +99,9 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
|
||||||
|
|
||||||
this.declaringClass = methodParameter.getDeclaringClass();
|
this.declaringClass = methodParameter.getDeclaringClass();
|
||||||
if (this.methodParameter.getMethod() != null) {
|
if (this.methodParameter.getMethod() != null) {
|
||||||
this.methodName = methodParameter.getMethod().getName();
|
this.methodName = this.methodParameter.getMethod().getName();
|
||||||
this.parameterTypes = methodParameter.getMethod().getParameterTypes();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.parameterTypes = methodParameter.getConstructor().getParameterTypes();
|
|
||||||
}
|
}
|
||||||
|
this.parameterTypes = methodParameter.getExecutable().getParameterTypes();
|
||||||
this.parameterIndex = methodParameter.getParameterIndex();
|
this.parameterIndex = methodParameter.getParameterIndex();
|
||||||
this.containingClass = methodParameter.getContainingClass();
|
this.containingClass = methodParameter.getContainingClass();
|
||||||
this.required = required;
|
this.required = required;
|
||||||
|
@ -334,6 +331,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
|
||||||
* Determine the name of the wrapped parameter/field.
|
* Determine the name of the wrapped parameter/field.
|
||||||
* @return the declared name (never {@code null})
|
* @return the declared name (never {@code null})
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public String getDependencyName() {
|
public String getDependencyName() {
|
||||||
return (this.field != null ? this.field.getName() : this.methodParameter.getParameterName());
|
return (this.field != null ? this.field.getName() : this.methodParameter.getParameterName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -44,7 +44,6 @@ public class DeprecatedBeanWarner implements BeanFactoryPostProcessor {
|
||||||
* <p>This can be specified to not log into the category of this warner class but rather
|
* <p>This can be specified to not log into the category of this warner class but rather
|
||||||
* into a specific named category.
|
* into a specific named category.
|
||||||
* @see org.apache.commons.logging.LogFactory#getLog(String)
|
* @see org.apache.commons.logging.LogFactory#getLog(String)
|
||||||
* @see org.apache.log4j.Logger#getLogger(String)
|
|
||||||
* @see java.util.logging.Logger#getLogger(String)
|
* @see java.util.logging.Logger#getLogger(String)
|
||||||
*/
|
*/
|
||||||
public void setLoggerName(String loggerName) {
|
public void setLoggerName(String loggerName) {
|
||||||
|
@ -61,10 +60,13 @@ public class DeprecatedBeanWarner implements BeanFactoryPostProcessor {
|
||||||
if (beanFactory.isFactoryBean(beanName)) {
|
if (beanFactory.isFactoryBean(beanName)) {
|
||||||
nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
|
nameToLookup = BeanFactory.FACTORY_BEAN_PREFIX + beanName;
|
||||||
}
|
}
|
||||||
Class<?> beanType = ClassUtils.getUserClass(beanFactory.getType(nameToLookup));
|
Class<?> beanType = beanFactory.getType(nameToLookup);
|
||||||
if (beanType != null && beanType.isAnnotationPresent(Deprecated.class)) {
|
if (beanType != null) {
|
||||||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
Class<?> userClass = ClassUtils.getUserClass(beanType);
|
||||||
logDeprecatedBean(beanName, beanType, beanDefinition);
|
if (userClass.isAnnotationPresent(Deprecated.class)) {
|
||||||
|
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
|
||||||
|
logDeprecatedBean(beanName, beanType, beanDefinition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue