Example usage for org.aspectj.lang.reflect AjType isAspect

List of usage examples for org.aspectj.lang.reflect AjType isAspect

Introduction

In this page you can find the example usage for org.aspectj.lang.reflect AjType isAspect.

Prototype

public boolean isAspect();

Source Link

Usage

From source file:org.springframework.aop.aspectj.annotation.AbstractAnnotationPointcutTests.java

License:Apache License

@Override
protected void setUp() throws Exception {
    this.lastMethodIdentifyingPointcut = null;

    // Look for all aspect fields in the class
    // create a proxy for them that will identify proxy. Can only call one one time
    ReflectionUtils.doWithFields(this.getClass(), new ReflectionUtils.FieldCallback() {
        public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
            AjType ajType = AjTypeSystem.getAjType(field.getType());
            if (ajType.isAspect()) {
                System.out.println(field + " is aspect, type=" + field.getType());
                // Assign to it
                field.setAccessible(true);
                Object value = createPointcutMethodIdentifyingProxyForAspect(field.getType());
                field.set(AbstractAnnotationPointcutTests.this, value);
            }/*from w  ww  .j  av a2s.c o  m*/
        }
    });
}

From source file:org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactory.java

License:Apache License

@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() + "]");
    }/*from w  ww .  j  av  a  2 s.co  m*/

    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.");
    }
}

From source file:org.springframework.aop.aspectj.annotation.AspectMetadata.java

License:Apache License

/**
 * Create a new AspectMetadata instance for the given aspect class.
 * @param aspectClass the aspect class/*from   www.  j a  v  a2  s  . co m*/
 * @param aspectName the name of the aspect
 */
public AspectMetadata(Class<?> aspectClass, String aspectName) {
    this.aspectName = aspectName;

    Class<?> currClass = aspectClass;
    AjType<?> ajType = null;
    while (!currClass.equals(Object.class)) {
        AjType<?> ajTypeToCheck = AjTypeSystem.getAjType(currClass);
        if (ajTypeToCheck.isAspect()) {
            ajType = ajTypeToCheck;
            break;
        }
        currClass = currClass.getSuperclass();
    }
    if (ajType == null) {
        throw new IllegalArgumentException("Class '" + aspectClass.getName() + "' is not an @AspectJ aspect");
    }
    this.ajType = ajType;
    if (this.ajType.getDeclarePrecedence().length > 0) {
        throw new IllegalArgumentException("DeclarePrecendence not presently supported in Spring AOP");
    }

    switch (this.ajType.getPerClause().getKind()) {
    case SINGLETON:
        this.perClausePointcut = Pointcut.TRUE;
        return;
    case PERTARGET:
    case PERTHIS:
        AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
        ajexp.setLocation("@Aspect annotation on " + aspectClass.getName());
        ajexp.setExpression(findPerClause(aspectClass));
        this.perClausePointcut = ajexp;
        return;
    case PERTYPEWITHIN:
        // Works with a type pattern
        this.perClausePointcut = new ComposablePointcut(new TypePatternClassFilter(findPerClause(aspectClass)));
        return;
    default:
        throw new AopConfigException("PerClause " + ajType.getPerClause().getKind()
                + " not supported by Spring AOP for " + aspectClass);
    }
}