Java Code Examples for org.aspectj.lang.reflect.PerClauseKind

The following examples show how to use org.aspectj.lang.reflect.PerClauseKind. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: AspectJProxyFactory.java    License: MIT License 6 votes vote down vote up
/**
 * Create a {@link MetadataAwareAspectInstanceFactory} for the supplied aspect type. If the aspect type
 * has no per clause, then a {@link SingletonMetadataAwareAspectInstanceFactory} is returned, otherwise
 * a {@link PrototypeAspectInstanceFactory} is returned.
 */
private MetadataAwareAspectInstanceFactory createAspectInstanceFactory(
		AspectMetadata am, Class<?> aspectClass, String aspectName) {

	MetadataAwareAspectInstanceFactory instanceFactory;
	if (am.getAjType().getPerClause().getKind() == PerClauseKind.SINGLETON) {
		// Create a shared aspect instance.
		Object instance = getSingletonAspectInstance(aspectClass);
		instanceFactory = new SingletonMetadataAwareAspectInstanceFactory(instance, aspectName);
	}
	else {
		// Create a factory for independent aspect instances.
		instanceFactory = new SimpleMetadataAwareAspectInstanceFactory(aspectClass, aspectName);
	}
	return instanceFactory;
}
 
Example 2
@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.");
	}
}
 
Example 3
Source Project: java-technology-stack   Source File: AspectJProxyFactory.java    License: MIT License 6 votes vote down vote up
/**
 * Create a {@link MetadataAwareAspectInstanceFactory} for the supplied aspect type. If the aspect type
 * has no per clause, then a {@link SingletonMetadataAwareAspectInstanceFactory} is returned, otherwise
 * a {@link PrototypeAspectInstanceFactory} is returned.
 */
private MetadataAwareAspectInstanceFactory createAspectInstanceFactory(
		AspectMetadata am, Class<?> aspectClass, String aspectName) {

	MetadataAwareAspectInstanceFactory instanceFactory;
	if (am.getAjType().getPerClause().getKind() == PerClauseKind.SINGLETON) {
		// Create a shared aspect instance.
		Object instance = getSingletonAspectInstance(aspectClass);
		instanceFactory = new SingletonMetadataAwareAspectInstanceFactory(instance, aspectName);
	}
	else {
		// Create a factory for independent aspect instances.
		instanceFactory = new SimpleMetadataAwareAspectInstanceFactory(aspectClass, aspectName);
	}
	return instanceFactory;
}
 
Example 4
@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.");
	}
}
 
Example 5
Source Project: lams   Source File: AspectJProxyFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a {@link MetadataAwareAspectInstanceFactory} for the supplied aspect type. If the aspect type
 * has no per clause, then a {@link SingletonMetadataAwareAspectInstanceFactory} is returned, otherwise
 * a {@link PrototypeAspectInstanceFactory} is returned.
 */
private MetadataAwareAspectInstanceFactory createAspectInstanceFactory(
		AspectMetadata am, Class<?> aspectClass, String aspectName) {

	MetadataAwareAspectInstanceFactory instanceFactory;
	if (am.getAjType().getPerClause().getKind() == PerClauseKind.SINGLETON) {
		// Create a shared aspect instance.
		Object instance = getSingletonAspectInstance(aspectClass);
		instanceFactory = new SingletonMetadataAwareAspectInstanceFactory(instance, aspectName);
	}
	else {
		// Create a factory for independent aspect instances.
		instanceFactory = new SimpleMetadataAwareAspectInstanceFactory(aspectClass, aspectName);
	}
	return instanceFactory;
}
 
Example 6
@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.");
	}
}
 
Example 7
Source Project: spring4-understanding   Source File: AspectJProxyFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a {@link MetadataAwareAspectInstanceFactory} for the supplied aspect type. If the aspect type
 * has no per clause, then a {@link SingletonMetadataAwareAspectInstanceFactory} is returned, otherwise
 * a {@link PrototypeAspectInstanceFactory} is returned.
 */
private MetadataAwareAspectInstanceFactory createAspectInstanceFactory(
		AspectMetadata am, Class<?> aspectClass, String aspectName) {

	MetadataAwareAspectInstanceFactory instanceFactory = null;
	if (am.getAjType().getPerClause().getKind() == PerClauseKind.SINGLETON) {
		// Create a shared aspect instance.
		Object instance = getSingletonAspectInstance(aspectClass);
		instanceFactory = new SingletonMetadataAwareAspectInstanceFactory(instance, aspectName);
	}
	else {
		// Create a factory for independent aspect instances.
		instanceFactory = new SimpleMetadataAwareAspectInstanceFactory(aspectClass, aspectName);
	}
	return instanceFactory;
}
 
Example 8
@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.");
	}
}
 
Example 9
Source Project: spring-analysis-note   Source File: AspectJProxyFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Add the supplied aspect instance to the chain. The type of the aspect instance
 * supplied must be a singleton aspect. True singleton lifecycle is not honoured when
 * using this method - the caller is responsible for managing the lifecycle of any
 * aspects added in this way.
 * @param aspectInstance the AspectJ aspect instance
 */
