Rename ExecutorContext => SpecificationContext

This commit is contained in:
Chris Beams
2011-02-08 19:08:41 +00:00
parent c5063004eb
commit 2d76dde611
23 changed files with 133 additions and 131 deletions

View File

@@ -20,7 +20,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.beans.factory.xml.XmlReaderContext;
import org.springframework.context.config.ExecutorContext;
import org.springframework.context.config.SpecificationContext;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -74,22 +74,22 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser {
.autowireCandidatePatterns(parserContext.getDelegate().getAutowireCandidatePatterns())
.source(readerContext.extractSource(element))
.sourceName(element.getTagName())
.execute(createExecutorContext(parserContext));
.execute(createSpecificationContext(parserContext));
return null;
}
// Adapt the given ParserContext instance into an ExecutorContext.
// TODO SPR-7420: create a common ParserContext-to-ExecutorContext adapter utility
// Adapt the given ParserContext instance into an SpecificationContext.
// TODO SPR-7420: create a common ParserContext-to-SpecificationContext adapter utility
// or otherwise unify these two types
private ExecutorContext createExecutorContext(ParserContext parserContext) {
ExecutorContext executorContext = new ExecutorContext();
executorContext.setRegistry(parserContext.getRegistry());
executorContext.setRegistrar(parserContext);
executorContext.setResourceLoader(parserContext.getReaderContext().getResourceLoader());
executorContext.setEnvironment(parserContext.getDelegate().getEnvironment());
executorContext.setProblemReporter(parserContext.getReaderContext().getProblemReporter());
return executorContext;
private SpecificationContext createSpecificationContext(ParserContext parserContext) {
SpecificationContext specificationContext = new SpecificationContext();
specificationContext.setRegistry(parserContext.getRegistry());
specificationContext.setRegistrar(parserContext);
specificationContext.setResourceLoader(parserContext.getReaderContext().getResourceLoader());
specificationContext.setEnvironment(parserContext.getDelegate().getEnvironment());
specificationContext.setProblemReporter(parserContext.getReaderContext().getProblemReporter());
return specificationContext;
}
}

View File

@@ -23,7 +23,7 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.config.AbstractSpecificationExecutor;
import org.springframework.context.config.ExecutorContext;
import org.springframework.context.config.SpecificationContext;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.filter.TypeFilter;
@@ -44,10 +44,10 @@ final class ComponentScanExecutor extends AbstractSpecificationExecutor<Componen
* the given specification and perform actual scanning and bean definition
* registration.
*/
protected void doExecute(ComponentScanSpec spec, ExecutorContext executorContext) {
BeanDefinitionRegistry registry = executorContext.getRegistry();
ResourceLoader resourceLoader = executorContext.getResourceLoader();
Environment environment = executorContext.getEnvironment();
protected void doExecute(ComponentScanSpec spec, SpecificationContext specificationContext) {
BeanDefinitionRegistry registry = specificationContext.getRegistry();
ResourceLoader resourceLoader = specificationContext.getResourceLoader();
Environment environment = specificationContext.getEnvironment();
ClassPathBeanDefinitionScanner scanner = spec.useDefaultFilters() == null ?
new ClassPathBeanDefinitionScanner(registry) :
@@ -104,7 +104,7 @@ final class ComponentScanExecutor extends AbstractSpecificationExecutor<Componen
}
}
executorContext.getRegistrar().registerComponent(compositeDef);
specificationContext.getRegistrar().registerComponent(compositeDef);
}
}

View File

