List of usage examples for org.springframework.aop.framework ProxyFactory copyFrom
public void copyFrom(ProxyConfig other)
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. j a v a 2 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());//from w w w .j a va 2s . 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; } }
From source file:prospring3.ch5.beanpostprocessor.DeassociateBeanPostProcessor.java
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof AopInfrastructureBean) { // Ignore AOP infrastructure such as scoped proxies. return bean; }// ww w . j a va2 s. com Class<?> targetClass = AopUtils.getTargetClass(bean); if (AopUtils.canApply(this.deassociatePointcutAdvisor, targetClass)) { if (bean instanceof Advised) { ((Advised) bean).addAdvisor(this.deassociatePointcutAdvisor); return bean; } else { ProxyFactory proxyFactory = new ProxyFactory(bean); // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig. proxyFactory.copyFrom(this); proxyFactory.addAdvisor(this.deassociatePointcutAdvisor); return proxyFactory.getProxy(this.classLoader); } } else { // This is not a repository. return bean; } }
From source file:org.pshow.ecm.security.MethodAuditPostProcessor.java
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof AopInfrastructureBean) { // Ignore AOP infrastructure such as scoped proxies. return bean; }//w w w. j a va 2 s. c o m Class<?> targetClass = AopUtils.getTargetClass(bean); if (AopUtils.canApply(this.advisor, targetClass)) { if (bean instanceof Advised) { ((Advised) bean).addAdvisor(this.advisor); return bean; } else { ProxyFactory proxyFactory = new ProxyFactory(bean); // Copy our properties (proxyTargetClass etc) inherited from // ProxyConfig. proxyFactory.copyFrom(this); proxyFactory.addAdvisor(this.advisor); return proxyFactory.getProxy(this.beanClassLoader); } } else { // This is not a repository. return bean; } }
From source file:dk.clanie.actor.ActorAnnotationBeanPostProcessor.java
public Object postProcessAfterInitialization(Object bean, String beanName) { if (bean instanceof AopInfrastructureBean) { // Ignore AOP infrastructure such as scoped proxies. return bean; }/*w w w. j a v a2 s . c o m*/ Class<?> targetClass = AopUtils.getTargetClass(bean); Actor annotation = AnnotationUtils.findAnnotation(targetClass, Actor.class); if (annotation != null) { // if (AopUtils.canApply(this.asyncAnnotationAdvisor, targetClass)) { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setMaxPoolSize(1); executor.setDaemon(true); String threadNamePrefix = beanName + ","; executor.setThreadNamePrefix(threadNamePrefix); executor.initialize(); ActorAnnotationAdvisor actorAnnotationAdvisor = new ActorAnnotationAdvisor(executor); if (bean instanceof Advised) { ((Advised) bean).addAdvisor(0, actorAnnotationAdvisor); return bean; } else { ProxyFactory proxyFactory = new ProxyFactory(bean); // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig. proxyFactory.copyFrom(this); proxyFactory.addAdvisor(actorAnnotationAdvisor); return proxyFactory.getProxy(this.beanClassLoader); } } else { // No async proxy needed. return bean; } }
From source file:org.sakaiproject.genericdao.springutil.CurrentClassLoaderBeanNameAutoProxyCreator.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2s . c om*/ protected Object createProxy(Class beanClass, String beanName, Object[] specificInterceptors, TargetSource targetSource) { if (spring12x) { ProxyFactory proxyFactory = new ProxyFactory(); // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig. proxyFactory.copyFrom(this); if (!shouldProxyTargetClass(beanClass, beanName)) { // Must allow for introductions; can't just set interfaces to // the target's interfaces only. Class[] targetInterfaces = ClassUtils.getAllInterfacesForClass(beanClass); for (int i = 0; i < targetInterfaces.length; i++) { proxyFactory.addInterface(targetInterfaces[i]); } } Advisor[] advisors = buildAdvisors(beanName, specificInterceptors); for (int i = 0; i < advisors.length; i++) { proxyFactory.addAdvisor(advisors[i]); } proxyFactory.setTargetSource(targetSource); customizeProxyFactory(proxyFactory); proxyFactory.setFrozen(this.freezeProxy); return proxyFactory.getProxy(myClassLoader); } else { return super.createProxy(beanClass, beanName, specificInterceptors, targetSource); } }
From source file:org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean.java
/** * Creates the proxy for target object. This method is invoked by a * BeanFactory after it has set all bean properties supplied. * /*from w ww .j a v a 2 s. c o m*/ * @throws IllegalStateException * if target is <code>null</code>. * @throws AopConfigException * if the proxy interfaces or proxyTargetClass are not set and the * target type is <code>org.springframework.aop.TargetSource</code>. */ public void afterPropertiesSet() throws IllegalStateException, AopConfigException { cachingInterceptor.afterPropertiesSet(); flushingInterceptor.afterPropertiesSet(); if (target == null) { throw new IllegalStateException("Property 'target' is required"); } ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.addAdvisor(new CachingModelSourceAdvisor(cachingInterceptor)); if (hasFlushingModels) { proxyFactory.addAdvisor(new FlushingModelSourceAdvisor(flushingInterceptor)); } proxyFactory.copyFrom(this); TargetSource targetSource = createTargetSource(target); proxyFactory.setTargetSource(targetSource); if (proxyInterfaces != null) { proxyFactory.setInterfaces(proxyInterfaces); } else if (!isProxyTargetClass()) { if (target instanceof TargetSource) { throw new AopConfigException("Either 'proxyInterfaces' or 'proxyTargetClass' is required " + "when using a TargetSource as 'target'"); } // rely on AOP infrastructure to tell us what interfaces to proxy proxyFactory.setInterfaces(ClassUtils.getAllInterfaces(target)); } proxy = proxyFactory.getProxy(); }
From source file:com.helpinput.spring.proxy.OptimizeTransactionProxyFactoryBean.java
public void afterPropertiesSet() { if (this.target == null) { throw new IllegalArgumentException("Property 'target' is required"); }/*w w w . ja v a 2s . c o m*/ if (this.target instanceof String) { throw new IllegalArgumentException("'target' needs to be a bean reference, not a bean name as value"); } ClassLoader proxyClassLoader = target.getClass().getClassLoader(); ProxyFactory proxyFactory = new ProxyFactory(); if (this.preInterceptors != null) { for (Object interceptor : this.preInterceptors) { proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor)); } } // Add the main interceptor (typically an Advisor). proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(createMainInterceptor())); if (this.postInterceptors != null) { for (Object interceptor : this.postInterceptors) { proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor)); } } proxyFactory.copyFrom(this); TargetSource targetSource = createTargetSource(this.target); proxyFactory.setTargetSource(targetSource); if (this.proxyInterfaces != null) { proxyFactory.setInterfaces(this.proxyInterfaces); } else if (!isProxyTargetClass()) { // Rely on AOP infrastructure to tell us what interfaces to proxy. proxyFactory.setInterfaces( ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), proxyClassLoader)); } /** * use this option to let proxyFactory user cglib to create proxy,otherwise in dynamic script ,this is no dynamic interface * ? cglib ??java?? */ proxyFactory.setOptimize(true); this.proxy = proxyFactory.getProxy(proxyClassLoader); }
From source file:org.activiti.spring.components.aop.ProcessStartAnnotationBeanPostProcessor.java
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof AopInfrastructureBean) { // Ignore AOP infrastructure such as scoped proxies. return bean; }//from ww w .j a va 2 s .c o m Class<?> targetClass = AopUtils.getTargetClass(bean); if (AopUtils.canApply(this.advisor, targetClass)) { if (bean instanceof Advised) { ((Advised) bean).addAdvisor(0, this.advisor); return bean; } else { ProxyFactory proxyFactory = new ProxyFactory(bean); // Copy our properties (proxyTargetClass etc) inherited from ProxyConfig. proxyFactory.copyFrom(this); proxyFactory.addAdvisor(this.advisor); return proxyFactory.getProxy(this.beanClassLoader); } } else { // No async proxy needed. return bean; } }