BitmapEncoderRegistry { private static synchronized void register(String classname, int priority, boolean complain) { Throwable error = null; try { final Class<?> clazz = Class.forName(classname); final BitmapEncoder encoder = (BitmapEncoder) clazz.newInstance(); encoders.add(new Entry(encoder, priority)); } catch (ClassNotFoundException e) { error = e; } catch (InstantiationException e) { error = e; } catch (IllegalAccessException e) { error = e; } if (error != null && complain) { throw new IllegalArgumentException( "The implementation being registered is unavailable or " + "cannot be instantiated: " + classname, error); } } private  BitmapEncoderRegistry(); static void register(String classname, int priority); static boolean supports(BitmapEncoder encoder, String mime); static boolean supports(String mime); static BitmapEncoder getInstance(String mime); static Set<String> getSupportedMIMETypes();  }
@Test public void testRegister() { System.out.println("register"); String classname = ImageIOBitmapEncoder.class.getName(); int priority = 42; BitmapEncoderRegistry.register(classname, priority); assertNotNull("image/png is supported by given provider", BitmapEncoderRegistry.getInstance("image/png")); try { BitmapEncoderRegistry.register("foobar." + classname, 1); fail("registering should be not possible"); } catch (IllegalArgumentException e) { } }