public void addAspect(Object aspectInstance) {
	Class<?> aspectClass = aspectInstance.getClass();
	String aspectName = aspectClass.getName();
	AspectMetadata am = createAspectMetadata(aspectClass, aspectName);
	if (am.getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON) {
		throw new IllegalArgumentException(
				"Aspect class [" + aspectClass.getName() + "] does not define a singleton aspect");
	}
	addAdvisorsFromAspectInstanceFactory(
			new SingletonMetadataAwareAspectInstanceFactory(aspectInstance, aspectName));
}
 
Example 10
Source Project: spring-analysis-note   Source File: AspectMetadataTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testSingletonAspect() {
	AspectMetadata am = new AspectMetadata(ExceptionAspect.class,"someBean");
	assertFalse(am.isPerThisOrPerTarget());
	assertSame(Pointcut.TRUE, am.getPerClausePointcut());
	assertEquals(PerClauseKind.SINGLETON, am.getAjType().getPerClause().getKind());
}
 
Example 11
Source Project: spring-analysis-note   Source File: AspectMetadataTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testPerTargetAspect() {
	AspectMetadata am = new AspectMetadata(PerTargetAspect.class,"someBean");
	assertTrue(am.isPerThisOrPerTarget());
	assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
	assertEquals(PerClauseKind.PERTARGET, am.getAjType().getPerClause().getKind());
}
 
Example 12
Source Project: spring-analysis-note   Source File: AspectMetadataTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testPerThisAspect() {
	AspectMetadata am = new AspectMetadata(PerThisAspect.class,"someBean");
	assertTrue(am.isPerThisOrPerTarget());
	assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
	assertEquals(PerClauseKind.PERTHIS, am.getAjType().getPerClause().getKind());
}
 
Example 13
Source Project: java-technology-stack   Source File: AspectJProxyFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Add the supplied aspect instance to the chain. The type of the aspect instance
 * supplied must be a singleton aspect. True singleton lifecycle is not honoured when
 * using this method - the caller is responsible for managing the lifecycle of any
 * aspects added in this way.
 * @param aspectInstance the AspectJ aspect instance
 */
public void addAspect(Object aspectInstance) {
	Class<?> aspectClass = aspectInstance.getClass();
	String aspectName = aspectClass.getName();
	AspectMetadata am = createAspectMetadata(aspectClass, aspectName);
	if (am.getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON) {
		throw new IllegalArgumentException(
				"Aspect class [" + aspectClass.getName() + "] does not define a singleton aspect");
	}
	addAdvisorsFromAspectInstanceFactory(
			new SingletonMetadataAwareAspectInstanceFactory(aspectInstance, aspectName));
}
 
Example 14
Source Project: java-technology-stack   Source File: AspectMetadataTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testSingletonAspect() {
	AspectMetadata am = new AspectMetadata(ExceptionAspect.class,"someBean");
	assertFalse(am.isPerThisOrPerTarget());
	assertSame(Pointcut.TRUE, am.getPerClausePointcut());
	assertEquals(PerClauseKind.SINGLETON, am.getAjType().getPerClause().getKind());
}
 
Example 15
Source Project: java-technology-stack   Source File: AspectMetadataTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testPerTargetAspect() {
	AspectMetadata am = new AspectMetadata(PerTargetAspect.class,"someBean");
	assertTrue(am.isPerThisOrPerTarget());
	assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
	assertEquals(PerClauseKind.PERTARGET, am.getAjType().getPerClause().getKind());
}
 
Example 16
Source Project: java-technology-stack   Source File: AspectMetadataTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testPerThisAspect() {
	AspectMetadata am = new AspectMetadata(PerThisAspect.class,"someBean");
	assertTrue(am.isPerThisOrPerTarget());
	assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
	assertEquals(PerClauseKind.PERTHIS, am.getAjType().getPerClause().getKind());
}
 
Example 17
Source Project: lams   Source File: AspectJProxyFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add the supplied aspect instance to the chain. The type of the aspect instance
 * supplied must be a singleton aspect. True singleton lifecycle is not honoured when
 * using this method - the caller is responsible for managing the lifecycle of any
 * aspects added in this way.
 * @param aspectInstance the AspectJ aspect instance
 */
public void addAspect(Object aspectInstance) {
	Class<?> aspectClass = aspectInstance.getClass();
	String aspectName = aspectClass.getName();
	AspectMetadata am = createAspectMetadata(aspectClass, aspectName);
	if (am.getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON) {
		throw new IllegalArgumentException(
				"Aspect class [" + aspectClass.getName() + "] does not define a singleton aspect");
	}
	addAdvisorsFromAspectInstanceFactory(
			new SingletonMetadataAwareAspectInstanceFactory(aspectInstance, aspectName));
}
 
Example 18
Source Project: spring4-understanding   Source File: AspectJProxyFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add the supplied aspect instance to the chain. The type of the aspect instance
 * supplied must be a singleton aspect. True singleton lifecycle is not honoured when
 * using this method - the caller is responsible for managing the lifecycle of any
 * aspects added in this way.
 * @param aspectInstance the AspectJ aspect instance
 */
