// unload everything that JAI can still refer to
final OperationRegistry opRegistry = JAI.getDefaultInstance().getOperationRegistry();
for(String mode : RegistryMode.getModeNames()) {
for (Iterator descriptors = opRegistry.getDescriptors(mode).iterator(); descriptors != null && descriptors.hasNext();) {
RegistryElementDescriptor red = (RegistryElementDescriptor) descriptors.next();
int factoryCount = 0;
int unregisteredCount = 0;
// look for all the factories for that operation
for (Iterator factories = opRegistry.getFactoryIterator(mode, red.getName()); factories != null && factories.hasNext();) {
Object factory = factories.next();
if(factory == null) {
continue;
}
factoryCount++;
if(webappClassLoader.equals(factory.getClass().getClassLoader())) {
boolean unregistered = false;
// we need to scan against all "products" to unregister the factory
Vector orderedProductList = opRegistry.getOrderedProductList(mode, red.getName());
if(orderedProductList != null) {
for(Iterator products = orderedProductList.iterator(); products != null && products.hasNext();) {
String product = (String) products.next();
try {
opRegistry.unregisterFactory(mode, red.getName(), product, factory);
LOGGER.info("Unregistering JAI factory " + factory.getClass());
} catch(Throwable t) {
// may fail due to the factory not being registered against that product
}
}