Polishing

This commit is contained in:
Juergen Hoeller
2012-12-12 03:31:18 +01:00
parent f19bc572da
commit 751c429897
4 changed files with 25 additions and 28 deletions

View File

@@ -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.

View File

@@ -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<BeanDefinitionHolder> 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<? extends BeanNameGenerator> 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<? extends ScopeMetadataResolver> 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<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
@@ -153,4 +152,5 @@ class ComponentScanAnnotationParser {
}
return typeFilters;
}
}

View File

@@ -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<Resource, MetadataReader> classReaderCache =
private final Map<Resource, MetadataReader> metadataReaderCache =
new LinkedHashMap<Resource, MetadataReader>(DEFAULT_CACHE_LIMIT, 0.75f, true) {
@Override
protected boolean removeEldestEntry(Map.Entry<Resource, MetadataReader> 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;
}

View File

@@ -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;
*
* <p><b>NOTE when using this redirect view in a Portlet environment:</b> Make sure
* that your controller respects the Portlet <code>sendRedirect</code> 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.
* <p>Defaults to <code>true</code>.
* @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<String, Object> model, String encodingScheme)
throws UnsupportedEncodingException {