Spring Framework ProxyFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework ProxyFactory class.

This code example shows how to use the following methods:getProxy, addAdvisor, setProxyTargetClass
	private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message, 
			boolean proxyTargetClass) throws Exception { 
 
		logAdvice.reset(); 
 
		ProxyFactory factory = new ProxyFactory(target); 
		factory.setProxyTargetClass(proxyTargetClass); 
		factory.addAdvisor(advisor); 
		TestService bean = (TestService) factory.getProxy(); 
 
		assertEquals(0, logAdvice.getCountThrows()); 
		try { 
			bean.sayHello(); 
			fail("Expected exception"); 
		} 
		catch (TestException ex) { 
			assertEquals(message, ex.getMessage()); 
		} 
		assertEquals(1, logAdvice.getCountThrows()); 
	} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProxy, addAdvisor, setProxyTargetClass, setTarget
     
    /** 
     * @see AbstractDynamicIntroductor#introduceInterfaces(Object , Class[] ) 
     */ 
    public Object introduceInterfaces(Object target, Class[] introducedInterfaces) {
        ProxyFactory proxyFactory = new ProxyFactory();
         
        proxyFactory.setProxyTargetClass(true);
        proxyFactory.addAdvisor(new BeanIntroductorAdvisor(introducedInterfaces));
        proxyFactory.setTarget(target);
         
        return proxyFactory.getProxy();
    } 
     
    /** 
     * @see AbstractDynamicIntroductor#introduceInterfaces(Object , Class[] , Class[] ) 
     */ 
    public Object introduceInterfaces(Object target, Class[] introducedInterfaces, Class[] targetInterfaces) {
        ProxyFactory proxyFactory = new ProxyFactory();
         
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProxy, addInterface, setTarget
 
	@Test
	public void testAopJdkProxyWithMultipleInterfaces() throws Exception {
		ModelMap map = new ModelMap();
		Map<?, ?> target = new HashMap<Object, Object>();
		ProxyFactory factory = new ProxyFactory();
		factory.setTarget(target);
		factory.addInterface(Serializable.class);
		factory.addInterface(Cloneable.class);
		factory.addInterface(Comparable.class);
		factory.addInterface(Map.class);
		Object proxy = factory.getProxy();
		map.addAttribute(proxy);
		assertSame(proxy, map.get("map"));
	} 
 
	@Test
	public void testAopJdkProxyWithDetectedInterfaces() throws Exception {
		ModelMap map = new ModelMap();
		Map<?, ?> target = new HashMap<Object, Object>();
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProxy, addAdvice
		String jndiName= "foobar"; 
		Context mockContext = mockContext(jndiName, ejb); 
 
		LocalSlsbInvokerInterceptor si = configuredInterceptor(mockContext, jndiName); 
 
		ProxyFactory pf = new ProxyFactory(new Class<?>[] { BusinessMethods.class } ); 
		pf.addAdvice(si); 
		BusinessMethods target = (BusinessMethods) pf.getProxy(); 
 
		assertTrue(target.targetMethod() == retVal); 
 
		verify(mockContext).close(); 
		verify(ejb).remove(); 
	} 
 
	@Test 
	public void testInvokesMethodOnEjbInstanceWithSeparateBusinessMethods() throws Exception { 
		Object retVal = new Object(); 
		LocalInterface ejb = mock(LocalInterface.class); 
		given(ejb.targetMethod()).willReturn(retVal); 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProxy, addAdvisor, setProxyTargetClass, setTarget
     
    /** 
     * @see AbstractDynamicIntroductor#introduceInterfaces(Object , Class[] ) 
     */ 
    public Object introduceInterfaces(Object target, Class[] introducedInterfaces) {
        ProxyFactory proxyFactory = new ProxyFactory();
         
        proxyFactory.setProxyTargetClass(true);
        proxyFactory.addAdvisor(new ImplementorIntroductorAdvisor(introducedInterfaces, this.implementor));
        proxyFactory.setTarget(target);
         
        return proxyFactory.getProxy();
    } 
     
    /** 
     * @see AbstractDynamicIntroductor#introduceInterfaces(Object , Class[] , Class[] ) 
     */ 
    public Object introduceInterfaces(Object target, Class[] introducedInterfaces, Class[] targetInterfaces) {
        ProxyFactory proxyFactory = new ProxyFactory();
         
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProxy, addAdvice, setInterfaces, setProxyTargetClass, setTarget
 
    private DataSource dataSource; 
 
    public Handle decorate(IDBI idbi, Handle handle) { 
 
        ProxyFactory pf = new ProxyFactory(); 
        pf.setProxyTargetClass(false); 
        pf.setInterfaces(new Class[] {Handle.class}); 
        pf.setTarget(handle); 
        pf.addAdvice(new SQLExceptionTranslatingThrowsAdvice(dataSource)); 
 
        Handle proxy = (Handle)pf.getProxy(); 
 
        return proxy; 
    } 
 
    public DataSource getDataSource() { 
        return dataSource; 
    } 
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProxy, addAdvisor, copyFrom
			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 { 
			// cannot apply advisor 
			return bean;
		} 
	} 
 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProxy, setTargetClass
     * 
     * @return 
     * @throws NoSuchMethodException 
     */ 
    public static MockMethodInvocation createSec2150MethodInvocation() throws NoSuchMethodException {
        ProxyFactory factory = new ProxyFactory(new Class[] {PersonRepository.class});
        factory.setTargetClass(CrudRepository.class);
        PersonRepository repository = (PersonRepository) factory.getProxy();
        return new MockMethodInvocation(repository, PersonRepository.class , "findAll");
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProxy, addAdvisor, copyFrom
			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;
		} 
	} 
 
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		return bean;
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getProxy, addAdvice, setInterfaces, setTarget
     */ 
    public Session getSession() { 
 
        Session unwrapped = SessionFactoryUtils.getSession(factory, false); 
 
        ProxyFactory proxyFactory = new ProxyFactory(); 
        proxyFactory.setInterfaces(new Class[]{ 
            Session.class, 
            org.hibernate.classic.Session.class, 
            org.hibernate.event.EventSource.class}); 
        proxyFactory.setTarget(unwrapped); 
        proxyFactory.addAdvice(0, this); 
        return (Session) proxyFactory.getProxy(); 
 
    } 
 
    /** 
     * Wraps all invocations to Session to prevent certain usages. 
     * Note: {@link QueryBuilder} may unwrap the session in certain 
     * cases. 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Spring Framework ProxyFactory Methods: