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


Java Pointcut类代码示例

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


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

示例1: matches

import org.springframework.aop.Pointcut; //导入依赖的package包/类
/**
 * Perform the least expensive check for a pointcut match.
 * @param pointcut the pointcut to match
 * @param method the candidate method
 * @param targetClass the target class
 * @param args arguments to the method
 * @return whether there's a runtime match
 */
public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object[] args) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	if (pointcut == Pointcut.TRUE) {
		return true;
	}
	if (pointcut.getClassFilter().matches(targetClass)) {
		// Only check if it gets past first hurdle.
		MethodMatcher mm = pointcut.getMethodMatcher();
		if (mm.matches(method, targetClass)) {
			// We may need additional runtime (argument) check.
			return (!mm.isRuntime() || mm.matches(method, targetClass, args));
		}
	}
	return false;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:Pointcuts.java

示例2: testPerTarget

import org.springframework.aop.Pointcut; //导入依赖的package包/类
@Test
public void testPerTarget() throws SecurityException, NoSuchMethodException {
	AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
	ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);

	InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
			new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(),"someBean"), null, 1, "someBean");
	assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
	assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
	assertTrue(ajpa.isPerInstance());

	assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class));
	assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
			TestBean.class.getMethod("getAge", (Class[]) null),
			TestBean.class));

	assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
			TestBean.class.getMethod("getSpouse", (Class[]) null),
			TestBean.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:AspectJPointcutAdvisorTests.java

示例3: testMatchExplicit

import org.springframework.aop.Pointcut; //导入依赖的package包/类
@Test
public void testMatchExplicit() {
	String expression = "execution(int org.springframework.tests.sample.beans.TestBean.getAge())";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
	assertMatchesGetAge(methodMatcher);
	assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:AspectJExpressionPointcutTests.java

示例4: testMatchWithTypePattern

import org.springframework.aop.Pointcut; //导入依赖的package包/类
@Test
public void testMatchWithTypePattern() throws Exception {
	String expression = "execution(* *..TestBean.*Age(..))";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
	assertMatchesGetAge(methodMatcher);
	assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:AspectJExpressionPointcutTests.java

示例5: testMatchWithArgs

import org.springframework.aop.Pointcut; //导入依赖的package包/类
@Test
public void testMatchWithArgs() throws Exception {
	String expression = "execution(void org.springframework.tests.sample.beans.TestBean.setSomeNumber(Number)) && args(Double)";

	Pointcut pointcut = getPointcut(expression);
	ClassFilter classFilter = pointcut.getClassFilter();
	MethodMatcher methodMatcher = pointcut.getMethodMatcher();

	assertMatchesTestBeanClass(classFilter);

	// not currently testable in a reliable fashion
	//assertDoesNotMatchStringClass(classFilter);

	assertTrue("Should match with setSomeNumber with Double input",
			methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Double(12)}));
	assertFalse("Should not match setSomeNumber with Integer input",
			methodMatcher.matches(setSomeNumber, TestBean.class, new Object[]{new Integer(11)}));
	assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class, null));
	assertTrue("Should be a runtime match", methodMatcher.isRuntime());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:AspectJExpressionPointcutTests.java

示例6: testUnionOfSpecificGetters

import org.springframework.aop.Pointcut; //导入依赖的package包/类
@Test
public void testUnionOfSpecificGetters() {
	Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut);
	assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
	assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
	assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class, null));
	assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
	assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));

	// Union with all setters
	union = Pointcuts.union(union, allClassSetterPointcut);
	assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
	assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
	assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class, null));
	assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
	assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));

	assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:PointcutsTests.java

示例7: matches

import org.springframework.aop.Pointcut; //导入依赖的package包/类
/**
 * Perform the least expensive check for a pointcut match.
 * @param pointcut the pointcut to match
 * @param method the candidate method
 * @param targetClass the target class
 * @param args arguments to the method
 * @return whether there's a runtime match
 */
public static boolean matches(Pointcut pointcut, Method method, Class<?> targetClass, Object... args) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	if (pointcut == Pointcut.TRUE) {
		return true;
	}
	if (pointcut.getClassFilter().matches(targetClass)) {
		// Only check if it gets past first hurdle.
		MethodMatcher mm = pointcut.getMethodMatcher();
		if (mm.matches(method, targetClass)) {
			// We may need additional runtime (argument) check.
			return (!mm.isRuntime() || mm.matches(method, targetClass, args));
		}
	}
	return false;
}
 
