final Class<?> type = droneInstance.getDroneType();
final Class<? extends Annotation> qualifier = droneInstance.getQualifier();
for (Sortable candidate : enhancers) {
if (candidate instanceof DroneInstanceEnhancer) {
DroneInstanceEnhancer enhancer = (DroneInstanceEnhancer) candidate;
if (enhancer.canEnhance(browser, type, qualifier)) {
log.log(Level.FINE,
"Deenhancing {0} @{1} using enhancer {2} with precedence {3}",
new Object[] { type.getSimpleName(), qualifier.getSimpleName(), enhancer.getClass().getName(),
enhancer.getPrecedence() });
droneEnhancementEvent.fire(new BeforeDroneDeenhanced(enhancer, browser, type, qualifier));
Object newBrowser = enhancer.deenhance(browser.asInstance(type), qualifier);
browser.set(newBrowser);
droneEnhancementEvent.fire(new AfterDroneDeenhanced(browser, type, qualifier));
}
}
else if (candidate instanceof Enhancer) {
Enhancer enhancer = (Enhancer) candidate;
if (enhancer.canEnhance(type, qualifier)) {
log.log(Level.WARNING,
"Deprecated Enhancer type, please implement DroneInstanceEnhancer instead. Deenhancing {0} @{1} using enhancer {2} with precedence {3}",
new Object[] { type.getSimpleName(), qualifier.getSimpleName(), enhancer.getClass().getName(),
enhancer.getPrecedence() });
droneEnhancementEvent.fire(new BeforeDroneDeenhanced(new DeprecatedEnhancerWrap(enhancer), browser, type,
qualifier));
Object newBrowser = enhancer.deenhance(browser.asInstance(type), qualifier);
browser.set(newBrowser);
droneEnhancementEvent.fire(new AfterDroneDeenhanced(browser, type, qualifier));
}
}