public void addAspect(Object aspectInstance) {
	Class<?> aspectClass = aspectInstance.getClass();
	String aspectName = aspectClass.getName();
	AspectMetadata am = createAspectMetadata(aspectClass, aspectName);
	if (am.getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON) {
		throw new IllegalArgumentException(
				"Aspect class [" + aspectClass.getName() + "] does not define a singleton aspect");
	}
	addAdvisorsFromAspectInstanceFactory(
			new SingletonMetadataAwareAspectInstanceFactory(aspectInstance, aspectName));
}
 
Example 19
Source Project: spring4-understanding   Source File: AspectMetadataTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSingletonAspect() {
	AspectMetadata am = new AspectMetadata(ExceptionAspect.class,"someBean");
	assertFalse(am.isPerThisOrPerTarget());
	assertSame(Pointcut.TRUE, am.getPerClausePointcut());
	assertEquals(PerClauseKind.SINGLETON, am.getAjType().getPerClause().getKind());
}
 
Example 20
Source Project: spring4-understanding   Source File: AspectMetadataTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPerTargetAspect() {
	AspectMetadata am = new AspectMetadata(PerTargetAspect.class,"someBean");
	assertTrue(am.isPerThisOrPerTarget());
	assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
	assertEquals(PerClauseKind.PERTARGET, am.getAjType().getPerClause().getKind());
}
 
Example 21
Source Project: spring4-understanding   Source File: AspectMetadataTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPerThisAspect() {
	AspectMetadata am = new AspectMetadata(PerThisAspect.class,"someBean");
	assertTrue(am.isPerThisOrPerTarget());
	assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
	assertEquals(PerClauseKind.PERTHIS, am.getAjType().getPerClause().getKind());
}
 
Example 22
Source Project: spring-analysis-note   Source File: AspectMetadata.java    License: MIT License 4 votes vote down vote up
/**
 * Return whether the aspect is defined as "perthis" or "pertarget".
 */
public boolean isPerThisOrPerTarget() {
	PerClauseKind kind = getAjType().getPerClause().getKind();
	return (kind == PerClauseKind.PERTARGET || kind == PerClauseKind.PERTHIS);
}
 
Example 23
Source Project: spring-analysis-note   Source File: AspectMetadata.java    License: MIT License 4 votes vote down vote up
/**
 * Return whether the aspect is defined as "pertypewithin".
 */
public boolean isPerTypeWithin() {
	PerClauseKind kind = getAjType().getPerClause().getKind();
	return (kind == PerClauseKind.PERTYPEWITHIN);
}
 
Example 24
Source Project: java-technology-stack   Source File: AspectMetadata.java    License: MIT License 4 votes vote down vote up
/**
 * Return whether the aspect is defined as "perthis" or "pertarget".
 */
public boolean isPerThisOrPerTarget() {
	PerClauseKind kind = getAjType().getPerClause().getKind();
	return (kind == PerClauseKind.PERTARGET || kind == PerClauseKind.PERTHIS);
}
 
Example 25
Source Project: java-technology-stack   Source File: AspectMetadata.java    License: MIT License 4 votes vote down vote up
/**
 * Return whether the aspect is defined as "pertypewithin".
 */
public boolean isPerTypeWithin() {
	PerClauseKind kind = getAjType().getPerClause().getKind();
	return (kind == PerClauseKind.PERTYPEWITHIN);
}
 
Example 26
Source Project: lams   Source File: AspectMetadata.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return whether the aspect is defined as "perthis" or "pertarget".
 */
public boolean isPerThisOrPerTarget() {
	PerClauseKind kind = getAjType().getPerClause().getKind();
	return (kind == PerClauseKind.PERTARGET || kind == PerClauseKind.PERTHIS);
}
 
Example 27
Source Project: lams   Source File: AspectMetadata.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return whether the aspect is defined as "pertypewithin".
 */
public boolean isPerTypeWithin() {
	PerClauseKind kind = getAjType().getPerClause().getKind();
	return (kind == PerClauseKind.PERTYPEWITHIN);
}
 
Example 28
Source Project: spring4-understanding   Source File: AspectMetadata.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Return whether the aspect is defined as "perthis" or "pertarget".
 */
public boolean isPerThisOrPerTarget() {
	PerClauseKind kind = getAjType().getPerClause().getKind();
	return (kind == PerClauseKind.PERTARGET || kind == PerClauseKind.PERTHIS);
}
 
Example 29
Source Project: spring4-understanding   Source File: AspectMetadata.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Return whether the aspect is defined as "pertypewithin".
 */
public boolean isPerTypeWithin() {
	PerClauseKind kind = getAjType().getPerClause().getKind();
	return (kind == PerClauseKind.PERTYPEWITHIN);
}
 
Example 30
/**
 * This is only of interest for Spring AOP: AspectJ instantiation semantics
 * are much richer. In AspectJ terminology, all a return of {@code true}
 * means here is that the aspect is not a SINGLETON.
 */
@Override
public boolean isPerInstance() {
	return (getAspectMetadata().getAjType().getPerClause().getKind() != PerClauseKind.SINGLETON);
}