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


Java ProxyFactory.addAdvisor方法代码示例

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


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

示例1: 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

示例2: testBasicAllowUnrecognisedObject

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

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("echoObject", new Class[] { Object.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[] { "noodle" });
    assertNotNull(answer);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:18,代码来源:ACLEntryAfterInvocationTest.java

示例3: testBasicAllowNode

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testBasicAllowNode() 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();

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

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

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

示例4: testBasicAllowNodePair

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

    Object o = new ClassWithMethods();
    Method method = o.getClass().getMethod("echoNodePair", 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();

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

    Pair<Long, NodeRef> rootNodePair = new Pair<Long, NodeRef>(Long.valueOf(1), rootNodeRef);
    Object answer = method.invoke(proxy, new Object[] { rootNodeRef });
    assertEquals(rootNodePair, answer);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:21,代码来源:ACLEntryAfterInvocationTest.java

示例5: testBasicAllowStore

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testBasicAllowStore() 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();

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

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

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

示例6: testMethodACL4

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public void testMethodACL4() 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.woof", "ACL_METHOD.BOO")));
    proxyFactory.setTargetSource(new SingletonTargetSource(o));
    Object proxy = proxyFactory.getProxy();

    try
    {
        method.invoke(proxy, new Object[] {});
    }
    catch (InvocationTargetException e)
    {

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

示例7: 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

示例8: 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

示例9: 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 ex) {
		assertEquals(message, ex.getMessage());
	}
	assertEquals(1, logAdvice.getCountThrows());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:GroovyAspectTests.java

示例10: 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:txazo,项目名称:spring,代码行数:31,代码来源:RemoteExporter.java

示例11: testMatches

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void testMatches() {
	TestBean target = new TestBean();
	target.setAge(27);
	NopInterceptor nop = new NopInterceptor();
	ControlFlowPointcut cflow = new ControlFlowPointcut(One.class, "getAge");
	ProxyFactory pf = new ProxyFactory(target);
	ITestBean proxied = (ITestBean) pf.getProxy();
	pf.addAdvisor(new DefaultPointcutAdvisor(cflow, nop));

	// Not advised, not under One
	assertEquals(target.getAge(), proxied.getAge());
	assertEquals(0, nop.getCount());

	// Will be advised
	assertEquals(target.getAge(), new One().getAge(proxied));
	assertEquals(1, nop.getCount());

	// Won't be advised
	assertEquals(target.getAge(), new One().nomatch(proxied));
	assertEquals(1, nop.getCount());
	assertEquals(3, cflow.getEvaluations());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:ControlFlowPointcutTests.java

示例12: DynamicAsyncInterfaceBean

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
public DynamicAsyncInterfaceBean() {
	ProxyFactory pf = new ProxyFactory(new HashMap<>());
	DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(new MethodInterceptor() {
		@Override
		public Object invoke(MethodInvocation invocation) throws Throwable {
			assertTrue(!Thread.currentThread().getName().equals(originalThreadName));
			if (Future.class.equals(invocation.getMethod().getReturnType())) {
				return new AsyncResult<String>(invocation.getArguments()[0].toString());
			}
			return null;
		}
	});
	advisor.addInterface(AsyncInterface.class);
	pf.addAdvisor(advisor);
	this.proxy = (AsyncInterface) pf.getProxy();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AsyncExecutionTests.java

示例13: testIntroductionInterceptorWithSuperInterface

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void testIntroductionInterceptorWithSuperInterface() throws Exception {
	TestBean raw = new TestBean();
	assertTrue(! (raw instanceof TimeStamped));
	ProxyFactory factory = new ProxyFactory(raw);

	TimeStamped ts = mock(SubTimeStamped.class);
	long timestamp = 111L;
	given(ts.getTimeStamp()).willReturn(timestamp);

	factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), TimeStamped.class));

	TimeStamped tsp = (TimeStamped) factory.getProxy();
	assertTrue(!(tsp instanceof SubTimeStamped));
	assertTrue(tsp.getTimeStamp() == timestamp);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:DelegatingIntroductionInterceptorTests.java

示例14: testSerializableDelegatingIntroductionInterceptorSerializable

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void testSerializableDelegatingIntroductionInterceptorSerializable() throws Exception {
	SerializablePerson serializableTarget = new SerializablePerson();
	String name = "Tony";
	serializableTarget.setName("Tony");

	ProxyFactory factory = new ProxyFactory(serializableTarget);
	factory.addInterface(Person.class);
	long time = 1000;
	TimeStamped ts = new SerializableTimeStamped(time);

	factory.addAdvisor(new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
	factory.addAdvice(new SerializableNopInterceptor());

	Person p = (Person) factory.getProxy();

	assertEquals(name, p.getName());
	assertEquals(time, ((TimeStamped) p).getTimeStamp());

	Person p1 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
	assertEquals(name, p1.getName());
	assertEquals(time, ((TimeStamped) p1).getTimeStamp());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DelegatingIntroductionInterceptorTests.java

示例15: testIntroductionMasksTargetImplementation

import org.springframework.aop.framework.ProxyFactory; //导入方法依赖的package包/类
@Test
public void testIntroductionMasksTargetImplementation() throws Exception {
	final long t = 1001L;
	@SuppressWarnings("serial")
	class TestII extends DelegatingIntroductionInterceptor implements TimeStamped {
		@Override
		public long getTimeStamp() {
			return t;
		}
	}

	DelegatingIntroductionInterceptor ii = new TestII();

	// != t
	TestBean target = new TargetClass(t + 1);

	ProxyFactory pf = new ProxyFactory(target);
	pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));

	TimeStamped ts = (TimeStamped) pf.getProxy();
	// From introduction interceptor, not target
	assertTrue(ts.getTimeStamp() == t);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DelegatingIntroductionInterceptorTests.java


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