Utility methods for AOP proxy factories.
Mainly for internal use within the AOP framework.
| Method from org.springframework.aop.framework.AopProxyUtils Detail: |
public static Class[] completeProxiedInterfaces(AdvisedSupport advised) {
Class[] specifiedInterfaces = advised.getProxiedInterfaces();
if (specifiedInterfaces.length == 0) {
// No user-specified interfaces: check whether target class is an interface.
Class targetClass = advised.getTargetClass();
if (targetClass != null && targetClass.isInterface()) {
specifiedInterfaces = new Class[] {targetClass};
}
}
boolean addSpringProxy = !advised.isInterfaceProxied(SpringProxy.class);
boolean addAdvised = !advised.isOpaque() && !advised.isInterfaceProxied(Advised.class);
int nonUserIfcCount = 0;
if (addSpringProxy) {
nonUserIfcCount++;
}
if (addAdvised) {
nonUserIfcCount++;
}
Class[] proxiedInterfaces = new Class[specifiedInterfaces.length + nonUserIfcCount];
System.arraycopy(specifiedInterfaces, 0, proxiedInterfaces, 0, specifiedInterfaces.length);
if (addSpringProxy) {
proxiedInterfaces[specifiedInterfaces.length] = SpringProxy.class;
}
if (addAdvised) {
proxiedInterfaces[proxiedInterfaces.length - 1] = Advised.class;
}
return proxiedInterfaces;
}
|
public static boolean equalsAdvisors(AdvisedSupport a,
AdvisedSupport b) {
return Arrays.equals(a.getAdvisors(), b.getAdvisors());
}
Check equality of the advisors behind the given AdvisedSupport objects. |
public static boolean equalsInProxy(AdvisedSupport a,
AdvisedSupport b) {
return (a == b ||
(equalsProxiedInterfaces(a, b) && equalsAdvisors(a, b) && a.getTargetSource().equals(b.getTargetSource())));
}
Check equality of the proxies behind the given AdvisedSupport objects.
Not the same as equality of the AdvisedSupport objects:
rather, equality of interfaces, advisors and target sources. |
public static boolean equalsProxiedInterfaces(AdvisedSupport a,
AdvisedSupport b) {
return Arrays.equals(a.getProxiedInterfaces(), b.getProxiedInterfaces());
}
Check equality of the proxied interfaces behind the given AdvisedSupport objects. |
public static Class getTargetClass(Object candidate) {
Assert.notNull(candidate, "Candidate object must not be null");
if (AopUtils.isCglibProxy(candidate)) {
return candidate.getClass().getSuperclass();
}
if (candidate instanceof Advised) {
return ((Advised) candidate).getTargetSource().getTargetClass();
}
return candidate.getClass();
} Deprecated! as - of Spring 2.0.3, in favor of AopUtils.getTargetClass
|
public static Class[] proxiedUserInterfaces(Object proxy) {
Class[] proxyInterfaces = proxy.getClass().getInterfaces();
int nonUserIfcCount = 0;
if (proxy instanceof SpringProxy) {
nonUserIfcCount++;
}
if (proxy instanceof Advised) {
nonUserIfcCount++;
}
Class[] userInterfaces = new Class[proxyInterfaces.length - nonUserIfcCount];
System.arraycopy(proxyInterfaces, 0, userInterfaces, 0, userInterfaces.length);
Assert.notEmpty(userInterfaces, "JDK proxy must implement one or more interfaces");
return userInterfaces;
}
Extract the user-specified interfaces that the given proxy implements,
i.e. all non-Advised interfaces that the proxy implements. |