Java 5 code style

This commit is contained in:
Juergen Hoeller 2009-02-05 21:04:13 +00:00
parent 460977263d
commit 92588cddc6
21 changed files with 117 additions and 90 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -98,8 +98,7 @@ public abstract class AopNamespaceUtils {
private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, Element sourceElement) {
if (sourceElement != null) {
boolean proxyTargetClass = Boolean.valueOf(
sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE)).booleanValue();
boolean proxyTargetClass = Boolean.valueOf(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
if (proxyTargetClass) {
AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
}

View File

@ -20,6 +20,8 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -38,7 +40,7 @@ import org.springframework.aop.target.EmptyTargetSource;
import org.springframework.aop.target.SingletonTargetSource;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.CollectionUtils;
/**
* Base class for AOP proxy configuration managers.
@ -309,12 +311,30 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
/**
* Add all of the given advisors to this proxy configuration.
* @param advisors the advisors to register
* @deprecated as of Spring 3.0, in favor of {@link #addAdvisors}
*/
@Deprecated
public void addAllAdvisors(Advisor[] advisors) {
addAdvisors(Arrays.asList(advisors));
}
/**
* Add all of the given advisors to this proxy configuration.
* @param advisors the advisors to register
*/
public void addAdvisors(Advisor... advisors) {
addAdvisors(Arrays.asList(advisors));
}
/**
* Add all of the given advisors to this proxy configuration.
* @param advisors the advisors to register
*/
public void addAdvisors(Collection<Advisor> advisors) {
if (isFrozen()) {
throw new AopConfigException("Cannot add advisor: Configuration is frozen.");
}
if (!ObjectUtils.isEmpty(advisors)) {
if (!CollectionUtils.isEmpty(advisors)) {
for (Advisor advisor : advisors) {
if (advisor instanceof IntroductionAdvisor) {
validateIntroductionAdvisor((IntroductionAdvisor) advisor);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -46,7 +46,7 @@ public abstract class AopContext {
* the controlling proxy configuration has been set to "true".
* @see ProxyConfig#setExposeProxy
*/
private static final ThreadLocal currentProxy = new NamedThreadLocal("Current AOP proxy");
private static final ThreadLocal<Object> currentProxy = new NamedThreadLocal<Object>("Current AOP proxy");
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2009 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.
@ -123,11 +123,9 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
* @param proxiedInterfaces the interfaces to introspect
*/
private void findDefinedEqualsAndHashCodeMethods(Class[] proxiedInterfaces) {
for (int i = 0; i < proxiedInterfaces.length; i++) {
Class proxiedInterface = proxiedInterfaces[i];
for (Class proxiedInterface : proxiedInterfaces) {
Method[] methods = proxiedInterface.getDeclaredMethods();
for (int j = 0; j < methods.length; j++) {
Method method = methods[j];
for (Method method : methods) {
if (AopUtils.isEqualsMethod(method)) {
this.equalsDefined = true;
}
@ -187,7 +185,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
}
// Get the interception chain for this method.
List chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);
List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass);
// Check whether we have any advice. If we don't, we can fallback on direct
// reflective invocation of the target, and avoid creating a MethodInvocation.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -112,7 +112,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
protected final Log logger = LogFactory.getLog(getClass());
/** Default value is same as non-ordered */
private int order = Integer.MAX_VALUE;
private int order = Ordered.LOWEST_PRECEDENCE;
/** Default is global AdvisorAdapterRegistry */
private AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -29,8 +29,8 @@ import org.springframework.core.NamedThreadLocal;
public class ProxyCreationContext {
/** ThreadLocal holding the current proxied bean name during Advisor matching */
private static final ThreadLocal currentProxiedBeanName =
new NamedThreadLocal("Name of currently proxied bean");
private static final ThreadLocal<String> currentProxiedBeanName =
new NamedThreadLocal<String>("Name of currently proxied bean");
/**
@ -38,7 +38,7 @@ public class ProxyCreationContext {
* @return the name of the bean, or <code>null</code> if none available
*/
public static String getCurrentProxiedBeanName() {
return (String) currentProxiedBeanName.get();
return currentProxiedBeanName.get();
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2009 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.
@ -24,7 +24,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
*
* <p>The default scope is "singleton", and the default is to <i>not</i> create
* scoped-proxies.
*
*
* @author Mark Fisher
* @since 2.5
* @see ScopeMetadataResolver
@ -37,36 +37,32 @@ public class ScopeMetadata {
private ScopedProxyMode scopedProxyMode = ScopedProxyMode.NO;
/**
* Get the name of the scope.
* @return said scope name
*/
public String getScopeName() {
return scopeName;
}
/**
* Set the name of the scope.
* @param scopeName said scope name
*/
public void setScopeName(String scopeName) {
this.scopeName = scopeName;
}
/**
* Get the proxy-mode to be applied to the scoped instance.
* @return said scoped-proxy mode
* Get the name of the scope.
*/
public ScopedProxyMode getScopedProxyMode() {
return scopedProxyMode;
public String getScopeName() {
return this.scopeName;
}
/**
* Set the proxy-mode to be applied to the scoped instance.
* @param scopedProxyMode said scoped-proxy mode
*/
public void setScopedProxyMode(ScopedProxyMode scopedProxyMode) {
this.scopedProxyMode = scopedProxyMode;
}
/**
* Get the proxy-mode to be applied to the scoped instance.
*/
public ScopedProxyMode getScopedProxyMode() {
return this.scopedProxyMode;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2009 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.
@ -28,7 +28,7 @@ package org.springframework.context.annotation;
* @see ScopeMetadata
*/
public enum ScopedProxyMode {
/**
* Do not create a scoped proxy.
* <p>This proxy-mode is not typically useful when used with a
@ -37,16 +37,16 @@ public enum ScopedProxyMode {
* is to be used as a dependency.
*/
NO,
/**
* Create a JDK dynamic proxy implementing <i>all</i> interfaces exposed by
* the class of the target object.
*/
INTERFACES,
/**
* Create a class-based proxy (requires CGLIB).
*/
TARGET_CLASS
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -40,10 +40,11 @@ import org.springframework.core.NamedThreadLocal;
*/
public abstract class LocaleContextHolder {
private static final ThreadLocal localeContextHolder = new NamedThreadLocal("Locale context");
private static final ThreadLocal<LocaleContext> localeContextHolder =
new NamedThreadLocal<LocaleContext>("Locale context");
private static final ThreadLocal inheritableLocaleContextHolder =
new NamedInheritableThreadLocal("Locale context");
private static final ThreadLocal<LocaleContext> inheritableLocaleContextHolder =
new NamedInheritableThreadLocal<LocaleContext>("Locale context");
/**
@ -87,9 +88,9 @@ public abstract class LocaleContextHolder {
* @return the current LocaleContext, or <code>null</code> if none
*/
public static LocaleContext getLocaleContext() {
LocaleContext localeContext = (LocaleContext) localeContextHolder.get();
LocaleContext localeContext = localeContextHolder.get();
if (localeContext == null) {
localeContext = (LocaleContext) inheritableLocaleContextHolder.get();
localeContext = inheritableLocaleContextHolder.get();
}
return localeContext;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -63,8 +63,13 @@ public class AspectJWeavingEnabler
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
LoadTimeWeaver weaverToUse = this.loadTimeWeaver;
if (weaverToUse == null && InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
weaverToUse = new InstrumentationLoadTimeWeaver(this.beanClassLoader);
if (weaverToUse == null) {
if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
weaverToUse = new InstrumentationLoadTimeWeaver(this.beanClassLoader);
}
else {
throw new IllegalStateException("No LoadTimeWeaver available");
}
}
weaverToUse.addTransformer(new AspectJClassBypassingClassFileTransformer(
new ClassPreProcessorAgentAdapter()));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -30,9 +30,8 @@ import org.springframework.util.Assert;
* to beans that implement the {@link LoadTimeWeaverAware} interface.
*
* <p>{@link org.springframework.context.ApplicationContext Application contexts}
* will automatically register this with their underlying
* {@link BeanFactory bean factory}, provided that a default
* <code>LoadTimeWeaver</code> is actually available.
* will automatically register this with their underlying {@link BeanFactory bean factory},
* provided that a default <code>LoadTimeWeaver</code> is actually available.
*
* <p>Applications should not use this class directly.
*

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -65,7 +65,8 @@ public class UserCredentialsDataSourceAdapter extends DelegatingDataSource {
private String password;
private final ThreadLocal threadBoundCredentials = new NamedThreadLocal("Current JDBC user credentials");
private final ThreadLocal<JdbcUserCredentials> threadBoundCredentials =
new NamedThreadLocal<JdbcUserCredentials>("Current JDBC user credentials");
/**
@ -126,7 +127,7 @@ public class UserCredentialsDataSourceAdapter extends DelegatingDataSource {
*/
@Override
public Connection getConnection() throws SQLException {
JdbcUserCredentials threadCredentials = (JdbcUserCredentials) this.threadBoundCredentials.get();
JdbcUserCredentials threadCredentials = this.threadBoundCredentials.get();
if (threadCredentials != null) {
return doGetConnection(threadCredentials.username, threadCredentials.password);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -76,7 +76,8 @@ public class UserCredentialsConnectionFactoryAdapter
private String password;
private final ThreadLocal threadBoundCredentials = new NamedThreadLocal("Current JMS user credentials");
private final ThreadLocal<JmsUserCredentials> threadBoundCredentials =
new NamedThreadLocal<JmsUserCredentials>("Current JMS user credentials");
/**
@ -141,7 +142,7 @@ public class UserCredentialsConnectionFactoryAdapter
* @see #doCreateConnection
*/
public final Connection createConnection() throws JMSException {
JmsUserCredentials threadCredentials = (JmsUserCredentials) this.threadBoundCredentials.get();
JmsUserCredentials threadCredentials = this.threadBoundCredentials.get();
if (threadCredentials != null) {
return doCreateConnection(threadCredentials.username, threadCredentials.password);
}
@ -186,7 +187,7 @@ public class UserCredentialsConnectionFactoryAdapter
* @see #doCreateQueueConnection
*/
public final QueueConnection createQueueConnection() throws JMSException {
JmsUserCredentials threadCredentials = (JmsUserCredentials) this.threadBoundCredentials.get();
JmsUserCredentials threadCredentials = this.threadBoundCredentials.get();
if (threadCredentials != null) {
return doCreateQueueConnection(threadCredentials.username, threadCredentials.password);
}
@ -235,7 +236,7 @@ public class UserCredentialsConnectionFactoryAdapter
* @see #doCreateTopicConnection
*/
public final TopicConnection createTopicConnection() throws JMSException {
JmsUserCredentials threadCredentials = (JmsUserCredentials) this.threadBoundCredentials.get();
JmsUserCredentials threadCredentials = this.threadBoundCredentials.get();
if (threadCredentials != null) {
return doCreateTopicConnection(threadCredentials.username, threadCredentials.password);
}

View File

@ -69,7 +69,7 @@ import org.springframework.util.ObjectUtils;
*/
public class SqlMapClientFactoryBean implements FactoryBean<SqlMapClient>, InitializingBean {
private static final ThreadLocal configTimeLobHandlerHolder = new ThreadLocal();
private static final ThreadLocal<LobHandler> configTimeLobHandlerHolder = new ThreadLocal<LobHandler>();
/**
* Return the LobHandler for the currently configured iBATIS SqlMapClient,
@ -83,7 +83,7 @@ public class SqlMapClientFactoryBean implements FactoryBean<SqlMapClient>, Initi
* @see org.springframework.orm.ibatis.support.BlobSerializableTypeHandler
*/
public static LobHandler getConfigTimeLobHandler() {
return (LobHandler) configTimeLobHandlerHolder.get();
return configTimeLobHandlerHolder.get();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -19,6 +19,7 @@ package org.springframework.dao.annotation;
import java.lang.annotation.Annotation;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.AopInfrastructureBean;
import org.springframework.aop.framework.ProxyConfig;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
@ -74,7 +75,7 @@ public class PersistenceExceptionTranslationPostProcessor extends ProxyConfig
/**
* Set the 'repository' annotation type.
* The default required annotation type is the {@link Repository} annotation.
* The default repository annotation type is the {@link Repository} annotation.
* <p>This setter property exists so that developers can provide their own
* (non-Spring-specific) annotation type to indicate that a class has a
* repository role.
@ -110,10 +111,14 @@ public class PersistenceExceptionTranslationPostProcessor extends ProxyConfig
}
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
Class<?> targetClass =
(bean instanceof Advised ? ((Advised) bean).getTargetSource().getTargetClass() : bean.getClass());
if (bean instanceof AopInfrastructureBean) {
// Ignore AOP infrastructure such as scoped proxies.
return bean;
}
Class targetClass = AopUtils.getTargetClass(bean);
if (targetClass == null) {
// Can't do much here
// Can't do much here.
return bean;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -66,7 +66,8 @@ public class ConnectionSpecConnectionFactoryAdapter extends DelegatingConnection
private ConnectionSpec connectionSpec;
private final ThreadLocal threadBoundSpec = new NamedThreadLocal("Current CCI ConnectionSpec");
private final ThreadLocal<ConnectionSpec> threadBoundSpec =
new NamedThreadLocal<ConnectionSpec>("Current CCI ConnectionSpec");
/**
@ -107,7 +108,7 @@ public class ConnectionSpecConnectionFactoryAdapter extends DelegatingConnection
*/
@Override
public final Connection getConnection() throws ResourceException {
ConnectionSpec threadSpec = (ConnectionSpec) this.threadBoundSpec.get();
ConnectionSpec threadSpec = this.threadBoundSpec.get();
if (threadSpec != null) {
return doGetConnection(threadSpec);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -59,8 +59,8 @@ public class ResourceAdapterApplicationContext extends GenericApplicationContext
beanFactory.registerResolvableDependency(BootstrapContext.class, this.bootstrapContext);
// JCA WorkManager resolved lazily - may not be available.
beanFactory.registerResolvableDependency(WorkManager.class, new ObjectFactory() {
public Object getObject() {
beanFactory.registerResolvableDependency(WorkManager.class, new ObjectFactory<WorkManager>() {
public WorkManager getObject() {
return bootstrapContext.getWorkManager();
}
});

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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,8 +72,8 @@ public abstract class TransactionAspectSupport implements InitializingBean {
* (e.g. before and after advice) if the aspect involves more than a
* single method (as will be the case for around advice).
*/
private static final ThreadLocal transactionInfoHolder =
new NamedThreadLocal("Current aspect-driven transaction");
private static final ThreadLocal<TransactionInfo> transactionInfoHolder =
new NamedThreadLocal<TransactionInfo>("Current aspect-driven transaction");
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -111,8 +111,8 @@ public abstract class PortletApplicationContextUtils {
beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false));
beanFactory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true));
beanFactory.registerResolvableDependency(PortletRequest.class, new ObjectFactory() {
public Object getObject() {
beanFactory.registerResolvableDependency(PortletRequest.class, new ObjectFactory<PortletRequest>() {
public PortletRequest getObject() {
RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
if (!(requestAttr instanceof PortletRequestAttributes)) {
throw new IllegalStateException("Current request is not a portlet request");
@ -120,8 +120,8 @@ public abstract class PortletApplicationContextUtils {
return ((PortletRequestAttributes) requestAttr).getRequest();
}
});
beanFactory.registerResolvableDependency(PortletSession.class, new ObjectFactory() {
public Object getObject() {
beanFactory.registerResolvableDependency(PortletSession.class, new ObjectFactory<PortletSession>() {
public PortletSession getObject() {
RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
if (!(requestAttr instanceof PortletRequestAttributes)) {
throw new IllegalStateException("Current request is not a portlet request");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -46,7 +46,8 @@ public abstract class RequestContextHolder {
private static final boolean jsfPresent =
ClassUtils.isPresent("javax.faces.context.FacesContext", RequestContextHolder.class.getClassLoader());
private static final ThreadLocal<RequestAttributes> requestAttributesHolder = new NamedThreadLocal<RequestAttributes>("Request attributes");
private static final ThreadLocal<RequestAttributes> requestAttributesHolder =
new NamedThreadLocal<RequestAttributes>("Request attributes");
private static final ThreadLocal<RequestAttributes> inheritableRequestAttributesHolder =
new NamedInheritableThreadLocal<RequestAttributes>("Request context");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@ -124,8 +124,8 @@ public abstract class WebApplicationContextUtils {
beanFactory.registerScope(WebApplicationContext.SCOPE_SESSION, new SessionScope(false));
beanFactory.registerScope(WebApplicationContext.SCOPE_GLOBAL_SESSION, new SessionScope(true));
beanFactory.registerResolvableDependency(ServletRequest.class, new ObjectFactory() {
public Object getObject() {
beanFactory.registerResolvableDependency(ServletRequest.class, new ObjectFactory<ServletRequest>() {
public ServletRequest getObject() {
RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
if (!(requestAttr instanceof ServletRequestAttributes)) {
throw new IllegalStateException("Current request is not a servlet request");
@ -133,8 +133,8 @@ public abstract class WebApplicationContextUtils {
return ((ServletRequestAttributes) requestAttr).getRequest();
}
});
beanFactory.registerResolvableDependency(HttpSession.class, new ObjectFactory() {
public Object getObject() {
beanFactory.registerResolvableDependency(HttpSession.class, new ObjectFactory<HttpSession>() {
public HttpSession getObject() {
RequestAttributes requestAttr = RequestContextHolder.currentRequestAttributes();
if (!(requestAttr instanceof ServletRequestAttributes)) {
throw new IllegalStateException("Current request is not a servlet request");