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


Java MethodBeforeAdvice类代码示例

本文整理汇总了Java中org.springframework.aop.MethodBeforeAdvice的典型用法代码示例。如果您正苦于以下问题:Java MethodBeforeAdvice类的具体用法?Java MethodBeforeAdvice怎么用?Java MethodBeforeAdvice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testCanGetStaticPartFromJoinPoint

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
@Test
public void testCanGetStaticPartFromJoinPoint() {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, Object target) throws Throwable {
			StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
			assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart());
			assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind());
			assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature());
			assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	// Any call will do
	itb.getAge();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:MethodInvocationProceedingJoinPointTests.java

示例2: testProxyConfigString

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
/**
 * Check that the string is informative.
 */
@Test
public void testProxyConfigString() {
	TestBean target = new TestBean();
	ProxyFactory pc = new ProxyFactory(target);
	pc.setInterfaces(new Class<?>[] {ITestBean.class});
	pc.addAdvice(new NopInterceptor());
	MethodBeforeAdvice mba = new CountingBeforeAdvice();
	Advisor advisor = new DefaultPointcutAdvisor(new NameMatchMethodPointcut(), mba);
	pc.addAdvisor(advisor);
	ITestBean proxied = (ITestBean) createProxy(pc);

	String proxyConfigString = ((Advised) proxied).toProxyConfigString();
	assertTrue(proxyConfigString.indexOf(advisor.toString()) != -1);
	assertTrue(proxyConfigString.indexOf("1 interface") != -1);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:AbstractAopProxyTests.java

示例3: SyntheticInstantiationAdvisor

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
public SyntheticInstantiationAdvisor(final MetadataAwareAspectInstanceFactory aif) {
	super(aif.getAspectMetadata().getPerClausePointcut(), new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, Object target) {
			// Simply instantiate the aspect
			aif.getAspectInstance();
		}
	});
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:ReflectiveAspectJAdvisorFactory.java

示例4: toShortAndLongStringFormedCorrectly

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, Object target) throws Throwable {
			// makeEncSJP, although meant for computing the enclosing join point,
			// it serves our purpose here
			JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
			JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();

			assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
			assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
			assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());

			assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
			assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
			assertEquals(aspectJVersionJp.toString(), jp.toString());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	itb.getAge();
	itb.setName("foo");
	itb.getDoctor();
	itb.getStringArray();
	itb.getSpouse();
	itb.setSpouse(new TestBean());
	try {
		itb.unreliableFileOperation();
	} catch (IOException ex) {
		// we don't realy care...
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:36,代码来源:MethodInvocationProceedingJoinPointTests.java

示例5: TestBeanAdvisor

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
public TestBeanAdvisor() {
	setAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, Object target) throws Throwable {
			++count;
		}
	});
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:AspectJAutoProxyCreatorTests.java

