public interface MedicalService {
@AllowedRole("None")
public void doNotCallMe();
@AllowedRole("All")
public void everyoneCallMe();
@AllowedRole("Doctor")
public void doctorCallMe()
@AllowedRole({"Nurse", "Doctor"})
public void medicalStaffCallMe();
}
I'd like be able to intercept the implementations of this interface
without having to repeat the annotations in each implementation.
Is this possible?
--
Gregory Kick
http://kickstyle.net/
Personally, I wouldn't be particularly comfortable using the first
approach because it would either have to assume that the method is
annotated or check that it is each time. I'd rather just move the
annotations down to the implementations so that I could use the
annotatedWith matcher and not have to risk the NPE if somebody drops
an annotation somewhere. It's probably not a big deal for this case,
but probably not a best practice either...
bindInterceptor(Matchers.any(), Matchers.annotatedWith(...), ...)
And in the interceptor be able to get the information contained in the
annotation about what roles should be allowed, i.e.
methodInvocation.getMethod().getAnnotation(AllowedRole.class)
public interface MedicalService {
@AllowedRole("None")
public void doNotCallMe();
@AllowedRole("All")
public void everyoneCallMe();
@AllowedRole("Doctor")
public void doctorCallMe()
@AllowedRole({"Nurse", "Doctor"})
public void medicalStaffCallMe();
public void unrestrictedCallMe();
}
And the interceptor should not be called for non-annotated methods.
Inherited Annotations in Java, by Mikhail Milonov
http://www.codeguru.com/java/article.php/c13793/
Thanks,
-Brad
On Jul 20, 1:53 pm, "Robbie Vanbrabant" <robbie.vanbrab...@gmail.com>
wrote:
> I guess we can conclude that it's not possible to achieve exactly what you
> want with Guice's current out of the box AOP support.
> - A custom Matcher is probably the best technical solution
> - I don't think that putting the annotations on the implementations is a bad
> idea if you don't have 3+ implementations.
> - You could try to live with some interception you don't need (my initial
> suggestion). In most cases, it's a performance loss that's acceptable.
>
> Robbie
>