Polishing (includes varargs for selected String array setters)

This commit is contained in:
Juergen Hoeller 2014-08-09 00:19:56 +02:00
parent d61353db51
commit c08ded769a
34 changed files with 376 additions and 390 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -240,7 +240,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
setArgumentNamesFromStringArray(tokens); setArgumentNamesFromStringArray(tokens);
} }
public void setArgumentNamesFromStringArray(String[] args) { public void setArgumentNamesFromStringArray(String... args) {
this.argumentNames = new String[args.length]; this.argumentNames = new String[args.length];
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
this.argumentNames[i] = StringUtils.trimWhitespace(args[i]); this.argumentNames[i] = StringUtils.trimWhitespace(args[i]);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -40,24 +40,24 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv
this.pointcut.setExpression(expression); this.pointcut.setExpression(expression);
} }
public String getExpression() {
return this.pointcut.getExpression();
}
public void setLocation(String location) { public void setLocation(String location) {
this.pointcut.setLocation(location); this.pointcut.setLocation(location);
} }
public void setParameterTypes(Class<?>[] types) {
this.pointcut.setParameterTypes(types);
}
public void setParameterNames(String[] names) {
this.pointcut.setParameterNames(names);
}
public String getLocation() { public String getLocation() {
return this.pointcut.getLocation(); return this.pointcut.getLocation();
} }
public String getExpression() { public void setParameterTypes(Class<?>[] types) {
return this.pointcut.getExpression(); this.pointcut.setParameterTypes(types);
}
public void setParameterNames(String... names) {
this.pointcut.setParameterNames(names);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -154,7 +154,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
* @see org.aopalliance.aop.Advice * @see org.aopalliance.aop.Advice
* @see org.springframework.aop.target.SingletonTargetSource * @see org.springframework.aop.target.SingletonTargetSource
*/ */
public void setInterceptorNames(String[] interceptorNames) { public void setInterceptorNames(String... interceptorNames) {
this.interceptorNames = interceptorNames; this.interceptorNames = interceptorNames;
} }

View File

@ -205,7 +205,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* Ordering is significant: The TargetSource returned from the first matching * Ordering is significant: The TargetSource returned from the first matching
* TargetSourceCreator (that is, the first that returns non-null) will be used. * TargetSourceCreator (that is, the first that returns non-null) will be used.
*/ */
public void setCustomTargetSourceCreators(TargetSourceCreator[] targetSourceCreators) { public void setCustomTargetSourceCreators(TargetSourceCreator... targetSourceCreators) {
this.customTargetSourceCreators = targetSourceCreators; this.customTargetSourceCreators = targetSourceCreators;
} }
@ -216,7 +216,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* This is perfectly valid, if "specific" interceptors such as matching * This is perfectly valid, if "specific" interceptors such as matching
* Advisors are all we want. * Advisors are all we want.
*/ */
public void setInterceptorNames(String[] interceptorNames) { public void setInterceptorNames(String... interceptorNames) {
this.interceptorNames = interceptorNames; this.interceptorNames = interceptorNames;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -60,7 +60,7 @@ public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator {
* @see org.springframework.beans.factory.FactoryBean * @see org.springframework.beans.factory.FactoryBean
* @see org.springframework.beans.factory.BeanFactory#FACTORY_BEAN_PREFIX * @see org.springframework.beans.factory.BeanFactory#FACTORY_BEAN_PREFIX
*/ */
public void setBeanNames(String[] beanNames) { public void setBeanNames(String... beanNames) {
Assert.notEmpty(beanNames, "'beanNames' must not be empty"); Assert.notEmpty(beanNames, "'beanNames' must not be empty");
this.beanNames = new ArrayList<String>(beanNames.length); this.beanNames = new ArrayList<String>(beanNames.length);
for (String mappedName : beanNames) { for (String mappedName : beanNames) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -47,7 +47,7 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
* @see #setMappedNames * @see #setMappedNames
*/ */
public void setMappedName(String mappedName) { public void setMappedName(String mappedName) {
setMappedNames(new String[] {mappedName}); setMappedNames(mappedName);
} }
/** /**
@ -55,7 +55,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(String... mappedNames) {
this.mappedNames = new LinkedList<String>(); this.mappedNames = new LinkedList<String>();
if (mappedNames != null) { if (mappedNames != null) {
this.mappedNames.addAll(Arrays.asList(mappedNames)); this.mappedNames.addAll(Arrays.asList(mappedNames));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -68,7 +68,7 @@ public class NameMatchMethodPointcutAdvisor extends AbstractGenericPointcutAdvis
* the pointcut matches. * the pointcut matches.
* @see NameMatchMethodPointcut#setMappedNames * @see NameMatchMethodPointcut#setMappedNames
*/ */
public void setMappedNames(String[] mappedNames) { public void setMappedNames(String... mappedNames) {
this.pointcut.setMappedNames(mappedNames); this.pointcut.setMappedNames(mappedNames);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -98,7 +98,7 @@ public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor
* @see #setPatterns * @see #setPatterns
*/ */
public void setPattern(String pattern) { public void setPattern(String pattern) {
setPatterns(new String[] {pattern}); setPatterns(pattern);
} }
/** /**
@ -108,7 +108,7 @@ public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor
* patterns matches, the pointcut matches. * patterns matches, the pointcut matches.
* @see AbstractRegexpMethodPointcut#setPatterns * @see AbstractRegexpMethodPointcut#setPatterns
*/ */
public void setPatterns(String[] patterns) { public void setPatterns(String... patterns) {
this.patterns = patterns; this.patterns = patterns;
} }

View File

@ -51,8 +51,8 @@ public aspect AnnotationBeanConfigurerAspect extends AbstractInterfaceDrivenDepe
public void setBeanFactory(BeanFactory beanFactory) { public void setBeanFactory(BeanFactory beanFactory) {
this.beanConfigurerSupport.setBeanFactory(beanFactory);
this.beanConfigurerSupport.setBeanWiringInfoResolver(new AnnotationBeanWiringInfoResolver()); this.beanConfigurerSupport.setBeanWiringInfoResolver(new AnnotationBeanWiringInfoResolver());
this.beanConfigurerSupport.setBeanFactory(beanFactory);
} }
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -93,7 +93,7 @@ public class ConfigurableMimeFileTypeMap extends FileTypeMap implements Initiali
* Java Activation Framework, for example:<br> * Java Activation Framework, for example:<br>
* {@code text/html html htm HTML HTM} * {@code text/html html htm HTML HTM}
*/ */
public void setMappings(String[] mappings) { public void setMappings(String... mappings) {
this.mappings = mappings; this.mappings = mappings;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -55,24 +55,25 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
Collection<CacheEvict> evicts = getAnnotations(ae, CacheEvict.class); Collection<CacheEvict> evicts = getAnnotations(ae, CacheEvict.class);
if (evicts != null) { if (evicts != null) {
ops = lazyInit(ops); ops = lazyInit(ops);
for (CacheEvict e : evicts) { for (CacheEvict evict : evicts) {
ops.add(parseEvictAnnotation(ae, e)); ops.add(parseEvictAnnotation(ae, evict));
} }
} }
Collection<CachePut> updates = getAnnotations(ae, CachePut.class); Collection<CachePut> puts = getAnnotations(ae, CachePut.class);
if (updates != null) { if (puts != null) {
ops = lazyInit(ops); ops = lazyInit(ops);
for (CachePut p : updates) { for (CachePut put : puts) {
ops.add(parseUpdateAnnotation(ae, p)); ops.add(parsePutAnnotation(ae, put));
} }
} }
Collection<Caching> caching = getAnnotations(ae, Caching.class); Collection<Caching> cachings = getAnnotations(ae, Caching.class);
if (caching != null) { if (cachings != null) {
ops = lazyInit(ops); ops = lazyInit(ops);
for (Caching c : caching) { for (Caching caching : cachings) {
ops.addAll(parseCachingAnnotation(ae, c)); ops.addAll(parseCachingAnnotation(ae, caching));
} }
} }
return ops; return ops;
} }
@ -81,34 +82,34 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
} }
CacheableOperation parseCacheableAnnotation(AnnotatedElement ae, Cacheable caching) { CacheableOperation parseCacheableAnnotation(AnnotatedElement ae, Cacheable caching) {
CacheableOperation cuo = new CacheableOperation(); CacheableOperation op = new CacheableOperation();
cuo.setCacheNames(caching.value()); op.setCacheNames(caching.value());
cuo.setCondition(caching.condition()); op.setCondition(caching.condition());
cuo.setUnless(caching.unless()); op.setUnless(caching.unless());
cuo.setKey(caching.key()); op.setKey(caching.key());
cuo.setName(ae.toString()); op.setName(ae.toString());
return cuo; return op;
} }
CacheEvictOperation parseEvictAnnotation(AnnotatedElement ae, CacheEvict caching) { CacheEvictOperation parseEvictAnnotation(AnnotatedElement ae, CacheEvict caching) {
CacheEvictOperation ceo = new CacheEvictOperation(); CacheEvictOperation op = new CacheEvictOperation();
ceo.setCacheNames(caching.value()); op.setCacheNames(caching.value());
ceo.setCondition(caching.condition()); op.setCondition(caching.condition());
ceo.setKey(caching.key()); op.setKey(caching.key());
ceo.setCacheWide(caching.allEntries()); op.setCacheWide(caching.allEntries());
ceo.setBeforeInvocation(caching.beforeInvocation()); op.setBeforeInvocation(caching.beforeInvocation());
ceo.setName(ae.toString()); op.setName(ae.toString());
return ceo; return op;
} }
CacheOperation parseUpdateAnnotation(AnnotatedElement ae, CachePut caching) { CacheOperation parsePutAnnotation(AnnotatedElement ae, CachePut caching) {
CachePutOperation cuo = new CachePutOperation(); CachePutOperation op = new CachePutOperation();
cuo.setCacheNames(caching.value()); op.setCacheNames(caching.value());
cuo.setCondition(caching.condition()); op.setCondition(caching.condition());
cuo.setUnless(caching.unless()); op.setUnless(caching.unless());
cuo.setKey(caching.key()); op.setKey(caching.key());
cuo.setName(ae.toString()); op.setName(ae.toString());
return cuo; return op;
} }
Collection<CacheOperation> parseCachingAnnotation(AnnotatedElement ae, Caching caching) { Collection<CacheOperation> parseCachingAnnotation(AnnotatedElement ae, Caching caching) {
@ -132,7 +133,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
if (!ObjectUtils.isEmpty(updates)) { if (!ObjectUtils.isEmpty(updates)) {
ops = lazyInit(ops); ops = lazyInit(ops);
for (CachePut update : updates) { for (CachePut update : updates) {
ops.add(parseUpdateAnnotation(ae, update)); ops.add(parsePutAnnotation(ae, update));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -26,32 +26,32 @@ import org.springframework.util.Assert;
* Base class for cache operations. * Base class for cache operations.
* *
* @author Costin Leau * @author Costin Leau
* @since 3.1
*/ */
public abstract class CacheOperation { public abstract class CacheOperation {
private Set<String> cacheNames = Collections.emptySet(); private String name = "";
private String condition = ""; private Set<String> cacheNames = Collections.emptySet();
private String key = ""; private String key = "";
private String name = ""; private String keyGenerator = "";
private String cacheManager = "";
private String cacheResolver = "";
private String condition = "";
public Set<String> getCacheNames() { public void setName(String name) {
return cacheNames; Assert.hasText(name);
} this.name = name;
public String getCondition() {
return condition;
}
public String getKey() {
return key;
} }
public String getName() { public String getName() {
return name; return this.name;
} }
public void setCacheName(String cacheName) { public void setCacheName(String cacheName) {
@ -59,17 +59,16 @@ public abstract class CacheOperation {
this.cacheNames = Collections.singleton(cacheName); this.cacheNames = Collections.singleton(cacheName);
} }
public void setCacheNames(String[] cacheNames) { public void setCacheNames(String... cacheNames) {
Assert.notEmpty(cacheNames);
this.cacheNames = new LinkedHashSet<String>(cacheNames.length); this.cacheNames = new LinkedHashSet<String>(cacheNames.length);
for (String string : cacheNames) { for (String cacheName : cacheNames) {
this.cacheNames.add(string); Assert.hasText(cacheName, "Cache name must be non-null if specified");
this.cacheNames.add(cacheName);
} }
} }
public void setCondition(String condition) { public Set<String> getCacheNames() {
Assert.notNull(condition); return this.cacheNames;
this.condition = condition;
} }
public void setKey(String key) { public void setKey(String key) {
@ -77,11 +76,47 @@ public abstract class CacheOperation {
this.key = key; this.key = key;
} }
public void setName(String name) { public String getKey() {
Assert.hasText(name); return this.key;
this.name = name;
} }
public void setKeyGenerator(String keyGenerator) {
Assert.notNull(keyGenerator);
this.keyGenerator = keyGenerator;
}
public String getKeyGenerator() {
return this.keyGenerator;
}
public void setCacheManager(String cacheManager) {
Assert.notNull(cacheManager);
this.cacheManager = cacheManager;
}
public String getCacheManager() {
return this.cacheManager;
}
public void setCacheResolver(String cacheResolver) {
Assert.notNull(cacheManager);
this.cacheResolver = cacheResolver;
}
public String getCacheResolver() {
return this.cacheResolver;
}
public void setCondition(String condition) {
Assert.notNull(condition);
this.condition = condition;
}
public String getCondition() {
return this.condition;
}
/** /**
* This implementation compares the {@code toString()} results. * This implementation compares the {@code toString()} results.
* @see #toString() * @see #toString()
@ -116,17 +151,15 @@ public abstract class CacheOperation {
* <p>Available to subclasses, for inclusion in their {@code toString()} result. * <p>Available to subclasses, for inclusion in their {@code toString()} result.
*/ */
protected StringBuilder getOperationDescription() { protected StringBuilder getOperationDescription() {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder(getClass().getSimpleName());
result.append(getClass().getSimpleName()); result.append("[").append(this.name);
result.append("["); result.append("] caches=").append(this.cacheNames);
result.append(this.name); result.append(" | key='").append(this.key);
result.append("] caches="); result.append("' | keyGenerator='").append(this.keyGenerator);
result.append(this.cacheNames); result.append("' | cacheManager='").append(this.cacheManager);
result.append(" | key='"); result.append("' | cacheResolver='").append(this.cacheResolver);
result.append(this.key); result.append("' | condition='").append(this.condition).append("'");
result.append("' | condition='");
result.append(this.condition);
result.append("'");
return result; return result;
} }
} }

View File

@ -167,7 +167,7 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo
* Set the name-matching patterns for determining autowire candidates. * Set the name-matching patterns for determining autowire candidates.
* @param autowireCandidatePatterns the patterns to match against * @param autowireCandidatePatterns the patterns to match against
*/ */
public void setAutowireCandidatePatterns(String[] autowireCandidatePatterns) { public void setAutowireCandidatePatterns(String... autowireCandidatePatterns) {
this.autowireCandidatePatterns = autowireCandidatePatterns; this.autowireCandidatePatterns = autowireCandidatePatterns;
} }
@ -224,7 +224,7 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry); AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
} }
return this.registry.getBeanDefinitionCount() - beanCountAtScanStart; return (this.registry.getBeanDefinitionCount() - beanCountAtScanStart);
} }
/** /**

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -68,7 +68,7 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean
* that bean is found in the {@code ignoredMethodsMappings} property. * that bean is found in the {@code ignoredMethodsMappings} property.
* @see #setIgnoredMethodMappings(java.util.Properties) * @see #setIgnoredMethodMappings(java.util.Properties)
*/ */
public void setIgnoredMethods(String[] ignoredMethodNames) { public void setIgnoredMethods(String... ignoredMethodNames) {
this.ignoredMethods = new HashSet<String>(Arrays.asList(ignoredMethodNames)); this.ignoredMethods = new HashSet<String>(Arrays.asList(ignoredMethodNames));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 the original author or authors. * Copyright 2002-2014 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,7 @@ public class ManagedNotification {
/** /**
* Set a list of notification types. * Set a list of notification types.
*/ */
public void setNotificationTypes(String[] notificationTypes) { public void setNotificationTypes(String... notificationTypes) {
this.notificationTypes = notificationTypes; this.notificationTypes = notificationTypes;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.naming.NameNotFoundException; import javax.naming.NameNotFoundException;
import javax.naming.NamingException; import javax.naming.NamingException;
@ -74,16 +73,6 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
} }
/**
* Set a list of names of shareable JNDI resources,
* which this factory is allowed to cache once obtained.
* @param shareableResources the JNDI names
* (typically within the "java:comp/env/" namespace)
*/
public void setShareableResources(String[] shareableResources) {
this.shareableResources.addAll(Arrays.asList(shareableResources));
}
/** /**
* Add the name of a shareable JNDI resource, * Add the name of a shareable JNDI resource,
* which this factory is allowed to cache once obtained. * which this factory is allowed to cache once obtained.
@ -94,6 +83,16 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
this.shareableResources.add(shareableResource); this.shareableResources.add(shareableResource);
} }
/**
* Set a list of names of shareable JNDI resources,
* which this factory is allowed to cache once obtained.
* @param shareableResources the JNDI names
* (typically within the "java:comp/env/" namespace)
*/
public void setShareableResources(String... shareableResources) {
this.shareableResources.addAll(Arrays.asList(shareableResources));
}
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Implementation of BeanFactory interface // Implementation of BeanFactory interface

View File

@ -130,7 +130,7 @@ public class PreparedStatementCreatorFactory {
/** /**
* Set the column names of the auto-generated keys. * Set the column names of the auto-generated keys.
*/ */
public void setGeneratedKeysColumnNames(String[] names) { public void setGeneratedKeysColumnNames(String... names) {
this.generatedKeysColumnNames = names; this.generatedKeysColumnNames = names;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2014 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,7 +22,6 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -292,7 +291,7 @@ public class TableMetaDataContext {
* Build the insert string based on configuration and metadata information * Build the insert string based on configuration and metadata information
* @return the insert string to be used * @return the insert string to be used
*/ */
public String createInsertString(String[] generatedKeyNames) { public String createInsertString(String... generatedKeyNames) {
HashSet<String> keys = new HashSet<String>(generatedKeyNames.length); HashSet<String> keys = new HashSet<String>(generatedKeyNames.length);
for (String key : generatedKeyNames) { for (String key : generatedKeyNames) {
keys.add(key.toUpperCase()); keys.add(key.toUpperCase());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -179,21 +179,6 @@ public abstract class AbstractJdbcInsert {
return Collections.unmodifiableList(this.declaredColumns); return Collections.unmodifiableList(this.declaredColumns);
} }
/**
* Get the names of any generated keys
*/
public String[] getGeneratedKeyNames() {
return this.generatedKeyNames;
}
/**
* Set the names of any generated keys
*/
public void setGeneratedKeyNames(String[] generatedKeyNames) {
checkIfConfigurationModificationIsAllowed();
this.generatedKeyNames = generatedKeyNames;
}
/** /**
* Specify the name of a single generated key column * Specify the name of a single generated key column
*/ */
@ -202,6 +187,21 @@ public abstract class AbstractJdbcInsert {
this.generatedKeyNames = new String[] {generatedKeyName}; this.generatedKeyNames = new String[] {generatedKeyName};
} }
/**
* Set the names of any generated keys
*/
public void setGeneratedKeyNames(String... generatedKeyNames) {
checkIfConfigurationModificationIsAllowed();
this.generatedKeyNames = generatedKeyNames;
}
/**
* Get the names of any generated keys
*/
public String[] getGeneratedKeyNames() {
return this.generatedKeyNames;
}
/** /**
* Specify whether the parameter metadata for the call should be used. The default is true. * Specify whether the parameter metadata for the call should be used. The default is true.
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -210,7 +210,7 @@ public abstract class RdbmsOperation implements InitializingBean {
* Set the column names of the auto-generated keys. * Set the column names of the auto-generated keys.
* @see java.sql.Connection#prepareStatement(String, String[]) * @see java.sql.Connection#prepareStatement(String, String[])
*/ */
public void setGeneratedKeysColumnNames(String[] names) { public void setGeneratedKeysColumnNames(String... names) {
if (isCompiled()) { if (isCompiled()) {
throw new InvalidDataAccessApiUsageException( throw new InvalidDataAccessApiUsageException(
"The column names for the generated keys must be set before the operation is compiled"); "The column names for the generated keys must be set before the operation is compiled");

View File

@ -230,7 +230,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi
* <p>Setting either this property, {@link #setContextPath "contextPath"} * <p>Setting either this property, {@link #setContextPath "contextPath"}
* or {@link #setClassesToBeBound "classesToBeBound"} is required. * or {@link #setClassesToBeBound "classesToBeBound"} is required.
*/ */
public void setPackagesToScan(String[] packagesToScan) { public void setPackagesToScan(String... packagesToScan) {
this.packagesToScan = packagesToScan; this.packagesToScan = packagesToScan;
} }

View File

@ -20,6 +20,7 @@ import java.util.Arrays;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationAttributes;
@ -44,13 +45,11 @@ public class ContextConfigurationAttributes {
private final Class<?> declaringClass; private final Class<?> declaringClass;
private String[] locations;
private Class<?>[] classes; private Class<?>[] classes;
private final boolean inheritLocations; private String[] locations;
private final Class<? extends ContextLoader> contextLoaderClass; private final boolean inheritLocations;
private final Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers; private final Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers;
@ -58,42 +57,8 @@ public class ContextConfigurationAttributes {
private final String name; private final String name;
private final Class<? extends ContextLoader> contextLoaderClass;
/**
* Resolve resource locations from the {@link ContextConfiguration#locations() locations}
* and {@link ContextConfiguration#value() value} attributes of the supplied
* {@link ContextConfiguration} annotation.
*
* @throws IllegalStateException if both the locations and value attributes have been declared
*/
private static String[] resolveLocations(Class<?> declaringClass, ContextConfiguration contextConfiguration) {
return resolveLocations(declaringClass, contextConfiguration.locations(), contextConfiguration.value());
}
/**
* Resolve resource locations from the supplied {@code locations} and
* {@code value} arrays, which correspond to attributes of the same names in
* the {@link ContextConfiguration} annotation.
*
* @throws IllegalStateException if both the locations and value attributes have been declared
*/
private static String[] resolveLocations(Class<?> declaringClass, String[] locations, String[] value) {
Assert.notNull(declaringClass, "declaringClass must not be null");
if (!ObjectUtils.isEmpty(value) && !ObjectUtils.isEmpty(locations)) {
String msg = String.format("Test class [%s] has been configured with @ContextConfiguration's 'value' %s "
+ "and 'locations' %s attributes. Only one declaration of resource "
+ "locations is permitted per @ContextConfiguration annotation.", declaringClass.getName(),
ObjectUtils.nullSafeToString(value), ObjectUtils.nullSafeToString(locations));
logger.error(msg);
throw new IllegalStateException(msg);
}
else if (!ObjectUtils.isEmpty(value)) {
locations = value;
}
return locations;
}
/** /**
* Construct a new {@link ContextConfigurationAttributes} instance for the * Construct a new {@link ContextConfigurationAttributes} instance for the
@ -118,11 +83,9 @@ public class ContextConfigurationAttributes {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs) { public ContextConfigurationAttributes(Class<?> declaringClass, AnnotationAttributes annAttrs) {
this( this(declaringClass,
declaringClass,
resolveLocations(declaringClass, annAttrs.getStringArray("locations"), annAttrs.getStringArray("value")), resolveLocations(declaringClass, annAttrs.getStringArray("locations"), annAttrs.getStringArray("value")),
annAttrs.getClassArray("classes"), annAttrs.getClassArray("classes"), annAttrs.getBoolean("inheritLocations"),
annAttrs.getBoolean("inheritLocations"),
(Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[]) annAttrs.getClassArray("initializers"), (Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[]) annAttrs.getClassArray("initializers"),
annAttrs.getBoolean("inheritInitializers"), annAttrs.getString("name"), annAttrs.getBoolean("inheritInitializers"), annAttrs.getString("name"),
(Class<? extends ContextLoader>) annAttrs.getClass("loader")); (Class<? extends ContextLoader>) annAttrs.getClass("loader"));
@ -133,7 +96,6 @@ public class ContextConfigurationAttributes {
* {@linkplain Class test class} that declared the * {@linkplain Class test class} that declared the
* {@link ContextConfiguration @ContextConfiguration} annotation and its * {@link ContextConfiguration @ContextConfiguration} annotation and its
* corresponding attributes. * corresponding attributes.
*
* @param declaringClass the test class that declared {@code @ContextConfiguration} * @param declaringClass the test class that declared {@code @ContextConfiguration}
* @param locations the resource locations declared via {@code @ContextConfiguration} * @param locations the resource locations declared via {@code @ContextConfiguration}
* @param classes the annotated classes declared via {@code @ContextConfiguration} * @param classes the annotated classes declared via {@code @ContextConfiguration}
@ -148,6 +110,7 @@ public class ContextConfigurationAttributes {
@Deprecated @Deprecated
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes,
boolean inheritLocations, Class<? extends ContextLoader> contextLoaderClass) { boolean inheritLocations, Class<? extends ContextLoader> contextLoaderClass) {
this(declaringClass, locations, classes, inheritLocations, null, true, null, contextLoaderClass); this(declaringClass, locations, classes, inheritLocations, null, true, null, contextLoaderClass);
} }
@ -156,7 +119,6 @@ public class ContextConfigurationAttributes {
* {@linkplain Class test class} that declared the * {@linkplain Class test class} that declared the
* {@link ContextConfiguration @ContextConfiguration} annotation and its * {@link ContextConfiguration @ContextConfiguration} annotation and its
* corresponding attributes. * corresponding attributes.
*
* @param declaringClass the test class that declared {@code @ContextConfiguration} * @param declaringClass the test class that declared {@code @ContextConfiguration}
* @param locations the resource locations declared via {@code @ContextConfiguration} * @param locations the resource locations declared via {@code @ContextConfiguration}
* @param classes the annotated classes declared via {@code @ContextConfiguration} * @param classes the annotated classes declared via {@code @ContextConfiguration}
@ -167,10 +129,11 @@ public class ContextConfigurationAttributes {
* @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is * @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is
* {@code null} * {@code null}
*/ */
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, public ContextConfigurationAttributes(
boolean inheritLocations, Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations,
Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers,
boolean inheritInitializers, Class<? extends ContextLoader> contextLoaderClass) { boolean inheritInitializers, Class<? extends ContextLoader> contextLoaderClass) {
this(declaringClass, locations, classes, inheritLocations, initializers, inheritInitializers, null, this(declaringClass, locations, classes, inheritLocations, initializers, inheritInitializers, null,
contextLoaderClass); contextLoaderClass);
} }
@ -180,7 +143,6 @@ public class ContextConfigurationAttributes {
* {@linkplain Class test class} that declared the * {@linkplain Class test class} that declared the
* {@link ContextConfiguration @ContextConfiguration} annotation and its * {@link ContextConfiguration @ContextConfiguration} annotation and its
* corresponding attributes. * corresponding attributes.
*
* @param declaringClass the test class that declared {@code @ContextConfiguration} * @param declaringClass the test class that declared {@code @ContextConfiguration}
* @param locations the resource locations declared via {@code @ContextConfiguration} * @param locations the resource locations declared via {@code @ContextConfiguration}
* @param classes the annotated classes declared via {@code @ContextConfiguration} * @param classes the annotated classes declared via {@code @ContextConfiguration}
@ -192,8 +154,8 @@ public class ContextConfigurationAttributes {
* @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is * @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is
* {@code null} * {@code null}
*/ */
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes, public ContextConfigurationAttributes(
boolean inheritLocations, Class<?> declaringClass, String[] locations, Class<?>[] classes, boolean inheritLocations,
Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers, Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers,
boolean inheritInitializers, String name, Class<? extends ContextLoader> contextLoaderClass) { boolean inheritInitializers, String name, Class<? extends ContextLoader> contextLoaderClass) {
@ -202,9 +164,9 @@ public class ContextConfigurationAttributes {
if (!ObjectUtils.isEmpty(locations) && !ObjectUtils.isEmpty(classes) && logger.isDebugEnabled()) { if (!ObjectUtils.isEmpty(locations) && !ObjectUtils.isEmpty(classes) && logger.isDebugEnabled()) {
logger.debug(String.format( logger.debug(String.format(
"Test class [%s] has been configured with @ContextConfiguration's 'locations' (or 'value') %s " "Test class [%s] has been configured with @ContextConfiguration's 'locations' (or 'value') %s " +
+ "and 'classes' %s attributes. Most SmartContextLoader implementations support " "and 'classes' %s attributes. Most SmartContextLoader implementations support " +
+ "only one declaration of resources per @ContextConfiguration annotation.", "only one declaration of resources per @ContextConfiguration annotation.",
declaringClass.getName(), ObjectUtils.nullSafeToString(locations), declaringClass.getName(), ObjectUtils.nullSafeToString(locations),
ObjectUtils.nullSafeToString(classes))); ObjectUtils.nullSafeToString(classes)));
} }
@ -215,77 +177,112 @@ public class ContextConfigurationAttributes {
this.inheritLocations = inheritLocations; this.inheritLocations = inheritLocations;
this.initializers = initializers; this.initializers = initializers;
this.inheritInitializers = inheritInitializers; this.inheritInitializers = inheritInitializers;
this.name = StringUtils.hasText(name) ? name : null; this.name = (StringUtils.hasText(name) ? name : null);
this.contextLoaderClass = contextLoaderClass; this.contextLoaderClass = contextLoaderClass;
} }
/**
* Resolve resource locations from the {@link ContextConfiguration#locations() locations}
* and {@link ContextConfiguration#value() value} attributes of the supplied
* {@link ContextConfiguration} annotation.
* @throws IllegalStateException if both the locations and value attributes have been declared
*/
private static String[] resolveLocations(Class<?> declaringClass, ContextConfiguration contextConfiguration) {
return resolveLocations(declaringClass, contextConfiguration.locations(), contextConfiguration.value());
}
/**
* Resolve resource locations from the supplied {@code locations} and
* {@code value} arrays, which correspond to attributes of the same names in
* the {@link ContextConfiguration} annotation.
* @throws IllegalStateException if both the locations and value attributes have been declared
*/
private static String[] resolveLocations(Class<?> declaringClass, String[] locations, String[] value) {
Assert.notNull(declaringClass, "declaringClass must not be null");
if (!ObjectUtils.isEmpty(value) && !ObjectUtils.isEmpty(locations)) {
throw new IllegalStateException(String.format("Test class [%s] has been configured with " +
"@ContextConfiguration's 'value' %s and 'locations' %s attributes. Only one declaration " +
"of resource locations is permitted per @ContextConfiguration annotation.",
declaringClass.getName(), ObjectUtils.nullSafeToString(value), ObjectUtils.nullSafeToString(locations)));
}
else if (!ObjectUtils.isEmpty(value)) {
locations = value;
}
return locations;
}
/** /**
* Get the {@linkplain Class class} that declared the * Get the {@linkplain Class class} that declared the
* {@link ContextConfiguration @ContextConfiguration} annotation. * {@link ContextConfiguration @ContextConfiguration} annotation.
* * @return the declaring class (never {@code null})
* @return the declaring class; never {@code null}
*/ */
public Class<?> getDeclaringClass() { public Class<?> getDeclaringClass() {
return declaringClass; return this.declaringClass;
}
/**
* Set the <em>processed</em> annotated classes, effectively overriding the
* original value declared via {@link ContextConfiguration @ContextConfiguration}.
* @see #getClasses()
*/
public void setClasses(Class<?>... classes) {
this.classes = classes;
}
/**
* Get the annotated classes that were declared via
* {@link ContextConfiguration @ContextConfiguration}.
* <p>Note: this is a mutable property. The returned value may therefore
* represent a <em>processed</em> value that does not match the original value
* declared via {@link ContextConfiguration @ContextConfiguration}.
* @return the annotated classes; potentially {@code null} or <em>empty</em>
* @see ContextConfiguration#classes
* @see #setClasses(Class[])
*/
public Class<?>[] getClasses() {
return this.classes;
}
/**
* Determine if this {@code ContextConfigurationAttributes} instance has
* class-based resources.
* @return {@code true} if the {@link #getClasses() classes} array is not empty
* @see #hasResources()
* @see #hasLocations()
*/
public boolean hasClasses() {
return !ObjectUtils.isEmpty(getClasses());
}
/**
* Set the <em>processed</em> resource locations, effectively overriding the
* original value declared via {@link ContextConfiguration @ContextConfiguration}.
* @see #getLocations()
*/
public void setLocations(String... locations) {
this.locations = locations;
} }
/** /**
* Get the resource locations that were declared via * Get the resource locations that were declared via
* {@link ContextConfiguration @ContextConfiguration}. * {@link ContextConfiguration @ContextConfiguration}.
*
* <p>Note: this is a mutable property. The returned value may therefore * <p>Note: this is a mutable property. The returned value may therefore
* represent a <em>processed</em> value that does not match the original value * represent a <em>processed</em> value that does not match the original value
* declared via {@link ContextConfiguration @ContextConfiguration}. * declared via {@link ContextConfiguration @ContextConfiguration}.
*
* @return the resource locations; potentially {@code null} or <em>empty</em> * @return the resource locations; potentially {@code null} or <em>empty</em>
* @see ContextConfiguration#value * @see ContextConfiguration#value
* @see ContextConfiguration#locations * @see ContextConfiguration#locations
* @see #setLocations(String[]) * @see #setLocations(String[])
*/ */
public String[] getLocations() { public String[] getLocations() {
return locations; return this.locations;
}
/**
* Set the <em>processed</em> resource locations, effectively overriding the
* original value declared via {@link ContextConfiguration @ContextConfiguration}.
*
* @see #getLocations()
*/
public void setLocations(String[] locations) {
this.locations = locations;
}
/**
* Get the annotated classes that were declared via
* {@link ContextConfiguration @ContextConfiguration}.
*
* <p>Note: this is a mutable property. The returned value may therefore
* represent a <em>processed</em> value that does not match the original value
* declared via {@link ContextConfiguration @ContextConfiguration}.
*
* @return the annotated classes; potentially {@code null} or <em>empty</em>
* @see ContextConfiguration#classes
* @see #setClasses(Class[])
*/
public Class<?>[] getClasses() {
return classes;
}
/**
* Set the <em>processed</em> annotated classes, effectively overriding the
* original value declared via {@link ContextConfiguration @ContextConfiguration}.
*
* @see #getClasses()
*/
public void setClasses(Class<?>[] classes) {
this.classes = classes;
} }
/** /**
* Determine if this {@code ContextConfigurationAttributes} instance has * Determine if this {@code ContextConfigurationAttributes} instance has
* path-based resource locations. * path-based resource locations.
*
* @return {@code true} if the {@link #getLocations() locations} array is not empty * @return {@code true} if the {@link #getLocations() locations} array is not empty
* @see #hasResources() * @see #hasResources()
* @see #hasClasses() * @see #hasClasses()
@ -294,79 +291,51 @@ public class ContextConfigurationAttributes {
return !ObjectUtils.isEmpty(getLocations()); return !ObjectUtils.isEmpty(getLocations());
} }
/**
* Determine if this {@code ContextConfigurationAttributes} instance has
* class-based resources.
*
* @return {@code true} if the {@link #getClasses() classes} array is not empty
* @see #hasResources()
* @see #hasLocations()
*/
public boolean hasClasses() {
return !ObjectUtils.isEmpty(getClasses());
}
/** /**
* Determine if this {@code ContextConfigurationAttributes} instance has * Determine if this {@code ContextConfigurationAttributes} instance has
* either path-based resource locations or class-based resources. * either path-based resource locations or class-based resources.
*
* @return {@code true} if either the {@link #getLocations() locations} * @return {@code true} if either the {@link #getLocations() locations}
* or the {@link #getClasses() classes} array is not empty * or the {@link #getClasses() classes} array is not empty
* @see #hasLocations() * @see #hasLocations()
* @see #hasClasses() * @see #hasClasses()
*/ */
public boolean hasResources() { public boolean hasResources() {
return hasLocations() || hasClasses(); return (hasLocations() || hasClasses());
} }
/** /**
* Get the {@code inheritLocations} flag that was declared via * Get the {@code inheritLocations} flag that was declared via
* {@link ContextConfiguration @ContextConfiguration}. * {@link ContextConfiguration @ContextConfiguration}.
*
* @return the {@code inheritLocations} flag * @return the {@code inheritLocations} flag
* @see ContextConfiguration#inheritLocations * @see ContextConfiguration#inheritLocations
*/ */
public boolean isInheritLocations() { public boolean isInheritLocations() {
return inheritLocations; return this.inheritLocations;
} }
/** /**
* Get the {@code ApplicationContextInitializer} classes that were declared via * Get the {@code ApplicationContextInitializer} classes that were declared via
* {@link ContextConfiguration @ContextConfiguration}. * {@link ContextConfiguration @ContextConfiguration}.
*
* @return the {@code ApplicationContextInitializer} classes * @return the {@code ApplicationContextInitializer} classes
* @since 3.2 * @since 3.2
*/ */
public Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] getInitializers() { public Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] getInitializers() {
return initializers; return this.initializers;
} }
/** /**
* Get the {@code inheritInitializers} flag that was declared via * Get the {@code inheritInitializers} flag that was declared via
* {@link ContextConfiguration @ContextConfiguration}. * {@link ContextConfiguration @ContextConfiguration}.
*
* @return the {@code inheritInitializers} flag * @return the {@code inheritInitializers} flag
* @since 3.2 * @since 3.2
*/ */
public boolean isInheritInitializers() { public boolean isInheritInitializers() {
return inheritInitializers; return this.inheritInitializers;
}
/**
* Get the {@code ContextLoader} class that was declared via
* {@link ContextConfiguration @ContextConfiguration}.
*
* @return the {@code ContextLoader} class
* @see ContextConfiguration#loader
*/
public Class<? extends ContextLoader> getContextLoaderClass() {
return contextLoaderClass;
} }
/** /**
* Get the name of the context hierarchy level that was declared via * Get the name of the context hierarchy level that was declared via
* {@link ContextConfiguration @ContextConfiguration}. * {@link ContextConfiguration @ContextConfiguration}.
*
* @return the name of the context hierarchy level or {@code null} if not applicable * @return the name of the context hierarchy level or {@code null} if not applicable
* @see ContextConfiguration#name() * @see ContextConfiguration#name()
* @since 3.2.2 * @since 3.2.2
@ -376,24 +345,16 @@ public class ContextConfigurationAttributes {
} }
/** /**
* Generate a unique hash code for all properties of this * Get the {@code ContextLoader} class that was declared via
* {@code ContextConfigurationAttributes} instance excluding the * {@link ContextConfiguration @ContextConfiguration}.
* {@linkplain #getName() name}. * @return the {@code ContextLoader} class
* @see ContextConfiguration#loader
*/ */
@Override public Class<? extends ContextLoader> getContextLoaderClass() {
public int hashCode() { return this.contextLoaderClass;
final int prime = 31;
int result = 1;
result = prime * result + declaringClass.hashCode();
result = prime * result + Arrays.hashCode(locations);
result = prime * result + Arrays.hashCode(classes);
result = prime * result + (inheritLocations ? 1231 : 1237);
result = prime * result + Arrays.hashCode(initializers);
result = prime * result + (inheritInitializers ? 1231 : 1237);
result = prime * result + contextLoaderClass.hashCode();
return result;
} }
/** /**
* Determine if the supplied object is equal to this * Determine if the supplied object is equal to this
* {@code ContextConfigurationAttributes} instance by comparing both object's * {@code ContextConfigurationAttributes} instance by comparing both object's
@ -406,56 +367,36 @@ public class ContextConfigurationAttributes {
* {@link #getContextLoaderClass() ContextLoader class}. * {@link #getContextLoaderClass() ContextLoader class}.
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object other) {
if (this == other) {
if (this == obj) {
return true; return true;
} }
if (!(obj instanceof ContextConfigurationAttributes)) { if (!(other instanceof ContextConfigurationAttributes)) {
return false; return false;
} }
ContextConfigurationAttributes otherAttr = (ContextConfigurationAttributes) other;
return (ObjectUtils.nullSafeEquals(this.declaringClass, otherAttr.declaringClass) &&
Arrays.equals(this.classes, otherAttr.classes)) &&
Arrays.equals(this.locations, otherAttr.locations) &&
this.inheritLocations == otherAttr.inheritLocations &&
Arrays.equals(this.initializers, otherAttr.initializers) &&
this.inheritInitializers == otherAttr.inheritInitializers &&
ObjectUtils.nullSafeEquals(this.name, otherAttr.name) &&
ObjectUtils.nullSafeEquals(this.contextLoaderClass, otherAttr.contextLoaderClass);
}
final ContextConfigurationAttributes that = (ContextConfigurationAttributes) obj; /**
* Generate a unique hash code for all properties of this
if (this.declaringClass == null) { * {@code ContextConfigurationAttributes} instance excluding the
if (that.declaringClass != null) { * {@linkplain #getName() name}.
return false; */
} @Override
} public int hashCode() {
else if (!this.declaringClass.equals(that.declaringClass)) { int result = this.declaringClass.hashCode();
return false; result = 31 * result + Arrays.hashCode(this.classes);
} result = 31 * result + Arrays.hashCode(this.locations);
result = 31 * result + Arrays.hashCode(this.initializers);
if (!Arrays.equals(this.locations, that.locations)) { return result;
return false;
}
if (!Arrays.equals(this.classes, that.classes)) {
return false;
}
if (this.inheritLocations != that.inheritLocations) {
return false;
}
if (!Arrays.equals(this.initializers, that.initializers)) {
return false;
}
if (this.inheritInitializers != that.inheritInitializers) {
return false;
}
if (this.contextLoaderClass == null) {
if (that.contextLoaderClass != null) {
return false;
}
}
else if (!this.contextLoaderClass.equals(that.contextLoaderClass)) {
return false;
}
return true;
} }
/** /**
@ -464,16 +405,16 @@ public class ContextConfigurationAttributes {
*/ */
@Override @Override
public String toString() { public String toString() {
return new ToStringCreator(this)// return new ToStringCreator(this)
.append("declaringClass", declaringClass.getName())// .append("declaringClass", this.declaringClass.getName())
.append("locations", ObjectUtils.nullSafeToString(locations))// .append("classes", ObjectUtils.nullSafeToString(this.classes))
.append("classes", ObjectUtils.nullSafeToString(classes))// .append("locations", ObjectUtils.nullSafeToString(this.locations))
.append("inheritLocations", inheritLocations)// .append("inheritLocations", this.inheritLocations)
.append("initializers", ObjectUtils.nullSafeToString(initializers))// .append("initializers", ObjectUtils.nullSafeToString(this.initializers))
.append("inheritInitializers", inheritInitializers)// .append("inheritInitializers", this.inheritInitializers)
.append("name", name)// .append("name", this.name)
.append("contextLoaderClass", contextLoaderClass.getName())// .append("contextLoaderClass", this.contextLoaderClass.getName())
.toString(); .toString();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2014 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,6 @@
package org.springframework.web.portlet.handler; package org.springframework.web.portlet.handler;
import java.io.IOException; import java.io.IOException;
import javax.portlet.PortletException; import javax.portlet.PortletException;
import javax.portlet.PortletRequest; import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse; import javax.portlet.PortletResponse;
@ -41,7 +40,7 @@ public class UserRoleAuthorizationInterceptor extends HandlerInterceptorAdapter
* Set the roles that this interceptor should treat as authorized. * Set the roles that this interceptor should treat as authorized.
* @param authorizedRoles array of role names * @param authorizedRoles array of role names
*/ */
public final void setAuthorizedRoles(String[] authorizedRoles) { public final void setAuthorizedRoles(String... authorizedRoles) {
this.authorizedRoles = authorizedRoles; this.authorizedRoles = authorizedRoles;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2014 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,7 +38,7 @@ public class UserRoleAuthorizationInterceptor extends HandlerInterceptorAdapter
* Set the roles that this interceptor should treat as authorized. * Set the roles that this interceptor should treat as authorized.
* @param authorizedRoles array of role names * @param authorizedRoles array of role names
*/ */
public final void setAuthorizedRoles(String[] authorizedRoles) { public final void setAuthorizedRoles(String... authorizedRoles) {
this.authorizedRoles = authorizedRoles; this.authorizedRoles = authorizedRoles;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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 class ParameterMethodNameResolver implements MethodNameResolver {
* can be considered a logical name only. * can be considered a logical name only.
* @see #setParamName * @see #setParamName
*/ */
public void setMethodParamNames(String[] methodParamNames) { public void setMethodParamNames(String... methodParamNames) {
this.methodParamNames = methodParamNames; this.methodParamNames = methodParamNames;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -60,7 +60,7 @@ public abstract class AbstractControllerUrlHandlerMapping extends AbstractDetect
* e.g. a {@link org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping}, * e.g. a {@link org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping},
* alongside this ControllerClassNameHandlerMapping for application controllers. * alongside this ControllerClassNameHandlerMapping for application controllers.
*/ */
public void setExcludedPackages(String[] excludedPackages) { public void setExcludedPackages(String... excludedPackages) {
this.excludedPackages = (excludedPackages != null) ? this.excludedPackages = (excludedPackages != null) ?
new HashSet<String>(Arrays.asList(excludedPackages)) : new HashSet<String>(); new HashSet<String>(Arrays.asList(excludedPackages)) : new HashSet<String>();
} }
@ -69,7 +69,7 @@ public abstract class AbstractControllerUrlHandlerMapping extends AbstractDetect
* Specify controller classes that should be excluded from this mapping. * Specify controller classes that should be excluded from this mapping.
* Any such classes will simply be ignored by this HandlerMapping. * Any such classes will simply be ignored by this HandlerMapping.
*/ */
public void setExcludedClasses(Class<?>[] excludedClasses) { public void setExcludedClasses(Class<?>... excludedClasses) {
this.excludedClasses = (excludedClasses != null) ? this.excludedClasses = (excludedClasses != null) ?
new HashSet<Class<?>>(Arrays.asList(excludedClasses)) : new HashSet<Class<?>>(); new HashSet<Class<?>>(Arrays.asList(excludedClasses)) : new HashSet<Class<?>>();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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 abstract class WebContentGenerator extends WebApplicationObjectSupport {
* <p>Default is GET, HEAD and POST for simple form controller types; * <p>Default is GET, HEAD and POST for simple form controller types;
* unrestricted for general controllers and interceptors. * unrestricted for general controllers and interceptors.
*/ */
public final void setSupportedMethods(String[] methods) { public final void setSupportedMethods(String... methods) {
if (methods != null) { if (methods != null) {
this.supportedMethods = new HashSet<String>(Arrays.asList(methods)); this.supportedMethods = new HashSet<String>(Arrays.asList(methods));
} }

View File

@ -227,7 +227,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
} }
/** /**
* Whether to add path variables in the model or not. * Specify whether to add path variables to the model or not.
* <p>Path variables are commonly bound to URI template variables through the {@code @PathVariable} * <p>Path variables are commonly bound to URI template variables through the {@code @PathVariable}
* annotation. They're are effectively URI template variables with type conversion applied to * annotation. They're are effectively URI template variables with type conversion applied to
* them to derive typed Object values. Such values are frequently needed in views for * them to derive typed Object values. Such values are frequently needed in views for
@ -235,14 +235,14 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
* <p>Path variables added to the model override static attributes (see {@link #setAttributes(Properties)}) * <p>Path variables added to the model override static attributes (see {@link #setAttributes(Properties)})
* but not attributes already present in the model. * but not attributes already present in the model.
* <p>By default this flag is set to {@code true}. Concrete view types can override this. * <p>By default this flag is set to {@code true}. Concrete view types can override this.
* @param exposePathVariables {@code true} to expose path variables, and {@code false} otherwise. * @param exposePathVariables {@code true} to expose path variables, and {@code false} otherwise
*/ */
public void setExposePathVariables(boolean exposePathVariables) { public void setExposePathVariables(boolean exposePathVariables) {
this.exposePathVariables = exposePathVariables; this.exposePathVariables = exposePathVariables;
} }
/** /**
* Returns the value of the flag indicating whether path variables should be added to the model or not. * Return whether to add path variables to the model or not.
*/ */
public boolean isExposePathVariables() { public boolean isExposePathVariables() {
return this.exposePathVariables; return this.exposePathVariables;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -141,7 +141,7 @@ public class InternalResourceView extends AbstractUrlBasedView {
* the {@link #setExposeContextBeansAsAttributes "exposeContextBeansAsAttributes"} * the {@link #setExposeContextBeansAsAttributes "exposeContextBeansAsAttributes"}
* flag on but do not list specific bean names for this property. * flag on but do not list specific bean names for this property.
*/ */
public void setExposedContextBeanNames(String[] exposedContextBeanNames) { public void setExposedContextBeanNames(String... exposedContextBeanNames) {
this.exposedContextBeanNames = new HashSet<String>(Arrays.asList(exposedContextBeanNames)); this.exposedContextBeanNames = new HashSet<String>(Arrays.asList(exposedContextBeanNames));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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,6 +70,7 @@ public class InternalResourceViewResolver extends UrlBasedViewResolver {
setViewClass(viewClass); setViewClass(viewClass);
} }
/** /**
* This resolver requires {@link InternalResourceView}. * This resolver requires {@link InternalResourceView}.
*/ */
@ -78,7 +79,6 @@ public class InternalResourceViewResolver extends UrlBasedViewResolver {
return InternalResourceView.class; return InternalResourceView.class;
} }
/** /**
* Specify whether to always include the view rather than forward to it. * Specify whether to always include the view rather than forward to it.
* <p>Default is "false". Switch this flag on to enforce the use of a * <p>Default is "false". Switch this flag on to enforce the use of a
@ -86,7 +86,7 @@ public class InternalResourceViewResolver extends UrlBasedViewResolver {
* @see InternalResourceView#setAlwaysInclude * @see InternalResourceView#setAlwaysInclude
*/ */
public void setAlwaysInclude(boolean alwaysInclude) { public void setAlwaysInclude(boolean alwaysInclude) {
this.alwaysInclude = Boolean.valueOf(alwaysInclude); this.alwaysInclude = alwaysInclude;
} }
/** /**
@ -108,7 +108,7 @@ public class InternalResourceViewResolver extends UrlBasedViewResolver {
* attributes. * attributes.
* @see InternalResourceView#setExposedContextBeanNames * @see InternalResourceView#setExposedContextBeanNames
*/ */
public void setExposedContextBeanNames(String[] exposedContextBeanNames) { public void setExposedContextBeanNames(String... exposedContextBeanNames) {
this.exposedContextBeanNames = exposedContextBeanNames; this.exposedContextBeanNames = exposedContextBeanNames;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -130,7 +130,7 @@ public class ResourceBundleViewResolver extends AbstractCachingViewResolver
* @see #setBasename * @see #setBasename
* @see java.util.ResourceBundle#getBundle(String) * @see java.util.ResourceBundle#getBundle(String)
*/ */
public void setBasenames(String[] basenames) { public void setBasenames(String... basenames) {
this.basenames = basenames; this.basenames = basenames;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -106,8 +106,6 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements
private String suffix = ""; private String suffix = "";
private String[] viewNames = null;
private String contentType; private String contentType;
private boolean redirectContextRelative = true; private boolean redirectContextRelative = true;
@ -116,13 +114,16 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements
private String requestContextAttribute; private String requestContextAttribute;
private int order = Integer.MAX_VALUE;
/** Map of static attributes, keyed by attribute name (String) */ /** Map of static attributes, keyed by attribute name (String) */
private final Map<String, Object> staticAttributes = new HashMap<String, Object>(); private final Map<String, Object> staticAttributes = new HashMap<String, Object>();
private Boolean exposePathVariables; private Boolean exposePathVariables;
private String[] viewNames;
private int order = Integer.MAX_VALUE;
/** /**
* Set the view class that should be used to create views. * Set the view class that should be used to create views.
* @param viewClass class that is assignable to the required view class * @param viewClass class that is assignable to the required view class
@ -303,6 +304,29 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements
return this.staticAttributes; return this.staticAttributes;
} }
/**
* Specify whether views resolved by this resolver should add path variables to the model or not.
* <p>>The default setting is to let each View decide (see {@link AbstractView#setExposePathVariables}.
* However, you can use this property to override that.
* @param exposePathVariables
* <ul>
* <li>{@code true} - all Views resolved by this resolver will expose path variables
* <li>{@code false} - no Views resolved by this resolver will expose path variables
* <li>{@code null} - individual Views can decide for themselves (this is used by the default)
* <ul>
* @see AbstractView#setExposePathVariables
*/
public void setExposePathVariables(Boolean exposePathVariables) {
this.exposePathVariables = exposePathVariables;
}
/**
* Return whether views resolved by this resolver should add path variables to the model or not.
*/
protected Boolean getExposePathVariables() {
return this.exposePathVariables;
}
/** /**
* Set the view names (or name patterns) that can be handled by this * Set the view names (or name patterns) that can be handled by this
* {@link org.springframework.web.servlet.ViewResolver}. View names can contain * {@link org.springframework.web.servlet.ViewResolver}. View names can contain
@ -310,7 +334,7 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements
* view name 'myReport'. * view name 'myReport'.
* @see #canHandle * @see #canHandle
*/ */
public void setViewNames(String[] viewNames) { public void setViewNames(String... viewNames) {
this.viewNames = viewNames; this.viewNames = viewNames;
} }
@ -339,22 +363,6 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements
return this.order; return this.order;
} }
/**
* Whether views resolved by this resolver should add path variables the model or not.
* The default setting is to allow each View decide (see {@link AbstractView#setExposePathVariables(boolean)}.
* However, you can use this property to override that.
* @param exposePathVariables
* <ul>
* <li>{@code true} - all Views resolved by this resolver will expose path variables
* <li>{@code false} - no Views resolved by this resolver will expose path variables
* <li>{@code null} - individual Views can decide for themselves (this is used by the default)
* <ul>
* @see AbstractView#setExposePathVariables(boolean)
*/
public void setExposePathVariables(Boolean exposePathVariables) {
this.exposePathVariables = exposePathVariables;
}
@Override @Override
protected void initApplicationContext() { protected void initApplicationContext() {
super.initApplicationContext(); super.initApplicationContext();
@ -363,6 +371,7 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements
} }
} }
/** /**
* This implementation returns just the view name, * This implementation returns just the view name,
* as this ViewResolver doesn't support localized resolution. * as this ViewResolver doesn't support localized resolution.
@ -460,15 +469,20 @@ public class UrlBasedViewResolver extends AbstractCachingViewResolver implements
protected AbstractUrlBasedView buildView(String viewName) throws Exception { protected AbstractUrlBasedView buildView(String viewName) throws Exception {
AbstractUrlBasedView view = (AbstractUrlBasedView) BeanUtils.instantiateClass(getViewClass()); AbstractUrlBasedView view = (AbstractUrlBasedView) BeanUtils.instantiateClass(getViewClass());
view.setUrl(getPrefix() + viewName + getSuffix()); view.setUrl(getPrefix() + viewName + getSuffix());
String contentType = getContentType(); String contentType = getContentType();
if (contentType != null) { if (contentType != null) {
view.setContentType(contentType); view.setContentType(contentType);
} }
view.setRequestContextAttribute(getRequestContextAttribute()); view.setRequestContextAttribute(getRequestContextAttribute());
view.setAttributesMap(getAttributesMap()); view.setAttributesMap(getAttributesMap());
if (this.exposePathVariables != null) {
Boolean exposePathVariables = getExposePathVariables();
if (exposePathVariables != null) {
view.setExposePathVariables(exposePathVariables); view.setExposePathVariables(exposePathVariables);
} }
return view; return view;
} }

View File

@ -228,7 +228,7 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
* @see net.sf.jasperreports.engine.data.JRBeanCollectionDataSource * @see net.sf.jasperreports.engine.data.JRBeanCollectionDataSource
* @see net.sf.jasperreports.engine.data.JRBeanArrayDataSource * @see net.sf.jasperreports.engine.data.JRBeanArrayDataSource
*/ */
public void setSubReportDataKeys(String[] subReportDataKeys) { public void setSubReportDataKeys(String... subReportDataKeys) {
this.subReportDataKeys = subReportDataKeys; this.subReportDataKeys = subReportDataKeys;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -75,7 +75,7 @@ public class JasperReportsViewResolver extends UrlBasedViewResolver {
* Set the {@code subReportDataKeys} the view class should use. * Set the {@code subReportDataKeys} the view class should use.
* @see AbstractJasperReportsView#setSubReportDataKeys * @see AbstractJasperReportsView#setSubReportDataKeys
*/ */
public void setSubReportDataKeys(String[] subReportDataKeys) { public void setSubReportDataKeys(String... subReportDataKeys) {
this.subReportDataKeys = subReportDataKeys; this.subReportDataKeys = subReportDataKeys;
} }