AptControlInterface mostDerived = (AptControlInterface) getMostDerivedInterface();
if ( mostDerived == null )
return;
InterfaceDeclaration intfDecl = mostDerived._intfDecl;
if ( intfDecl == null )
return;
AnnotationMirror controlMirror = null;
for (AnnotationMirror annot : intfDecl.getAnnotationMirrors())
{
if (annot.getAnnotationType().getDeclaration().getQualifiedName().equals(
"org.apache.beehive.controls.api.bean.ControlInterface"))
{
controlMirror = annot;
break;
}
}
assert ( controlMirror != null ) : "Found a control interface that isn't annotated properly: " + intfDecl;
AptAnnotationHelper controlAnnot = new AptAnnotationHelper(controlMirror);
//
// Read the name of the checker class from the @ControlInterface annotation,
// dynamically load and run it.
//
DeclaredType checkerMirror = (DeclaredType)controlAnnot.getObjectValue("checker");
if ( checkerMirror == null )
{
// try the deprecated 'checkerClass' attribute
checkerMirror = (DeclaredType)controlAnnot.getObjectValue("checkerClass");
}
if ( checkerMirror != null && checkerMirror.getDeclaration() != null )
{
// TODO: optimize to not invoke default checker?
String checkerName = checkerMirror.toString();
try
{
ClassLoader loader = getExternalClassLoader();
Class checkerClass = loader.loadClass( checkerName );
if ( !ControlChecker.class.isAssignableFrom(checkerClass) )
{
_ap.printError( intfDecl, "control.interface.illegal.checker", intfDecl.getSimpleName(), checkerName );
}
else
{
Constructor ctor = checkerClass.getConstructor();
ControlChecker checker = (ControlChecker) ctor.newInstance();
CheckerAnnotationProcessorEnvironmentImpl ape =
new CheckerAnnotationProcessorEnvironmentImpl(_ap);
checker.check( _intfDecl, ape );
}
}
catch ( Exception e ) {
_ap.printError( intfDecl, "control.interface.checker.load.failed", intfDecl.getSimpleName(), checkerName );
}
}
}