0N/A/*
2362N/A * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.imageio.spi;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.lang.reflect.Constructor;
0N/Aimport java.lang.reflect.Method;
0N/Aimport java.util.Arrays;
0N/Aimport java.util.Iterator;
0N/Aimport javax.imageio.ImageReader;
0N/Aimport javax.imageio.metadata.IIOMetadata;
0N/Aimport javax.imageio.metadata.IIOMetadataFormat;
0N/Aimport javax.imageio.metadata.IIOMetadataFormatImpl;
0N/Aimport javax.imageio.stream.ImageInputStream;
0N/A
0N/A/**
0N/A * A superclass containing instance variables and methods common to
0N/A * <code>ImageReaderSpi</code> and <code>ImageWriterSpi</code>.
0N/A *
0N/A * @see IIORegistry
0N/A * @see ImageReaderSpi
0N/A * @see ImageWriterSpi
0N/A *
0N/A */
0N/Apublic abstract class ImageReaderWriterSpi extends IIOServiceProvider {
0N/A
0N/A /**
0N/A * An array of strings to be returned from
0N/A * <code>getFormatNames</code>, initially <code>null</code>.
0N/A * Constructors should set this to a non-<code>null</code> value.
0N/A */
0N/A protected String[] names = null;
0N/A
0N/A /**
0N/A * An array of strings to be returned from
0N/A * <code>getFileSuffixes</code>, initially <code>null</code>.
0N/A */
0N/A protected String[] suffixes = null;
0N/A
0N/A /**
0N/A * An array of strings to be returned from
0N/A * <code>getMIMETypes</code>, initially <code>null</code>.
0N/A */
0N/A protected String[] MIMETypes = null;
0N/A
0N/A /**
0N/A * A <code>String</code> containing the name of the associated
0N/A * plug-in class, initially <code>null</code>.
0N/A */
0N/A protected String pluginClassName = null;
0N/A
0N/A /**
0N/A * A boolean indicating whether this plug-in supports the
0N/A * standard metadata format for stream metadata, initially
0N/A * <code>false</code>.
0N/A */
0N/A protected boolean supportsStandardStreamMetadataFormat = false;
0N/A
0N/A /**
0N/A * A <code>String</code> containing the name of the native stream
0N/A * metadata format supported by this plug-in, initially
0N/A * <code>null</code>.
0N/A */
0N/A protected String nativeStreamMetadataFormatName = null;
0N/A
0N/A /**
0N/A * A <code>String</code> containing the class name of the native
0N/A * stream metadata format supported by this plug-in, initially
0N/A * <code>null</code>.
0N/A */
0N/A protected String nativeStreamMetadataFormatClassName = null;
0N/A
0N/A /**
0N/A * An array of <code>String</code>s containing the names of any
0N/A * additional stream metadata formats supported by this plug-in,
0N/A * initially <code>null</code>.
0N/A */
0N/A protected String[] extraStreamMetadataFormatNames = null;
0N/A
0N/A /**
0N/A * An array of <code>String</code>s containing the class names of
0N/A * any additional stream metadata formats supported by this plug-in,
0N/A * initially <code>null</code>.
0N/A */
0N/A protected String[] extraStreamMetadataFormatClassNames = null;
0N/A
0N/A /**
0N/A * A boolean indicating whether this plug-in supports the
0N/A * standard metadata format for image metadata, initially
0N/A * <code>false</code>.
0N/A */
0N/A protected boolean supportsStandardImageMetadataFormat = false;
0N/A
0N/A /**
0N/A * A <code>String</code> containing the name of the
0N/A * native stream metadata format supported by this plug-in,
0N/A * initially <code>null</code>.
0N/A */
0N/A protected String nativeImageMetadataFormatName = null;
0N/A
0N/A /**
0N/A * A <code>String</code> containing the class name of the
0N/A * native stream metadata format supported by this plug-in,
0N/A * initially <code>null</code>.
0N/A */
0N/A protected String nativeImageMetadataFormatClassName = null;
0N/A
0N/A /**
0N/A * An array of <code>String</code>s containing the names of any
0N/A * additional image metadata formats supported by this plug-in,
0N/A * initially <code>null</code>.
0N/A */
0N/A protected String[] extraImageMetadataFormatNames = null;
0N/A
0N/A /**
0N/A * An array of <code>String</code>s containing the class names of
0N/A * any additional image metadata formats supported by this
0N/A * plug-in, initially <code>null</code>.
0N/A */
0N/A protected String[] extraImageMetadataFormatClassNames = null;
0N/A
0N/A /**
0N/A * Constructs an <code>ImageReaderWriterSpi</code> with a given
0N/A * set of values.
0N/A *
0N/A * @param vendorName the vendor name, as a non-<code>null</code>
0N/A * <code>String</code>.
0N/A * @param version a version identifier, as a non-<code>null</code>
0N/A * <code>String</code>.
0N/A * @param names a non-<code>null</code> array of
0N/A * <code>String</code>s indicating the format names. At least one
0N/A * entry must be present.
0N/A * @param suffixes an array of <code>String</code>s indicating the
0N/A * common file suffixes. If no suffixes are defined,
0N/A * <code>null</code> should be supplied. An array of length 0
0N/A * will be normalized to <code>null</code>.
0N/A * @param MIMETypes an array of <code>String</code>s indicating
0N/A * the format's MIME types. If no MIME types are defined,
0N/A * <code>null</code> should be supplied. An array of length 0
0N/A * will be normalized to <code>null</code>.
0N/A * @param pluginClassName the fully-qualified name of the
0N/A * associated <code>ImageReader</code> or <code>ImageWriter</code>
0N/A * class, as a non-<code>null</code> <code>String</code>.
0N/A * @param supportsStandardStreamMetadataFormat a
0N/A * <code>boolean</code> that indicates whether a stream metadata
0N/A * object can use trees described by the standard metadata format.
0N/A * @param nativeStreamMetadataFormatName a
0N/A * <code>String</code>, or <code>null</code>, to be returned from
0N/A * <code>getNativeStreamMetadataFormatName</code>.
0N/A * @param nativeStreamMetadataFormatClassName a
0N/A * <code>String</code>, or <code>null</code>, to be used to instantiate
0N/A * a metadata format object to be returned from
0N/A * <code>getNativeStreamMetadataFormat</code>.
0N/A * @param extraStreamMetadataFormatNames an array of
0N/A * <code>String</code>s, or <code>null</code>, to be returned from
0N/A * <code>getExtraStreamMetadataFormatNames</code>. An array of length
0N/A * 0 is normalized to <code>null</code>.
0N/A * @param extraStreamMetadataFormatClassNames an array of
0N/A * <code>String</code>s, or <code>null</code>, to be used to instantiate
0N/A * a metadata format object to be returned from
0N/A * <code>getStreamMetadataFormat</code>. An array of length
0N/A * 0 is normalized to <code>null</code>.
0N/A * @param supportsStandardImageMetadataFormat a
0N/A * <code>boolean</code> that indicates whether an image metadata
0N/A * object can use trees described by the standard metadata format.
0N/A * @param nativeImageMetadataFormatName a
0N/A * <code>String</code>, or <code>null</code>, to be returned from
0N/A * <code>getNativeImageMetadataFormatName</code>.
0N/A * @param nativeImageMetadataFormatClassName a
0N/A * <code>String</code>, or <code>null</code>, to be used to instantiate
0N/A * a metadata format object to be returned from
0N/A * <code>getNativeImageMetadataFormat</code>.
0N/A * @param extraImageMetadataFormatNames an array of
0N/A * <code>String</code>s to be returned from
0N/A * <code>getExtraImageMetadataFormatNames</code>. An array of length 0
0N/A * is normalized to <code>null</code>.
0N/A * @param extraImageMetadataFormatClassNames an array of
0N/A * <code>String</code>s, or <code>null</code>, to be used to instantiate
0N/A * a metadata format object to be returned from
0N/A * <code>getImageMetadataFormat</code>. An array of length
0N/A * 0 is normalized to <code>null</code>.
0N/A *
0N/A * @exception IllegalArgumentException if <code>vendorName</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>version</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>names</code>
0N/A * is <code>null</code> or has length 0.
0N/A * @exception IllegalArgumentException if <code>pluginClassName</code>
0N/A * is <code>null</code>.
0N/A */
0N/A public ImageReaderWriterSpi(String vendorName,
0N/A String version,
0N/A String[] names,
0N/A String[] suffixes,
0N/A String[] MIMETypes,
0N/A String pluginClassName,
0N/A boolean supportsStandardStreamMetadataFormat,
0N/A String nativeStreamMetadataFormatName,
0N/A String nativeStreamMetadataFormatClassName,
0N/A String[] extraStreamMetadataFormatNames,
0N/A String[] extraStreamMetadataFormatClassNames,
0N/A boolean supportsStandardImageMetadataFormat,
0N/A String nativeImageMetadataFormatName,
0N/A String nativeImageMetadataFormatClassName,
0N/A String[] extraImageMetadataFormatNames,
0N/A String[] extraImageMetadataFormatClassNames) {
0N/A super(vendorName, version);
0N/A if (names == null) {
0N/A throw new IllegalArgumentException("names == null!");
0N/A }
0N/A if (names.length == 0) {
0N/A throw new IllegalArgumentException("names.length == 0!");
0N/A }
0N/A if (pluginClassName == null) {
0N/A throw new IllegalArgumentException("pluginClassName == null!");
0N/A }
0N/A
0N/A this.names = (String[])names.clone();
0N/A // If length == 0, leave it null
0N/A if (suffixes != null && suffixes.length > 0) {
0N/A this.suffixes = (String[])suffixes.clone();
0N/A }
0N/A // If length == 0, leave it null
0N/A if (MIMETypes != null && MIMETypes.length > 0) {
0N/A this.MIMETypes = (String[])MIMETypes.clone();
0N/A }
0N/A this.pluginClassName = pluginClassName;
0N/A
0N/A this.supportsStandardStreamMetadataFormat =
0N/A supportsStandardStreamMetadataFormat;
0N/A this.nativeStreamMetadataFormatName = nativeStreamMetadataFormatName;
0N/A this.nativeStreamMetadataFormatClassName =
0N/A nativeStreamMetadataFormatClassName;
0N/A // If length == 0, leave it null
0N/A if (extraStreamMetadataFormatNames != null &&
0N/A extraStreamMetadataFormatNames.length > 0) {
0N/A this.extraStreamMetadataFormatNames =
0N/A (String[])extraStreamMetadataFormatNames.clone();
0N/A }
0N/A // If length == 0, leave it null
0N/A if (extraStreamMetadataFormatClassNames != null &&
0N/A extraStreamMetadataFormatClassNames.length > 0) {
0N/A this.extraStreamMetadataFormatClassNames =
0N/A (String[])extraStreamMetadataFormatClassNames.clone();
0N/A }
0N/A this.supportsStandardImageMetadataFormat =
0N/A supportsStandardImageMetadataFormat;
0N/A this.nativeImageMetadataFormatName = nativeImageMetadataFormatName;
0N/A this.nativeImageMetadataFormatClassName =
0N/A nativeImageMetadataFormatClassName;
0N/A // If length == 0, leave it null
0N/A if (extraImageMetadataFormatNames != null &&
0N/A extraImageMetadataFormatNames.length > 0) {
0N/A this.extraImageMetadataFormatNames =
0N/A (String[])extraImageMetadataFormatNames.clone();
0N/A }
0N/A // If length == 0, leave it null
0N/A if (extraImageMetadataFormatClassNames != null &&
0N/A extraImageMetadataFormatClassNames.length > 0) {
0N/A this.extraImageMetadataFormatClassNames =
0N/A (String[])extraImageMetadataFormatClassNames.clone();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Constructs a blank <code>ImageReaderWriterSpi</code>. It is up
0N/A * to the subclass to initialize instance variables and/or
0N/A * override method implementations in order to provide working
0N/A * versions of all methods.
0N/A */
0N/A public ImageReaderWriterSpi() {
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of <code>String</code>s containing
0N/A * human-readable names for the formats that are generally usable
0N/A * by the <code>ImageReader</code> or <code>ImageWriter</code>
0N/A * implementation associated with this service provider. For
0N/A * example, a single <code>ImageReader</code> might be able to
0N/A * process both PBM and PNM files.
0N/A *
0N/A * @return a non-<code>null</code> array of <code>String</code>s
0N/A * or length at least 1 containing informal format names
0N/A * associated with this reader or writer.
0N/A */
0N/A public String[] getFormatNames() {
0N/A return (String[])names.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of <code>String</code>s containing a list of
0N/A * file suffixes associated with the formats that are generally
0N/A * usable by the <code>ImageReader</code> or
0N/A * <code>ImageWriter</code> implementation associated with this
0N/A * service provider. For example, a single
0N/A * <code>ImageReader</code> might be able to process files with
0N/A * '.pbm' and '.pnm' suffixes, or both '.jpg' and '.jpeg'
0N/A * suffixes. If there are no known file suffixes,
0N/A * <code>null</code> will be returned.
0N/A *
0N/A * <p> Returning a particular suffix does not guarantee that files
0N/A * with that suffix can be processed; it merely indicates that it
0N/A * may be worthwhile attempting to decode or encode such files
0N/A * using this service provider.
0N/A *
0N/A * @return an array of <code>String</code>s or length at least 1
0N/A * containing common file suffixes associated with this reader or
0N/A * writer, or <code>null</code>.
0N/A */
0N/A public String[] getFileSuffixes() {
0N/A return suffixes == null ? null : (String[])suffixes.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of <code>String</code>s containing a list of
0N/A * MIME types associated with the formats that are generally
0N/A * usable by the <code>ImageReader</code> or
0N/A * <code>ImageWriter</code> implementation associated with this
0N/A * service provider.
0N/A *
0N/A * <p> Ideally, only a single MIME type would be required in order
0N/A * to describe a particular format. However, for several reasons
0N/A * it is necessary to associate a list of types with each service
0N/A * provider. First, many common image file formats do not have
0N/A * standard MIME types, so a list of commonly used unofficial
0N/A * names will be required, such as <code>image/x-pbm</code> and
0N/A * <code>image/x-portable-bitmap</code>. Some file formats have
0N/A * official MIME types but may sometimes be referred to using
0N/A * their previous unofficial designations, such as
0N/A * <code>image/x-png</code> instead of the official
0N/A * <code>image/png</code>. Finally, a single service provider may
0N/A * be capable of parsing multiple distinct types from the MIME
0N/A * point of view, for example <code>image/x-xbitmap</code> and
0N/A * <code>image/x-xpixmap</code>.
0N/A *
0N/A * <p> Returning a particular MIME type does not guarantee that
0N/A * files claiming to be of that type can be processed; it merely
0N/A * indicates that it may be worthwhile attempting to decode or
0N/A * encode such files using this service provider.
0N/A *
0N/A * @return an array of <code>String</code>s or length at least 1
0N/A * containing MIME types associated with this reader or writer, or
0N/A * <code>null</code>.
0N/A */
0N/A public String[] getMIMETypes() {
0N/A return MIMETypes == null ? null : (String[])MIMETypes.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns the fully-qualified class name of the
0N/A * <code>ImageReader</code> or <code>ImageWriter</code> plug-in
0N/A * associated with this service provider.
0N/A *
0N/A * @return the class name, as a non-<code>null</code>
0N/A * <code>String</code>.
0N/A */
0N/A public String getPluginClassName() {
0N/A return pluginClassName;
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the standard metadata format is
0N/A * among the document formats recognized by the
0N/A * <code>getAsTree</code> and <code>setFromTree</code> methods on
0N/A * the stream metadata objects produced or consumed by this
0N/A * plug-in.
0N/A *
0N/A * @return <code>true</code> if the standard format is supported
0N/A * for stream metadata.
0N/A */
0N/A public boolean isStandardStreamMetadataFormatSupported() {
0N/A return supportsStandardStreamMetadataFormat;
0N/A }
0N/A
0N/A /**
0N/A * Returns the name of the "native" stream metadata format for
0N/A * this plug-in, which typically allows for lossless encoding and
0N/A * transmission of the stream metadata stored in the format handled by
0N/A * this plug-in. If no such format is supported,
0N/A * <code>null</code>will be returned.
0N/A *
0N/A * <p> The default implementation returns the
0N/A * <code>nativeStreamMetadataFormatName</code> instance variable,
0N/A * which is typically set by the constructor.
0N/A *
0N/A * @return the name of the native stream metadata format, or
0N/A * <code>null</code>.
0N/A *
0N/A */
0N/A public String getNativeStreamMetadataFormatName() {
0N/A return nativeStreamMetadataFormatName;
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of <code>String</code>s containing the names
0N/A * of additional document formats, other than the native and
0N/A * standard formats, recognized by the
0N/A * <code>getAsTree</code> and <code>setFromTree</code> methods on
0N/A * the stream metadata objects produced or consumed by this
0N/A * plug-in.
0N/A *
0N/A * <p> If the plug-in does not handle metadata, null should be
0N/A * returned.
0N/A *
0N/A * <p> The set of formats may differ according to the particular
0N/A * images being read or written; this method should indicate all
0N/A * the additional formats supported by the plug-in under any
0N/A * circumstances.
0N/A *
0N/A * <p> The default implementation returns a clone of the
0N/A * <code>extraStreamMetadataFormatNames</code> instance variable,
0N/A * which is typically set by the constructor.
0N/A *
0N/A * @return an array of <code>String</code>s, or null.
0N/A *
0N/A * @see IIOMetadata#getMetadataFormatNames
0N/A * @see #getExtraImageMetadataFormatNames
0N/A * @see #getNativeStreamMetadataFormatName
0N/A */
0N/A public String[] getExtraStreamMetadataFormatNames() {
0N/A return extraStreamMetadataFormatNames == null ?
0N/A null : (String[])extraStreamMetadataFormatNames.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the standard metadata format is
0N/A * among the document formats recognized by the
0N/A * <code>getAsTree</code> and <code>setFromTree</code> methods on
0N/A * the image metadata objects produced or consumed by this
0N/A * plug-in.
0N/A *
0N/A * @return <code>true</code> if the standard format is supported
0N/A * for image metadata.
0N/A */
0N/A public boolean isStandardImageMetadataFormatSupported() {
0N/A return supportsStandardImageMetadataFormat;
0N/A }
0N/A
0N/A /**
0N/A * Returns the name of the "native" image metadata format for
0N/A * this plug-in, which typically allows for lossless encoding and
0N/A * transmission of the image metadata stored in the format handled by
0N/A * this plug-in. If no such format is supported,
0N/A * <code>null</code>will be returned.
0N/A *
0N/A * <p> The default implementation returns the
0N/A * <code>nativeImageMetadataFormatName</code> instance variable,
0N/A * which is typically set by the constructor.
0N/A *
0N/A * @return the name of the native image metadata format, or
0N/A * <code>null</code>.
0N/A *
0N/A * @see #getExtraImageMetadataFormatNames
0N/A */
0N/A public String getNativeImageMetadataFormatName() {
0N/A return nativeImageMetadataFormatName;
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of <code>String</code>s containing the names
0N/A * of additional document formats, other than the native and
0N/A * standard formats, recognized by the
0N/A * <code>getAsTree</code> and <code>setFromTree</code> methods on
0N/A * the image metadata objects produced or consumed by this
0N/A * plug-in.
0N/A *
0N/A * <p> If the plug-in does not handle image metadata, null should
0N/A * be returned.
0N/A *
0N/A * <p> The set of formats may differ according to the particular
0N/A * images being read or written; this method should indicate all
0N/A * the additional formats supported by the plug-in under any circumstances.
0N/A *
0N/A * <p> The default implementation returns a clone of the
0N/A * <code>extraImageMetadataFormatNames</code> instance variable,
0N/A * which is typically set by the constructor.
0N/A *
0N/A * @return an array of <code>String</code>s, or null.
0N/A *
0N/A * @see IIOMetadata#getMetadataFormatNames
0N/A * @see #getExtraStreamMetadataFormatNames
0N/A * @see #getNativeImageMetadataFormatName
0N/A */
0N/A public String[] getExtraImageMetadataFormatNames() {
0N/A return extraImageMetadataFormatNames == null ?
0N/A null : (String[])extraImageMetadataFormatNames.clone();
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>IIOMetadataFormat</code> object describing the
0N/A * given stream metadata format, or <code>null</code> if no
0N/A * description is available. The supplied name must be the native
0N/A * stream metadata format name, the standard metadata format name,
0N/A * or one of those returned by
0N/A * <code>getExtraStreamMetadataFormatNames</code>.
0N/A *
0N/A * @param formatName the desired stream metadata format.
0N/A *
0N/A * @return an <code>IIOMetadataFormat</code> object.
0N/A *
0N/A * @exception IllegalArgumentException if <code>formatName</code>
0N/A * is <code>null</code> or is not a supported name.
0N/A */
0N/A public IIOMetadataFormat getStreamMetadataFormat(String formatName) {
0N/A return getMetadataFormat(formatName,
0N/A supportsStandardStreamMetadataFormat,
0N/A nativeStreamMetadataFormatName,
0N/A nativeStreamMetadataFormatClassName,
0N/A extraStreamMetadataFormatNames,
0N/A extraStreamMetadataFormatClassNames);
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>IIOMetadataFormat</code> object describing the
0N/A * given image metadata format, or <code>null</code> if no
0N/A * description is available. The supplied name must be the native
0N/A * iamge metadata format name, the standard metadata format name,
0N/A * or one of those returned by
0N/A * <code>getExtraImageMetadataFormatNames</code>.
0N/A *
0N/A * @param formatName the desired image metadata format.
0N/A *
0N/A * @return an <code>IIOMetadataFormat</code> object.
0N/A *
0N/A * @exception IllegalArgumentException if <code>formatName</code>
0N/A * is <code>null</code> or is not a supported name.
0N/A */
0N/A public IIOMetadataFormat getImageMetadataFormat(String formatName) {
0N/A return getMetadataFormat(formatName,
0N/A supportsStandardImageMetadataFormat,
0N/A nativeImageMetadataFormatName,
0N/A nativeImageMetadataFormatClassName,
0N/A extraImageMetadataFormatNames,
0N/A extraImageMetadataFormatClassNames);
0N/A }
0N/A
0N/A private IIOMetadataFormat getMetadataFormat(String formatName,
0N/A boolean supportsStandard,
0N/A String nativeName,
0N/A String nativeClassName,
0N/A String [] extraNames,
0N/A String [] extraClassNames) {
0N/A if (formatName == null) {
0N/A throw new IllegalArgumentException("formatName == null!");
0N/A }
0N/A if (supportsStandard && formatName.equals
0N/A (IIOMetadataFormatImpl.standardMetadataFormatName)) {
0N/A
0N/A return IIOMetadataFormatImpl.getStandardFormatInstance();
0N/A }
0N/A String formatClassName = null;
0N/A if (formatName.equals(nativeName)) {
0N/A formatClassName = nativeClassName;
0N/A } else if (extraNames != null) {
0N/A for (int i = 0; i < extraNames.length; i++) {
0N/A if (formatName.equals(extraNames[i])) {
0N/A formatClassName = extraClassNames[i];
0N/A break; // out of for
0N/A }
0N/A }
0N/A }
0N/A if (formatClassName == null) {
0N/A throw new IllegalArgumentException("Unsupported format name");
0N/A }
0N/A try {
0N/A Class cls = Class.forName(formatClassName, true,
0N/A ClassLoader.getSystemClassLoader());
0N/A Method meth = cls.getMethod("getInstance");
0N/A return (IIOMetadataFormat) meth.invoke(null);
0N/A } catch (Exception e) {
0N/A RuntimeException ex =
0N/A new IllegalStateException ("Can't obtain format");
0N/A ex.initCause(e);
0N/A throw ex;
0N/A }
0N/A }
0N/A}