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


Java Aspect类代码示例

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


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

示例1: validate

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
@Override
public void validate(Class<?> aspectClass) throws AopConfigException {
	// If the parent has the annotation and isn't abstract it's an error
	if (aspectClass.getSuperclass().getAnnotation(Aspect.class) != null &&
			!Modifier.isAbstract(aspectClass.getSuperclass().getModifiers())) {
		throw new AopConfigException("[" + aspectClass.getName() + "] cannot extend concrete aspect [" +
				aspectClass.getSuperclass().getName() + "]");
	}

	AjType<?> ajType = AjTypeSystem.getAjType(aspectClass);
	if (!ajType.isAspect()) {
		throw new NotAnAtAspectException(aspectClass);
	}
	if (ajType.getPerClause().getKind() == PerClauseKind.PERCFLOW) {
		throw new AopConfigException(aspectClass.getName() + " uses percflow instantiation model: " +
				"This is not supported in Spring AOP.");
	}
	if (ajType.getPerClause().getKind() == PerClauseKind.PERCFLOWBELOW) {
		throw new AopConfigException(aspectClass.getName() + " uses percflowbelow instantiation model: " +
				"This is not supported in Spring AOP.");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:AbstractAspectJAdvisorFactory.java

示例2: testCustomAnnotationExcludeFilterAndDefaults

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
@Test
public void testCustomAnnotationExcludeFilterAndDefaults() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
	scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(11, beanCount);
	assertFalse(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:ClassPathBeanDefinitionScannerTests.java

示例3: testMultipleCustomExcludeFiltersAndDefaults

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
@Test
public void testMultipleCustomExcludeFiltersAndDefaults() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
	scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
	scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(10, beanCount);
	assertFalse(context.containsBean("fooServiceImpl"));
	assertFalse(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:ClassPathBeanDefinitionScannerTests.java

示例4: validate

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
public void validate(Class<?> aspectClass) throws AopConfigException {
	// If the parent has the annotation and isn't abstract it's an error
	if (aspectClass.getSuperclass().getAnnotation(Aspect.class) != null &&
			!Modifier.isAbstract(aspectClass.getSuperclass().getModifiers())) {
		throw new AopConfigException("[" + aspectClass.getName() + "] cannot extend concrete aspect [" +
				aspectClass.getSuperclass().getName() + "]");
	}

	AjType<?> ajType = AjTypeSystem.getAjType(aspectClass);
	if (!ajType.isAspect()) {
		throw new NotAnAtAspectException(aspectClass);
	}
	if (ajType.getPerClause().getKind() == PerClauseKind.PERCFLOW) {
		throw new AopConfigException(aspectClass.getName() + " uses percflow instantiation model: " +
				"This is not supported in Spring AOP.");
	}
	if (ajType.getPerClause().getKind() == PerClauseKind.PERCFLOWBELOW) {
		throw new AopConfigException(aspectClass.getName() + " uses percflowbelow instantiation model: " +
				"This is not supported in Spring AOP.");
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:22,代码来源:AbstractAspectJAdvisorFactory.java

示例5: testCustomAnnotationExcludeFilterAndDefaults

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
@Test
public void testCustomAnnotationExcludeFilterAndDefaults() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
	scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(9, beanCount);
	assertFalse(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:ClassPathBeanDefinitionScannerTests.java

示例6: testMultipleCustomExcludeFiltersAndDefaults

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
@Test
public void testMultipleCustomExcludeFiltersAndDefaults() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
	scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
	scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(8, beanCount);
	assertFalse(context.containsBean("fooServiceImpl"));
	assertFalse(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:18,代码来源:ClassPathBeanDefinitionScannerTests.java

示例7: addAspect

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
@Override
public synchronized boolean addAspect(Object aspect) {
    if (super.addAspect(aspect)) {
        return true;
    }
    if (!aspect.getClass().isAnnotationPresent(Aspect.class)) {
        return false;
    }
    Class aspectClass = aspect.getClass();
    String aspectName = aspectClass.getName();
    AspectMetadata am = createAspectMetadata(aspectClass, aspectName);
    if (am == null) {
        return false;
    }
    if (am.getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON) {
        throw new IllegalArgumentException(
                "Aspect class [" + aspectClass.getName() + "] does not define a singleton aspect");
    }
    return addAdvisorsFromAspectInstanceFactory(
            new SingletonMetadataAwareAspectInstanceFactory(aspect, aspectName));
}
 
开发者ID:tivv,项目名称:wraop,代码行数:22,代码来源:AspectJWrapperFactorySpi.java

示例8: findPerClause

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
/**
 * Extract contents from String of form {@code pertarget(contents)}.
 */
private String findPerClause(Class<?> aspectClass) {
	// TODO when AspectJ provides this, we can remove this hack. Hence we don't
	// bother to make it elegant. Or efficient. Or robust :-)
	String str = aspectClass.getAnnotation(Aspect.class).value();
	str = str.substring(str.indexOf("(") + 1);
	str = str.substring(0, str.length() - 1);
	return str;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:AspectMetadata.java

示例9: testWithAspectAnnotationOnly

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
@Test
public void testWithAspectAnnotationOnly() throws Exception {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Aspect.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(1, candidates.size());
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:ClassPathScanningCandidateComponentProviderTests.java

示例10: getAspectClass

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
/**
 * @param className
 * @return
 */
private static Class<?> getAspectClass(final String className)
{
	final Class<?> clazz = ClasspathUtil.loadClass(className);
	ValidationUtil.validateNotNull("Aspect class", clazz);
	if (!isAnnotatedWith(clazz, Aspect.class))
	{
		throw new BeanInitializationException("Aspect class " + className
				+ " is not annotated with @Aspect!");
	}
	return clazz;
}
 
开发者ID:openfurther,项目名称:further-open-core,代码行数:16,代码来源:AspectBeanDefinitionParser.java

示例11: hasAspectAnnotation

import org.aspectj.lang.annotation.Aspect; //导入依赖的package包/类
private boolean hasAspectAnnotation(Class<?> clazz) {
	return (AnnotationUtils.findAnnotation(clazz, Aspect.class) != null);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:4,代码来源:AbstractAspectJAdvisorFactory.java


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