Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle attributes in interceptor binding

I have an annotation:

@Inherited
@InterceptorBinding
@Retention(RUNTIME)
@Target({METHOD, TYPE})
public @interface Example {
}

And a interceptor class for its handling:

@Interceptor
@Example
public class ExampleInterceptor implements Serializable {
...
}

I would like to add a parameter text:

public @interface Example {
    String text();
}

But I don't know how to handle the parameter in the interceptor class. How to modify the annotation of the class?

@Interceptor
@Example(text=???????)
public class ExampleInterceptor implements Serializable {
...
}

If I write @Example(text="my text"), the interceptor is called just when a method/class is annotated with @Example(text="my text"). But I want the interceptor to be called independetly on a parameter value - @Example(text="other text").

And how to get the parameter value? Do I have to use reflexion or is there a better way?

like image 216
ziri Avatar asked May 05 '12 21:05

ziri


1 Answers

The interceptor is called for every attribute value when annotation @Nonbinding is used.

Annotation:

public @interface Example {
    @Nonbinding String text() default "";
}

Interceptor:

@Interceptor
@Example
public class ExampleInterceptor implements Serializable {
    ...
}
like image 106
ziri Avatar answered Sep 24 '22 04:09

ziri