Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/imageio/metadata/IIOMetadata.java
38918 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.imageio.metadata;2627import org.w3c.dom.Node;28import java.lang.reflect.Method;2930/**31* An abstract class to be extended by objects that represent metadata32* (non-image data) associated with images and streams. Plug-ins33* represent metadata using opaque, plug-in specific objects. These34* objects, however, provide the ability to access their internal35* information as a tree of <code>IIOMetadataNode</code> objects that36* support the XML DOM interfaces as well as additional interfaces for37* storing non-textual data and retrieving information about legal38* data values. The format of such trees is plug-in dependent, but39* plug-ins may choose to support a plug-in neutral format described40* below. A single plug-in may support multiple metadata formats,41* whose names maybe determined by calling42* <code>getMetadataFormatNames</code>. The plug-in may also support43* a single special format, referred to as the "native" format, which44* is designed to encode its metadata losslessly. This format will45* typically be designed specifically to work with a specific file46* format, so that images may be loaded and saved in the same format47* with no loss of metadata, but may be less useful for transferring48* metadata between an <code>ImageReader</code> and an49* <code>ImageWriter</code> for different image formats. To convert50* between two native formats as losslessly as the image file formats51* will allow, an <code>ImageTranscoder</code> object must be used.52*53* @see javax.imageio.ImageReader#getImageMetadata54* @see javax.imageio.ImageReader#getStreamMetadata55* @see javax.imageio.ImageReader#readAll56* @see javax.imageio.ImageWriter#getDefaultStreamMetadata57* @see javax.imageio.ImageWriter#getDefaultImageMetadata58* @see javax.imageio.ImageWriter#write59* @see javax.imageio.ImageWriter#convertImageMetadata60* @see javax.imageio.ImageWriter#convertStreamMetadata61* @see javax.imageio.IIOImage62* @see javax.imageio.ImageTranscoder63*64*/65public abstract class IIOMetadata {6667/**68* A boolean indicating whether the concrete subclass supports the69* standard metadata format, set via the constructor.70*/71protected boolean standardFormatSupported;7273/**74* The name of the native metadata format for this object,75* initialized to <code>null</code> and set via the constructor.76*/77protected String nativeMetadataFormatName = null;7879/**80* The name of the class implementing <code>IIOMetadataFormat</code>81* and representing the native metadata format, initialized to82* <code>null</code> and set via the constructor.83*/84protected String nativeMetadataFormatClassName = null;8586/**87* An array of names of formats, other than the standard and88* native formats, that are supported by this plug-in,89* initialized to <code>null</code> and set via the constructor.90*/91protected String[] extraMetadataFormatNames = null;9293/**94* An array of names of classes implementing <code>IIOMetadataFormat</code>95* and representing the metadata formats, other than the standard and96* native formats, that are supported by this plug-in,97* initialized to <code>null</code> and set via the constructor.98*/99protected String[] extraMetadataFormatClassNames = null;100101/**102* An <code>IIOMetadataController</code> that is suggested for use103* as the controller for this <code>IIOMetadata</code> object. It104* may be retrieved via <code>getDefaultController</code>. To105* install the default controller, call106* <code>setController(getDefaultController())</code>. This107* instance variable should be set by subclasses that choose to108* provide their own default controller, usually a GUI, for109* setting parameters.110*111* @see IIOMetadataController112* @see #getDefaultController113*/114protected IIOMetadataController defaultController = null;115116/**117* The <code>IIOMetadataController</code> that will be118* used to provide settings for this <code>IIOMetadata</code>119* object when the <code>activateController</code> method120* is called. This value overrides any default controller,121* even when <code>null</code>.122*123* @see IIOMetadataController124* @see #setController(IIOMetadataController)125* @see #hasController()126* @see #activateController()127*/128protected IIOMetadataController controller = null;129130/**131* Constructs an empty <code>IIOMetadata</code> object. The132* subclass is responsible for supplying values for all protected133* instance variables that will allow any non-overridden default134* implementations of methods to satisfy their contracts. For example,135* <code>extraMetadataFormatNames</code> should not have length 0.136*/137protected IIOMetadata() {}138139/**140* Constructs an <code>IIOMetadata</code> object with the given141* format names and format class names, as well as a boolean142* indicating whether the standard format is supported.143*144* <p> This constructor does not attempt to check the class names145* for validity. Invalid class names may cause exceptions in146* subsequent calls to <code>getMetadataFormat</code>.147*148* @param standardMetadataFormatSupported <code>true</code> if149* this object can return or accept a DOM tree using the standard150* metadata format.151* @param nativeMetadataFormatName the name of the native metadata152* format, as a <code>String</code>, or <code>null</code> if there153* is no native format.154* @param nativeMetadataFormatClassName the name of the class of155* the native metadata format, or <code>null</code> if there is156* no native format.157* @param extraMetadataFormatNames an array of <code>String</code>s158* indicating additional formats supported by this object, or159* <code>null</code> if there are none.160* @param extraMetadataFormatClassNames an array of <code>String</code>s161* indicating the class names of any additional formats supported by162* this object, or <code>null</code> if there are none.163*164* @exception IllegalArgumentException if165* <code>extraMetadataFormatNames</code> has length 0.166* @exception IllegalArgumentException if167* <code>extraMetadataFormatNames</code> and168* <code>extraMetadataFormatClassNames</code> are neither both169* <code>null</code>, nor of the same length.170*/171protected IIOMetadata(boolean standardMetadataFormatSupported,172String nativeMetadataFormatName,173String nativeMetadataFormatClassName,174String[] extraMetadataFormatNames,175String[] extraMetadataFormatClassNames) {176this.standardFormatSupported = standardMetadataFormatSupported;177this.nativeMetadataFormatName = nativeMetadataFormatName;178this.nativeMetadataFormatClassName = nativeMetadataFormatClassName;179if (extraMetadataFormatNames != null) {180if (extraMetadataFormatNames.length == 0) {181throw new IllegalArgumentException182("extraMetadataFormatNames.length == 0!");183}184if (extraMetadataFormatClassNames == null) {185throw new IllegalArgumentException186("extraMetadataFormatNames != null && extraMetadataFormatClassNames == null!");187}188if (extraMetadataFormatClassNames.length !=189extraMetadataFormatNames.length) {190throw new IllegalArgumentException191("extraMetadataFormatClassNames.length != extraMetadataFormatNames.length!");192}193this.extraMetadataFormatNames =194(String[]) extraMetadataFormatNames.clone();195this.extraMetadataFormatClassNames =196(String[]) extraMetadataFormatClassNames.clone();197} else {198if (extraMetadataFormatClassNames != null) {199throw new IllegalArgumentException200("extraMetadataFormatNames == null && extraMetadataFormatClassNames != null!");201}202}203}204205/**206* Returns <code>true</code> if the standard metadata format is207* supported by <code>getMetadataFormat</code>,208* <code>getAsTree</code>, <code>setFromTree</code>, and209* <code>mergeTree</code>.210*211* <p> The default implementation returns the value of the212* <code>standardFormatSupported</code> instance variable.213*214* @return <code>true</code> if the standard metadata format215* is supported.216*217* @see #getAsTree218* @see #setFromTree219* @see #mergeTree220* @see #getMetadataFormat221*/222public boolean isStandardMetadataFormatSupported() {223return standardFormatSupported;224}225226/**227* Returns <code>true</code> if this object does not support the228* <code>mergeTree</code>, <code>setFromTree</code>, and229* <code>reset</code> methods.230*231* @return true if this <code>IIOMetadata</code> object cannot be232* modified.233*/234public abstract boolean isReadOnly();235236/**237* Returns the name of the "native" metadata format for this238* plug-in, which typically allows for lossless encoding and239* transmission of the metadata stored in the format handled by240* this plug-in. If no such format is supported,241* <code>null</code>will be returned.242*243* <p> The structure and contents of the "native" metadata format244* are defined by the plug-in that created this245* <code>IIOMetadata</code> object. Plug-ins for simple formats246* will usually create a dummy node for the root, and then a247* series of child nodes representing individual tags, chunks, or248* keyword/value pairs. A plug-in may choose whether or not to249* document its native format.250*251* <p> The default implementation returns the value of the252* <code>nativeMetadataFormatName</code> instance variable.253*254* @return the name of the native format, or <code>null</code>.255*256* @see #getExtraMetadataFormatNames257* @see #getMetadataFormatNames258*/259public String getNativeMetadataFormatName() {260return nativeMetadataFormatName;261}262263/**264* Returns an array of <code>String</code>s containing the names265* of additional metadata formats, other than the native and standard266* formats, recognized by this plug-in's267* <code>getAsTree</code>, <code>setFromTree</code>, and268* <code>mergeTree</code> methods. If there are no such additional269* formats, <code>null</code> is returned.270*271* <p> The default implementation returns a clone of the272* <code>extraMetadataFormatNames</code> instance variable.273*274* @return an array of <code>String</code>s with length at least275* 1, or <code>null</code>.276*277* @see #getAsTree278* @see #setFromTree279* @see #mergeTree280* @see #getNativeMetadataFormatName281* @see #getMetadataFormatNames282*/283public String[] getExtraMetadataFormatNames() {284if (extraMetadataFormatNames == null) {285return null;286}287return (String[])extraMetadataFormatNames.clone();288}289290/**291* Returns an array of <code>String</code>s containing the names292* of all metadata formats, including the native and standard293* formats, recognized by this plug-in's <code>getAsTree</code>,294* <code>setFromTree</code>, and <code>mergeTree</code> methods.295* If there are no such formats, <code>null</code> is returned.296*297* <p> The default implementation calls298* <code>getNativeMetadataFormatName</code>,299* <code>isStandardMetadataFormatSupported</code>, and300* <code>getExtraMetadataFormatNames</code> and returns the301* combined results.302*303* @return an array of <code>String</code>s.304*305* @see #getNativeMetadataFormatName306* @see #isStandardMetadataFormatSupported307* @see #getExtraMetadataFormatNames308*/309public String[] getMetadataFormatNames() {310String nativeName = getNativeMetadataFormatName();311String standardName = isStandardMetadataFormatSupported() ?312IIOMetadataFormatImpl.standardMetadataFormatName : null;313String[] extraNames = getExtraMetadataFormatNames();314315int numFormats = 0;316if (nativeName != null) {317++numFormats;318}319if (standardName != null) {320++numFormats;321}322if (extraNames != null) {323numFormats += extraNames.length;324}325if (numFormats == 0) {326return null;327}328329String[] formats = new String[numFormats];330int index = 0;331if (nativeName != null) {332formats[index++] = nativeName;333}334if (standardName != null) {335formats[index++] = standardName;336}337if (extraNames != null) {338for (int i = 0; i < extraNames.length; i++) {339formats[index++] = extraNames[i];340}341}342343return formats;344}345346/**347* Returns an <code>IIOMetadataFormat</code> object describing the348* given metadata format, or <code>null</code> if no description349* is available. The supplied name must be one of those returned350* by <code>getMetadataFormatNames</code> (<i>i.e.</i>, either the351* native format name, the standard format name, or one of those352* returned by <code>getExtraMetadataFormatNames</code>).353*354* <p> The default implementation checks the name against the355* global standard metadata format name, and returns that format356* if it is supported. Otherwise, it checks against the native357* format names followed by any additional format names. If a358* match is found, it retrieves the name of the359* <code>IIOMetadataFormat</code> class from360* <code>nativeMetadataFormatClassName</code> or361* <code>extraMetadataFormatClassNames</code> as appropriate, and362* constructs an instance of that class using its363* <code>getInstance</code> method.364*365* @param formatName the desired metadata format.366*367* @return an <code>IIOMetadataFormat</code> object.368*369* @exception IllegalArgumentException if <code>formatName</code>370* is <code>null</code> or is not one of the names recognized by371* the plug-in.372* @exception IllegalStateException if the class corresponding to373* the format name cannot be loaded.374*/375public IIOMetadataFormat getMetadataFormat(String formatName) {376if (formatName == null) {377throw new IllegalArgumentException("formatName == null!");378}379if (standardFormatSupported380&& formatName.equals381(IIOMetadataFormatImpl.standardMetadataFormatName)) {382return IIOMetadataFormatImpl.getStandardFormatInstance();383}384String formatClassName = null;385if (formatName.equals(nativeMetadataFormatName)) {386formatClassName = nativeMetadataFormatClassName;387} else if (extraMetadataFormatNames != null) {388for (int i = 0; i < extraMetadataFormatNames.length; i++) {389if (formatName.equals(extraMetadataFormatNames[i])) {390formatClassName = extraMetadataFormatClassNames[i];391break; // out of for392}393}394}395if (formatClassName == null) {396throw new IllegalArgumentException("Unsupported format name");397}398try {399Class cls = null;400final Object o = this;401402// firstly we try to use classloader used for loading403// the IIOMetadata implemantation for this plugin.404ClassLoader loader = (ClassLoader)405java.security.AccessController.doPrivileged(406new java.security.PrivilegedAction() {407public Object run() {408return o.getClass().getClassLoader();409}410});411412try {413cls = Class.forName(formatClassName, true,414loader);415} catch (ClassNotFoundException e) {416// we failed to load IIOMetadataFormat class by417// using IIOMetadata classloader.Next try is to418// use thread context classloader.419loader = (ClassLoader)420java.security.AccessController.doPrivileged(421new java.security.PrivilegedAction() {422public Object run() {423return Thread.currentThread().getContextClassLoader();424}425});426try {427cls = Class.forName(formatClassName, true,428loader);429} catch (ClassNotFoundException e1) {430// finally we try to use system classloader in case431// if we failed to load IIOMetadataFormat implementation432// class above.433cls = Class.forName(formatClassName, true,434ClassLoader.getSystemClassLoader());435}436}437438Method meth = cls.getMethod("getInstance");439return (IIOMetadataFormat) meth.invoke(null);440} catch (Exception e) {441RuntimeException ex =442new IllegalStateException ("Can't obtain format");443ex.initCause(e);444throw ex;445}446447}448449/**450* Returns an XML DOM <code>Node</code> object that represents the451* root of a tree of metadata contained within this object452* according to the conventions defined by a given metadata453* format.454*455* <p> The names of the available metadata formats may be queried456* using the <code>getMetadataFormatNames</code> method.457*458* @param formatName the desired metadata format.459*460* @return an XML DOM <code>Node</code> object forming the461* root of a tree.462*463* @exception IllegalArgumentException if <code>formatName</code>464* is <code>null</code> or is not one of the names returned by465* <code>getMetadataFormatNames</code>.466*467* @see #getMetadataFormatNames468* @see #setFromTree469* @see #mergeTree470*/471public abstract Node getAsTree(String formatName);472473/**474* Alters the internal state of this <code>IIOMetadata</code>475* object from a tree of XML DOM <code>Node</code>s whose syntax476* is defined by the given metadata format. The previous state is477* altered only as necessary to accommodate the nodes that are478* present in the given tree. If the tree structure or contents479* are invalid, an <code>IIOInvalidTreeException</code> will be480* thrown.481*482* <p> As the semantics of how a tree or subtree may be merged with483* another tree are completely format-specific, plug-in authors may484* implement this method in whatever manner is most appropriate for485* the format, including simply replacing all existing state with the486* contents of the given tree.487*488* @param formatName the desired metadata format.489* @param root an XML DOM <code>Node</code> object forming the490* root of a tree.491*492* @exception IllegalStateException if this object is read-only.493* @exception IllegalArgumentException if <code>formatName</code>494* is <code>null</code> or is not one of the names returned by495* <code>getMetadataFormatNames</code>.496* @exception IllegalArgumentException if <code>root</code> is497* <code>null</code>.498* @exception IIOInvalidTreeException if the tree cannot be parsed499* successfully using the rules of the given format.500*501* @see #getMetadataFormatNames502* @see #getAsTree503* @see #setFromTree504*/505public abstract void mergeTree(String formatName, Node root)506throws IIOInvalidTreeException;507508/**509* Returns an <code>IIOMetadataNode</code> representing the chroma510* information of the standard <code>javax_imageio_1.0</code>511* metadata format, or <code>null</code> if no such information is512* available. This method is intended to be called by the utility513* routine <code>getStandardTree</code>.514*515* <p> The default implementation returns <code>null</code>.516*517* <p> Subclasses should override this method to produce an518* appropriate subtree if they wish to support the standard519* metadata format.520*521* @return an <code>IIOMetadataNode</code>, or <code>null</code>.522*523* @see #getStandardTree524*/525protected IIOMetadataNode getStandardChromaNode() {526return null;527}528529/**530* Returns an <code>IIOMetadataNode</code> representing the531* compression information of the standard532* <code>javax_imageio_1.0</code> metadata format, or533* <code>null</code> if no such information is available. This534* method is intended to be called by the utility routine535* <code>getStandardTree</code>.536*537* <p> The default implementation returns <code>null</code>.538*539* <p> Subclasses should override this method to produce an540* appropriate subtree if they wish to support the standard541* metadata format.542*543* @return an <code>IIOMetadataNode</code>, or <code>null</code>.544*545* @see #getStandardTree546*/547protected IIOMetadataNode getStandardCompressionNode() {548return null;549}550551/**552* Returns an <code>IIOMetadataNode</code> representing the data553* format information of the standard554* <code>javax_imageio_1.0</code> metadata format, or555* <code>null</code> if no such information is available. This556* method is intended to be called by the utility routine557* <code>getStandardTree</code>.558*559* <p> The default implementation returns <code>null</code>.560*561* <p> Subclasses should override this method to produce an562* appropriate subtree if they wish to support the standard563* metadata format.564*565* @return an <code>IIOMetadataNode</code>, or <code>null</code>.566*567* @see #getStandardTree568*/569protected IIOMetadataNode getStandardDataNode() {570return null;571}572573/**574* Returns an <code>IIOMetadataNode</code> representing the575* dimension information of the standard576* <code>javax_imageio_1.0</code> metadata format, or577* <code>null</code> if no such information is available. This578* method is intended to be called by the utility routine579* <code>getStandardTree</code>.580*581* <p> The default implementation returns <code>null</code>.582*583* <p> Subclasses should override this method to produce an584* appropriate subtree if they wish to support the standard585* metadata format.586*587* @return an <code>IIOMetadataNode</code>, or <code>null</code>.588*589* @see #getStandardTree590*/591protected IIOMetadataNode getStandardDimensionNode() {592return null;593}594595/**596* Returns an <code>IIOMetadataNode</code> representing the document597* information of the standard <code>javax_imageio_1.0</code>598* metadata format, or <code>null</code> if no such information is599* available. This method is intended to be called by the utility600* routine <code>getStandardTree</code>.601*602* <p> The default implementation returns <code>null</code>.603*604* <p> Subclasses should override this method to produce an605* appropriate subtree if they wish to support the standard606* metadata format.607*608* @return an <code>IIOMetadataNode</code>, or <code>null</code>.609*610* @see #getStandardTree611*/612protected IIOMetadataNode getStandardDocumentNode() {613return null;614}615616/**617* Returns an <code>IIOMetadataNode</code> representing the textual618* information of the standard <code>javax_imageio_1.0</code>619* metadata format, or <code>null</code> if no such information is620* available. This method is intended to be called by the utility621* routine <code>getStandardTree</code>.622*623* <p> The default implementation returns <code>null</code>.624*625* <p> Subclasses should override this method to produce an626* appropriate subtree if they wish to support the standard627* metadata format.628*629* @return an <code>IIOMetadataNode</code>, or <code>null</code>.630*631* @see #getStandardTree632*/633protected IIOMetadataNode getStandardTextNode() {634return null;635}636637/**638* Returns an <code>IIOMetadataNode</code> representing the tiling639* information of the standard <code>javax_imageio_1.0</code>640* metadata format, or <code>null</code> if no such information is641* available. This method is intended to be called by the utility642* routine <code>getStandardTree</code>.643*644* <p> The default implementation returns <code>null</code>.645*646* <p> Subclasses should override this method to produce an647* appropriate subtree if they wish to support the standard648* metadata format.649*650* @return an <code>IIOMetadataNode</code>, or <code>null</code>.651*652* @see #getStandardTree653*/654protected IIOMetadataNode getStandardTileNode() {655return null;656}657658/**659* Returns an <code>IIOMetadataNode</code> representing the660* transparency information of the standard661* <code>javax_imageio_1.0</code> metadata format, or662* <code>null</code> if no such information is available. This663* method is intended to be called by the utility routine664* <code>getStandardTree</code>.665*666* <p> The default implementation returns <code>null</code>.667*668* <p> Subclasses should override this method to produce an669* appropriate subtree if they wish to support the standard670* metadata format.671*672* @return an <code>IIOMetadataNode</code>, or <code>null</code>.673*/674protected IIOMetadataNode getStandardTransparencyNode() {675return null;676}677678/**679* Appends a new node to an existing node, if the new node is680* non-<code>null</code>.681*/682private void append(IIOMetadataNode root, IIOMetadataNode node) {683if (node != null) {684root.appendChild(node);685}686}687688/**689* A utility method to return a tree of690* <code>IIOMetadataNode</code>s representing the metadata691* contained within this object according to the conventions of692* the standard <code>javax_imageio_1.0</code> metadata format.693*694* <p> This method calls the various <code>getStandard*Node</code>695* methods to supply each of the subtrees rooted at the children696* of the root node. If any of those methods returns697* <code>null</code>, the corresponding subtree will be omitted.698* If all of them return <code>null</code>, a tree consisting of a699* single root node will be returned.700*701* @return an <code>IIOMetadataNode</code> representing the root702* of a metadata tree in the <code>javax_imageio_1.0</code>703* format.704*705* @see #getStandardChromaNode706* @see #getStandardCompressionNode707* @see #getStandardDataNode708* @see #getStandardDimensionNode709* @see #getStandardDocumentNode710* @see #getStandardTextNode711* @see #getStandardTileNode712* @see #getStandardTransparencyNode713*/714protected final IIOMetadataNode getStandardTree() {715IIOMetadataNode root = new IIOMetadataNode716(IIOMetadataFormatImpl.standardMetadataFormatName);717append(root, getStandardChromaNode());718append(root, getStandardCompressionNode());719append(root, getStandardDataNode());720append(root, getStandardDimensionNode());721append(root, getStandardDocumentNode());722append(root, getStandardTextNode());723append(root, getStandardTileNode());724append(root, getStandardTransparencyNode());725return root;726}727728/**729* Sets the internal state of this <code>IIOMetadata</code> object730* from a tree of XML DOM <code>Node</code>s whose syntax is731* defined by the given metadata format. The previous state is732* discarded. If the tree's structure or contents are invalid, an733* <code>IIOInvalidTreeException</code> will be thrown.734*735* <p> The default implementation calls <code>reset</code>736* followed by <code>mergeTree(formatName, root)</code>.737*738* @param formatName the desired metadata format.739* @param root an XML DOM <code>Node</code> object forming the740* root of a tree.741*742* @exception IllegalStateException if this object is read-only.743* @exception IllegalArgumentException if <code>formatName</code>744* is <code>null</code> or is not one of the names returned by745* <code>getMetadataFormatNames</code>.746* @exception IllegalArgumentException if <code>root</code> is747* <code>null</code>.748* @exception IIOInvalidTreeException if the tree cannot be parsed749* successfully using the rules of the given format.750*751* @see #getMetadataFormatNames752* @see #getAsTree753* @see #mergeTree754*/755public void setFromTree(String formatName, Node root)756throws IIOInvalidTreeException {757reset();758mergeTree(formatName, root);759}760761/**762* Resets all the data stored in this object to default values,763* usually to the state this object was in immediately after764* construction, though the precise semantics are plug-in specific.765* Note that there are many possible default values, depending on766* how the object was created.767*768* @exception IllegalStateException if this object is read-only.769*770* @see javax.imageio.ImageReader#getStreamMetadata771* @see javax.imageio.ImageReader#getImageMetadata772* @see javax.imageio.ImageWriter#getDefaultStreamMetadata773* @see javax.imageio.ImageWriter#getDefaultImageMetadata774*/775public abstract void reset();776777/**778* Sets the <code>IIOMetadataController</code> to be used779* to provide settings for this <code>IIOMetadata</code>780* object when the <code>activateController</code> method781* is called, overriding any default controller. If the782* argument is <code>null</code>, no controller will be783* used, including any default. To restore the default, use784* <code>setController(getDefaultController())</code>.785*786* <p> The default implementation sets the <code>controller</code>787* instance variable to the supplied value.788*789* @param controller An appropriate790* <code>IIOMetadataController</code>, or <code>null</code>.791*792* @see IIOMetadataController793* @see #getController794* @see #getDefaultController795* @see #hasController796* @see #activateController()797*/798public void setController(IIOMetadataController controller) {799this.controller = controller;800}801802/**803* Returns whatever <code>IIOMetadataController</code> is currently804* installed. This could be the default if there is one,805* <code>null</code>, or the argument of the most recent call806* to <code>setController</code>.807*808* <p> The default implementation returns the value of the809* <code>controller</code> instance variable.810*811* @return the currently installed812* <code>IIOMetadataController</code>, or <code>null</code>.813*814* @see IIOMetadataController815* @see #setController816* @see #getDefaultController817* @see #hasController818* @see #activateController()819*/820public IIOMetadataController getController() {821return controller;822}823824/**825* Returns the default <code>IIOMetadataController</code>, if there826* is one, regardless of the currently installed controller. If827* there is no default controller, returns <code>null</code>.828*829* <p> The default implementation returns the value of the830* <code>defaultController</code> instance variable.831*832* @return the default <code>IIOMetadataController</code>, or833* <code>null</code>.834*835* @see IIOMetadataController836* @see #setController(IIOMetadataController)837* @see #getController838* @see #hasController839* @see #activateController()840*/841public IIOMetadataController getDefaultController() {842return defaultController;843}844845/**846* Returns <code>true</code> if there is a controller installed847* for this <code>IIOMetadata</code> object.848*849* <p> The default implementation returns <code>true</code> if the850* <code>getController</code> method returns a851* non-<code>null</code> value.852*853* @return <code>true</code> if a controller is installed.854*855* @see IIOMetadataController856* @see #setController(IIOMetadataController)857* @see #getController858* @see #getDefaultController859* @see #activateController()860*/861public boolean hasController() {862return (getController() != null);863}864865/**866* Activates the installed <code>IIOMetadataController</code> for867* this <code>IIOMetadata</code> object and returns the resulting868* value. When this method returns <code>true</code>, all values for this869* <code>IIOMetadata</code> object will be ready for the next write870* operation. If <code>false</code> is871* returned, no settings in this object will have been disturbed872* (<i>i.e.</i>, the user canceled the operation).873*874* <p> Ordinarily, the controller will be a GUI providing a user875* interface for a subclass of <code>IIOMetadata</code> for a876* particular plug-in. Controllers need not be GUIs, however.877*878* <p> The default implementation calls <code>getController</code>879* and the calls <code>activate</code> on the returned object if880* <code>hasController</code> returns <code>true</code>.881*882* @return <code>true</code> if the controller completed normally.883*884* @exception IllegalStateException if there is no controller885* currently installed.886*887* @see IIOMetadataController888* @see #setController(IIOMetadataController)889* @see #getController890* @see #getDefaultController891* @see #hasController892*/893public boolean activateController() {894if (!hasController()) {895throw new IllegalStateException("hasController() == false!");896}897return getController().activate(this);898}899}900901902