Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-27 00:27:52 +00:00
parent 6bbc966a21
commit b0790bf5e7
248 changed files with 2374 additions and 3208 deletions

View File

@@ -74,7 +74,7 @@ import org.springframework.util.StringUtils;
public class AspectJExpressionPointcut extends AbstractExpressionPointcut
implements ClassFilter, IntroductionAwareMethodMatcher, BeanFactoryAware {
private static final Set DEFAULT_SUPPORTED_PRIMITIVES = new HashSet();
private static final Set<PointcutPrimitive> DEFAULT_SUPPORTED_PRIMITIVES = new HashSet<PointcutPrimitive>();
static {
DEFAULT_SUPPORTED_PRIMITIVES.add(PointcutPrimitive.EXECUTION);
@@ -92,7 +92,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
private static final Log logger = LogFactory.getLog(AspectJExpressionPointcut.class);
private final Map shadowMapCache = new HashMap();
private final Map<Method, ShadowMatch> shadowMatchCache = new HashMap<Method, ShadowMatch>();
private PointcutParser pointcutParser;
@@ -364,8 +364,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
synchronized (this.shadowMapCache) {
ShadowMatch shadowMatch = (ShadowMatch) this.shadowMapCache.get(targetMethod);
synchronized (this.shadowMatchCache) {
ShadowMatch shadowMatch = this.shadowMatchCache.get(targetMethod);
if (shadowMatch == null) {
try {
shadowMatch = this.pointcutExpression.matchesMethodExecution(targetMethod);
@@ -378,7 +378,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
shadowMatch = this.pointcutExpression.matchesMethodExecution(originalMethod);
}
this.shadowMapCache.put(targetMethod, shadowMatch);
this.shadowMatchCache.put(targetMethod, shadowMatch);
}
return shadowMatch;
}
@@ -520,8 +520,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
if (beanFactory != null) {
String[] aliases = beanFactory.getAliases(advisedBeanName);
for (int i = 0; i < aliases.length; i++) {
if (this.expressionPattern.matches(aliases[i])) {
for (String alias : aliases) {
if (this.expressionPattern.matches(alias)) {
return true;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ import org.springframework.util.ClassUtils;
public class AspectJProxyFactory extends ProxyCreatorSupport {
/** Cache for singleton aspect instances */
private static final Map aspectCache = new HashMap();
private static final Map<Class, Object> aspectCache = new HashMap<Class, Object>();
private final AspectJAdvisorFactory aspectFactory = new ReflectiveAspectJAdvisorFactory();
@@ -199,6 +199,7 @@ public class AspectJProxyFactory extends ProxyCreatorSupport {
* (if necessary for proxy creation).
* @return the new proxy
*/
@SuppressWarnings("unchecked")
public <T> T getProxy() {
return (T) createAopProxy().getProxy();
}
@@ -211,6 +212,7 @@ public class AspectJProxyFactory extends ProxyCreatorSupport {
* @param classLoader the class loader to create the proxy with
* @return the new proxy
*/
@SuppressWarnings("unchecked")
public <T> T getProxy(ClassLoader classLoader) {
return (T) createAopProxy().getProxy(classLoader);
}

View File

@@ -142,8 +142,8 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
ProxyFactory proxyFactory = new ProxyFactory();
if (this.preInterceptors != null) {
for (int i = 0; i < this.preInterceptors.length; i++) {
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(this.preInterceptors[i]));
for (Object interceptor : this.preInterceptors) {
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor));
}
}
@@ -151,8 +151,8 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(createMainInterceptor()));
if (this.postInterceptors != null) {
for (int i = 0; i < this.postInterceptors.length; i++) {
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(this.postInterceptors[i]));
for (Object interceptor : this.postInterceptors) {
proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor));
}
}
@@ -170,7 +170,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), this.proxyClassLoader));
}
this.proxy = getProxy(proxyFactory);
this.proxy = proxyFactory.getProxy(this.proxyClassLoader);
}
/**
@@ -188,19 +188,6 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig
}
}
/**
* Return the proxy object to expose.
* <p>The default implementation uses a <code>getProxy</code> call with
* the factory's bean class loader. Can be overridden to specify a
* custom class loader.
* @param aopProxy the prepared AopProxy instance to get the proxy from
* @return the proxy object to expose
* @see AopProxy#getProxy(ClassLoader)
*/
protected Object getProxy(AopProxy aopProxy) {
return aopProxy.getProxy(this.proxyClassLoader);
}
public Object getObject() {
if (this.proxy == null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -362,7 +362,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* <p>Use with care, and remember to {@link #updateAdvisorArray() refresh the advisor array}
* and {@link #adviceChanged() fire advice changed events} when making any modifications.
*/
protected final List getAdvisorsInternal() {
protected final List<Advisor> getAdvisorsInternal() {
return this.advisors;
}
@@ -454,7 +454,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* @param targetClass the target class
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
*/
public List getInterceptorsAndDynamicInterceptionAdvice(Method method, Class targetClass) {
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, Class targetClass) {
MethodCacheKey cacheKey = new MethodCacheKey(method);
List<Object> cached = this.methodCache.get(cacheKey);
if (cached == null) {

View File

@@ -90,7 +90,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
protected final static Log logger = LogFactory.getLog(Cglib2AopProxy.class);
/** Keeps track of the Classes that we have validated for final methods */
private static final Map validatedClasses = new WeakHashMap();
private static final Map<Class, Boolean> validatedClasses = new WeakHashMap<Class, Boolean>();
/** The configuration used to configure this proxy */
@@ -103,7 +103,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
/** Dispatcher used for methods on Advised */
private final transient AdvisedDispatcher advisedDispatcher;
private transient Map fixedInterceptorMap;
private transient Map<String, Integer> fixedInterceptorMap;
private transient int fixedInterceptorOffset;
@@ -158,8 +158,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
if (AopUtils.isCglibProxyClass(rootClass)) {
proxySuperClass = rootClass.getSuperclass();
Class[] additionalInterfaces = rootClass.getInterfaces();
for (int i = 0; i < additionalInterfaces.length; i++) {
Class additionalInterface = additionalInterfaces[i];
for (Class additionalInterface : additionalInterfaces) {
this.advised.addInterface(additionalInterface);
}
}
@@ -250,8 +249,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
*/
private void doValidateClass(Class proxySuperClass) {
Method[] methods = proxySuperClass.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
for (Method method : methods) {
if (!Object.class.equals(method.getDeclaringClass()) && Modifier.isFinal(method.getModifiers())) {
logger.warn("Unable to proxy method [" + method + "] because it is final: " +
"All calls to this method via a proxy will be routed directly to the proxy.");
@@ -271,22 +269,21 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
// Choose a "straight to target" interceptor. (used for calls that are
// unadvised but can return this). May be required to expose the proxy.
Callback targetInterceptor = null;
if (exposeProxy) {
targetInterceptor = isStatic ?
(Callback) new StaticUnadvisedExposedInterceptor(this.advised.getTargetSource().getTarget()) :
(Callback) new DynamicUnadvisedExposedInterceptor(this.advised.getTargetSource());
new StaticUnadvisedExposedInterceptor(this.advised.getTargetSource().getTarget()) :
new DynamicUnadvisedExposedInterceptor(this.advised.getTargetSource());
}
else {
targetInterceptor = isStatic ?
(Callback) new StaticUnadvisedInterceptor(this.advised.getTargetSource().getTarget()) :
(Callback) new DynamicUnadvisedInterceptor(this.advised.getTargetSource());
new StaticUnadvisedInterceptor(this.advised.getTargetSource().getTarget()) :
new DynamicUnadvisedInterceptor(this.advised.getTargetSource());
}
// Choose a "direct to target" dispatcher (used for
// unadvised calls to static targets that cannot return this).
Callback targetDispatcher = isStatic ?
(Callback) new StaticDispatcher(this.advised.getTargetSource().getTarget()) : new SerializableNoOp();
new StaticDispatcher(this.advised.getTargetSource().getTarget()) : new SerializableNoOp();
Callback[] mainCallbacks = new Callback[]{
aopInterceptor, // for normal advice
@@ -305,29 +302,26 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
if (isStatic && isFrozen) {
Method[] methods = rootClass.getMethods();
Callback[] fixedCallbacks = new Callback[methods.length];
this.fixedInterceptorMap = new HashMap(methods.length);
this.fixedInterceptorMap = new HashMap<String, Integer>(methods.length);
// TODO: small memory optimisation here (can skip creation for
// methods with no advice)
for (int x = 0; x < methods.length; x++) {
List chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(methods[x], rootClass);
List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(methods[x], rootClass);
fixedCallbacks[x] = new FixedChainStaticTargetInterceptor(
chain, this.advised.getTargetSource().getTarget(), this.advised.getTargetClass());
this.fixedInterceptorMap.put(methods[x].toString(), new Integer(x));
this.fixedInterceptorMap.put(methods[x].toString(), x);
}
// Now copy both the callbacks from mainCallbacks
// and fixedCallbacks into the callbacks array.
callbacks = new Callback[mainCallbacks.length + fixedCallbacks.length];
for (int x = 0; x < mainCallbacks.length; x++) {
callbacks[x] = mainCallbacks[x];
}
for (int x = 0; x < fixedCallbacks.length; x++) {
callbacks[x + mainCallbacks.length] = fixedCallbacks[x];
}
this.fixedInterceptorOffset = mainCallbacks.length;
}
else {
@@ -523,20 +517,19 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) {
Object other = args[0];
if (proxy == other) {
return Boolean.TRUE;
return true;
}
AdvisedSupport otherAdvised = null;
if (other instanceof Factory) {
Callback callback = ((Factory) other).getCallback(INVOKE_EQUALS);
if (!(callback instanceof EqualsInterceptor)) {
return Boolean.FALSE;
return false;
}
otherAdvised = ((EqualsInterceptor) callback).advised;
AdvisedSupport otherAdvised = ((EqualsInterceptor) callback).advised;
return AopProxyUtils.equalsInProxy(this.advised, otherAdvised);
}
else {
return Boolean.FALSE;
return false;
}
return (AopProxyUtils.equalsInProxy(this.advised, otherAdvised) ? Boolean.TRUE : Boolean.FALSE);
}
}
@@ -554,7 +547,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
}
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) {
return new Integer(Cglib2AopProxy.class.hashCode() * 13 + this.advised.getTargetSource().hashCode());
return Cglib2AopProxy.class.hashCode() * 13 + this.advised.getTargetSource().hashCode();
}
}
@@ -564,24 +557,23 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
*/
private static class FixedChainStaticTargetInterceptor implements MethodInterceptor, Serializable {
private final List adviceChain;
private final List<Object> adviceChain;
private final Object target;
private final Class targetClass;
public FixedChainStaticTargetInterceptor(List adviceChain, Object target, Class targetClass) {
public FixedChainStaticTargetInterceptor(List<Object> adviceChain, Object target, Class targetClass) {
this.adviceChain = adviceChain;
this.target = target;
this.targetClass = targetClass;
}
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
Object retVal = null;
MethodInvocation invocation = new CglibMethodInvocation(proxy, this.target, method, args,
this.targetClass, this.adviceChain, methodProxy);
// If we get here, we need to create a MethodInvocation.
retVal = invocation.proceed();
Object retVal = invocation.proceed();
retVal = massageReturnTypeIfNecessary(proxy, this.target, method, retVal);
return retVal;
}
@@ -601,13 +593,11 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
}
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
MethodInvocation invocation = null;
Object oldProxy = null;
boolean setProxyContext = false;
Class targetClass = null;
Object target = null;
try {
Object retVal = null;
if (this.advised.exposeProxy) {
// Make invocation available if necessary.
oldProxy = AopContext.setCurrentProxy(proxy);
@@ -619,7 +609,8 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
if (target != null) {
targetClass = target.getClass();
}
List chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);
List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);
Object retVal = null;
// Check whether we only have one InvokerInterceptor: that is,
// no real advice, but just reflective invocation of the target.
if (chain.isEmpty() && Modifier.isPublic(method.getModifiers())) {
@@ -631,12 +622,8 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
}
else {
// We need to create a method invocation...
invocation = new CglibMethodInvocation(proxy, target, method, args,
targetClass, chain, methodProxy);
// If we get here, we need to create a MethodInvocation.
retVal = invocation.proceed();
retVal = new CglibMethodInvocation(proxy, target, method, args, targetClass, chain, methodProxy).proceed();
}
retVal = massageReturnTypeIfNecessary(proxy, target, method, retVal);
return retVal;
}
@@ -686,7 +673,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
private boolean protectedMethod;
public CglibMethodInvocation(Object proxy, Object target, Method method, Object[] arguments,
Class targetClass, List interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
Class targetClass, List<Object> interceptorsAndDynamicMethodMatchers, MethodProxy methodProxy) {
super(proxy, target, method, arguments, targetClass, interceptorsAndDynamicMethodMatchers);
this.methodProxy = methodProxy;
this.protectedMethod = Modifier.isProtected(method.getModifiers());
@@ -715,11 +702,11 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
private final AdvisedSupport advised;
private final Map fixedInterceptorMap;
private final Map<String, Integer> fixedInterceptorMap;
private final int fixedInterceptorOffset;
public ProxyCallbackFilter(AdvisedSupport advised, Map fixedInterceptorMap, int fixedInterceptorOffset) {
public ProxyCallbackFilter(AdvisedSupport advised, Map<String, Integer> fixedInterceptorMap, int fixedInterceptorOffset) {
this.advised = advised;
this.fixedInterceptorMap = fixedInterceptorMap;
this.fixedInterceptorOffset = fixedInterceptorOffset;
@@ -807,7 +794,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
}
// We know that we are optimising so we can use the
// FixedStaticChainInterceptors.
int index = ((Integer) this.fixedInterceptorMap.get(key)).intValue();
int index = this.fixedInterceptorMap.get(key);
return (index + this.fixedInterceptorOffset);
}
else {
@@ -910,23 +897,17 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
private boolean equalsPointcuts(Advisor a, Advisor b) {
// If only one of the advisor (but not both) is PointcutAdvisor, then it is a mismatch.
// Takes care of the situations where an IntroductionAdvisor is used (see SPR-3959).
if (a instanceof PointcutAdvisor ^ b instanceof PointcutAdvisor) {
return false;
}
// If both are PointcutAdvisor, match their pointcuts.
if (a instanceof PointcutAdvisor && b instanceof PointcutAdvisor) {
return ObjectUtils.nullSafeEquals(((PointcutAdvisor) a).getPointcut(), ((PointcutAdvisor) b).getPointcut());
}
// If neither is PointcutAdvisor, then from the pointcut matching perspective, it is a match.
return true;
return (!(a instanceof PointcutAdvisor) ||
(b instanceof PointcutAdvisor &&
ObjectUtils.nullSafeEquals(((PointcutAdvisor) a).getPointcut(), ((PointcutAdvisor) b).getPointcut())));
}
@Override
public int hashCode() {
int hashCode = 0;
Advisor[] advisors = this.advised.getAdvisors();
for (int i = 0; i < advisors.length; i++) {
Advice advice = advisors[i].getAdvice();
for (Advisor advisor : advisors) {
Advice advice = advisor.getAdvice();
if (advice != null) {
hashCode = 13 * hashCode + advice.getClass().hashCode();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ import org.springframework.util.ClassUtils;
* @author Rob Harrop
* @since 14.03.2003
*/
public class ProxyFactory extends ProxyCreatorSupport implements AopProxy {
public class ProxyFactory extends ProxyCreatorSupport {
/**
* Create a new ProxyFactory.
@@ -93,8 +93,9 @@ public class ProxyFactory extends ProxyCreatorSupport implements AopProxy {
* (if necessary for proxy creation).
* @return the proxy object
*/
public Object getProxy() {
return createAopProxy().getProxy();
@SuppressWarnings("unchecked")
public <T> T getProxy() {
return (T) createAopProxy().getProxy();
}
/**
@@ -106,8 +107,9 @@ public class ProxyFactory extends ProxyCreatorSupport implements AopProxy {
* (or <code>null</code> for the low-level proxy facility's default)
* @return the proxy object
*/
public Object getProxy(ClassLoader classLoader) {
return createAopProxy().getProxy(classLoader);
@SuppressWarnings("unchecked")
public <T> T getProxy(ClassLoader classLoader) {
return (T) createAopProxy().getProxy(classLoader);
}

View File

@@ -433,8 +433,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
}
// Materialize interceptor chain from bean names.
for (int i = 0; i < this.interceptorNames.length; i++) {
String name = this.interceptorNames[i];
for (String name : this.interceptorNames) {
if (logger.isTraceEnabled()) {
logger.trace("Configuring advisor or advice '" + name + "'");
}
@@ -452,16 +451,16 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
// If we get here, we need to add a named interceptor.
// We must check if it's a singleton or prototype.
Object advice = null;
if (this.singleton || this.beanFactory.isSingleton(this.interceptorNames[i])) {
if (this.singleton || this.beanFactory.isSingleton(name)) {
// Add the real Advisor/Advice to the chain.
advice = this.beanFactory.getBean(this.interceptorNames[i]);
advice = this.beanFactory.getBean(name);
}
else {
// It's a prototype Advice or Advisor: replace with a prototype.
// Avoid unnecessary creation of prototype bean just for advisor chain initialization.
advice = new PrototypePlaceholderAdvisor(this.interceptorNames[i]);
advice = new PrototypePlaceholderAdvisor(name);
}
addAdvisorOnChainCreation(advice, this.interceptorNames[i]);
addAdvisorOnChainCreation(advice, name);
}
}
}
@@ -477,11 +476,10 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
*/
private List freshAdvisorChain() {
Advisor[] advisors = getAdvisors();
List freshAdvisors = new ArrayList(advisors.length);
for (int i = 0; i < advisors.length; i++) {
if (advisors[i] instanceof PrototypePlaceholderAdvisor) {
PrototypePlaceholderAdvisor pa = (PrototypePlaceholderAdvisor) advisors[i];
List<Advisor> freshAdvisors = new ArrayList<Advisor>(advisors.length);
for (Advisor advisor : advisors) {
if (advisor instanceof PrototypePlaceholderAdvisor) {
PrototypePlaceholderAdvisor pa = (PrototypePlaceholderAdvisor) advisor;
if (logger.isDebugEnabled()) {
logger.debug("Refreshing bean named '" + pa.getBeanName() + "'");
}
@@ -497,7 +495,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
}
else {
// Add the shared instance.
freshAdvisors.add(advisors[i]);
freshAdvisors.add(advisor);
}
}
return freshAdvisors;
@@ -511,24 +509,21 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, Advisor.class);
String[] globalInterceptorNames =
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, Interceptor.class);
List beans = new ArrayList(globalAdvisorNames.length + globalInterceptorNames.length);
Map names = new HashMap();
for (int i = 0; i < globalAdvisorNames.length; i++) {
String name = globalAdvisorNames[i];
List<Object> beans = new ArrayList<Object>(globalAdvisorNames.length + globalInterceptorNames.length);
Map<Object, String> names = new HashMap<Object, String>(beans.size());
for (String name : globalAdvisorNames) {
Object bean = beanFactory.getBean(name);
beans.add(bean);
names.put(bean, name);
}
for (int i = 0; i < globalInterceptorNames.length; i++) {
String name = globalInterceptorNames[i];
for (String name : globalInterceptorNames) {
Object bean = beanFactory.getBean(name);
beans.add(bean);
names.put(bean, name);
}
Collections.sort(beans, new OrderComparator());
for (Iterator it = beans.iterator(); it.hasNext();) {
Object bean = it.next();
String name = (String) names.get(bean);
for (Object bean : beans) {
String name = names.get(bean);
if (name.startsWith(prefix)) {
addAdvisorOnChainCreation(bean, name);
}
@@ -551,7 +546,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
if (logger.isTraceEnabled()) {
logger.trace("Adding advisor with name '" + name + "'");
}
addAdvisor((Advisor) advisor);
addAdvisor(advisor);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
/**
* Lazily initialized map of user-specific attributes for this invocation.
*/
private Map userAttributes;
private Map<String, Object> userAttributes;
/**
* List of MethodInterceptor and InterceptorAndDynamicMethodMatcher
@@ -102,7 +102,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
*/
protected ReflectiveMethodInvocation(
Object proxy, Object target, Method method, Object[] arguments,
Class targetClass, List interceptorsAndDynamicMethodMatchers) {
Class targetClass, List<Object> interceptorsAndDynamicMethodMatchers) {
this.proxy = proxy;
this.target = target;
@@ -213,7 +213,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
// Force initialization of the user attributes Map,
// for having a shared Map reference in the clone.
if (this.userAttributes == null) {
this.userAttributes = new HashMap();
this.userAttributes = new HashMap<String, Object>();
}
// Create the MethodInvocation clone.
@@ -232,7 +232,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
public void setUserAttribute(String key, Object value) {
if (value != null) {
if (this.userAttributes == null) {
this.userAttributes = new HashMap();
this.userAttributes = new HashMap<String, Object>();
}
this.userAttributes.put(key, value);
}
@@ -254,9 +254,9 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
* @return any user attributes associated with this invocation
* (never <code>null</code>)
*/
public Map getUserAttributes() {
public Map<String, Object> getUserAttributes() {
if (this.userAttributes == null) {
this.userAttributes = new HashMap();
this.userAttributes = new HashMap<String, Object>();
}
return this.userAttributes;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
private final Object throwsAdvice;
/** Methods on throws advice, keyed by exception class */
private final Map exceptionHandlerMap = new HashMap();
private final Map<Class, Method> exceptionHandlerMap = new HashMap<Class, Method>();
/**
@@ -75,10 +75,8 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
this.throwsAdvice = throwsAdvice;
Method[] methods = throwsAdvice.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
for (Method method : methods) {
if (method.getName().equals(AFTER_THROWING) &&
//m.getReturnType() == null &&
(method.getParameterTypes().length == 1 || method.getParameterTypes().length == 4) &&
Throwable.class.isAssignableFrom(method.getParameterTypes()[method.getParameterTypes().length - 1])
) {
@@ -110,10 +108,10 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
if (logger.isTraceEnabled()) {
logger.trace("Trying to find handler for exception of type [" + exceptionClass.getName() + "]");
}
Method handler = (Method) this.exceptionHandlerMap.get(exceptionClass);
Method handler = this.exceptionHandlerMap.get(exceptionClass);
while (handler == null && !exceptionClass.equals(Throwable.class)) {
exceptionClass = exceptionClass.getSuperclass();
handler = (Method) this.exceptionHandlerMap.get(exceptionClass);
handler = this.exceptionHandlerMap.get(exceptionClass);
}
if (handler != null && logger.isDebugEnabled()) {
logger.debug("Found handler for exception of type [" + exceptionClass.getName() + "]: " + handler);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2087 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.
@@ -56,7 +56,7 @@ public class DelegatePerTargetObjectIntroductionInterceptor extends Introduction
/**
* Hold weak references to keys as we don't want to interfere with garbage collection..
*/
private Map delegateMap = new WeakHashMap();
private final Map<Object, Object> delegateMap = new WeakHashMap<Object, Object>();
private Class defaultImplType;
@@ -115,7 +115,7 @@ public class DelegatePerTargetObjectIntroductionInterceptor extends Introduction
}
private Object getIntroductionDelegateFor(Object targetObject) {
synchronized(this.delegateMap) {
synchronized (this.delegateMap) {
if (this.delegateMap.containsKey(targetObject)) {
return this.delegateMap.get(targetObject);
}

View File

@@ -18,7 +18,6 @@ package org.springframework.aop.target;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.springframework.aop.IntroductionAdvisor;
@@ -26,6 +25,7 @@ import org.springframework.aop.support.DefaultIntroductionAdvisor;
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.NamedThreadLocal;
/**
* Alternative to an object pool. This TargetSource uses a threading model in which
@@ -56,17 +56,13 @@ public class ThreadLocalTargetSource extends AbstractPrototypeBasedTargetSource
* thread. Unlike most ThreadLocals, which are static, this variable
* is meant to be per thread per instance of the ThreadLocalTargetSource class.
*/
private final ThreadLocal targetInThread = new ThreadLocal() {
@Override
public String toString() {
return "Thread-local instance of bean '" + getTargetBeanName() + "'";
}
};
private final ThreadLocal<Object> targetInThread =
new NamedThreadLocal<Object>("Thread-local instance of bean '" + getTargetBeanName() + "'");
/**
* Set of managed targets, enabling us to keep track of the targets we've created.
*/
private final Set targetSet = Collections.synchronizedSet(new HashSet());
private final Set<Object> targetSet = Collections.synchronizedSet(new HashSet<Object>());
private int invocationCount;
@@ -104,8 +100,8 @@ public class ThreadLocalTargetSource extends AbstractPrototypeBasedTargetSource
public void destroy() {
logger.debug("Destroying ThreadLocalTargetSource bindings");
synchronized (this.targetSet) {
for (Iterator it = this.targetSet.iterator(); it.hasNext(); ) {
destroyPrototypeInstance(it.next());
for (Object target : this.targetSet) {
destroyPrototypeInstance(target);
}
this.targetSet.clear();
}