当前位置: 首页>>代码示例>>Java>>正文


Java ProxyFactory.getProxy方法代码示例

本文整理汇总了Java中org.springframework.aop.framework.ProxyFactory.getProxy方法的典型用法代码示例。如果您正苦于以下问题:Java ProxyFactory.getProxy方法的具体用法?Java ProxyFactory.getProxy怎么用?Java ProxyFactory.getProxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.aop.framework.ProxyFactory的用法示例。


在下文中一共展示了ProxyFactory.getProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBasicDenyParentAssocNode

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testBasicDenyParentAssocNode() throws Exception
{
    runAs("andy");

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("testOneChildAssociationRef", new Class[] { ChildAssociationRef.class });

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_PARENT.0.sys:base.Read")));

    proxyFactory.setTargetSource(new SingletonTargetSource(o));

    Object proxy = proxyFactory.getProxy();

    try
    {
        method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(systemNodeRef) });
        assertNotNull(null);
    }
    catch (InvocationTargetException e)
    {

    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:27,代码来源:ACLEntryVoterTest.java

示例2: onBootstrap

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Override
protected void onBootstrap(ApplicationEvent event)
{
    if (rmiRegistryHost == null)
    {
        throw new AlfrescoRuntimeException("Property 'rmiRegistryHost' not set");
    }
    if (rmiRegistryPort == 0)
    {
        throw new AlfrescoRuntimeException("Property 'rmiRegistryPort' not set");
    }

    RmiClientInterceptor rmiClientInterceptor = new RmiClientInterceptor();
    rmiClientInterceptor.setRefreshStubOnConnectFailure(true);
    rmiClientInterceptor.setServiceUrl("rmi://" + rmiRegistryHost + ":" + rmiRegistryPort + "/emailService");
    emailServiceProxy = (EmailService) ProxyFactory.getProxy(EmailService.class, rmiClientInterceptor);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:EmailServiceRemotable.java

示例3: create

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Helper method to create a {@link PermissionCheckedValue} from an existing <code>Object</code>.
 * 
 * @param object        the <code>Object</code> to proxy
 * @return                  a <code>Object</code> of the same type but including the
 *                          {@link PermissionCheckedValue} interface
 */
@SuppressWarnings("unchecked")
public static final <T extends Object> T create(T object)
{
    // Create the mixin
    DelegatingIntroductionInterceptor mixin = new PermissionCheckedValueMixin();
    // Create the advisor
    IntroductionAdvisor advisor = new DefaultIntroductionAdvisor(mixin, PermissionCheckedValue.class);
    // Proxy
    ProxyFactory pf = new ProxyFactory(object);
    pf.addAdvisor(advisor);
    Object proxiedObject = pf.getProxy();
    
    // Done
    return (T) proxiedObject;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:PermissionCheckedValue.java

示例4: testBasicAllowChildAssociationRef2

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testBasicAllowChildAssociationRef2() throws Exception
{
    runAs("andy");

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("echoChildAssocRef", new Class[] { ChildAssociationRef.class });

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_PARENT.sys:base.Read")));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();

    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));

    Object answer = method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(rootNodeRef) });
    assertEquals(answer, nodeService.getPrimaryParent(rootNodeRef));

    answer = method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(systemNodeRef) });
    assertEquals(answer, nodeService.getPrimaryParent(systemNodeRef));
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:ACLEntryAfterInvocationTest.java

示例5: testBasicAllowNullNode

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testBasicAllowNullNode() throws Exception
{
    runAs("andy");

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("echoNodeRef", new Class[] { NodeRef.class });

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();

    Object answer = method.invoke(proxy, new Object[] { null });
    assertNull(answer);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:ACLEntryAfterInvocationTest.java

示例6: testBasicAllowNullStore

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testBasicAllowNullStore() throws Exception
{
    runAs("andy");

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("echoStoreRef", new Class[] { StoreRef.class });

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();

    Object answer = method.invoke(proxy, new Object[] { null });
    assertNull(answer);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:ACLEntryAfterInvocationTest.java

示例7: testBasicDenyStore

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testBasicDenyStore() throws Exception
{
    runAs("andy");

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("echoStoreRef", new Class[] { StoreRef.class });

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();

    try
    {
        Object answer = method.invoke(proxy, new Object[] { rootNodeRef.getStoreRef() });
        assertNotNull(answer);
    }
    catch (InvocationTargetException e)
    {

    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:25,代码来源:ACLEntryAfterInvocationTest.java

示例8: testBasicAllowChildAssociationRef1

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testBasicAllowChildAssociationRef1() throws Exception
{
    runAs("andy");

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("echoChildAssocRef", new Class[] { ChildAssociationRef.class });

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("AFTER_ACL_NODE.sys:base.Read")));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();

    permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ), "andy", AccessStatus.ALLOWED));

    Object answer = method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(rootNodeRef) });
    assertEquals(answer, nodeService.getPrimaryParent(rootNodeRef));

    answer = method.invoke(proxy, new Object[] { nodeService.getPrimaryParent(systemNodeRef) });
    assertEquals(answer, nodeService.getPrimaryParent(systemNodeRef));

}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:ACLEntryAfterInvocationTest.java

示例9: getProxyForService

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Get a proxy for the given service object, implementing the specified
 * service interface.
 * <p>Used to export a proxy that does not expose any internals but just
 * a specific interface intended for remote access. Furthermore, a
 * {@link RemoteInvocationTraceInterceptor} will be registered (by default).
 * @return the proxy
 * @see #setServiceInterface
 * @see #setRegisterTraceInterceptor
 * @see RemoteInvocationTraceInterceptor
 */
