org.aspectj.lang.reflect.PerClauseKind Java Examples

The following examples show how to use org.aspectj.lang.reflect.PerClauseKind. 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 File: AspectJProxyFactory.java    From spring-analysis-note with 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
Source File: AbstractAspectJAdvisorFactory.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 File: AbstractAspectJAdvisorFactory.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: AspectJProxyFactory.java    From spring4-understanding with 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 #5
Source File: AbstractAspectJAdvisorFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 #6
Source File: AspectJProxyFactory.java    From java-technology-stack with 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 #7
Source File: AbstractAspectJAdvisorFactory.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 #8
Source File: AspectJProxyFactory.java    From lams with 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 #9
Source File: AspectMetadataTests.java    From spring4-understanding with 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 #10
Source File: AspectJProxyFactory.java    From spring-analysis-note with 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 #11
Source File: AspectMetadataTests.java    From spring4-understanding with 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 #12
Source File: AspectMetadataTests.java    From spring4-understanding with 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 #13
Source File: AspectJProxyFactory.java    From spring4-understanding with 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 #14
Source File: AspectJProxyFactory.java    From lams with 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 #15
Source File: AspectMetadataTests.java    From java-technology-stack with 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 #16
Source File: AspectMetadataTests.java    From java-technology-stack with 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 #17
Source File: AspectMetadataTests.java    From java-technology-stack with 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 #18
Source File: AspectJProxyFactory.java    From java-technology-stack with 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 #19
Source File: AspectMetadataTests.java    From spring-analysis-note with 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 #20
Source File: AspectMetadataTests.java    From spring-analysis-note with 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 #21
Source File: AspectMetadataTests.java    From spring-analysis-note with 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 #22
Source File: AspectMetadata.java    From spring-analysis-note with 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 File: AspectMetadata.java    From spring-analysis-note with 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 File: AspectMetadata.java    From spring4-understanding with 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 #25
Source File: AspectMetadata.java    From spring4-understanding with 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 #26
Source File: AspectMetadata.java    From lams with 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 #27
Source File: AspectMetadata.java    From lams with 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 #28
Source File: AspectMetadata.java    From java-technology-stack with 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 #29
Source File: AspectMetadata.java    From java-technology-stack with 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 #30
Source File: InstantiationModelAwarePointcutAdvisorImpl.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
}