List of usage examples for org.springframework.aop.framework ProxyFactory addAdvisor
@Override public void addAdvisor(Advisor advisor)
From source file:staticpc.StaticPointcutExample.java
public static void main(String[] args) { BeanOne one = new BeanOne(); BeanTwo two = new BeanTwo(); BeanOne proxyOne;//from w w w .j a v a 2s . com BeanTwo proxyTwo; Pointcut pc = new SimpleStaticPointCut(); Advice advice = new SimpleAdvice(); Advisor advisor = new DefaultPointcutAdvisor(pc, advice); ProxyFactory pf = new ProxyFactory(); pf.setTarget(one); pf.addAdvisor(advisor); proxyOne = (BeanOne) pf.getProxy(); pf = new ProxyFactory(); pf.setTarget(two); pf.addAdvisor(advisor); proxyTwo = (BeanTwo) pf.getProxy(); proxyOne.foo(); proxyOne.bar(); proxyTwo.foo(); proxyTwo.bar(); }
From source file:introducitons.IntroducitonExample.java
public static void main(String[] args) { TargetBean target = new TargetBean(); target.setName("Loup Garou"); ProxyFactory pf = new ProxyFactory(); pf.setTarget(target);//from www. ja v a2 s .c om Advisor advisor = new IsModifiedAdvisor(); pf.addAdvisor(advisor); pf.setOptimize(true); TargetBean proxy = (TargetBean) pf.getProxy(); IsModified proxyInterface = (IsModified) proxy; System.out.println("Proxy is target bean ? : " + (proxy instanceof TargetBean)); System.out.println("Proxy is child of Ismodified? : " + (proxy instanceof IsModified)); System.out.println("Has been modified interface? : " + proxyInterface.isModified()); proxy.setName("Loup Garou"); System.out.println("Has been modified? Loup Garou != Loup Garou : " + proxyInterface.isModified()); proxy.setName("Za Warudo"); System.out.println("Has been modified? : " + proxyInterface.isModified()); }
From source file:com.aop.ProxyFactoryTest.java
public static void main(String[] args) { UserService userService = new UserServiceImpl(); ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.setTarget(userService); proxyFactory.setInterfaces(new Class[] { UserService.class }); NameMatchMethodPointcutAdvisor advisor = new NameMatchMethodPointcutAdvisor(); advisor.setMappedName("addUser"); advisor.setAdvice(new CheckInterceptor()); proxyFactory.addAdvisor(advisor); UserService userServiceProxy = (UserService) proxyFactory.getProxy(); userServiceProxy.addUser();//w w w.j av a 2s . c om }
From source file:org.jdal.remoting.caucho.HessianProxyFactoryBean.java
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); ProxyFactory pf = new ProxyFactory(new Class[] { getServiceInterface(), RemoteClient.class }); pf.addAdvisor(new RemoteClientAdvisor(this)); pf.addAdvice(this); this.serviceProxy = pf.getProxy(getBeanClassLoader()); }
From source file:org.jdal.remoting.httpinvoker.HttpInvokerProxyFactoryBean.java
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); if (getServiceInterface() == null) { throw new IllegalArgumentException("Property 'serviceInterface' is required"); }//w w w.j a va 2 s. c o m ProxyFactory pf = new ProxyFactory(new Class[] { getServiceInterface(), RemoteClient.class }); pf.addAdvisor(new RemoteClientAdvisor(getRemoteReference())); pf.addAdvice(this); this.serviceProxy = pf.getProxy(getBeanClassLoader()); }
From source file:org.jdal.remoting.caucho.BurlapProxyFactoryBean.java
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); ProxyFactory pf = new ProxyFactory(new Class[] { getServiceInterface(), RemoteClient.class }); pf.addAdvisor(new RemoteClientAdvisor(getRemoteReference())); pf.addAdvice(this); this.serviceProxy = pf.getProxy(getBeanClassLoader()); }
From source file:org.jdal.remoting.rmi.RmiProxyFactoryBean.java
/** * {@inheritDoc}//from w ww. j av a2s. c om */ @Override public void afterPropertiesSet() { super.afterPropertiesSet(); if (getServiceInterface() == null) { throw new IllegalArgumentException("Property 'serviceInterface' is required"); } ProxyFactory pf = new ProxyFactory(new Class[] { getServiceInterface(), RemoteClient.class }); pf.addAdvisor(new RemoteClientAdvisor(getRemoteReference())); pf.addAdvice(this); serviceProxy = pf.getProxy(); }
From source file:org.joyrest.oauth2.initializer.OAuth2Initializer.java
private DefaultTokenServices txProxiedTokenServices(DefaultTokenServices tokenServices, DataSource dataSource) { AnnotationTransactionAttributeSource attrSource = new AnnotationTransactionAttributeSource(); DataSourceTransactionManager txManager = new DataSourceTransactionManager(dataSource); TransactionInterceptor txInterceptor = transactionInterceptor(attrSource, txManager); BeanFactoryTransactionAttributeSourceAdvisor txAdvisor = transactionAdvisor(attrSource, txInterceptor); ClassLoader classLoader = ClassUtils.getDefaultClassLoader(); ProxyFactory proxyFactory = new ProxyFactory(tokenServices); proxyFactory.addAdvice(txInterceptor); proxyFactory.addAdvisor(txAdvisor); proxyFactory.setInterfaces(ClassUtils .getAllInterfacesForClass(new SingletonTargetSource(tokenServices).getTargetClass(), classLoader)); return (DefaultTokenServices) proxyFactory.getProxy(classLoader); }
From source file:com.ryantenney.metrics.spring.AdvisingBeanPostProcessor.java
@Override public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof AopInfrastructureBean) { return bean; }//from www . jav a2 s . c o m final Class<?> targetClass = AopUtils.getTargetClass(bean); if (AopUtils.canApply(pointcut, targetClass)) { final Advice advice = adviceFactory.getAdvice(bean, targetClass); final Advisor advisor = new DefaultPointcutAdvisor(pointcut, advice); if (bean instanceof Advised) { LOG.debug("Bean {} is already proxied, adding Advisor to existing proxy", beanName); ((Advised) bean).addAdvisor(0, advisor); return bean; } else { LOG.debug("Proxying bean {} of type {}", beanName, targetClass.getCanonicalName()); final ProxyFactory proxyFactory = new ProxyFactory(bean); if (proxyConfig != null) { proxyFactory.copyFrom(proxyConfig); } proxyFactory.addAdvisor(advisor); final Object proxy = proxyFactory.getProxy(this.beanClassLoader); return proxy; } } return bean; }
From source file:flex.contrib.factories.config.SecurityExceptionTranslationPostProcessor.java
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { Class<?> targetClass = (bean instanceof Advised ? ((Advised) bean).getTargetSource().getTargetClass() : bean.getClass());// w w w. jav a2 s. c o m if (targetClass == null) { // Can't do much here return bean; } if (AopUtils.canApply(this.securityExceptionTranslationAdvisor, targetClass)) { if (bean instanceof Advised) { ((Advised) bean).addAdvisor(this.securityExceptionTranslationAdvisor); return bean; } else { ProxyFactory proxyFactory = new ProxyFactory(bean); // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig. proxyFactory.copyFrom(this); proxyFactory.addAdvisor(this.securityExceptionTranslationAdvisor); return proxyFactory.getProxy(this.beanClassLoader); } } else { // This is not a repository. return bean; } }