示例6: SyntheticInstantiationAdvisor

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
public SyntheticInstantiationAdvisor(final MetadataAwareAspectInstanceFactory aif) {
	super(aif.getAspectMetadata().getPerClausePointcut(), new MethodBeforeAdvice() {
		public void before(Method method, Object[] args, Object target) {
			// Simply instantiate the aspect
			aif.getAspectInstance();
		}
	});
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:9,代码来源:ReflectiveAspectJAdvisorFactory.java

示例7: toShortAndLongStringFormedCorrectly

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
@Test
public void toShortAndLongStringFormedCorrectly() throws Exception {
	final Object raw = new TestBean();
	ProxyFactory pf = new ProxyFactory(raw);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		@Override
		public void before(Method method, Object[] args, Object target) throws Throwable {
			// makeEncSJP, although meant for computing the enclosing join point,
			// it serves our purpose here
			JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
			JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();

			assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
			assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
			assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());

			assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
			assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
			assertEquals(aspectJVersionJp.toString(), jp.toString());
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	itb.getAge();
	itb.setName("foo");
	itb.getDoctor();
	itb.getStringArray();
	itb.getSpouses();
	itb.setSpouse(new TestBean());
	try {
		itb.unreliableFileOperation();
	} catch (IOException ex) {
		// we don't realy care...
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:36,代码来源:MethodInvocationProceedingJoinPointTests.java

示例8: supportsAdvice

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
@Override
public boolean supportsAdvice(Advice advice) {
	return (advice instanceof MethodBeforeAdvice);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:MethodBeforeAdviceAdapter.java

示例9: getInterceptor

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
@Override
public MethodInterceptor getInterceptor(Advisor advisor) {
	MethodBeforeAdvice advice = (MethodBeforeAdvice) advisor.getAdvice();
	return new MethodBeforeAdviceInterceptor(advice);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:6,代码来源:MethodBeforeAdviceAdapter.java

示例10: MethodBeforeAdviceInterceptor

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
/**
 * Create a new MethodBeforeAdviceInterceptor for the given advice.
 * @param advice the MethodBeforeAdvice to wrap
 */
public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) {
	Assert.notNull(advice, "Advice must not be null");
	this.advice = advice;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:MethodBeforeAdviceInterceptor.java

示例11: testCanGetMethodSignatureFromJoinPoint

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
@Test
public void testCanGetMethodSignatureFromJoinPoint() {
	final Object raw = new TestBean();
	// Will be set by advice during a method call
	final int newAge = 23;

	ProxyFactory pf = new ProxyFactory(raw);
	pf.setExposeProxy(true);
	pf.addAdvisor(ExposeInvocationInterceptor.ADVISOR);
	pf.addAdvice(new MethodBeforeAdvice() {
		private int depth;

		@Override
		public void before(Method method, Object[] args, Object target) throws Throwable {
			JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
			assertTrue("Method named in toString", jp.toString().contains(method.getName()));
			// Ensure that these don't cause problems
			jp.toShortString();
			jp.toLongString();

			assertSame(target, AbstractAspectJAdvice.currentJoinPoint().getTarget());
			assertFalse(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget()));

			ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis();
			assertTrue(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis()));

			assertNotSame(target, thisProxy);

			// Check getting again doesn't cause a problem
			assertSame(thisProxy, AbstractAspectJAdvice.currentJoinPoint().getThis());

			// Try reentrant call--will go through this advice.
			// Be sure to increment depth to avoid infinite recursion
			if (depth++ == 0) {
				// Check that toString doesn't cause a problem
				thisProxy.toString();
				// Change age, so this will be returned by invocation
				thisProxy.setAge(newAge);
				assertEquals(newAge, thisProxy.getAge());
			}

			assertSame(AopContext.currentProxy(), thisProxy);
			assertSame(target, raw);

			assertSame(method.getName(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getName());
			assertEquals(method.getModifiers(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers());

			MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature();
			assertSame("Return same MethodSignature repeatedly", msig, AbstractAspectJAdvice.currentJoinPoint().getSignature());
			assertSame("Return same JoinPoint repeatedly", AbstractAspectJAdvice.currentJoinPoint(), AbstractAspectJAdvice.currentJoinPoint());
			assertEquals(method.getDeclaringClass(), msig.getDeclaringType());
			assertTrue(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes()));
			assertEquals(method.getReturnType(), msig.getReturnType());
			assertTrue(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes()));
			msig.toLongString();
			msig.toShortString();
		}
	});
	ITestBean itb = (ITestBean) pf.getProxy();
	// Any call will do
	assertEquals("Advice reentrantly set age", newAge, itb.getAge());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:63,代码来源:MethodInvocationProceedingJoinPointTests.java

示例12: supportsAdvice

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
public boolean supportsAdvice(Advice advice) {
	return (advice instanceof MethodBeforeAdvice);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:4,代码来源:MethodBeforeAdviceAdapter.java

示例13: getInterceptor

import org.springframework.aop.MethodBeforeAdvice; //导入依赖的package包/类
public MethodInterceptor getInterceptor(Advisor advisor) {
	MethodBeforeAdvice advice = (MethodBeforeAdvice) advisor.getAdvice();
	return new MethodBeforeAdviceInterceptor(advice);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:5,代码来源:MethodBeforeAdviceAdapter.java


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