Package org.springframework.aop.framework

Examples of org.springframework.aop.framework.ProxyFactoryBean


            return null;
        }
        Assert.isTrue(beanNamesForType.length == 1 , "Expecting to only find a single bean for type " + interfaceName + ", but found " + Arrays.asList(beanNamesForType));
        lazyTargetSource.setTargetBeanName(beanNamesForType[0]);
        lazyTargetSource.setBeanFactory(applicationContext);
        ProxyFactoryBean proxyFactory = new ProxyFactoryBean();
        proxyFactory = objectPostProcessor.postProcess(proxyFactory);
        proxyFactory.setTargetSource(lazyTargetSource);
        return (T) proxyFactory.getObject();
    }
View Full Code Here


   
    // Obtain JcrInterceptor bean
    final JpaInterceptor jpaInterceptor = JpaInterceptorLocator.getJpaInterceptor();

    // Proxy worker so that Jpa EntityManager will be properly handled
    final ProxyFactoryBean pfb = new ProxyFactoryBean();
    pfb.setTarget(targetWorker);
    pfb.setInterfaces(targetWorker.getClass().getInterfaces());
    pfb.addAdvice(jpaInterceptor);
  
    this.worker = (IWorker)pfb.getObject();

    this.workTracker = tp.submit(this.worker); // XXX is execute okay?
    this.rendering = true;
    this.startTime = System.currentTimeMillis ();
  }
View Full Code Here

   
    private static IChannelPublisher wrapChannelPublisher(IChannelPublisher channelPublisher) {
        final JpaInterceptor jpaInterceptor = JpaInterceptorLocator.getJpaInterceptor();

        // Proxy IChannelPublisher so that Jpa EntityManager will be properly handled
        final ProxyFactoryBean pfb = new ProxyFactoryBean();
        pfb.setTarget(channelPublisher);
        pfb.setInterfaces(channelPublisher.getClass().getInterfaces());
        pfb.addAdvice(jpaInterceptor);
       
        return (IChannelPublisher)pfb.getObject();
    }
View Full Code Here

  protected void crudAdded(String name, JsfCrudAdapter<?, ?> jsfCrudAdapter) {
  }

  public Object addJSFMessageHandling(
      Object target) {
    ProxyFactoryBean proxyCreatorSupport = new ProxyFactoryBean();
    proxyCreatorSupport.setTarget(target);
    proxyCreatorSupport.addAdvice(new JsfMessageInterceptor());
    proxyCreatorSupport.setOptimize(true);
    proxyCreatorSupport.setOpaque(false);
    return proxyCreatorSupport.getObject();
  }
View Full Code Here

  @ExternalBean
  public abstract TransactionInterceptor transactionInterceptor();
 
  @SuppressWarnings("unchecked")
  public <T> T addTransactionSupport(T target) {
    ProxyFactoryBean proxyCreatorSupport = new ProxyFactoryBean();
    proxyCreatorSupport.setTarget(target);
    proxyCreatorSupport.addAdvice(transactionInterceptor());
    proxyCreatorSupport.setOptimize(true);
    proxyCreatorSupport.setOpaque(false);
    return (T)proxyCreatorSupport.getObject();
  }
View Full Code Here

    }
  }

  @Test
  public void testLoggingTheCurrentlyExecutingMethodName() throws Throwable {
    ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
    proxyFactoryBean.setProxyTargetClass(true);
    proxyFactoryBean.addAdvice(new CurrentMethodExposingMethodInterceptor());
    proxyFactoryBean.setTarget(new TestClassWithAMethod());

    TestClassWithAMethod testClassWithAMethod = (TestClassWithAMethod) proxyFactoryBean.getObject();
    testClassWithAMethod.testMe();
  }
View Full Code Here

        if (this.beanNames != null) {
            for (Iterator it = this.beanNames.iterator(); it.hasNext();) {
                String mappedName = (String) it.next();
                if (isMatch(beanName, mappedName)) {
                    if (ProxyFactoryBean.class.isAssignableFrom(bean.getClass())) {
                        ProxyFactoryBean proxyFactoryBean = (ProxyFactoryBean) bean;
                        String[] orignInterceptorNames = getInterceptorFromProxyFactoryBean(proxyFactoryBean);
                        String[] newInterceptorNames = new String[orignInterceptorNames.length
                                                                  + interceptorNames.length];
                        if (applyCommonInterceptorsFirst) {// 如果是true,则将Auto-proxy的拦截器定义到最前面
                            // 构造新的的拦截器列表
                            System.arraycopy(interceptorNames, 0, newInterceptorNames, 0, interceptorNames.length);
                            System.arraycopy(orignInterceptorNames, 0, newInterceptorNames, interceptorNames.length,
                                             orignInterceptorNames.length);
                        } else {
                            System.arraycopy(orignInterceptorNames, 0, newInterceptorNames, 0,
                                             orignInterceptorNames.length);
                            System.arraycopy(interceptorNames, 0, newInterceptorNames, orignInterceptorNames.length,
                                             interceptorNames.length);
                        }
                        // 重新设置新的inteceptorNames
                        proxyFactoryBean.setInterceptorNames(newInterceptorNames);
                        return proxyFactoryBean;
                    } else {
                        // 如果是单例,对应的代理bean对象为同一个
                        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
                        proxyFactoryBean.setBeanFactory(beanFactory);
                        proxyFactoryBean.setBeanClassLoader(proxyClassLoader);
                        proxyFactoryBean.setInterceptorNames(interceptorNames);
                        proxyFactoryBean.copyFrom(this); // 拷贝对应的一些Proxy config
                        proxyFactoryBean.setTarget(bean);
                        return proxyFactoryBean.getObject();
                    }
                }
            }
        }
View Full Code Here

        LazyInitTargetSource lazyTargetSource = new LazyInitTargetSource();
        String[] beanNamesForType = context.getBeanNamesForType(interfaceName);
        Assert.isTrue(beanNamesForType.length == 1 , "Expecting to only find a single bean for type " + interfaceName + ", but found " + Arrays.asList(beanNamesForType));
        lazyTargetSource.setTargetBeanName(beanNamesForType[0]);
        lazyTargetSource.setBeanFactory(context);
        ProxyFactoryBean proxyFactory = new ProxyFactoryBean();
        proxyFactory.setTargetSource(lazyTargetSource);
        proxyFactory.setInterfaces(new Class[] { interfaceName });
        return (T) proxyFactory.getObject();
    }
View Full Code Here

        if(org.apache.commons.lang.StringUtils.isNotEmpty(pack)){
           Set<Class<?>> classSet = PackagesToScanUtil.getClasses(pack);
           for(Class<?> miniDaoClass : classSet){
             if(miniDaoClass.isAnnotationPresent(MiniDao.class)){
               //单独加载一个接口的代理类
               ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
               proxyFactoryBean.setBeanFactory(beanFactory);
               proxyFactoryBean.setInterfaces(new Class[]{miniDaoClass});
               proxyFactoryBean.setInterceptorNames(new String[]{"miniDaoHandler"});
               String beanName = MiniDaoUtil.getFirstSmall(miniDaoClass.getSimpleName());
               if(!beanFactory.containsBean(beanName)){
                
                 //logger.info(".................MiniDaoBean.................init...................."+miniDaoClass.getName());
                 logger.info("MiniDao Interface [/"+miniDaoClass.getName()+"/] onto Spring Bean '"+beanName+"'");
                 beanFactory.registerSingleton(beanName,proxyFactoryBean.getObject());
               }
             }
           }
        }
      }
View Full Code Here

TOP

Related Classes of org.springframework.aop.framework.ProxyFactoryBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.