Java 5 code style
This commit is contained in:
@@ -25,7 +25,6 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarEntry;
|
||||
@@ -297,12 +296,12 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
path = path.substring(1);
|
||||
}
|
||||
Enumeration resourceUrls = getClassLoader().getResources(path);
|
||||
Set result = new LinkedHashSet(16);
|
||||
Set<Resource> result = new LinkedHashSet<Resource>(16);
|
||||
while (resourceUrls.hasMoreElements()) {
|
||||
URL url = (URL) resourceUrls.nextElement();
|
||||
result.add(convertClassLoaderURL(url));
|
||||
}
|
||||
return (Resource[]) result.toArray(new Resource[result.size()]);
|
||||
return result.toArray(new Resource[result.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,9 +331,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
String rootDirPath = determineRootDir(locationPattern);
|
||||
String subPattern = locationPattern.substring(rootDirPath.length());
|
||||
Resource[] rootDirResources = getResources(rootDirPath);
|
||||
Set result = new LinkedHashSet(16);
|
||||
for (int i = 0; i < rootDirResources.length; i++) {
|
||||
Resource rootDirResource = resolveRootDirResource(rootDirResources[i]);
|
||||
Set<Resource> result = new LinkedHashSet<Resource>(16);
|
||||
for (Resource rootDirResource : rootDirResources) {
|
||||
rootDirResource = resolveRootDirResource(rootDirResource);
|
||||
if (isJarResource(rootDirResource)) {
|
||||
result.addAll(doFindPathMatchingJarResources(rootDirResource, subPattern));
|
||||
}
|
||||
@@ -345,7 +344,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Resolved location pattern [" + locationPattern + "] to resources " + result);
|
||||
}
|
||||
return (Resource[]) result.toArray(new Resource[result.size()]);
|
||||
return result.toArray(new Resource[result.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,7 +415,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
* @see java.net.JarURLConnection
|
||||
* @see org.springframework.util.PathMatcher
|
||||
*/
|
||||
protected Set doFindPathMatchingJarResources(Resource rootDirResource, String subPattern) throws IOException {
|
||||
protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource, String subPattern)
|
||||
throws IOException {
|
||||
|
||||
URLConnection con = rootDirResource.getURL().openConnection();
|
||||
JarFile jarFile = null;
|
||||
String jarFileUrl = null;
|
||||
@@ -461,7 +462,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
// The Sun JRE does not return a slash here, but BEA JRockit does.
|
||||
rootEntryPath = rootEntryPath + "/";
|
||||
}
|
||||
Set result = new LinkedHashSet(8);
|
||||
Set<Resource> result = new LinkedHashSet<Resource>(8);
|
||||
for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) {
|
||||
JarEntry entry = (JarEntry) entries.nextElement();
|
||||
String entryPath = entry.getName();
|
||||
@@ -511,7 +512,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
* @see #retrieveMatchingFiles
|
||||
* @see org.springframework.util.PathMatcher
|
||||
*/
|
||||
protected Set doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException {
|
||||
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
|
||||
throws IOException {
|
||||
|
||||
File rootDir = null;
|
||||
try {
|
||||
rootDir = rootDirResource.getFile().getAbsoluteFile();
|
||||
@@ -521,7 +524,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
logger.debug("Cannot search for matching files underneath " + rootDirResource +
|
||||
" because it does not correspond to a directory in the file system", ex);
|
||||
}
|
||||
return Collections.EMPTY_SET;
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return doFindMatchingFileSystemResources(rootDir, subPattern);
|
||||
}
|
||||
@@ -536,14 +539,13 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
* @see #retrieveMatchingFiles
|
||||
* @see org.springframework.util.PathMatcher
|
||||
*/
|
||||
protected Set doFindMatchingFileSystemResources(File rootDir, String subPattern) throws IOException {
|
||||
protected Set<Resource> doFindMatchingFileSystemResources(File rootDir, String subPattern) throws IOException {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Looking for matching resources in directory tree [" + rootDir.getPath() + "]");
|
||||
}
|
||||
Set matchingFiles = retrieveMatchingFiles(rootDir, subPattern);
|
||||
Set result = new LinkedHashSet(matchingFiles.size());
|
||||
for (Iterator it = matchingFiles.iterator(); it.hasNext();) {
|
||||
File file = (File) it.next();
|
||||
Set<File> matchingFiles = retrieveMatchingFiles(rootDir, subPattern);
|
||||
Set<Resource> result = new LinkedHashSet<Resource>(matchingFiles.size());
|
||||
for (File file : matchingFiles) {
|
||||
result.add(new FileSystemResource(file));
|
||||
}
|
||||
return result;
|
||||
@@ -558,7 +560,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
* @return the Set of matching File instances
|
||||
* @throws IOException if directory contents could not be retrieved
|
||||
*/
|
||||
protected Set retrieveMatchingFiles(File rootDir, String pattern) throws IOException {
|
||||
protected Set<File> retrieveMatchingFiles(File rootDir, String pattern) throws IOException {
|
||||
if (!rootDir.isDirectory()) {
|
||||
throw new IllegalArgumentException("Resource path [" + rootDir + "] does not denote a directory");
|
||||
}
|
||||
@@ -567,7 +569,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
fullPattern += "/";
|
||||
}
|
||||
fullPattern = fullPattern + StringUtils.replace(pattern, File.separator, "/");
|
||||
Set result = new LinkedHashSet(8);
|
||||
Set<File> result = new LinkedHashSet<File>(8);
|
||||
doRetrieveMatchingFiles(fullPattern, rootDir, result);
|
||||
return result;
|
||||
}
|
||||
@@ -581,7 +583,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
* @param result the Set of matching File instances to add to
|
||||
* @throws IOException if directory contents could not be retrieved
|
||||
*/
|
||||
protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set result) throws IOException {
|
||||
protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> result) throws IOException {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Searching directory [" + dir.getAbsolutePath() +
|
||||
"] for files matching pattern [" + fullPattern + "]");
|
||||
@@ -590,8 +592,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
if (dirContents == null) {
|
||||
throw new IOException("Could not retrieve contents of directory [" + dir.getAbsolutePath() + "]");
|
||||
}
|
||||
for (int i = 0; i < dirContents.length; i++) {
|
||||
File content = dirContents[i];
|
||||
for (File content : dirContents) {
|
||||
String currPath = StringUtils.replace(content.getAbsolutePath(), File.separator, "/");
|
||||
if (content.isDirectory() && getPathMatcher().matchStart(fullPattern, currPath + "/")) {
|
||||
doRetrieveMatchingFiles(fullPattern, content, result);
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.sql.DataSource;
|
||||
@@ -52,7 +51,6 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
|
||||
import org.springframework.jdbc.support.JdbcUtils;
|
||||
import org.springframework.jdbc.support.lob.LobHandler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -108,13 +106,17 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implements BeanClassLoaderAware {
|
||||
|
||||
private static final ThreadLocal configTimeDataSourceHolder = new ThreadLocal();
|
||||
private static final ThreadLocal<DataSource> configTimeDataSourceHolder =
|
||||
new ThreadLocal<DataSource>();
|
||||
|
||||
private static final ThreadLocal configTimeTransactionManagerHolder = new ThreadLocal();
|
||||
private static final ThreadLocal<TransactionManager> configTimeTransactionManagerHolder =
|
||||
new ThreadLocal<TransactionManager>();
|
||||
|
||||
private static final ThreadLocal configTimeCacheProviderHolder = new ThreadLocal();
|
||||
private static final ThreadLocal<CacheProvider> configTimeCacheProviderHolder =
|
||||
new ThreadLocal<CacheProvider>();
|
||||
|
||||
private static final ThreadLocal configTimeLobHandlerHolder = new ThreadLocal();
|
||||
private static final ThreadLocal<LobHandler> configTimeLobHandlerHolder =
|
||||
new ThreadLocal<LobHandler>();
|
||||
|
||||
/**
|
||||
* Return the DataSource for the currently configured Hibernate SessionFactory,
|
||||
@@ -126,7 +128,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
* @see LocalDataSourceConnectionProvider
|
||||
*/
|
||||
public static DataSource getConfigTimeDataSource() {
|
||||
return (DataSource) configTimeDataSourceHolder.get();
|
||||
return configTimeDataSourceHolder.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +141,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
* @see LocalTransactionManagerLookup
|
||||
*/
|
||||
public static TransactionManager getConfigTimeTransactionManager() {
|
||||
return (TransactionManager) configTimeTransactionManagerHolder.get();
|
||||
return configTimeTransactionManagerHolder.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +153,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
* @see #setCacheProvider
|
||||
*/
|
||||
public static CacheProvider getConfigTimeCacheProvider() {
|
||||
return (CacheProvider) configTimeCacheProviderHolder.get();
|
||||
return configTimeCacheProviderHolder.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +168,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
* @see org.springframework.orm.hibernate3.support.BlobSerializableType
|
||||
*/
|
||||
public static LobHandler getConfigTimeLobHandler() {
|
||||
return (LobHandler) configTimeLobHandlerHolder.get();
|
||||
return configTimeLobHandlerHolder.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +206,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
|
||||
private Properties collectionCacheStrategies;
|
||||
|
||||
private Map eventListeners;
|
||||
private Map<String, Object> eventListeners;
|
||||
|
||||
private boolean schemaUpdate = false;
|
||||
|
||||
@@ -484,7 +486,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
* listener objects as values
|
||||
* @see org.hibernate.cfg.Configuration#setListener(String, Object)
|
||||
*/
|
||||
public void setEventListeners(Map eventListeners) {
|
||||
public void setEventListeners(Map<String, Object> eventListeners) {
|
||||
this.eventListeners = eventListeners;
|
||||
}
|
||||
|
||||
@@ -506,6 +508,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected SessionFactory buildSessionFactory() throws Exception {
|
||||
// Create Configuration instance.
|
||||
Configuration config = newConfiguration();
|
||||
@@ -576,23 +579,22 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
if (this.typeDefinitions != null) {
|
||||
// Register specified Hibernate type definitions.
|
||||
Mappings mappings = config.createMappings();
|
||||
for (int i = 0; i < this.typeDefinitions.length; i++) {
|
||||
TypeDefinitionBean typeDef = this.typeDefinitions[i];
|
||||
for (TypeDefinitionBean typeDef : this.typeDefinitions) {
|
||||
mappings.addTypeDef(typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters());
|
||||
}
|
||||
}
|
||||
|
||||
if (this.filterDefinitions != null) {
|
||||
// Register specified Hibernate FilterDefinitions.
|
||||
for (int i = 0; i < this.filterDefinitions.length; i++) {
|
||||
config.addFilterDefinition(this.filterDefinitions[i]);
|
||||
for (FilterDefinition filterDef : this.filterDefinitions) {
|
||||
config.addFilterDefinition(filterDef);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.configLocations != null) {
|
||||
for (int i = 0; i < this.configLocations.length; i++) {
|
||||
for (Resource resource : this.configLocations) {
|
||||
// Load Hibernate configuration from given location.
|
||||
config.configure(this.configLocations[i].getURL());
|
||||
config.configure(resource.getURL());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,42 +622,40 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
|
||||
if (this.mappingResources != null) {
|
||||
// Register given Hibernate mapping definitions, contained in resource files.
|
||||
for (int i = 0; i < this.mappingResources.length; i++) {
|
||||
Resource resource = new ClassPathResource(this.mappingResources[i].trim(), this.beanClassLoader);
|
||||
for (String mapping : this.mappingResources) {
|
||||
Resource resource = new ClassPathResource(mapping.trim(), this.beanClassLoader);
|
||||
config.addInputStream(resource.getInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mappingLocations != null) {
|
||||
// Register given Hibernate mapping definitions, contained in resource files.
|
||||
for (int i = 0; i < this.mappingLocations.length; i++) {
|
||||
config.addInputStream(this.mappingLocations[i].getInputStream());
|
||||
for (Resource resource : this.mappingLocations) {
|
||||
config.addInputStream(resource.getInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
if (this.cacheableMappingLocations != null) {
|
||||
// Register given cacheable Hibernate mapping definitions, read from the file system.
|
||||
for (int i = 0; i < this.cacheableMappingLocations.length; i++) {
|
||||
config.addCacheableFile(this.cacheableMappingLocations[i].getFile());
|
||||
for (Resource resource : this.cacheableMappingLocations) {
|
||||
config.addCacheableFile(resource.getFile());
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mappingJarLocations != null) {
|
||||
// Register given Hibernate mapping definitions, contained in jar files.
|
||||
for (int i = 0; i < this.mappingJarLocations.length; i++) {
|
||||
Resource resource = this.mappingJarLocations[i];
|
||||
for (Resource resource : this.mappingJarLocations) {
|
||||
config.addJar(resource.getFile());
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mappingDirectoryLocations != null) {
|
||||
// Register all Hibernate mapping definitions in the given directories.
|
||||
for (int i = 0; i < this.mappingDirectoryLocations.length; i++) {
|
||||
File file = this.mappingDirectoryLocations[i].getFile();
|
||||
for (Resource resource : this.mappingDirectoryLocations) {
|
||||
File file = resource.getFile();
|
||||
if (!file.isDirectory()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Mapping directory location [" + this.mappingDirectoryLocations[i] +
|
||||
"] does not denote a directory");
|
||||
"Mapping directory location [" + resource + "] does not denote a directory");
|
||||
}
|
||||
config.addDirectory(file);
|
||||
}
|
||||
@@ -698,13 +698,11 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
|
||||
if (this.eventListeners != null) {
|
||||
// Register specified Hibernate event listeners.
|
||||
for (Iterator it = this.eventListeners.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Assert.isTrue(entry.getKey() instanceof String, "Event listener key needs to be of type String");
|
||||
String listenerType = (String) entry.getKey();
|
||||
for (Map.Entry<String, Object> entry : this.eventListeners.entrySet()) {
|
||||
String listenerType = entry.getKey();
|
||||
Object listenerObject = entry.getValue();
|
||||
if (listenerObject instanceof Collection) {
|
||||
Collection listeners = (Collection) listenerObject;
|
||||
Collection<Object> listeners = (Collection<Object>) listenerObject;
|
||||
EventListeners listenerRegistry = config.getEventListeners();
|
||||
Object[] listenerArray =
|
||||
(Object[]) Array.newInstance(listenerRegistry.getListenerClassFor(listenerType), listeners.size());
|
||||
@@ -979,8 +977,8 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
|
||||
try {
|
||||
Statement stmt = con.createStatement();
|
||||
try {
|
||||
for (int i = 0; i < sql.length; i++) {
|
||||
executeSchemaStatement(stmt, sql[i]);
|
||||
for (String sqlStmt : sql) {
|
||||
executeSchemaStatement(stmt, sqlStmt);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -17,11 +17,9 @@
|
||||
package org.springframework.orm.hibernate3;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.Transaction;
|
||||
@@ -108,8 +106,8 @@ public abstract class SessionFactoryUtils {
|
||||
|
||||
static final Log logger = LogFactory.getLog(SessionFactoryUtils.class);
|
||||
|
||||
private static final ThreadLocal deferredCloseHolder =
|
||||
new NamedThreadLocal("Hibernate Sessions registered for deferred close");
|
||||
private static final ThreadLocal<Map<SessionFactory, Set<Session>>> deferredCloseHolder =
|
||||
new NamedThreadLocal<Map<SessionFactory, Set<Session>>>("Hibernate Sessions registered for deferred close");
|
||||
|
||||
|
||||
/**
|
||||
@@ -297,7 +295,7 @@ public abstract class SessionFactoryUtils {
|
||||
new SpringSessionSynchronization(sessionHolder, sessionFactory, jdbcExceptionTranslator, false));
|
||||
sessionHolder.setSynchronizedWithTransaction(true);
|
||||
// Switch to FlushMode.AUTO, as we have to assume a thread-bound Session
|
||||
// with FlushMode.NEVER, which needs to allow flushing within the transaction.
|
||||
// with FlushMode.MANUAL, which needs to allow flushing within the transaction.
|
||||
FlushMode flushMode = session.getFlushMode();
|
||||
if (flushMode.lessThan(FlushMode.COMMIT) &&
|
||||
!TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
|
||||
@@ -332,7 +330,7 @@ public abstract class SessionFactoryUtils {
|
||||
holderToUse.addSession(session);
|
||||
}
|
||||
if (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
|
||||
session.setFlushMode(FlushMode.NEVER);
|
||||
session.setFlushMode(FlushMode.MANUAL);
|
||||
}
|
||||
TransactionSynchronizationManager.registerSynchronization(
|
||||
new SpringSessionSynchronization(holderToUse, sessionFactory, jdbcExceptionTranslator, true));
|
||||
@@ -685,7 +683,7 @@ public abstract class SessionFactoryUtils {
|
||||
*/
|
||||
public static boolean isDeferredCloseActive(SessionFactory sessionFactory) {
|
||||
Assert.notNull(sessionFactory, "No SessionFactory specified");
|
||||
Map holderMap = (Map) deferredCloseHolder.get();
|
||||
Map<SessionFactory, Set<Session>> holderMap = deferredCloseHolder.get();
|
||||
return (holderMap != null && holderMap.containsKey(sessionFactory));
|
||||
}
|
||||
|
||||
@@ -705,12 +703,12 @@ public abstract class SessionFactoryUtils {
|
||||
public static void initDeferredClose(SessionFactory sessionFactory) {
|
||||
Assert.notNull(sessionFactory, "No SessionFactory specified");
|
||||
logger.debug("Initializing deferred close of Hibernate Sessions");
|
||||
Map holderMap = (Map) deferredCloseHolder.get();
|
||||
Map<SessionFactory, Set<Session>> holderMap = deferredCloseHolder.get();
|
||||
if (holderMap == null) {
|
||||
holderMap = new HashMap();
|
||||
holderMap = new HashMap<SessionFactory, Set<Session>>();
|
||||
deferredCloseHolder.set(holderMap);
|
||||
}
|
||||
holderMap.put(sessionFactory, new LinkedHashSet(4));
|
||||
holderMap.put(sessionFactory, new LinkedHashSet<Session>(4));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -722,18 +720,15 @@ public abstract class SessionFactoryUtils {
|
||||
*/
|
||||
public static void processDeferredClose(SessionFactory sessionFactory) {
|
||||
Assert.notNull(sessionFactory, "No SessionFactory specified");
|
||||
|
||||
Map holderMap = (Map) deferredCloseHolder.get();
|
||||
Map<SessionFactory, Set<Session>> holderMap = deferredCloseHolder.get();
|
||||
if (holderMap == null || !holderMap.containsKey(sessionFactory)) {
|
||||
throw new IllegalStateException("Deferred close not active for SessionFactory [" + sessionFactory + "]");
|
||||
}
|
||||
|
||||
logger.debug("Processing deferred close of Hibernate Sessions");
|
||||
Set sessions = (Set) holderMap.remove(sessionFactory);
|
||||
for (Iterator it = sessions.iterator(); it.hasNext();) {
|
||||
closeSession((Session) it.next());
|
||||
Set<Session> sessions = holderMap.remove(sessionFactory);
|
||||
for (Session session : sessions) {
|
||||
closeSession(session);
|
||||
}
|
||||
|
||||
if (holderMap.isEmpty()) {
|
||||
deferredCloseHolder.set(null);
|
||||
}
|
||||
@@ -765,12 +760,12 @@ public abstract class SessionFactoryUtils {
|
||||
* @see #processDeferredClose
|
||||
*/
|
||||
static void closeSessionOrRegisterDeferredClose(Session session, SessionFactory sessionFactory) {
|
||||
Map holderMap = (Map) deferredCloseHolder.get();
|
||||
Map<SessionFactory, Set<Session>> holderMap = deferredCloseHolder.get();
|
||||
if (holderMap != null && sessionFactory != null && holderMap.containsKey(sessionFactory)) {
|
||||
logger.debug("Registering Hibernate Session for deferred close");
|
||||
// Switch Session to FlushMode.NEVER for remaining lifetime.
|
||||
session.setFlushMode(FlushMode.NEVER);
|
||||
Set sessions = (Set) holderMap.get(sessionFactory);
|
||||
// Switch Session to FlushMode.MANUAL for remaining lifetime.
|
||||
session.setFlushMode(FlushMode.MANUAL);
|
||||
Set<Session> sessions = holderMap.get(sessionFactory);
|
||||
sessions.add(session);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,14 +17,13 @@
|
||||
package org.springframework.dao.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Implementation of PersistenceExceptionTranslator that supports chaining,
|
||||
* Implementation of {@link PersistenceExceptionTranslator} that supports chaining,
|
||||
* allowing the addition of PersistenceExceptionTranslator instances in order.
|
||||
* Returns <code>non-null</code> on the first (if any) match.
|
||||
*
|
||||
@@ -35,7 +34,7 @@ import org.springframework.util.Assert;
|
||||
public class ChainedPersistenceExceptionTranslator implements PersistenceExceptionTranslator {
|
||||
|
||||
/** List of PersistenceExceptionTranslators */
|
||||
private final List delegates = new ArrayList(4);
|
||||
private final List<PersistenceExceptionTranslator> delegates = new ArrayList<PersistenceExceptionTranslator>(4);
|
||||
|
||||
|
||||
/**
|
||||
@@ -50,18 +49,18 @@ public class ChainedPersistenceExceptionTranslator implements PersistenceExcepti
|
||||
* Return all registered PersistenceExceptionTranslator delegates (as array).
|
||||
*/
|
||||
public final PersistenceExceptionTranslator[] getDelegates() {
|
||||
return (PersistenceExceptionTranslator[])
|
||||
this.delegates.toArray(new PersistenceExceptionTranslator[this.delegates.size()]);
|
||||
return this.delegates.toArray(new PersistenceExceptionTranslator[this.delegates.size()]);
|
||||
}
|
||||
|
||||
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||
DataAccessException translatedDex = null;
|
||||
for (Iterator it = this.delegates.iterator(); translatedDex == null && it.hasNext(); ) {
|
||||
PersistenceExceptionTranslator pet = (PersistenceExceptionTranslator) it.next();
|
||||
translatedDex = pet.translateExceptionIfPossible(ex);
|
||||
for (PersistenceExceptionTranslator pet : this.delegates) {
|
||||
DataAccessException translatedDex = pet.translateExceptionIfPossible(ex);
|
||||
if (translatedDex != null) {
|
||||
return translatedDex;
|
||||
}
|
||||
}
|
||||
return translatedDex;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.dao.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
@@ -119,15 +118,15 @@ public class PersistenceExceptionTranslationInterceptor
|
||||
*/
|
||||
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) {
|
||||
// Find all translators, being careful not to activate FactoryBeans.
|
||||
Map pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
beanFactory, PersistenceExceptionTranslator.class, false, false);
|
||||
if (pets.isEmpty()) {
|
||||
throw new IllegalStateException(
|
||||
"No persistence exception translators found in bean factory. Cannot perform exception translation.");
|
||||
}
|
||||
ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
|
||||
for (Iterator it = pets.values().iterator(); it.hasNext();) {
|
||||
cpet.addDelegate((PersistenceExceptionTranslator) it.next());
|
||||
for (PersistenceExceptionTranslator pet : pets.values()) {
|
||||
cpet.addDelegate(pet);
|
||||
}
|
||||
return cpet;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.transaction.interceptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -50,7 +49,7 @@ public class MethodMapTransactionAttributeSource
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
/** Map from method name to attribute value */
|
||||
private Map methodMap;
|
||||
private Map<String, TransactionAttribute> methodMap;
|
||||
|
||||
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
|
||||
|
||||
@@ -59,10 +58,11 @@ public class MethodMapTransactionAttributeSource
|
||||
private boolean initialized = false;
|
||||
|
||||
/** Map from Method to TransactionAttribute */
|
||||
private final Map transactionAttributeMap = new HashMap();
|
||||
private final Map<Method, TransactionAttribute> transactionAttributeMap =
|
||||
new HashMap<Method, TransactionAttribute>();
|
||||
|
||||
/** Map from Method to name pattern used for registration */
|
||||
private final Map methodNameMap = new HashMap();
|
||||
private final Map<Method, String> methodNameMap = new HashMap<Method, String>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ public class MethodMapTransactionAttributeSource
|
||||
* @see TransactionAttribute
|
||||
* @see TransactionAttributeEditor
|
||||
*/
|
||||
public void setMethodMap(Map methodMap) {
|
||||
public void setMethodMap(Map<String, TransactionAttribute> methodMap) {
|
||||
this.methodMap = methodMap;
|
||||
}
|
||||
|
||||
@@ -100,35 +100,12 @@ public class MethodMapTransactionAttributeSource
|
||||
/**
|
||||
* Initialize the specified {@link #setMethodMap(java.util.Map) "methodMap"}, if any.
|
||||
* @param methodMap Map from method names to <code>TransactionAttribute</code> instances
|
||||
* (or Strings to be converted to <code>TransactionAttribute</code> instances)
|
||||
* @see #setMethodMap
|
||||
*/
|
||||
protected void initMethodMap(Map methodMap) {
|
||||
protected void initMethodMap(Map<String, TransactionAttribute> methodMap) {
|
||||
if (methodMap != null) {
|
||||
Iterator it = methodMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Object key = entry.getKey();
|
||||
if (!(key instanceof String)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid method map key [" + key + "]: only Strings allowed");
|
||||
}
|
||||
Object value = entry.getValue();
|
||||
// Check whether we need to convert from String to TransactionAttribute.
|
||||
TransactionAttribute attr = null;
|
||||
if (value instanceof TransactionAttribute) {
|
||||
attr = (TransactionAttribute) value;
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor();
|
||||
editor.setAsText((String) value);
|
||||
attr = (TransactionAttribute) editor.getValue();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Value [" + value + "] is neither of type [" +
|
||||
TransactionAttribute.class.getName() + "] nor a String");
|
||||
}
|
||||
addTransactionalMethod((String) key, attr);
|
||||
for (Map.Entry<String, TransactionAttribute> entry : methodMap.entrySet()) {
|
||||
addTransactionalMethod(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,14 +142,11 @@ public class MethodMapTransactionAttributeSource
|
||||
Assert.notNull(mappedName, "Mapped name must not be null");
|
||||
String name = clazz.getName() + '.' + mappedName;
|
||||
|
||||
// TODO address method overloading? At present this will
|
||||
// simply match all methods that have the given name.
|
||||
// Consider EJB syntax (int, String) etc.?
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
List matchingMethods = new ArrayList();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (isMatch(methods[i].getName(), mappedName)) {
|
||||
matchingMethods.add(methods[i]);
|
||||
List<Method> matchingMethods = new ArrayList<Method>();
|
||||
for (Method method : methods) {
|
||||
if (isMatch(method.getName(), mappedName)) {
|
||||
matchingMethods.add(method);
|
||||
}
|
||||
}
|
||||
if (matchingMethods.isEmpty()) {
|
||||
@@ -181,9 +155,8 @@ public class MethodMapTransactionAttributeSource
|
||||
}
|
||||
|
||||
// register all matching methods
|
||||
for (Iterator it = matchingMethods.iterator(); it.hasNext();) {
|
||||
Method method = (Method) it.next();
|
||||
String regMethodName = (String) this.methodNameMap.get(method);
|
||||
for (Method method : matchingMethods) {
|
||||
String regMethodName = this.methodNameMap.get(method);
|
||||
if (regMethodName == null || (!regMethodName.equals(name) && regMethodName.length() <= name.length())) {
|
||||
// No already registered method name, or more specific
|
||||
// method name specification now -> (re-)register method.
|
||||
@@ -195,7 +168,7 @@ public class MethodMapTransactionAttributeSource
|
||||
addTransactionalMethod(method, attr);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled() && regMethodName != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Keeping attribute for transactional method [" + method + "]: current name '" +
|
||||
name + "' is not more specific than '" + regMethodName + "'");
|
||||
}
|
||||
@@ -233,7 +206,7 @@ public class MethodMapTransactionAttributeSource
|
||||
|
||||
public TransactionAttribute getTransactionAttribute(Method method, Class targetClass) {
|
||||
if (this.eagerlyInitialized) {
|
||||
return (TransactionAttribute) this.transactionAttributeMap.get(method);
|
||||
return this.transactionAttributeMap.get(method);
|
||||
}
|
||||
else {
|
||||
synchronized (this.transactionAttributeMap) {
|
||||
@@ -241,7 +214,7 @@ public class MethodMapTransactionAttributeSource
|
||||
initMethodMap(this.methodMap);
|
||||
this.initialized = true;
|
||||
}
|
||||
return (TransactionAttribute) this.transactionAttributeMap.get(method);
|
||||
return this.transactionAttributeMap.get(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,8 @@ package org.springframework.transaction.interceptor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
|
||||
protected static final Log logger = LogFactory.getLog(NameMatchTransactionAttributeSource.class);
|
||||
|
||||
/** Keys are method names; values are TransactionAttributes */
|
||||
private Map nameMap = new HashMap();
|
||||
private Map<String, TransactionAttribute> nameMap = new HashMap<String, TransactionAttribute>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,24 +57,9 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
|
||||
* @see TransactionAttribute
|
||||
* @see TransactionAttributeEditor
|
||||
*/
|
||||
public void setNameMap(Map nameMap) {
|
||||
Iterator it = nameMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
String name = (String) entry.getKey();
|
||||
|
||||
// Check whether we need to convert from String to TransactionAttribute.
|
||||
TransactionAttribute attr = null;
|
||||
if (entry.getValue() instanceof TransactionAttribute) {
|
||||
attr = (TransactionAttribute) entry.getValue();
|
||||
}
|
||||
else {
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor();
|
||||
editor.setAsText(entry.getValue().toString());
|
||||
attr = (TransactionAttribute) editor.getValue();
|
||||
}
|
||||
|
||||
addTransactionalMethod(name, attr);
|
||||
public void setNameMap(Map<String, TransactionAttribute> nameMap) {
|
||||
for (Map.Entry<String, TransactionAttribute> entry : nameMap.entrySet()) {
|
||||
addTransactionalMethod(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +72,9 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
|
||||
*/
|
||||
public void setProperties(Properties transactionAttributes) {
|
||||
TransactionAttributeEditor tae = new TransactionAttributeEditor();
|
||||
for (Iterator it = transactionAttributes.keySet().iterator(); it.hasNext(); ) {
|
||||
String methodName = (String) it.next();
|
||||
Enumeration propNames = transactionAttributes.propertyNames();
|
||||
while (propNames.hasMoreElements()) {
|
||||
String methodName = (String) propNames.nextElement();
|
||||
String value = transactionAttributes.getProperty(methodName);
|
||||
tae.setAsText(value);
|
||||
TransactionAttribute attr = (TransactionAttribute) tae.getValue();
|
||||
@@ -114,16 +100,15 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
|
||||
public TransactionAttribute getTransactionAttribute(Method method, Class targetClass) {
|
||||
// look for direct name match
|
||||
String methodName = method.getName();
|
||||
TransactionAttribute attr = (TransactionAttribute) this.nameMap.get(methodName);
|
||||
TransactionAttribute attr = this.nameMap.get(methodName);
|
||||
|
||||
if (attr == null) {
|
||||
// Look for most specific name match.
|
||||
String bestNameMatch = null;
|
||||
for (Iterator it = this.nameMap.keySet().iterator(); it.hasNext();) {
|
||||
String mappedName = (String) it.next();
|
||||
for (String mappedName : this.nameMap.keySet()) {
|
||||
if (isMatch(methodName, mappedName) &&
|
||||
(bestNameMatch == null || bestNameMatch.length() <= mappedName.length())) {
|
||||
attr = (TransactionAttribute) this.nameMap.get(mappedName);
|
||||
attr = this.nameMap.get(mappedName);
|
||||
bestNameMatch = mappedName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.transaction.interceptor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -50,7 +49,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
/** Static for optimal serializability */
|
||||
private static final Log logger = LogFactory.getLog(RuleBasedTransactionAttribute.class);
|
||||
|
||||
private List rollbackRules;
|
||||
private List<RollbackRuleAttribute> rollbackRules;
|
||||
|
||||
|
||||
/**
|
||||
@@ -78,7 +77,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
*/
|
||||
public RuleBasedTransactionAttribute(RuleBasedTransactionAttribute other) {
|
||||
super(other);
|
||||
this.rollbackRules = new ArrayList(other.rollbackRules);
|
||||
this.rollbackRules = new ArrayList<RollbackRuleAttribute>(other.rollbackRules);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +90,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
* @see #setTimeout
|
||||
* @see #setReadOnly
|
||||
*/
|
||||
public RuleBasedTransactionAttribute(int propagationBehavior, List rollbackRules) {
|
||||
public RuleBasedTransactionAttribute(int propagationBehavior, List<RollbackRuleAttribute> rollbackRules) {
|
||||
super(propagationBehavior);
|
||||
this.rollbackRules = rollbackRules;
|
||||
}
|
||||
@@ -103,7 +102,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
* @see RollbackRuleAttribute
|
||||
* @see NoRollbackRuleAttribute
|
||||
*/
|
||||
public void setRollbackRules(List rollbackRules) {
|
||||
public void setRollbackRules(List<RollbackRuleAttribute> rollbackRules) {
|
||||
this.rollbackRules = rollbackRules;
|
||||
}
|
||||
|
||||
@@ -111,9 +110,9 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
* Return the list of <code>RollbackRuleAttribute</code> objects
|
||||
* (never <code>null</code>).
|
||||
*/
|
||||
public List getRollbackRules() {
|
||||
public List<RollbackRuleAttribute> getRollbackRules() {
|
||||
if (this.rollbackRules == null) {
|
||||
this.rollbackRules = new LinkedList();
|
||||
this.rollbackRules = new LinkedList<RollbackRuleAttribute>();
|
||||
}
|
||||
return this.rollbackRules;
|
||||
}
|
||||
@@ -135,8 +134,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
int deepest = Integer.MAX_VALUE;
|
||||
|
||||
if (this.rollbackRules != null) {
|
||||
for (Iterator it = this.rollbackRules.iterator(); it.hasNext();) {
|
||||
RollbackRuleAttribute rule = (RollbackRuleAttribute) it.next();
|
||||
for (RollbackRuleAttribute rule : this.rollbackRules) {
|
||||
int depth = rule.getDepth(ex);
|
||||
if (depth >= 0 && depth < deepest) {
|
||||
deepest = depth;
|
||||
@@ -163,8 +161,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
public String toString() {
|
||||
StringBuilder result = getDefinitionDescription();
|
||||
if (this.rollbackRules != null) {
|
||||
for (Iterator it = this.rollbackRules.iterator(); it.hasNext();) {
|
||||
RollbackRuleAttribute rule = (RollbackRuleAttribute) it.next();
|
||||
for (RollbackRuleAttribute rule : this.rollbackRules) {
|
||||
String sign = (rule instanceof NoRollbackRuleAttribute ? PREFIX_COMMIT_RULE : PREFIX_ROLLBACK_RULE);
|
||||
result.append(',').append(sign).append(rule.getExceptionName());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.transaction.interceptor;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.util.Iterator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.propertyeditors.PropertiesEditor;
|
||||
@@ -59,14 +59,13 @@ public class TransactionAttributeSourceEditor extends PropertyEditorSupport {
|
||||
|
||||
// Now we have properties, process each one individually.
|
||||
TransactionAttributeEditor tae = new TransactionAttributeEditor();
|
||||
for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
|
||||
String name = (String) iter.next();
|
||||
Enumeration propNames = props.propertyNames();
|
||||
while (propNames.hasMoreElements()) {
|
||||
String name = (String) propNames.nextElement();
|
||||
String value = props.getProperty(name);
|
||||
|
||||
// Convert value to a transaction attribute.
|
||||
tae.setAsText(value);
|
||||
TransactionAttribute attr = (TransactionAttribute) tae.getValue();
|
||||
|
||||
// Register name and attribute.
|
||||
source.addTransactionalMethod(name, attr);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.transaction.support;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -471,7 +470,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||
if (isValidateExistingTransaction()) {
|
||||
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
|
||||
Integer currentIsolationLevel = TransactionSynchronizationManager.getCurrentTransactionIsolationLevel();
|
||||
if (currentIsolationLevel == null || currentIsolationLevel.intValue() != definition.getIsolationLevel()) {
|
||||
if (currentIsolationLevel == null || currentIsolationLevel != definition.getIsolationLevel()) {
|
||||
Constants isoConstants = DefaultTransactionDefinition.constants;
|
||||
throw new IllegalTransactionStateException("Participating transaction with definition [" +
|
||||
definition + "] specifies isolation level which is incompatible with existing transaction: " +
|
||||
@@ -505,7 +504,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||
TransactionSynchronizationManager.setActualTransactionActive(transaction != null);
|
||||
TransactionSynchronizationManager.setCurrentTransactionIsolationLevel(
|
||||
(definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) ?
|
||||
new Integer(definition.getIsolationLevel()) : null);
|
||||
definition.getIsolationLevel() : null);
|
||||
TransactionSynchronizationManager.setCurrentTransactionReadOnly(definition.isReadOnly());
|
||||
TransactionSynchronizationManager.setCurrentTransactionName(definition.getName());
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
@@ -637,10 +636,11 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||
* synchronization for the current thread.
|
||||
* @return the List of suspended TransactionSynchronization objects
|
||||
*/
|
||||
private List doSuspendSynchronization() {
|
||||
List suspendedSynchronizations = TransactionSynchronizationManager.getSynchronizations();
|
||||
for (Iterator it = suspendedSynchronizations.iterator(); it.hasNext();) {
|
||||
((TransactionSynchronization) it.next()).suspend();
|
||||
private List<TransactionSynchronization> doSuspendSynchronization() {
|
||||
List<TransactionSynchronization> suspendedSynchronizations =
|
||||
TransactionSynchronizationManager.getSynchronizations();
|
||||
for (TransactionSynchronization synchronization : suspendedSynchronizations) {
|
||||
synchronization.suspend();
|
||||
}
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
return suspendedSynchronizations;
|
||||
@@ -651,10 +651,9 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||
* and resume all given synchronizations.
|
||||
* @param suspendedSynchronizations List of TransactionSynchronization objects
|
||||
*/
|
||||
private void doResumeSynchronization(List suspendedSynchronizations) {
|
||||
private void doResumeSynchronization(List<TransactionSynchronization> suspendedSynchronizations) {
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
for (Iterator it = suspendedSynchronizations.iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
for (TransactionSynchronization synchronization : suspendedSynchronizations) {
|
||||
synchronization.resume();
|
||||
TransactionSynchronizationManager.registerSynchronization(synchronization);
|
||||
}
|
||||
|
||||
@@ -77,25 +77,25 @@ public abstract class TransactionSynchronizationManager {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TransactionSynchronizationManager.class);
|
||||
|
||||
private static final Comparator synchronizationComparator = new OrderComparator();
|
||||
private static final Comparator<Object> synchronizationComparator = new OrderComparator();
|
||||
|
||||
private static final ThreadLocal resources =
|
||||
new NamedThreadLocal("Transactional resources");
|
||||
private static final ThreadLocal<Map<Object, Object>> resources =
|
||||
new NamedThreadLocal<Map<Object, Object>>("Transactional resources");
|
||||
|
||||
private static final ThreadLocal synchronizations =
|
||||
new NamedThreadLocal("Transaction synchronizations");
|
||||
private static final ThreadLocal<List<TransactionSynchronization>> synchronizations =
|
||||
new NamedThreadLocal<List<TransactionSynchronization>>("Transaction synchronizations");
|
||||
|
||||
private static final ThreadLocal currentTransactionName =
|
||||
new NamedThreadLocal("Current transaction name");
|
||||
private static final ThreadLocal<String> currentTransactionName =
|
||||
new NamedThreadLocal<String>("Current transaction name");
|
||||
|
||||
private static final ThreadLocal currentTransactionReadOnly =
|
||||
new NamedThreadLocal("Current transaction read-only status");
|
||||
private static final ThreadLocal<Boolean> currentTransactionReadOnly =
|
||||
new NamedThreadLocal<Boolean>("Current transaction read-only status");
|
||||
|
||||
private static final ThreadLocal currentTransactionIsolationLevel =
|
||||
new NamedThreadLocal("Current transaction isolation level");
|
||||
private static final ThreadLocal<Integer> currentTransactionIsolationLevel =
|
||||
new NamedThreadLocal<Integer>("Current transaction isolation level");
|
||||
|
||||
private static final ThreadLocal actualTransactionActive =
|
||||
new NamedThreadLocal("Actual transaction active");
|
||||
private static final ThreadLocal<Boolean> actualTransactionActive =
|
||||
new NamedThreadLocal<Boolean>("Actual transaction active");
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -111,9 +111,9 @@ public abstract class TransactionSynchronizationManager {
|
||||
* currently no resources bound
|
||||
* @see #hasResource
|
||||
*/
|
||||
public static Map getResourceMap() {
|
||||
Map map = (Map) resources.get();
|
||||
return (map != null ? Collections.unmodifiableMap(map) : Collections.EMPTY_MAP);
|
||||
public static Map<Object, Object> getResourceMap() {
|
||||
Map<Object, Object> map = resources.get();
|
||||
return (map != null ? Collections.unmodifiableMap(map) : Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +149,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
* Actually check the value of the resource that is bound for the given key.
|
||||
*/
|
||||
private static Object doGetResource(Object actualKey) {
|
||||
Map map = (Map) resources.get();
|
||||
Map<Object, Object> map = resources.get();
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -172,10 +172,10 @@ public abstract class TransactionSynchronizationManager {
|
||||
public static void bindResource(Object key, Object value) throws IllegalStateException {
|
||||
Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);
|
||||
Assert.notNull(value, "Value must not be null");
|
||||
Map map = (Map) resources.get();
|
||||
Map<Object, Object> map = resources.get();
|
||||
// set ThreadLocal Map if none found
|
||||
if (map == null) {
|
||||
map = new HashMap();
|
||||
map = new HashMap<Object, Object>();
|
||||
resources.set(map);
|
||||
}
|
||||
if (map.put(actualKey, value) != null) {
|
||||
@@ -219,7 +219,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
* Actually remove the value of the resource that is bound for the given key.
|
||||
*/
|
||||
private static Object doUnbindResource(Object actualKey) {
|
||||
Map map = (Map) resources.get();
|
||||
Map<Object, Object> map = resources.get();
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -259,7 +259,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
throw new IllegalStateException("Cannot activate transaction synchronization - already active");
|
||||
}
|
||||
logger.trace("Initializing transaction synchronization");
|
||||
synchronizations.set(new LinkedList());
|
||||
synchronizations.set(new LinkedList<TransactionSynchronization>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,8 +279,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
if (!isSynchronizationActive()) {
|
||||
throw new IllegalStateException("Transaction synchronization is not active");
|
||||
}
|
||||
List synchs = (List) synchronizations.get();
|
||||
synchs.add(synchronization);
|
||||
synchronizations.get().add(synchronization);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,17 +289,17 @@ public abstract class TransactionSynchronizationManager {
|
||||
* @throws IllegalStateException if synchronization is not active
|
||||
* @see TransactionSynchronization
|
||||
*/
|
||||
public static List getSynchronizations() throws IllegalStateException {
|
||||
public static List<TransactionSynchronization> getSynchronizations() throws IllegalStateException {
|
||||
if (!isSynchronizationActive()) {
|
||||
throw new IllegalStateException("Transaction synchronization is not active");
|
||||
}
|
||||
List synchs = (List) synchronizations.get();
|
||||
List<TransactionSynchronization> synchs = synchronizations.get();
|
||||
// Sort lazily here, not in registerSynchronization.
|
||||
Collections.sort(synchs, synchronizationComparator);
|
||||
// Return unmodifiable snapshot, to avoid ConcurrentModificationExceptions
|
||||
// while iterating and invoking synchronization callbacks that in turn
|
||||
// might register further synchronizations.
|
||||
return Collections.unmodifiableList(new ArrayList(synchs));
|
||||
return Collections.unmodifiableList(new ArrayList<TransactionSynchronization>(synchs));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +337,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
* @see org.springframework.transaction.TransactionDefinition#getName()
|
||||
*/
|
||||
public static String getCurrentTransactionName() {
|
||||
return (String) currentTransactionName.get();
|
||||
return currentTransactionName.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,7 +408,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
* @see org.springframework.transaction.TransactionDefinition#getIsolationLevel()
|
||||
*/
|
||||
public static Integer getCurrentTransactionIsolationLevel() {
|
||||
return (Integer) currentTransactionIsolationLevel.get();
|
||||
return currentTransactionIsolationLevel.get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.transaction.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -67,8 +66,7 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @see TransactionSynchronization#beforeCommit(boolean)
|
||||
*/
|
||||
public static void triggerBeforeCommit(boolean readOnly) {
|
||||
for (Iterator it = TransactionSynchronizationManager.getSynchronizations().iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
for (TransactionSynchronization synchronization : TransactionSynchronizationManager.getSynchronizations()) {
|
||||
synchronization.beforeCommit(readOnly);
|
||||
}
|
||||
}
|
||||
@@ -78,8 +76,7 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @see TransactionSynchronization#beforeCompletion()
|
||||
*/
|
||||
public static void triggerBeforeCompletion() {
|
||||
for (Iterator it = TransactionSynchronizationManager.getSynchronizations().iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
for (TransactionSynchronization synchronization : TransactionSynchronizationManager.getSynchronizations()) {
|
||||
try {
|
||||
synchronization.beforeCompletion();
|
||||
}
|
||||
@@ -96,8 +93,7 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @see TransactionSynchronization#afterCommit()
|
||||
*/
|
||||
public static void triggerAfterCommit() {
|
||||
List synchronizations = TransactionSynchronizationManager.getSynchronizations();
|
||||
invokeAfterCommit(synchronizations);
|
||||
invokeAfterCommit(TransactionSynchronizationManager.getSynchronizations());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,19 +102,10 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @param synchronizations List of TransactionSynchronization objects
|
||||
* @see TransactionSynchronization#afterCommit()
|
||||
*/
|
||||
public static void invokeAfterCommit(List synchronizations) {
|
||||
public static void invokeAfterCommit(List<TransactionSynchronization> synchronizations) {
|
||||
if (synchronizations != null) {
|
||||
for (Iterator it = synchronizations.iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
try {
|
||||
synchronization.afterCommit();
|
||||
}
|
||||
catch (AbstractMethodError tserr) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Spring 2.0's TransactionSynchronization.afterCommit method not implemented in " +
|
||||
"synchronization class [" + synchronization.getClass().getName() + "]", tserr);
|
||||
}
|
||||
}
|
||||
for (TransactionSynchronization synchronization : synchronizations) {
|
||||
synchronization.afterCommit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,10 +136,9 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @see TransactionSynchronization#STATUS_ROLLED_BACK
|
||||
* @see TransactionSynchronization#STATUS_UNKNOWN
|
||||
*/
|
||||
public static void invokeAfterCompletion(List synchronizations, int completionStatus) {
|
||||
public static void invokeAfterCompletion(List<TransactionSynchronization> synchronizations, int completionStatus) {
|
||||
if (synchronizations != null) {
|
||||
for (Iterator it = synchronizations.iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
for (TransactionSynchronization synchronization : synchronizations) {
|
||||
try {
|
||||
synchronization.afterCompletion(completionStatus);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.springframework.web.context.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -50,7 +48,8 @@ public class ServletContextAttributeExporter implements ServletContextAware {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Map attributes;
|
||||
private Map<String, Object> attributes;
|
||||
|
||||
|
||||
/**
|
||||
* Set the ServletContext attributes to expose as key-value pairs.
|
||||
@@ -59,19 +58,17 @@ public class ServletContextAttributeExporter implements ServletContextAware {
|
||||
* <p>Usually, you will use bean references for the values,
|
||||
* to export Spring-defined beans as ServletContext attributes.
|
||||
* Of course, it is also possible to define plain values to export.
|
||||
* @param attributes Map with String keys and Object values
|
||||
*/
|
||||
public void setAttributes(Map attributes) {
|
||||
public void setAttributes(Map<String, Object> attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public void setServletContext(ServletContext servletContext) {
|
||||
for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
String attributeName = (String) entry.getKey();
|
||||
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
|
||||
String attributeName = entry.getKey();
|
||||
if (logger.isWarnEnabled()) {
|
||||
if (servletContext.getAttribute(attributeName) != null) {
|
||||
logger.warn("Overwriting existing ServletContext attribute with name '" + attributeName + "'");
|
||||
logger.warn("Replacing existing ServletContext attribute with name '" + attributeName + "'");
|
||||
}
|
||||
}
|
||||
servletContext.setAttribute(attributeName, entry.getValue());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,6 @@ import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -68,12 +67,14 @@ public class ServletContextResourcePatternResolver extends PathMatchingResourceP
|
||||
* @see javax.servlet.ServletContext#getResourcePaths
|
||||
*/
|
||||
@Override
|
||||
protected Set doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException {
|
||||
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
|
||||
throws IOException {
|
||||
|
||||
if (rootDirResource instanceof ServletContextResource) {
|
||||
ServletContextResource scResource = (ServletContextResource) rootDirResource;
|
||||
ServletContext sc = scResource.getServletContext();
|
||||
String fullPattern = scResource.getPath() + subPattern;
|
||||
Set result = new LinkedHashSet(8);
|
||||
Set<Resource> result = new LinkedHashSet<Resource>(8);
|
||||
doRetrieveMatchingServletContextResources(sc, fullPattern, scResource.getPath(), result);
|
||||
return result;
|
||||
}
|
||||
@@ -95,11 +96,12 @@ public class ServletContextResourcePatternResolver extends PathMatchingResourceP
|
||||
* @see javax.servlet.ServletContext#getResourcePaths
|
||||
*/
|
||||
protected void doRetrieveMatchingServletContextResources(
|
||||
ServletContext servletContext, String fullPattern, String dir, Set result) throws IOException {
|
||||
ServletContext servletContext, String fullPattern, String dir, Set<Resource> result)
|
||||
throws IOException {
|
||||
|
||||
Set candidates = servletContext.getResourcePaths(dir);
|
||||
if (candidates != null) {
|
||||
boolean dirDepthNotFixed = (fullPattern.indexOf("**") != -1);
|
||||
boolean dirDepthNotFixed = fullPattern.contains("**");
|
||||
for (Iterator it = candidates.iterator(); it.hasNext();) {
|
||||
String currPath = (String) it.next();
|
||||
if (!currPath.startsWith(dir)) {
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
package org.springframework.web.jsf;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.PhaseEvent;
|
||||
import javax.faces.event.PhaseId;
|
||||
@@ -68,19 +66,13 @@ public class DelegatingPhaseListenerMulticaster implements PhaseListener {
|
||||
}
|
||||
|
||||
public void beforePhase(PhaseEvent event) {
|
||||
Collection listeners = getDelegates(event.getFacesContext());
|
||||
Iterator it = listeners.iterator();
|
||||
while (it.hasNext()) {
|
||||
PhaseListener listener = (PhaseListener) it.next();
|
||||
for (PhaseListener listener : getDelegates(event.getFacesContext())) {
|
||||
listener.beforePhase(event);
|
||||
}
|
||||
}
|
||||
|
||||
public void afterPhase(PhaseEvent event) {
|
||||
Collection listeners = getDelegates(event.getFacesContext());
|
||||
Iterator it = listeners.iterator();
|
||||
while (it.hasNext()) {
|
||||
PhaseListener listener = (PhaseListener) it.next();
|
||||
for (PhaseListener listener : getDelegates(event.getFacesContext())) {
|
||||
listener.afterPhase(event);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +85,7 @@ public class DelegatingPhaseListenerMulticaster implements PhaseListener {
|
||||
* @see #getBeanFactory
|
||||
* @see org.springframework.beans.factory.ListableBeanFactory#getBeansOfType(Class)
|
||||
*/
|
||||
protected Collection getDelegates(FacesContext facesContext) {
|
||||
protected Collection<PhaseListener> getDelegates(FacesContext facesContext) {
|
||||
ListableBeanFactory bf = getBeanFactory(facesContext);
|
||||
return BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, PhaseListener.class, true, false).values();
|
||||
}
|
||||
|
||||
@@ -19,10 +19,8 @@ package org.springframework.web.util;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.http.Cookie;
|
||||
@@ -177,7 +175,7 @@ public abstract class WebUtils {
|
||||
return false;
|
||||
}
|
||||
String param = servletContext.getInitParameter(HTML_ESCAPE_CONTEXT_PARAM);
|
||||
return Boolean.valueOf(param).booleanValue();
|
||||
return Boolean.valueOf(param);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,7 +419,7 @@ public abstract class WebUtils {
|
||||
* @param servletName the name of the offending servlet
|
||||
*/
|
||||
public static void exposeErrorRequestAttributes(HttpServletRequest request, Throwable ex, String servletName) {
|
||||
exposeRequestAttributeIfNotPresent(request, ERROR_STATUS_CODE_ATTRIBUTE, new Integer(HttpServletResponse.SC_OK));
|
||||
exposeRequestAttributeIfNotPresent(request, ERROR_STATUS_CODE_ATTRIBUTE, HttpServletResponse.SC_OK);
|
||||
exposeRequestAttributeIfNotPresent(request, ERROR_EXCEPTION_TYPE_ATTRIBUTE, ex.getClass());
|
||||
exposeRequestAttributeIfNotPresent(request, ERROR_MESSAGE_ATTRIBUTE, ex.getMessage());
|
||||
exposeRequestAttributeIfNotPresent(request, ERROR_EXCEPTION_ATTRIBUTE, ex);
|
||||
@@ -467,16 +465,10 @@ public abstract class WebUtils {
|
||||
* @param request current HTTP request
|
||||
* @param attributes the attributes Map
|
||||
*/
|
||||
public static void exposeRequestAttributes(ServletRequest request, Map attributes) {
|
||||
public static void exposeRequestAttributes(ServletRequest request, Map<String, Object> attributes) {
|
||||
Assert.notNull(request, "Request must not be null");
|
||||
Iterator it = attributes.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
if (!(entry.getKey() instanceof String)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid key [" + entry.getKey() + "] in attributes Map - only Strings allowed as attribute keys");
|
||||
}
|
||||
request.setAttribute((String) entry.getKey(), entry.getValue());
|
||||
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
|
||||
request.setAttribute(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,9 +483,9 @@ public abstract class WebUtils {
|
||||
Assert.notNull(request, "Request must not be null");
|
||||
Cookie cookies[] = request.getCookies();
|
||||
if (cookies != null) {
|
||||
for (int i = 0; i < cookies.length; i++) {
|
||||
if (name.equals(cookies[i].getName())) {
|
||||
return cookies[i];
|
||||
for (Cookie cookie : cookies) {
|
||||
if (name.equals(cookie.getName())) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -515,8 +507,7 @@ public abstract class WebUtils {
|
||||
if (request.getParameter(name) != null) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < SUBMIT_IMAGE_SUFFIXES.length; i++) {
|
||||
String suffix = SUBMIT_IMAGE_SUFFIXES[i];
|
||||
for (String suffix : SUBMIT_IMAGE_SUFFIXES) {
|
||||
if (request.getParameter(name + suffix) != null) {
|
||||
return true;
|
||||
}
|
||||
@@ -533,6 +524,7 @@ public abstract class WebUtils {
|
||||
* @return the value of the parameter, or <code>null</code>
|
||||
* if the parameter does not exist in given request
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String findParameterValue(ServletRequest request, String name) {
|
||||
return findParameterValue(request.getParameterMap(), name);
|
||||
}
|
||||
@@ -560,21 +552,22 @@ public abstract class WebUtils {
|
||||
* @return the value of the parameter, or <code>null</code>
|
||||
* if the parameter does not exist in given request
|
||||
*/
|
||||
public static String findParameterValue(Map parameters, String name) {
|
||||
public static String findParameterValue(Map<String, ?> parameters, String name) {
|
||||
// First try to get it as a normal name=value parameter
|
||||
String value = (String) parameters.get(name);
|
||||
if (value != null) {
|
||||
return value;
|
||||
Object value = parameters.get(name);
|
||||
if (value instanceof String[]) {
|
||||
String[] values = (String[]) value;
|
||||
return (values.length > 0 ? values[0] : null);
|
||||
}
|
||||
else if (value != null) {
|
||||
return value.toString();
|
||||
}
|
||||
// If no value yet, try to get it as a name_value=xyz parameter
|
||||
String prefix = name + "_";
|
||||
Iterator paramNames = parameters.keySet().iterator();
|
||||
while (paramNames.hasNext()) {
|
||||
String paramName = (String) paramNames.next();
|
||||
for (String paramName : parameters.keySet()) {
|
||||
if (paramName.startsWith(prefix)) {
|
||||
// Support images buttons, which would submit parameters as name_value.x=123
|
||||
for (int i = 0; i < SUBMIT_IMAGE_SUFFIXES.length; i++) {
|
||||
String suffix = SUBMIT_IMAGE_SUFFIXES[i];
|
||||
for (String suffix : SUBMIT_IMAGE_SUFFIXES) {
|
||||
if (paramName.endsWith(suffix)) {
|
||||
return paramName.substring(prefix.length(), paramName.length() - suffix.length());
|
||||
}
|
||||
@@ -600,10 +593,10 @@ public abstract class WebUtils {
|
||||
* @see javax.servlet.ServletRequest#getParameterValues
|
||||
* @see javax.servlet.ServletRequest#getParameterMap
|
||||
*/
|
||||
public static Map getParametersStartingWith(ServletRequest request, String prefix) {
|
||||
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
|
||||
Assert.notNull(request, "Request must not be null");
|
||||
Enumeration paramNames = request.getParameterNames();
|
||||
Map params = new TreeMap();
|
||||
Map<String, Object> params = new TreeMap<String, Object>();
|
||||
if (prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ import junit.framework.TestCase;
|
||||
public class WebUtilsTests extends TestCase {
|
||||
|
||||
public void testFindParameterValue() {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("myKey1", "myValue1");
|
||||
params.put("myKey2_myValue2", "xxx");
|
||||
params.put("myKey3_myValue3.x", "xxx");
|
||||
params.put("myKey4_myValue4.y", "yyy");
|
||||
params.put("myKey4_myValue4.y", new String[] {"yyy"});
|
||||
|
||||
assertNull(WebUtils.findParameterValue(params, "myKey0"));
|
||||
assertEquals("myValue1", WebUtils.findParameterValue(params, "myKey1"));
|
||||
|
||||
Reference in New Issue
Block a user