protected Object getProxyForService() {
	checkService();
	checkServiceInterface();
	ProxyFactory proxyFactory = new ProxyFactory();
	proxyFactory.addInterface(getServiceInterface());
	if (this.registerTraceInterceptor != null ?
			this.registerTraceInterceptor.booleanValue() : this.interceptors == null) {
		proxyFactory.addAdvice(new RemoteInvocationTraceInterceptor(getExporterName()));
	}
	if (this.interceptors != null) {
		AdvisorAdapterRegistry adapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();
		for (int i = 0; i < this.interceptors.length; i++) {
			proxyFactory.addAdvisor(adapterRegistry.wrap(this.interceptors[i]));
		}
	}
	proxyFactory.setTarget(getService());
	proxyFactory.setOpaque(true);
	return proxyFactory.getProxy(getBeanClassLoader());
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:RemoteExporter.java

示例10: testMethodACL3

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testMethodACL3() throws Exception
{
    runAs("andy");

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("testMethod", new Class[] {});

    AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance();

    ProxyFactory proxyFactory = new ProxyFactory();
    proxyFactory.addAdvisor(advisorAdapterRegistry.wrap(new Interceptor("ACL_METHOD.andy", "ACL_METHOD."
            + PermissionService.ALL_AUTHORITIES)));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();

    method.invoke(proxy, new Object[] {});

}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:ACLEntryVoterTest.java

示例11: createRefreshableProxy

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
    * Create a refreshable proxy for the given AOP TargetSource.
    * 
    * @param ts
    *            the refreshable TargetSource
    * @param interfaces
    *            the proxy interfaces (may be {@code null} to indicate proxying
    *            of all interfaces implemented by the target class)
    * @return the generated proxy
    * @see RefreshableScriptTargetSource
    */
   protected Object createRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) {
ProxyFactory proxyFactory = new ProxyFactory();
proxyFactory.setTargetSource(ts);
ClassLoader classLoader = this.beanClassLoader;

if (interfaces == null) {
    interfaces = ClassUtils.getAllInterfacesForClass(ts.getTargetClass(), this.beanClassLoader);
}
proxyFactory.setInterfaces(interfaces);
if (proxyTargetClass) {
    classLoader = null; // force use of Class.getClassLoader()
    proxyFactory.setProxyTargetClass(true);
}

DelegatingIntroductionInterceptor introduction = new DelegatingIntroductionInterceptor(ts);
introduction.suppressInterface(TargetSource.class);
proxyFactory.addAdvice(introduction);

return proxyFactory.getProxy(classLoader);
   }
 
开发者ID:ilivoo,项目名称:game,代码行数:32,代码来源:MyScriptFactoryPostProcessor.java

示例12: testInvokesMethodOnEjbInstanceWithSeparateBusinessMethods

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void testInvokesMethodOnEjbInstanceWithSeparateBusinessMethods() throws Exception {
	Object retVal = new Object();
	LocalInterface ejb = mock(LocalInterface.class);
	given(ejb.targetMethod()).willReturn(retVal);

	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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:LocalSlsbInvokerInterceptorTests.java

示例13: transactionAttributeDeclaredOnCglibClassMethod

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
/**
 * Test the important case where the invocation is on a proxied interface method
 * but the attribute is defined on the target class.
 */
@Test
public void transactionAttributeDeclaredOnCglibClassMethod() throws Exception {
	Method classMethod = ITestBean.class.getMethod("getAge");
	TestBean1 tb = new TestBean1();
	ProxyFactory pf = new ProxyFactory(tb);
	pf.setProxyTargetClass(true);
	Object proxy = pf.getProxy();

	AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
	TransactionAttribute actual = atas.getTransactionAttribute(classMethod, proxy.getClass());

	RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
	rbta.getRollbackRules().add(new RollbackRuleAttribute(Exception.class));
	assertEquals(rbta.getRollbackRules(), ((RuleBasedTransactionAttribute) actual).getRollbackRules());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AnnotationTransactionAttributeSourceTests.java

示例14: testAdvice

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
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 e) {
		assertEquals(message, e.getMessage());
	}
	assertEquals(1, logAdvice.getCountThrows());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:TrickyAspectJPointcutExpressionTests.java

示例15: resolveArgumentTypeVariableWithNonGenericConverter

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test  // SPR-11225
public void resolveArgumentTypeVariableWithNonGenericConverter() throws Exception {
	Method method = MyParameterizedController.class.getMethod("handleDto", Identifiable.class);
	HandlerMethod handlerMethod = new HandlerMethod(new MySimpleParameterizedController(), method);
	MethodParameter methodParam = handlerMethod.getMethodParameters()[0];

	String content = "{\"name\" : \"Jad\"}";
	this.servletRequest.setContent(content.getBytes("UTF-8"));
	this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);

	List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
	HttpMessageConverter target = new MappingJackson2HttpMessageConverter();
	HttpMessageConverter proxy = ProxyFactory.getProxy(HttpMessageConverter.class, new SingletonTargetSource(target));
	converters.add(proxy);
	RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);

	SimpleBean result = (SimpleBean) processor.resolveArgument(methodParam, mavContainer, webRequest, binderFactory);

	assertNotNull(result);
	assertEquals("Jad", result.getName());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:RequestResponseBodyMethodProcessorTests.java


注:本文中的org.springframework.aop.framework.ProxyFactory.getProxy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。