List of usage examples for javax.imageio.metadata IIOMetadataFormatImpl getStandardFormatInstance
public static IIOMetadataFormat getStandardFormatInstance()
From source file:Main.java
public static IIOMetadataFormat instantiateMetadataFormat(String formatName, boolean standardFormatSupported, String nativeMetadataFormatName, String nativeMetadataFormatClassName, String[] extraMetadataFormatNames, String[] extraMetadataFormatClassNames) { if (formatName == null) { throw new IllegalArgumentException("formatName == null!"); }//from w w w . j a v a 2s . c o m if (formatName.equals(IIOMetadataFormatImpl.standardMetadataFormatName)) { if (standardFormatSupported) { return IIOMetadataFormatImpl.getStandardFormatInstance(); } } String className = null; if (formatName.equals(nativeMetadataFormatName)) { className = nativeMetadataFormatClassName; } else if (extraMetadataFormatNames != null) { for (int i = 0; i < extraMetadataFormatNames.length; i++) { if (formatName.equals(extraMetadataFormatNames[i])) { className = extraMetadataFormatClassNames[i]; break; } } } if (className == null) { throw new IllegalArgumentException("Unsupported format name"); } // Get the context class loader and try to use it first ClassLoader contextClassloader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); } }); Class cls; try { cls = Class.forName(className, true, contextClassloader); } catch (ClassNotFoundException e) { try { // Use current class loader cls = Class.forName(className); } catch (ClassNotFoundException e1) { throw new IllegalStateException("Can't obtain format"); } } try { //???AWT: //Method getInstance = cls.getMethod("getInstance"); //return (IIOMetadataFormat) getInstance.invoke(null); return null; } catch (Exception e) { IllegalStateException e1 = new IllegalStateException("Can't obtain format"); e1.initCause(e); // Add some details to the message throw e1; } }