类org.springframework.beans.factory.Aware源码实例Demo

下面列出了怎么用org.springframework.beans.factory.Aware的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * Invoke {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
 * {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
 * if implemented by the given object.
 */
public static void invokeAwareMethods(Object parserStrategyBean, Environment environment,
		ResourceLoader resourceLoader, BeanDefinitionRegistry registry) {

	if (parserStrategyBean instanceof Aware) {
		if (parserStrategyBean instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory ?
					((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
			if (classLoader != null) {
				((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
			}
		}
		if (parserStrategyBean instanceof BeanFactoryAware && registry instanceof BeanFactory) {
			((BeanFactoryAware) parserStrategyBean).setBeanFactory((BeanFactory) registry);
		}
		if (parserStrategyBean instanceof EnvironmentAware) {
			((EnvironmentAware) parserStrategyBean).setEnvironment(environment);
		}
		if (parserStrategyBean instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) parserStrategyBean).setResourceLoader(resourceLoader);
		}
	}
}
 
private void invokeAwareInterfaces(Object bean) {
	if (bean instanceof Aware) {
		if (bean instanceof EnvironmentAware) {
			((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
		}
		if (bean instanceof EmbeddedValueResolverAware) {
			((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
		}
		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);
		}
	}
}
 
private void invokeAwareMethods(final String beanName, final Object bean) {
	if (bean instanceof Aware) {
		if (bean instanceof BeanNameAware) {
			((BeanNameAware) bean).setBeanName(beanName);
		}
		if (bean instanceof BeanClassLoaderAware) {
			ClassLoader bcl = getBeanClassLoader();
			if (bcl != null) {
				((BeanClassLoaderAware) bean).setBeanClassLoader(bcl);
			}
		}
		if (bean instanceof BeanFactoryAware) {
			((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
		}
	}
}
 
/**
 * Invoke {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
 * {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
 * if implemented by the given object.
 */
public static void invokeAwareMethods(Object parserStrategyBean, Environment environment,
		ResourceLoader resourceLoader, BeanDefinitionRegistry registry) {

	if (parserStrategyBean instanceof Aware) {
		if (parserStrategyBean instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory ?
					((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
			if (classLoader != null) {
				((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
			}
		}
		if (parserStrategyBean instanceof BeanFactoryAware && registry instanceof BeanFactory) {
			((BeanFactoryAware) parserStrategyBean).setBeanFactory((BeanFactory) registry);
		}
		if (parserStrategyBean instanceof EnvironmentAware) {
			((EnvironmentAware) parserStrategyBean).setEnvironment(environment);
		}
		if (parserStrategyBean instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) parserStrategyBean).setResourceLoader(resourceLoader);
		}
	}
}
 
private void invokeAwareInterfaces(Object bean) {
	if (bean instanceof Aware) {
		if (bean instanceof EnvironmentAware) {
			((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
		}
		if (bean instanceof EmbeddedValueResolverAware) {
			((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
		}
		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);
		}
	}
}
 
private void invokeAwareMethods(final String beanName, final Object bean) {
	if (bean instanceof Aware) {
		if (bean instanceof BeanNameAware) {
			((BeanNameAware) bean).setBeanName(beanName);
		}
		if (bean instanceof BeanClassLoaderAware) {
			ClassLoader bcl = getBeanClassLoader();
			if (bcl != null) {
				((BeanClassLoaderAware) bean).setBeanClassLoader(bcl);
			}
		}
		if (bean instanceof BeanFactoryAware) {
			((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
		}
	}
}
 
源代码7 项目: spring-init   文件: FunctionalInstallerListener.java
public static void invokeAwareMethods(Object target, Environment environment, ResourceLoader resourceLoader,
		BeanDefinitionRegistry registry) {

	if (target instanceof Aware) {
		if (target instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory
					? ((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
			if (classLoader != null) {
				((BeanClassLoaderAware) target).setBeanClassLoader(classLoader);
			}
		}
		if (target instanceof BeanFactoryAware && registry instanceof BeanFactory) {
			((BeanFactoryAware) target).setBeanFactory((BeanFactory) registry);
		}
		if (target instanceof EnvironmentAware) {
			((EnvironmentAware) target).setEnvironment(environment);
		}
		if (target instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) target).setResourceLoader(resourceLoader);
		}
	}
}
 
源代码8 项目: lams   文件: ParserStrategyUtils.java
/**
 * Invoke {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
 * {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
 * if implemented by the given object.
 */
public static void invokeAwareMethods(Object parserStrategyBean, Environment environment,
		ResourceLoader resourceLoader, BeanDefinitionRegistry registry) {

	if (parserStrategyBean instanceof Aware) {
		if (parserStrategyBean instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (registry instanceof ConfigurableBeanFactory ?
					((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader());
			((BeanClassLoaderAware) parserStrategyBean).setBeanClassLoader(classLoader);
		}
		if (parserStrategyBean instanceof BeanFactoryAware && registry instanceof BeanFactory) {
			((BeanFactoryAware) parserStrategyBean).setBeanFactory((BeanFactory) registry);
		}
		if (parserStrategyBean instanceof EnvironmentAware) {
			((EnvironmentAware) parserStrategyBean).setEnvironment(environment);
		}
		if (parserStrategyBean instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) parserStrategyBean).setResourceLoader(resourceLoader);
		}
	}
}
 
源代码9 项目: lams   文件: ApplicationContextAwareProcessor.java
private void invokeAwareInterfaces(Object bean) {
	if (bean instanceof Aware) {
		if (bean instanceof EnvironmentAware) {
			((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
		}
		if (bean instanceof EmbeddedValueResolverAware) {
			((EmbeddedValueResolverAware) bean).setEmbeddedValueResolver(this.embeddedValueResolver);
		}
		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);
		}
	}
}
 
/**
 * Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
 * {@link BeanFactoryAware} contracts if implemented by the given {@code bean}.
 */
private void invokeAwareMethods(Object importStrategyBean) {
	if (importStrategyBean instanceof Aware) {
		if (importStrategyBean instanceof EnvironmentAware) {
			((EnvironmentAware) importStrategyBean).setEnvironment(this.environment);
		}
		if (importStrategyBean instanceof ResourceLoaderAware) {
			((ResourceLoaderAware) importStrategyBean).setResourceLoader(this.resourceLoader);
		}
		if (importStrategyBean instanceof BeanClassLoaderAware) {
			ClassLoader classLoader = (this.registry instanceof ConfigurableBeanFactory ?
					((ConfigurableBeanFactory) this.registry).getBeanClassLoader() :
					this.resourceLoader.getClassLoader());
			((BeanClassLoaderAware) importStrategyBean).setBeanClassLoader(classLoader);
		}
		if (importStrategyBean instanceof BeanFactoryAware && this.registry instanceof BeanFactory) {
			((BeanFactoryAware) importStrategyBean).setBeanFactory((BeanFactory) this.registry);
		}
	}
}
 
/**��beanʵ�ֵ�aware�������лص�
 * @param bean
 */
private void invokeAwareInterfaces(Object bean) {
	if (bean instanceof Aware) {
		if (bean instanceof EnvironmentAware) {
			((EnvironmentAware) bean).setEnvironment(this.applicationContext.getEnvironment());
		}
		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);
		}
	}
}
 
源代码12 项目: lams   文件: AbstractAutowireCapableBeanFactory.java
private void invokeAwareMethods(final String beanName, final Object bean) {
	if (bean instanceof Aware) {
		if (bean instanceof BeanNameAware) {
			((BeanNameAware) bean).setBeanName(beanName);
		}
		if (bean instanceof BeanClassLoaderAware) {
			((BeanClassLoaderAware) bean).setBeanClassLoader(getBeanClassLoader());
		}
		if (bean instanceof BeanFactoryAware) {
			((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
		}
	}
}
 
protected void invokeAwareInterfaces(Object bean) {
	if (bean instanceof Aware) {
		//扩展 DisruptorEventPublisherAware
		if (bean instanceof DisruptorEventPublisherAware) {
			DisruptorEventPublisherAware awareBean = (DisruptorEventPublisherAware) bean;  
			awareBean.setDisruptorEventPublisher( this.disruptorContext );
		}
	}
}
 
private void invokeAwareMethods(final String beanName, final Object bean) {
	if (bean instanceof Aware) {
		if (bean instanceof BeanNameAware) {
			((BeanNameAware) bean).setBeanName(beanName);
		}
		if (bean instanceof BeanClassLoaderAware) {
			((BeanClassLoaderAware) bean).setBeanClassLoader(getBeanClassLoader());
		}
		if (bean instanceof BeanFactoryAware) {
			((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
		}
	}
}
 
private void invokeAwareMethods(final String beanName, final Object bean) {
	if (bean instanceof Aware) {
		if (bean instanceof BeanNameAware) {
			((BeanNameAware) bean).setBeanName(beanName);
		}
		if (bean instanceof BeanClassLoaderAware) {
			((BeanClassLoaderAware) bean).setBeanClassLoader(getBeanClassLoader());
		}
		if (bean instanceof BeanFactoryAware) {
			((BeanFactoryAware) bean).setBeanFactory(AbstractAutowireCapableBeanFactory.this);
		}
	}
}
 
/**
 * Determine whether the given interface is just a container callback and
 * therefore not to be considered as a reasonable proxy interface.
 * <p>If no reasonable proxy interface is found for a given bean, it will get
 * proxied with its full target class, assuming that as the user's intention.
 * @param ifc the interface to check
 * @return whether the given interface is just a container callback
 */
protected boolean isConfigurationCallbackInterface(Class<?> ifc) {
	return (InitializingBean.class == ifc || DisposableBean.class == ifc || Closeable.class == ifc ||
			AutoCloseable.class == ifc || ObjectUtils.containsElement(ifc.getInterfaces(), Aware.class));
}
 
/**
 * Determine whether the given interface is just a container callback and
 * therefore not to be considered as a reasonable proxy interface.
 * <p>If no reasonable proxy interface is found for a given bean, it will get
 * proxied with its full target class, assuming that as the user's intention.
 * @param ifc the interface to check
 * @return whether the given interface is just a container callback
 */
protected boolean isConfigurationCallbackInterface(Class<?> ifc) {
	return (InitializingBean.class == ifc || DisposableBean.class == ifc || Closeable.class == ifc ||
			AutoCloseable.class == ifc || ObjectUtils.containsElement(ifc.getInterfaces(), Aware.class));
}
 
源代码18 项目: lams   文件: ProxyProcessorSupport.java
/**
 * Determine whether the given interface is just a container callback and
 * therefore not to be considered as a reasonable proxy interface.
 * <p>If no reasonable proxy interface is found for a given bean, it will get
 * proxied with its full target class, assuming that as the user's intention.
 * @param ifc the interface to check
 * @return whether the given interface is just a container callback
 */
protected boolean isConfigurationCallbackInterface(Class<?> ifc) {
	return (InitializingBean.class == ifc || DisposableBean.class == ifc ||
			Closeable.class == ifc || "java.lang.AutoCloseable".equals(ifc.getName()) ||
			ObjectUtils.containsElement(ifc.getInterfaces(), Aware.class));
}
 
/**
 * Determine whether the given interface is just a container callback and
 * therefore not to be considered as a reasonable proxy interface.
 * <p>If no reasonable proxy interface is found for a given bean, it will get
 * proxied with its full target class, assuming that as the user's intention.
 * @param ifc the interface to check
 * @return whether the given interface is just a container callback
 */
protected boolean isConfigurationCallbackInterface(Class<?> ifc) {
	return (InitializingBean.class == ifc || DisposableBean.class == ifc ||
			ObjectUtils.containsElement(ifc.getInterfaces(), Aware.class));
}
 
 同包方法