@AspectJ le niveau de la Classe d'Annotation des Conseils avec l'Annotation comme un argument de méthode

Comment puis-je obtenir de l'annotation à être passé comme argument pour les Conseils définies pour
au niveau de la classe d'annotation? Est-il possible?

De la poste ici je suis en mesure d'obtenir le point cut qui identifie l'ensemble de la méthode publique de la classe qui est marquée par une Annotation. Je suis en mesure d'obtenir les conseils sont appliqués aussi bien. Cependant, je ne sais pas comment faire pour obtenir l'annotation de la variable passée en argument dans le cas ci-dessus.

Pour une méthode de niveau d'annotation, je suis en mesure d'obtenir la coupe transverse (pointcut) et des conseils dans lequel je peux obtenir l'annotation passé comme argument, mais je ne sais pas comment pour obtenir le même pour la classe-niveau d'annotation.

Le code ci-dessous fonctionne, mais j'ai besoin d'obtenir l'annotation comme argument de la “les conseils deLogExecutionTimeByClass” dans le programme ci-dessous et je ne pouvais pas en mesure d'obtenir des conseils appropriés ou coupe transverse (pointcut) pour la même.

Annotation:

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface LogExecutionTime {
String level();
}

Aspect:

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class LogTimeAspect {

    /*
     * Pointcut to match all the public methods.
    */
    @Pointcut("execution(public * *(..))")
    public void publicMethod() {}

    /*
     * Advice for the public methods that are marked with Annotation "LogExecutionTime" and it works as expected no issue.
    */ 
    @Around("publicMethod() && @annotation(annotation) ")
    public Object LogExecutionTimeByMethod(final ProceedingJoinPoint joinPoint,final LogExecutionTime annotation) throws Throwable 
    {
        System.out.println("Invoking the method " +joinPoint.getSignature() +" by LogExecutionTimeByMethod Advice");
        return joinPoint.proceed();
    }


    /*
     * Pointcut to match all the public methods that are defined under the Class marked with Annotation LogExecutionTime.
    */
    @Pointcut("within(@LogExecutionTime *)")
    public void beanAnnotatedWithMonitor() {}

    @Pointcut("publicMethod() && beanAnnotatedWithMonitor()")
    public void publicMethodInsideAClassMarkedWithAtMonitor() {}

    /*
     * Below Advice works but I need the LogExecutionTime annotation as an argument to below method. (similar to the advice "LogExecutionTimeByMethod" 
     * defined above)
    */
    @Around("publicMethodInsideAClassMarkedWithAtMonitor()")
    public Object LogExecutionTimeByClass(final ProceedingJoinPoint joinPoint) throws Throwable 
    {
        System.out.println("Invoking the method " +joinPoint.getSignature() +" by  LogExecutionTimeByClass Advice");
        //System.out.println("Invoked by " + annotation.value()); //Need the Annotation Variable here as well...
        return joinPoint.proceed();
    }

/*
    */
}

Annoté De La Classe:

@LogExecutionTime(level="Class_Level_Invocation")
public class Operator {

    @LogExecutionTime(level="Method_Level_Invocation")
    public void operate()  throws InterruptedException {
        Thread.sleep(1000);
    }

    public void operate1() throws InterruptedException {
        Thread.sleep(1000);
    }
}

Programme Principal:

public class AspectJMain {
     public static void main(String[] args) throws InterruptedException {
            Operator op = new Operator();
            op.operate();
            op.operate1();
        }
}

De sortie:

Invoking the method void Operator.operate() by LogExecutionTimeByMethod Advice
Invoking the method void Operator.operate() by  LogExecutionTimeByClass Advice
Invoking the method void Operator.operate1() by  LogExecutionTimeByClass Advice

Veuillez noter que l'utilisation de Printemps de l'est n'est pas une option. J'ai utiliser compilateur AspectJ.
J'ai compilé mes classes et emballé comme pot et utiliser ApsectJ compilateur à l'aspect tissé à l'aide de commande ci-dessous.

ajc -inpath core.jar -outjar ..\lib\core_woven.jar -1.5

Un pointeur serait utile.

InformationsquelleAutor param83 | 2013-07-05