mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-21 05:09:13 +00:00
Introduce "Aware" superinterface
All existing *Aware interfaces have been refactored to extend this
new marker interface, serving two purposes:
* Easy access to a type hierarchy that can answer the question
"What *Aware interfaces are available?", without requiring
text-based searches. Also clearly excludes false positives like
TargetClassAware and ParamAware, which while similarly named,
are not semantically similar to traditional *Aware interfaces
in Spring.
* Minor potential performance improvements in
AbstractAutowireCapableBeanFactory and
ApplicationContextAwareProcessor. Both have blocks of sequential
instanceof checks in order to invoke any *Aware interface callback
methods. For a bean that implements none of these interfaces,
the whole sequence can be avoided by guarding first with
if (bean instanceof Aware) {
...
}
Implementors of custom *Aware-style interfaces (and presumably
the BeanPostProcessors that handle them), are encouraged to refactor to
extending this interface for consistency with the framework as well as
the points above.
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3840 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2011 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,6 +17,7 @@
|
||||
package org.springframework.context;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.Aware;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by any object that wishes to be notified
|
||||
@@ -48,13 +49,14 @@ import org.springframework.beans.BeansException;
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @see ResourceLoaderAware
|
||||
* @see ApplicationEventPublisherAware
|
||||
* @see MessageSourceAware
|
||||
* @see org.springframework.context.support.ApplicationObjectSupport
|
||||
* @see org.springframework.beans.factory.BeanFactoryAware
|
||||
*/
|
||||
public interface ApplicationContextAware {
|
||||
public interface ApplicationContextAware extends Aware {
|
||||
|
||||
/**
|
||||
* Set the ApplicationContext that this object runs in.
|
||||
|
||||
+5
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
* Copyright 2002-2011 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,16 +16,19 @@
|
||||
|
||||
package org.springframework.context;
|
||||
|
||||
import org.springframework.beans.factory.Aware;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by any object that wishes to be notified
|
||||
* of the ApplicationEventPublisher (typically the ApplicationContext)
|
||||
* that it runs in.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 1.1.1
|
||||
* @see ApplicationContextAware
|
||||
*/
|
||||
public interface ApplicationEventPublisherAware {
|
||||
public interface ApplicationEventPublisherAware extends Aware {
|
||||
|
||||
/**
|
||||
* Set the ApplicationEventPublisher that this object runs in.
|
||||
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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,6 +16,7 @@
|
||||
|
||||
package org.springframework.context;
|
||||
|
||||
import org.springframework.beans.factory.Aware;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
|
||||
/**
|
||||
@@ -26,10 +27,11 @@ import org.springframework.util.StringValueResolver;
|
||||
* ApplicationContextAware/BeanFactoryAware interfaces.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 3.0.3
|
||||
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#resolveEmbeddedValue
|
||||
*/
|
||||
public interface EmbeddedValueResolverAware {
|
||||
public interface EmbeddedValueResolverAware extends Aware {
|
||||
|
||||
/**
|
||||
* Set the StringValueResolver to use for resolving embedded definition values.
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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,6 +16,7 @@
|
||||
|
||||
package org.springframework.context;
|
||||
|
||||
import org.springframework.beans.factory.Aware;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,7 @@ import org.springframework.core.env.Environment;
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
public interface EnvironmentAware {
|
||||
public interface EnvironmentAware extends Aware {
|
||||
|
||||
/**
|
||||
* Set the {@code Environment} that this object runs in.
|
||||
|
||||
+5
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2005 the original author or authors.
|
||||
* Copyright 2002-2011 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,6 +16,8 @@
|
||||
|
||||
package org.springframework.context;
|
||||
|
||||
import org.springframework.beans.factory.Aware;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by any object that wishes to be notified
|
||||
* of the MessageSource (typically the ApplicationContext) that it runs in.
|
||||
@@ -25,10 +27,11 @@ package org.springframework.context;
|
||||
* it is defined as bean with name "messageSource" in the application context.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 1.1.1
|
||||
* @see ApplicationContextAware
|
||||
*/
|
||||
public interface MessageSourceAware {
|
||||
public interface MessageSourceAware extends Aware {
|
||||
|
||||
/**
|
||||
* Set the MessageSource that this object runs in.
|
||||
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2011 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,6 +16,7 @@
|
||||
|
||||
package org.springframework.context;
|
||||
|
||||
import org.springframework.beans.factory.Aware;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
/**
|
||||
@@ -47,6 +48,7 @@ import org.springframework.core.io.ResourceLoader;
|
||||
* automatic type conversion by the bean factory.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 10.03.2004
|
||||
* @see ApplicationContextAware
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
@@ -57,7 +59,7 @@ import org.springframework.core.io.ResourceLoader;
|
||||
* @see org.springframework.core.io.support.PathMatchingResourcePatternResolver
|
||||
* @see org.springframework.context.support.ReloadableResourceBundleMessageSource
|
||||
*/
|
||||
public interface ResourceLoaderAware {
|
||||
public interface ResourceLoaderAware extends Aware {
|
||||
|
||||
/**
|
||||
* Set the ResourceLoader that this object runs in.
|
||||
|
||||
+21
-18
@@ -21,6 +21,7 @@ import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.Aware;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
@@ -97,24 +98,26 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor {
|
||||
}
|
||||
|
||||
private void invokeAwareInterfaces(Object bean) {
|
||||
if (bean instanceof EmbeddedValueResolverAware) {
|
||||
((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(
|
||||
new EmbeddedValueResolver(this.applicationContext.getBeanFactory()));
|
||||
}
|
||||
if (bean instanceof ResourceLoaderAware) {
|
||||
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof ApplicationEventPublisherAware) {
|
||||
((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof MessageSourceAware) {
|
||||
((MessageSourceAware) bean).setMessageSource(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof ApplicationContextAware) {
|
||||
((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof EnvironmentAware) {
|
||||
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
|
||||
if (bean instanceof Aware) {
|
||||
if (bean instanceof EmbeddedValueResolverAware) {
|
||||
((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(
|
||||
new EmbeddedValueResolver(this.applicationContext.getBeanFactory()));
|
||||
}
|
||||
if (bean instanceof ResourceLoaderAware) {
|
||||
((ResourceLoaderAware) bean).setResourceLoader(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof ApplicationEventPublisherAware) {
|
||||
((ApplicationEventPublisherAware) bean).setApplicationEventPublisher(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof MessageSourceAware) {
|
||||
((MessageSourceAware) bean).setMessageSource(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof ApplicationContextAware) {
|
||||
((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
|
||||
}
|
||||
if (bean instanceof EnvironmentAware) {
|
||||
((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2011 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,6 +16,7 @@
|
||||
|
||||
package org.springframework.context.weaving;
|
||||
|
||||
import org.springframework.beans.factory.Aware;
|
||||
import org.springframework.instrument.classloading.LoadTimeWeaver;
|
||||
|
||||
/**
|
||||
@@ -23,10 +24,11 @@ import org.springframework.instrument.classloading.LoadTimeWeaver;
|
||||
* of the application context's default {@link LoadTimeWeaver}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 2.5
|
||||
* @see org.springframework.context.ConfigurableApplicationContext#LOAD_TIME_WEAVER_BEAN_NAME
|
||||
*/
|
||||
public interface LoadTimeWeaverAware {
|
||||
public interface LoadTimeWeaverAware extends Aware {
|
||||
|
||||
/**
|
||||
* Set the {@link LoadTimeWeaver} of this object's containing
|
||||
|
||||
+5
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2011 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,6 +16,8 @@
|
||||
|
||||
package org.springframework.jmx.export.notification;
|
||||
|
||||
import org.springframework.beans.factory.Aware;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by any Spring-managed resource that is to be
|
||||
* registered with an {@link javax.management.MBeanServer} and wishes to send
|
||||
@@ -33,10 +35,11 @@ package org.springframework.jmx.export.notification;
|
||||
* interface (or implementing a full {@link javax.management.modelmbean.ModelMBean}).
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Chris Beams
|
||||
* @since 2.0
|
||||
* @see NotificationPublisher
|
||||
*/
|
||||
public interface NotificationPublisherAware {
|
||||
public interface NotificationPublisherAware extends Aware {
|
||||
|
||||
/**
|
||||
* Set the {@link NotificationPublisher} instance for the current managed resource instance.
|
||||
|
||||
Reference in New Issue
Block a user