@@ -44,7 +44,7 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.config.ExecutorContext;
import org.springframework.context.config.SpecificationContext;
import org.springframework.context.config.FeatureSpecification;
import org.springframework.core.Conventions;
import org.springframework.core.env.Environment;
@@ -91,7 +91,7 @@ class ConfigurationClassBeanDefinitionReader {
private final MetadataReaderFactory metadataReaderFactory;
private ExecutorContext executorContext;
private SpecificationContext specificationContext;
/**
* Create a new {@link ConfigurationClassBeanDefinitionReader} instance that will be used
@@ -107,12 +107,12 @@ class ConfigurationClassBeanDefinitionReader {
this.sourceExtractor = sourceExtractor;
this.problemReporter = problemReporter;
this.metadataReaderFactory = metadataReaderFactory;
this.executorContext = new ExecutorContext();
this.executorContext.setRegistry(this.registry);
this.executorContext.setRegistrar(new SimpleComponentRegistrar(this.registry));
this.executorContext.setResourceLoader(resourceLoader);
this.executorContext.setEnvironment(environment);
this.executorContext.setProblemReporter(problemReporter);
this.specificationContext = new SpecificationContext();
this.specificationContext.setRegistry(this.registry);
this.specificationContext.setRegistrar(new SimpleComponentRegistrar(this.registry));
this.specificationContext.setResourceLoader(resourceLoader);
this.specificationContext.setEnvironment(environment);
this.specificationContext.setProblemReporter(problemReporter);
}
@@ -149,7 +149,7 @@ class ConfigurationClassBeanDefinitionReader {
// TODO SPR-7420: this is where we can catch user-defined types and avoid instantiating them for STS purposes
FeatureAnnotationParser processor = (FeatureAnnotationParser) BeanUtils.instantiateClass(Class.forName((String)annotationAttributes.get("parser")));
FeatureSpecification spec = processor.process(metadata);
spec.execute(this.executorContext);
spec.execute(this.specificationContext);
}
}
} catch (BeanDefinitionParsingException ex) {

View File

@@ -47,7 +47,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.config.ExecutorContext;
import org.springframework.context.config.SpecificationContext;
import org.springframework.context.config.FeatureSpecification;
import org.springframework.context.config.SourceAwareSpecification;
import org.springframework.core.MethodParameter;
@@ -224,13 +224,13 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
}
final EarlyBeanReferenceProxyCreator proxyCreator = new EarlyBeanReferenceProxyCreator(beanFactory);
final ExecutorContext executorContext = createExecutorContext(beanFactory);
final SpecificationContext specificationContext = createSpecificationContext(beanFactory);
for (final Object featureConfigBean : featureConfigBeans.values()) {
ReflectionUtils.doWithMethods(featureConfigBean.getClass(),
new ReflectionUtils.MethodCallback() {
public void doWith(Method featureMethod) throws IllegalArgumentException, IllegalAccessException {
processFeatureMethod(featureMethod, featureConfigBean, executorContext, proxyCreator);
processFeatureMethod(featureMethod, featureConfigBean, specificationContext, proxyCreator);
} },
new ReflectionUtils.MethodFilter() {
public boolean matches(Method candidateMethod) {
@@ -316,7 +316,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
* @throws SecurityException
*/
private void processFeatureMethod(final Method featureMethod, Object configInstance,
ExecutorContext executorContext, EarlyBeanReferenceProxyCreator proxyCreator) {
SpecificationContext specificationContext, EarlyBeanReferenceProxyCreator proxyCreator) {
try {
// get the return type
if (!(FeatureSpecification.class.isAssignableFrom(featureMethod.getReturnType()))) {
@@ -347,22 +347,24 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
((SourceAwareSpecification)spec).source(featureMethod);
((SourceAwareSpecification)spec).sourceName(featureMethod.getName());
}
spec.execute(executorContext);
spec.execute(specificationContext);
} catch (Exception ex) {
throw new FeatureMethodExecutionException(ex);
}
}
private ExecutorContext createExecutorContext(ConfigurableListableBeanFactory beanFactory) {
// TODO SPR-7420: consider unifying the two through a superinterface.
// TODO SPR-7420: create a common ParserContext-to-SpecificationContext adapter util
private SpecificationContext createSpecificationContext(ConfigurableListableBeanFactory beanFactory) {
final BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
ExecutorContext executorContext = new ExecutorContext();
executorContext.setEnvironment(this.environment);
executorContext.setResourceLoader(this.resourceLoader);
executorContext.setRegistry(registry);
executorContext.setRegistrar(new SimpleComponentRegistrar(registry));
SpecificationContext specificationContext = new SpecificationContext();
specificationContext.setEnvironment(this.environment);
specificationContext.setResourceLoader(this.resourceLoader);
specificationContext.setRegistry(registry);
specificationContext.setRegistrar(new SimpleComponentRegistrar(registry));
// TODO SPR-7420: how to get hold of the current problem reporter here?
executorContext.setProblemReporter(new FailFastProblemReporter());
return executorContext;
specificationContext.setProblemReporter(new FailFastProblemReporter());
return specificationContext;
}
private ConfigurationClassBeanDefinitionReader getConfigurationClassBeanDefinitionReader(BeanDefinitionRegistry registry) {

View File

@@ -69,10 +69,10 @@ public abstract class AbstractFeatureSpecification implements SourceAwareSpecifi
return this.sourceName;
}
public void execute(ExecutorContext executorContext) {
public void execute(SpecificationContext specificationContext) {
FeatureSpecificationExecutor executor =
BeanUtils.instantiateClass(this.executorType, FeatureSpecificationExecutor.class);
executor.execute(this, executorContext);
executor.execute(this, specificationContext);
}
}

View File

@@ -34,13 +34,13 @@ public abstract class AbstractSpecificationExecutor<S extends FeatureSpecificati
* only if valid.
*/
@SuppressWarnings("unchecked")
public final void execute(FeatureSpecification spec, ExecutorContext executorContext) {
public final void execute(FeatureSpecification spec, SpecificationContext specificationContext) {
Assert.notNull(spec, "Specification must not be null");
Assert.notNull(spec, "ExecutorContext must not be null");
Assert.notNull(spec, "SpecificationContext must not be null");
Class<?> typeArg = GenericTypeResolver.resolveTypeArgument(this.getClass(), AbstractSpecificationExecutor.class);
Assert.isTrue(typeArg.equals(spec.getClass()), "Specification cannot be executed by this executor");
if (spec.validate(executorContext.getProblemReporter())) {
doExecute((S)spec, executorContext);
if (spec.validate(specificationContext.getProblemReporter())) {
doExecute((S)spec, specificationContext);
}
}
@@ -49,6 +49,6 @@ public abstract class AbstractSpecificationExecutor<S extends FeatureSpecificati
* against a bean factory.
* @param specification the {@linkplain FeatureSpecification#validate() validated} specification
*/
protected abstract void doExecute(S specification, ExecutorContext executorContext);
protected abstract void doExecute(S specification, SpecificationContext specificationContext);
}

View File

@@ -122,6 +122,6 @@ public interface FeatureSpecification {
* specified within. Should work by delegating to an underlying
* {@link FeatureSpecificationExecutor} for proper separation of concerns.
*/
void execute(ExecutorContext executorContext);
void execute(SpecificationContext specificationContext);
}

View File

@@ -36,6 +36,6 @@ public interface FeatureSpecificationExecutor {
* Execute the given specification, usually resulting in registration
* of bean definitions against a bean factory.
*/
void execute(FeatureSpecification spec, ExecutorContext executorContext);
void execute(FeatureSpecification spec, SpecificationContext specificationContext);
}

View File

@@ -28,7 +28,7 @@ import org.springframework.core.io.ResourceLoader;
* @author Chris Beams
* @since 3.1
*/
public class ExecutorContext {
public class SpecificationContext {
private BeanDefinitionRegistry registry;
private ComponentRegistrar registrar;
@@ -36,7 +36,7 @@ public class ExecutorContext {
private Environment environment;
private ProblemReporter problemReporter;
public ExecutorContext() { }
public SpecificationContext() { }
public void setRegistry(BeanDefinitionRegistry registry) {
this.registry = registry;