From ad9049e68a9b4a86d1b3ad04519f56cc3c701583 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 17 Oct 2013 22:19:17 +0200 Subject: [PATCH] Polishing --- .../factory/support/BeanDefinitionReader.java | 38 +++++++++---------- .../DefaultBeanDefinitionDocumentReader.java | 18 +++++++-- .../annotation/ConfigurationClassParser.java | 8 ++-- .../support/GenericXmlApplicationContext.java | 12 +++--- .../springframework/core/MethodParameter.java | 4 +- 5 files changed, 44 insertions(+), 36 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java index f5d1e77781..bd8b8f51b5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -22,7 +22,7 @@ import org.springframework.core.io.ResourceLoader; /** * Simple interface for bean definition readers. - * Specifies load methods with Resource parameters. + * Specifies load methods with Resource and String location parameters. * *

Concrete bean definition readers can of course add additional * load and register methods for bean definitions, specific to @@ -45,23 +45,23 @@ public interface BeanDefinitionReader { */ BeanDefinitionRegistry getRegistry(); - /** - * Return the resource loader to use for resource locations. - * Can be checked for the ResourcePatternResolver interface and cast - * accordingly, for loading multiple resources for a given resource pattern. - *

Null suggests that absolute resource loading is not available - * for this bean definition reader. - *

This is mainly meant to be used for importing further resources - * from within a bean definition resource, for example via the "import" - * tag in XML bean definitions. It is recommended, however, to apply - * such imports relative to the defining resource; only explicit full - * resource locations will trigger absolute resource loading. - *

There is also a {@code loadBeanDefinitions(String)} method available, - * for loading bean definitions from a resource location (or location pattern). - * This is a convenience to avoid explicit ResourceLoader handling. - * @see #loadBeanDefinitions(String) - * @see org.springframework.core.io.support.ResourcePatternResolver - */ + /** + * Return the resource loader to use for resource locations. + * Can be checked for the ResourcePatternResolver interface and cast + * accordingly, for loading multiple resources for a given resource pattern. + *

Null suggests that absolute resource loading is not available + * for this bean definition reader. + *

This is mainly meant to be used for importing further resources + * from within a bean definition resource, for example via the "import" + * tag in XML bean definitions. It is recommended, however, to apply + * such imports relative to the defining resource; only explicit full + * resource locations will trigger absolute resource loading. + *

There is also a {@code loadBeanDefinitions(String)} method available, + * for loading bean definitions from a resource location (or location pattern). + * This is a convenience to avoid explicit ResourceLoader handling. + * @see #loadBeanDefinitions(String) + * @see org.springframework.core.io.support.ResourcePatternResolver + */ ResourceLoader getResourceLoader(); /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java index a422d5b4fc..0be926af27 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java @@ -133,7 +133,7 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume // then ultimately reset this.delegate back to its original (parent) reference. // this behavior emulates a stack of delegates without actually necessitating one. BeanDefinitionParserDelegate parent = this.delegate; - this.delegate = createHelper(this.readerContext, root, parent); + this.delegate = createDelegate(this.readerContext, root, parent); preProcessXml(root); parseBeanDefinitions(root, this.delegate); @@ -142,12 +142,22 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume this.delegate = parent; } + protected BeanDefinitionParserDelegate createDelegate( + XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) { + + BeanDefinitionParserDelegate delegate = createHelper(readerContext, root, parentDelegate); + if (delegate == null) { + delegate = new BeanDefinitionParserDelegate(readerContext, this.environment); + delegate.initDefaults(root, parentDelegate); + } + return delegate; + } + + @Deprecated protected BeanDefinitionParserDelegate createHelper( XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) { - BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext, environment); - delegate.initDefaults(root, parentDelegate); - return delegate; + return null; } /** diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index c1748314bc..fb3ce41924 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -287,11 +287,11 @@ class ConfigurationClassParser { private void processPropertySource(AnnotationAttributes propertySource) throws IOException { String name = propertySource.getString("name"); String[] locations = propertySource.getStringArray("value"); - int nLocations = locations.length; - if (nLocations == 0) { + int locationCount = locations.length; + if (locationCount == 0) { throw new IllegalArgumentException("At least one @PropertySource(value) location is required"); } - for (int i = 0; i < nLocations; i++) { + for (int i = 0; i < locationCount; i++) { locations[i] = this.environment.resolveRequiredPlaceholders(locations[i]); } ClassLoader classLoader = this.resourceLoader.getClassLoader(); @@ -301,7 +301,7 @@ class ConfigurationClassParser { } } else { - if (nLocations == 1) { + if (locationCount == 1) { this.propertySources.push(new ResourcePropertySource(name, locations[0], classLoader)); } else { diff --git a/spring-context/src/main/java/org/springframework/context/support/GenericXmlApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/GenericXmlApplicationContext.java index e120f667fb..eef4d80ba4 100644 --- a/spring-context/src/main/java/org/springframework/context/support/GenericXmlApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/GenericXmlApplicationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -45,10 +45,9 @@ public class GenericXmlApplicationContext extends GenericApplicationContext { /** * Create a new GenericXmlApplicationContext that needs to be - * {@linkplain #load loaded} and then manually {@link #refresh refreshed}. + * {@link #load loaded} and then manually {@link #refresh refreshed}. */ public GenericXmlApplicationContext() { - reader.setEnvironment(this.getEnvironment()); } /** @@ -91,14 +90,13 @@ public class GenericXmlApplicationContext extends GenericApplicationContext { } /** - * {@inheritDoc} - *

Delegates the given environment to underlying {@link XmlBeanDefinitionReader}. - * Should be called before any call to {@link #load}. + * Delegates the given environment to underlying {@link XmlBeanDefinitionReader}. + * Should be called before any call to {@code #load}. */ @Override public void setEnvironment(ConfigurableEnvironment environment) { super.setEnvironment(environment); - this.reader.setEnvironment(this.getEnvironment()); + this.reader.setEnvironment(getEnvironment()); } /** diff --git a/spring-core/src/main/java/org/springframework/core/MethodParameter.java b/spring-core/src/main/java/org/springframework/core/MethodParameter.java index 28e9f90677..d2f497d814 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -179,7 +179,7 @@ public class MethodParameter { /** * Return the class that declares the underlying Method or Constructor. */ - public Class getDeclaringClass() { + public Class getDeclaringClass() { return getMember().getDeclaringClass(); }