From 751c42989706e16f7996c9794a26f2a16eea7e71 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 12 Dec 2012 03:31:18 +0100 Subject: [PATCH] Polishing --- ...ssPathScanningCandidateComponentProvider.java | 15 ++++++++------- .../ComponentScanAnnotationParser.java | 16 ++++++++-------- .../CachingMetadataReaderFactory.java | 10 +++++----- .../web/servlet/view/RedirectView.java | 12 ++++-------- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java b/org.springframework.context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java index 2afeba197e..75247273f7 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java +++ b/org.springframework.context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java @@ -25,6 +25,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; @@ -120,6 +121,13 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC this.metadataReaderFactory = new CachingMetadataReaderFactory(resourceLoader); } + /** + * Return the ResourceLoader that this component provider uses. + */ + public final ResourceLoader getResourceLoader() { + return this.resourcePatternResolver; + } + /** * Set the Environment to use when resolving placeholders and evaluating * {@link Profile @Profile}-annotated component classes. @@ -134,13 +142,6 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC return this.environment; } - /** - * Return the ResourceLoader that this component provider uses. - */ - public final ResourceLoader getResourceLoader() { - return this.resourcePatternResolver; - } - /** * Set the resource pattern to use when scanning the classpath. * This value will be appended to each base package name. diff --git a/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java b/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java index a549b8d0af..90c4c092e7 100644 --- a/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java +++ b/org.springframework.context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java @@ -54,8 +54,7 @@ class ComponentScanAnnotationParser { private final BeanNameGenerator beanNameGenerator; - public ComponentScanAnnotationParser( - ResourceLoader resourceLoader, Environment environment, + public ComponentScanAnnotationParser(ResourceLoader resourceLoader, Environment environment, BeanNameGenerator beanNameGenerator, BeanDefinitionRegistry registry) { this.resourceLoader = resourceLoader; @@ -67,7 +66,7 @@ class ComponentScanAnnotationParser { public Set parse(AnnotationAttributes componentScan) { ClassPathBeanDefinitionScanner scanner = - new ClassPathBeanDefinitionScanner(registry, componentScan.getBoolean("useDefaultFilters")); + new ClassPathBeanDefinitionScanner(this.registry, componentScan.getBoolean("useDefaultFilters")); Assert.notNull(this.environment, "Environment must not be null"); scanner.setEnvironment(this.environment); @@ -77,14 +76,14 @@ class ComponentScanAnnotationParser { Class generatorClass = componentScan.getClass("nameGenerator"); boolean useInheritedGenerator = BeanNameGenerator.class.equals(generatorClass); - scanner.setBeanNameGenerator(useInheritedGenerator - ? this.beanNameGenerator - : BeanUtils.instantiateClass(generatorClass)); + scanner.setBeanNameGenerator(useInheritedGenerator ? this.beanNameGenerator : + BeanUtils.instantiateClass(generatorClass)); ScopedProxyMode scopedProxyMode = componentScan.getEnum("scopedProxy"); if (scopedProxyMode != ScopedProxyMode.DEFAULT) { scanner.setScopedProxyMode(scopedProxyMode); - } else { + } + else { Class resolverClass = componentScan.getClass("scopeResolver"); scanner.setScopeMetadataResolver(BeanUtils.instantiateClass(resolverClass)); } @@ -121,7 +120,7 @@ class ComponentScanAnnotationParser { throw new IllegalStateException("At least one base package must be specified"); } - return scanner.doScan(basePackages.toArray(new String[]{})); + return scanner.doScan(StringUtils.toStringArray(basePackages)); } private List typeFiltersFor(AnnotationAttributes filterAttributes) { @@ -153,4 +152,5 @@ class ComponentScanAnnotationParser { } return typeFilters; } + } diff --git a/org.springframework.core/src/main/java/org/springframework/core/type/classreading/CachingMetadataReaderFactory.java b/org.springframework.core/src/main/java/org/springframework/core/type/classreading/CachingMetadataReaderFactory.java index 725b70f964..5be422034c 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/type/classreading/CachingMetadataReaderFactory.java +++ b/org.springframework.core/src/main/java/org/springframework/core/type/classreading/CachingMetadataReaderFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ public class CachingMetadataReaderFactory extends SimpleMetadataReaderFactory { private volatile int cacheLimit = DEFAULT_CACHE_LIMIT; - private final Map classReaderCache = + private final Map metadataReaderCache = new LinkedHashMap(DEFAULT_CACHE_LIMIT, 0.75f, true) { @Override protected boolean removeEldestEntry(Map.Entry eldest) { @@ -95,11 +95,11 @@ public class CachingMetadataReaderFactory extends SimpleMetadataReaderFactory { if (getCacheLimit() <= 0) { return super.getMetadataReader(resource); } - synchronized (this.classReaderCache) { - MetadataReader metadataReader = this.classReaderCache.get(resource); + synchronized (this.metadataReaderCache) { + MetadataReader metadataReader = this.metadataReaderCache.get(resource); if (metadataReader == null) { metadataReader = super.getMetadataReader(resource); - this.classReaderCache.put(resource, metadataReader); + this.metadataReaderCache.put(resource, metadataReader); } return metadataReader; } diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/RedirectView.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/RedirectView.java index 43f15df2e9..14adcfa3ea 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/RedirectView.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/RedirectView.java @@ -28,7 +28,6 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -77,10 +76,6 @@ import org.springframework.web.util.WebUtils; * *

NOTE when using this redirect view in a Portlet environment: Make sure * that your controller respects the Portlet sendRedirect constraints. - * When e.g. using {@link org.springframework.web.portlet.mvc.SimpleFormController}, - * make sure to set your controller's - * {@link org.springframework.web.portlet.mvc.AbstractFormController#setRedirectAction "redirectAction"} - * property to "true", in order to make the controller base class behave accordingly. * * @author Rod Johnson * @author Juergen Hoeller @@ -97,6 +92,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { private static final Pattern URI_TEMPLATE_VARIABLE_PATTERN = Pattern.compile("\\{([^/]+?)\\}"); + private boolean contextRelative = false; private boolean http10Compatible = true; @@ -109,6 +105,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { private boolean expandUriTemplateVariables = true; + /** * Constructor for use as a bean. */ @@ -233,7 +230,6 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { * and close curly braces "{", "}" and you don't want them interpreted * as URI variables. *

Defaults to true. - * @param expandUriTemplateVariables */ public void setExpandUriTemplateVariables(boolean expandUriTemplateVariables) { this.expandUriTemplateVariables = expandUriTemplateVariables; @@ -265,7 +261,6 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { throws IOException { String targetUrl = createTargetUrl(model, request); - targetUrl = updateTargetUrl(targetUrl, model, request, response); FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request); @@ -278,7 +273,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { FlashMapManager flashMapManager = RequestContextUtils.getFlashMapManager(request); flashMapManager.saveOutputFlashMap(flashMap, request, response); - sendRedirect(request, response, targetUrl.toString(), this.http10Compatible); + sendRedirect(request, response, targetUrl, this.http10Compatible); } /** @@ -362,6 +357,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { * @throws UnsupportedEncodingException if string encoding failed * @see #queryProperties */ + @SuppressWarnings("unchecked") protected void appendQueryProperties(StringBuilder targetUrl, Map model, String encodingScheme) throws UnsupportedEncodingException {