开发者ID:txazo,项目名称:spring,代码行数:24,代码来源:Pointcuts.java

示例8: advisor

import org.springframework.aop.Pointcut; //导入依赖的package包/类
/**
 *
 *
 * @return .
 */
@Bean
public Advisor advisor(final ContextService contextService) {
    return new AbstractPointcutAdvisor() {
            private static final long serialVersionUID = -192186951500259942L;

            @Override
            public Advice getAdvice() {
                return advice(contextService);
            }

            @Override
            public Pointcut getPointcut() {
                return new StaticMethodMatcherPointcut() {
                        @Override
                        public boolean matches(Method method, Class<?> clazz) {
                            return method.getAnnotation(Conversation.class) != null;
                        }
                    };
            }
        };
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:27,代码来源:ConversationConfiguration.java

示例9: packageTraceAdvisor

import org.springframework.aop.Pointcut; //导入依赖的package包/类
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public Advisor packageTraceAdvisor() {
    ComposablePointcut resultPointcut = new ComposablePointcut();
    {
        List<String> basePackages = findBasePackages();
        String pointcutExpression = makeExpression(basePackages);
        AspectJExpressionPointcut packagePointcut = new AspectJExpressionPointcut();
        log.info("Include package Pointcut expression : {}", pointcutExpression);
        packagePointcut.setExpression(pointcutExpression);
        resultPointcut.intersection((Pointcut) packagePointcut);
    }

    String excludeAnnotation = buildExcludeAnnotation();
    log.info("Exclude Annotation Pointcut expression : {}", excludeAnnotation);

    AspectJExpressionPointcut basePointcut = new AspectJExpressionPointcut();
    basePointcut.setExpression(excludeAnnotation);
    resultPointcut.intersection((Pointcut) basePointcut);

    DefaultPointcutAdvisor pointcutAdvisor = new DefaultPointcutAdvisor(resultPointcut, new TraceAopInterceptor(traceLogManager));
    pointcutAdvisor.setOrder(Integer.MAX_VALUE);
    return pointcutAdvisor;
}
 
开发者ID:acupple,项目名称:stormv-spring-tracer,代码行数:25,代码来源:SimpleTraceConfiguration.java

示例10: checkAdvice

import org.springframework.aop.Pointcut; //导入依赖的package包/类
private void checkAdvice(Object target,
		Pointcut pointcut, boolean adviced) {
	ProxyFactoryBean pfBean = new ProxyFactoryBean();
	pfBean.setTarget(target);
	pfBean.addAdvisor(new DefaultPointcutAdvisor(pointcut, new UppercaseAdvice()));
	Hello proxiedHello = (Hello)pfBean.getObject();
	
	if (adviced) {
		assertThat(proxiedHello.sayHello("Jung"), is("HELLO JUNG"));
		assertThat(proxiedHello.sayHi("Jung"), is("HI JUNG"));
		assertThat(proxiedHello.sayThankYou("Jung"), is("Thank you Jung"));			
	}
	else {
		assertThat(proxiedHello.sayHello("Jung"), is("Hello Jung"));
		assertThat(proxiedHello.sayHi("Jung"), is("Hi Jung"));
		assertThat(proxiedHello.sayThankYou("Jung"), is("Thank you Jung"));			
	}
}
 
开发者ID:UCJung,项目名称:javalab,代码行数:19,代码来源:HelloTest.java

示例11: matches

import org.springframework.aop.Pointcut; //导入依赖的package包/类
/**
 * Perform the least expensive check for a pointcut match.
 * @param pointcut the pointcut to match
 * @param method the candidate method
 * @param targetClass the target class
 * @param args arguments to the method
 * @return whether there's a runtime match
 */
public static boolean matches(Pointcut pointcut, Method method, Class targetClass, Object[] args) {
	Assert.notNull(pointcut, "Pointcut must not be null");
	if (pointcut == Pointcut.TRUE) {
		return true;
	}
	if (pointcut.getClassFilter().matches(targetClass)) {
		// Only check if it gets past first hurdle.
		MethodMatcher mm = pointcut.getMethodMatcher();
		if (mm.matches(method, targetClass)) {
			// We may need additional runtime (argument) check.
			return (!mm.isRuntime() || mm.matches(method, targetClass, args));
		}
	}
	return false;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:Pointcuts.java

示例12: createProxy

import org.springframework.aop.Pointcut; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T createProxy(Class<T> clazz, int timeout) {
	RabbitTemplate rabbitTemplate = RabbitConfiguration.rabbitTemplate();
	if (rabbitTemplate == null) {
		throw new RuntimeException("��Ϣ�������Ѿ�崻�������ϵ����Ա��");
	}
	AmqpProxyFactoryBean amqpProxyFactoryBean = new AmqpProxyFactoryBean();
	amqpProxyFactoryBean.setAmqpTemplate(rabbitTemplate);
	amqpProxyFactoryBean.setServiceInterface(clazz);
	amqpProxyFactoryBean.afterPropertiesSet();
	amqpProxyFactoryBean.setRemoteInvocationFactory(new SimpleRemoteInvocationFactory());

	Object springOrigProxy = createProxy(amqpProxyFactoryBean);
	RabbitMethodInterceptor methodInterceptor = new RabbitMethodInterceptor(timeout);

	ProxyFactory factory = new ProxyFactory();
	factory.addAdvisor(new DefaultPointcutAdvisor(Pointcut.TRUE, methodInterceptor));
	factory.setProxyTargetClass(false);
	factory.addInterface(clazz);
	factory.setTarget(springOrigProxy);
	return (T) factory.getProxy();

}
 
开发者ID:jiangchanghui,项目名称:JavaFxClient,代码行数:24,代码来源:ServiceProxyFactory.java

示例13: buildPointcut

import org.springframework.aop.Pointcut; //导入依赖的package包/类
/**
 * Calculate a pointcut for the given async annotation types, if any.
 * @param asyncAnnotationTypes the async annotation types to introspect
 * @return the applicable Pointcut object, or {@code null} if none
 */
protected Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotationTypes) {
	ComposablePointcut result = null;
	for (Class<? extends Annotation> asyncAnnotationType : asyncAnnotationTypes) {
		Pointcut cpc = new AnnotationMatchingPointcut(asyncAnnotationType, true);
		Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(asyncAnnotationType);
		if (result == null) {
			result = new ComposablePointcut(cpc).union(mpc);
		}
		else {
			result.union(cpc).union(mpc);
		}
	}
	return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:AsyncAnnotationAdvisor.java

示例14: afterPropertiesSet

import org.springframework.aop.Pointcut; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
	Pointcut pointcut = new AnnotationMatchingPointcut(this.validatedAnnotationType, true);
	Advice advice = (this.validator != null ? new MethodValidationInterceptor(this.validator) :
			new MethodValidationInterceptor());
	this.advisor = new DefaultPointcutAdvisor(pointcut, advice);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:MethodValidationPostProcessor.java

示例15: InstantiationModelAwarePointcutAdvisorImpl

import org.springframework.aop.Pointcut; //导入依赖的package包/类
public InstantiationModelAwarePointcutAdvisorImpl(AspectJAdvisorFactory af, AspectJExpressionPointcut ajexp,
		MetadataAwareAspectInstanceFactory aif, Method method, int declarationOrderInAspect, String aspectName) {

	this.declaredPointcut = ajexp;
	this.method = method;
	this.atAspectJAdvisorFactory = af;
	this.aspectInstanceFactory = aif;
	this.declarationOrder = declarationOrderInAspect;
	this.aspectName = aspectName;

	if (aif.getAspectMetadata().isLazilyInstantiated()) {
		// Static part of the pointcut is a lazy type.
		Pointcut preInstantiationPointcut =
				Pointcuts.union(aif.getAspectMetadata().getPerClausePointcut(), this.declaredPointcut);

		// Make it dynamic: must mutate from pre-instantiation to post-instantiation state.
		// If it's not a dynamic pointcut, it may be optimized out
		// by the Spring AOP infrastructure after the first evaluation.
		this.pointcut = new PerTargetInstantiationModelPointcut(this.declaredPointcut, preInstantiationPointcut, aif);
		this.lazy = true;
	}
	else {
		// A singleton aspect.
		this.instantiatedAdvice = instantiateAdvice(this.declaredPointcut);
		this.pointcut = declaredPointcut;
		this.lazy = false;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:InstantiationModelAwarePointcutAdvisorImpl.java


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