Mutant World

Saturday, March 12, 2005

Negatable Marker Annotations

Eamonn has posted a very interesting blog entry on negatable annotations.

In the last part of the post, he suggests that such a marker annotation can be used to annotate an MBean-like interface to say that it really is (or not) an MBean interface.

Such a marker annotation should be meta-annotated with @Inherited, since it would be inherited, but unfortunately @Inherited only works if the annotation annotates a class, not an interface.

I wonder if Eamonn meant to annotate the class, more or less this way:


@Inherited
public @interface MBean
{
boolean value() default true;
}

@MBean
public class BaseService
{
...
}

@MBean(false)
public class DerivedService extends BaseService
{
...
}

In plain JMX, it would be impossible for the MBeanServer to avoid to register DerivedService as MBean.
But a negatable marker annotation enabled MBeanServer can avoid the registration following Eamonn's suggestion:

Class c = mbean.getClass();
MBean ann = c.getAnnotation(MBean.class);
boolean isMBean = (ann != null && ann.value());

0 Comments:

Post a Comment

<< Home