Skip to content

Instantly share code, notes, and snippets.

@nschlimm
Created July 30, 2011 12:57
Show Gist options
  • Save nschlimm/1115496 to your computer and use it in GitHub Desktop.
Save nschlimm/1115496 to your computer and use it in GitHub Desktop.
DecoratorPostProcessor main
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (metaData.isDecoratedBean(beanName)) {
return buildDelegateProxy(bean, beanName);
} else {
return bean;
}
}
@SuppressWarnings("serial")
public Object buildDelegateProxy(final Object bean, final String beanName) {
final SimpleBeanTargetSource targetSource = new SimpleBeanTargetSource() {{setTargetBeanName(beanName); setTargetClass(bean.getClass()); setBeanFactory(beanFactory);}};
ProxyFactory pf = new ProxyFactory() {{setTargetSource(targetSource); setProxyTargetClass(true);}};
DelegateMethodInterceptor interceptor = new DelegateMethodInterceptor(chainingStrategy.getChainedDecorators(beanFactory, metaData.getQualifiedDecoratorChain(beanName), bean));
pf.addAdvice(interceptor); pf.addInterface(DelegateProxyInspector.class);
Object proxy = pf.getProxy();
return proxy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment