Declare isStatic and releaseTarget as default methods on TargetSource

Closes gh-31820
This commit is contained in:
Juergen Hoeller
2023-12-12 12:39:52 +01:00
parent eae53560e4
commit 6bb9775309
11 changed files with 14 additions and 98 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,10 +49,13 @@ public interface TargetSource extends TargetClassAware {
* Will all calls to {@link #getTarget()} return the same object?
* <p>In that case, there will be no need to invoke {@link #releaseTarget(Object)},
* and the AOP framework can cache the return value of {@link #getTarget()}.
* <p>The default implementation returns {@code false}.
* @return {@code true} if the target is immutable
* @see #getTarget
*/
boolean isStatic();
default boolean isStatic() {
return false;
}
/**
* Return a target instance. Invoked immediately before the
@@ -67,9 +70,11 @@ public interface TargetSource extends TargetClassAware {
/**
* Release the given target object obtained from the
* {@link #getTarget()} method, if any.
* <p>The default implementation is empty.
* @param target object obtained from a call to {@link #getTarget()}
* @throws Exception if the object can't be released
*/
void releaseTarget(Object target) throws Exception;
default void releaseTarget(Object target) throws Exception {
}
}

View File

@@ -153,16 +153,6 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
}
}
@Override
public boolean isStatic() {
return false;
}
@Override
public void releaseTarget(Object target) throws Exception {
// Nothing to do here.
}
/**
* Copy configuration from the other AbstractBeanFactoryBasedTargetSource object.

View File

@@ -72,11 +72,6 @@ public abstract class AbstractLazyCreationTargetSource implements TargetSource {
return (this.lazyTarget != null ? this.lazyTarget.getClass() : null);
}
@Override
public boolean isStatic() {
return false;
}
/**
* Returns the lazy-initialized target object,
* creating it on-the-fly if it doesn't exist already.
@@ -91,11 +86,6 @@ public abstract class AbstractLazyCreationTargetSource implements TargetSource {
return this.lazyTarget;
}
@Override
public void releaseTarget(Object target) throws Exception {
// nothing to do
}
/**
* Subclasses should implement this method to return the lazy initialized object.

View File

@@ -116,13 +116,6 @@ public final class EmptyTargetSource implements TargetSource, Serializable {
return null;
}
/**
* Nothing to release.
*/
@Override
public void releaseTarget(Object target) {
}
/**
* Returns the canonical instance on deserialization in case

View File

@@ -66,21 +66,11 @@ public class HotSwappableTargetSource implements TargetSource, Serializable {
return this.target.getClass();
}
@Override
public final boolean isStatic() {
return false;
}
@Override
public synchronized Object getTarget() {
return this.target;
}
@Override
public void releaseTarget(Object target) {
// nothing to do
}
/**
* Swap the target, returning the old target object.

View File

@@ -67,11 +67,6 @@ public class SingletonTargetSource implements TargetSource, Serializable {
return this.target;
}
@Override
public void releaseTarget(Object target) {
// nothing to do
}
@Override
public boolean isStatic() {
return true;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -73,14 +73,6 @@ public abstract class AbstractRefreshableTargetSource implements TargetSource, R
return this.targetObject.getClass();
}
/**
* Not static.
*/
@Override
public boolean isStatic() {
return false;
}
@Override
@Nullable
public final synchronized Object getTarget() {
@@ -90,13 +82,6 @@ public abstract class AbstractRefreshableTargetSource implements TargetSource, R
return this.targetObject;
}
/**
* No need to release target.
*/
@Override
public void releaseTarget(Object object) {
}
@Override
public final synchronized void refresh() {