jdk/src/share/classes/javax/imageio/metadata/IIOMetadata.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 5506 202f599c92aa
child 22584 eed64ee05369
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.imageio.metadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * An abstract class to be extended by objects that represent metadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * (non-image data) associated with images and streams.  Plug-ins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * represent metadata using opaque, plug-in specific objects.  These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * objects, however, provide the ability to access their internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * information as a tree of <code>IIOMetadataNode</code> objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * support the XML DOM interfaces as well as additional interfaces for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * storing non-textual data and retrieving information about legal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * data values.  The format of such trees is plug-in dependent, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * plug-ins may choose to support a plug-in neutral format described
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * below.  A single plug-in may support multiple metadata formats,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * whose names maybe determined by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>getMetadataFormatNames</code>.  The plug-in may also support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * a single special format, referred to as the "native" format, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * is designed to encode its metadata losslessly.  This format will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * typically be designed specifically to work with a specific file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * format, so that images may be loaded and saved in the same format
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
    48
 * with no loss of metadata, but may be less useful for transferring
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * metadata between an <code>ImageReader</code> and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <code>ImageWriter</code> for different image formats.  To convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * between two native formats as losslessly as the image file formats
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * will allow, an <code>ImageTranscoder</code> object must be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see javax.imageio.ImageReader#getImageMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see javax.imageio.ImageReader#getStreamMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see javax.imageio.ImageReader#readAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see javax.imageio.ImageWriter#getDefaultStreamMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see javax.imageio.ImageWriter#getDefaultImageMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @see javax.imageio.ImageWriter#write
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see javax.imageio.ImageWriter#convertImageMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see javax.imageio.ImageWriter#convertStreamMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see javax.imageio.IIOImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see javax.imageio.ImageTranscoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
public abstract class IIOMetadata {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * A boolean indicating whether the concrete subclass supports the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * standard metadata format, set via the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected boolean standardFormatSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * The name of the native metadata format for this object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * initialized to <code>null</code> and set via the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    protected String nativeMetadataFormatName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * The name of the class implementing <code>IIOMetadataFormat</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * and representing the native metadata format, initialized to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * <code>null</code> and set via the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected String nativeMetadataFormatClassName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * An array of names of formats, other than the standard and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * native formats, that are supported by this plug-in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * initialized to <code>null</code> and set via the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected String[] extraMetadataFormatNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * An array of names of classes implementing <code>IIOMetadataFormat</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * and representing the metadata formats, other than the standard and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * native formats, that are supported by this plug-in,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * initialized to <code>null</code> and set via the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected String[] extraMetadataFormatClassNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * An <code>IIOMetadataController</code> that is suggested for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * as the controller for this <code>IIOMetadata</code> object.  It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * may be retrieved via <code>getDefaultController</code>.  To
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * install the default controller, call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <code>setController(getDefaultController())</code>.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * instance variable should be set by subclasses that choose to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * provide their own default controller, usually a GUI, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * setting parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see IIOMetadataController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    protected IIOMetadataController defaultController = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * The <code>IIOMetadataController</code> that will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * used to provide settings for this <code>IIOMetadata</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * object when the <code>activateController</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * is called.  This value overrides any default controller,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * even when <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see IIOMetadataController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see #setController(IIOMetadataController)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see #hasController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected IIOMetadataController controller = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Constructs an empty <code>IIOMetadata</code> object.  The
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   133
     * subclass is responsible for supplying values for all protected
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * instance variables that will allow any non-overridden default
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   135
     * implementations of methods to satisfy their contracts.  For example,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <code>extraMetadataFormatNames</code> should not have length 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    protected IIOMetadata() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Constructs an <code>IIOMetadata</code> object with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * format names and format class names, as well as a boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * indicating whether the standard format is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <p> This constructor does not attempt to check the class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * for validity.  Invalid class names may cause exceptions in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * subsequent calls to <code>getMetadataFormat</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param standardMetadataFormatSupported <code>true</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * this object can return or accept a DOM tree using the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param nativeMetadataFormatName the name of the native metadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * format, as a <code>String</code>, or <code>null</code> if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * is no native format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param nativeMetadataFormatClassName the name of the class of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * the native metadata format, or <code>null</code> if there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * no native format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param extraMetadataFormatNames an array of <code>String</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * indicating additional formats supported by this object, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * <code>null</code> if there are none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param extraMetadataFormatClassNames an array of <code>String</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * indicating the class names of any additional formats supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * this object, or <code>null</code> if there are none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <code>extraMetadataFormatNames</code> has length 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <code>extraMetadataFormatNames</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <code>extraMetadataFormatClassNames</code> are neither both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <code>null</code>, nor of the same length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    protected IIOMetadata(boolean standardMetadataFormatSupported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                          String nativeMetadataFormatName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                          String nativeMetadataFormatClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                          String[] extraMetadataFormatNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                          String[] extraMetadataFormatClassNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        this.standardFormatSupported = standardMetadataFormatSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        this.nativeMetadataFormatName = nativeMetadataFormatName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this.nativeMetadataFormatClassName = nativeMetadataFormatClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (extraMetadataFormatNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (extraMetadataFormatNames.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    ("extraMetadataFormatNames.length == 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            if (extraMetadataFormatClassNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    ("extraMetadataFormatNames != null && extraMetadataFormatClassNames == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            if (extraMetadataFormatClassNames.length !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                extraMetadataFormatNames.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    ("extraMetadataFormatClassNames.length != extraMetadataFormatNames.length!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            this.extraMetadataFormatNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                (String[]) extraMetadataFormatNames.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            this.extraMetadataFormatClassNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                (String[]) extraMetadataFormatClassNames.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (extraMetadataFormatClassNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    ("extraMetadataFormatNames == null && extraMetadataFormatClassNames != null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Returns <code>true</code> if the standard metadata format is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * supported by <code>getMetadataFormat</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <code>getAsTree</code>, <code>setFromTree</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * <code>mergeTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <p> The default implementation returns the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <code>standardFormatSupported</code> instance variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return <code>true</code> if the standard metadata format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @see #getAsTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see #setFromTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @see #mergeTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see #getMetadataFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public boolean isStandardMetadataFormatSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return standardFormatSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Returns <code>true</code> if this object does not support the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <code>mergeTree</code>, <code>setFromTree</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <code>reset</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return true if this <code>IIOMetadata</code> object cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public abstract boolean isReadOnly();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Returns the name of the "native" metadata format for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * plug-in, which typically allows for lossless encoding and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * transmission of the metadata stored in the format handled by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * this plug-in.  If no such format is supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <code>null</code>will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <p> The structure and contents of the "native" metadata format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * are defined by the plug-in that created this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <code>IIOMetadata</code> object.  Plug-ins for simple formats
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * will usually create a dummy node for the root, and then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * series of child nodes representing individual tags, chunks, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * keyword/value pairs.  A plug-in may choose whether or not to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * document its native format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <p> The default implementation returns the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <code>nativeMetadataFormatName</code> instance variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @return the name of the native format, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @see #getExtraMetadataFormatNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see #getMetadataFormatNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public String getNativeMetadataFormatName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return nativeMetadataFormatName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Returns an array of <code>String</code>s containing the names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * of additional metadata formats, other than the native and standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * formats, recognized by this plug-in's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <code>getAsTree</code>, <code>setFromTree</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <code>mergeTree</code> methods.  If there are no such additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * formats, <code>null</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <p> The default implementation returns a clone of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <code>extraMetadataFormatNames</code> instance variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return an array of <code>String</code>s with length at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * 1, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @see #getAsTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @see #setFromTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @see #mergeTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @see #getNativeMetadataFormatName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @see #getMetadataFormatNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public String[] getExtraMetadataFormatNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if (extraMetadataFormatNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return (String[])extraMetadataFormatNames.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Returns an array of <code>String</code>s containing the names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * of all metadata formats, including the native and standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * formats, recognized by this plug-in's <code>getAsTree</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * <code>setFromTree</code>, and <code>mergeTree</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * If there are no such formats, <code>null</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * <p> The default implementation calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * <code>getNativeMetadataFormatName</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * <code>isStandardMetadataFormatSupported</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * <code>getExtraMetadataFormatNames</code> and returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * combined results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @return an array of <code>String</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see #getNativeMetadataFormatName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @see #isStandardMetadataFormatSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @see #getExtraMetadataFormatNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public String[] getMetadataFormatNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        String nativeName = getNativeMetadataFormatName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        String standardName = isStandardMetadataFormatSupported() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            IIOMetadataFormatImpl.standardMetadataFormatName : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        String[] extraNames = getExtraMetadataFormatNames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        int numFormats = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (nativeName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            ++numFormats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (standardName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            ++numFormats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (extraNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            numFormats += extraNames.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (numFormats == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        String[] formats = new String[numFormats];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (nativeName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            formats[index++] = nativeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (standardName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            formats[index++] = standardName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (extraNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            for (int i = 0; i < extraNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                formats[index++] = extraNames[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return formats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Returns an <code>IIOMetadataFormat</code> object describing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * given metadata format, or <code>null</code> if no description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * is available.  The supplied name must be one of those returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * by <code>getMetadataFormatNames</code> (<i>i.e.</i>, either the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * native format name, the standard format name, or one of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * returned by <code>getExtraMetadataFormatNames</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <p> The default implementation checks the name against the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * global standard metadata format name, and returns that format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * if it is supported.  Otherwise, it checks against the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * format names followed by any additional format names.  If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * match is found, it retrieves the name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * <code>IIOMetadataFormat</code> class from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * <code>nativeMetadataFormatClassName</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <code>extraMetadataFormatClassNames</code> as appropriate, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * constructs an instance of that class using its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <code>getInstance</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @param formatName the desired metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @return an <code>IIOMetadataFormat</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @exception IllegalArgumentException if <code>formatName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * is <code>null</code> or is not one of the names recognized by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * the plug-in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @exception IllegalStateException if the class corresponding to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * the format name cannot be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public IIOMetadataFormat getMetadataFormat(String formatName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (formatName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            throw new IllegalArgumentException("formatName == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (standardFormatSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            && formatName.equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                (IIOMetadataFormatImpl.standardMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            return IIOMetadataFormatImpl.getStandardFormatInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        String formatClassName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (formatName.equals(nativeMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            formatClassName = nativeMetadataFormatClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        } else if (extraMetadataFormatNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            for (int i = 0; i < extraMetadataFormatNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                if (formatName.equals(extraMetadataFormatNames[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    formatClassName = extraMetadataFormatClassNames[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    break;  // out of for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (formatClassName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            throw new IllegalArgumentException("Unsupported format name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            Class cls = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            final Object o = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            // firstly we try to use classloader used for loading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            // the IIOMetadata implemantation for this plugin.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            ClassLoader loader = (ClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                return o.getClass().getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                cls = Class.forName(formatClassName, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                    loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                // we failed to load IIOMetadataFormat class by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                // using IIOMetadata classloader.Next try is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                // use thread context classloader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                loader = (ClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                        new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                    return Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    cls = Class.forName(formatClassName, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                        loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                } catch (ClassNotFoundException e1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    // finally we try to use system classloader in case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    // if we failed to load IIOMetadataFormat implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    // class above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    cls = Class.forName(formatClassName, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                        ClassLoader.getSystemClassLoader());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            Method meth = cls.getMethod("getInstance");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            return (IIOMetadataFormat) meth.invoke(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            RuntimeException ex =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                new IllegalStateException ("Can't obtain format");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            ex.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            throw ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Returns an XML DOM <code>Node</code> object that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * root of a tree of metadata contained within this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * according to the conventions defined by a given metadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * <p> The names of the available metadata formats may be queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * using the <code>getMetadataFormatNames</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param formatName the desired metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @return an XML DOM <code>Node</code> object forming the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * root of a tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @exception IllegalArgumentException if <code>formatName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * is <code>null</code> or is not one of the names returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * <code>getMetadataFormatNames</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @see #getMetadataFormatNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @see #setFromTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @see #mergeTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public abstract Node getAsTree(String formatName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * Alters the internal state of this <code>IIOMetadata</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * object from a tree of XML DOM <code>Node</code>s whose syntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * is defined by the given metadata format.  The previous state is
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
   478
     * altered only as necessary to accommodate the nodes that are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * present in the given tree.  If the tree structure or contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * are invalid, an <code>IIOInvalidTreeException</code> will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * <p> As the semantics of how a tree or subtree may be merged with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * another tree are completely format-specific, plug-in authors may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * implement this method in whatever manner is most appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * the format, including simply replacing all existing state with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * contents of the given tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @param formatName the desired metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @param root an XML DOM <code>Node</code> object forming the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * root of a tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @exception IllegalStateException if this object is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @exception IllegalArgumentException if <code>formatName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * is <code>null</code> or is not one of the names returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * <code>getMetadataFormatNames</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @exception IllegalArgumentException if <code>root</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @exception IIOInvalidTreeException if the tree cannot be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * successfully using the rules of the given format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see #getMetadataFormatNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @see #getAsTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see #setFromTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public abstract void mergeTree(String formatName, Node root)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        throws IIOInvalidTreeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Returns an <code>IIOMetadataNode</code> representing the chroma
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * information of the standard <code>javax_imageio_1.0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * metadata format, or <code>null</code> if no such information is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * available.  This method is intended to be called by the utility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * routine <code>getStandardTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * <p> The default implementation returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * <p> Subclasses should override this method to produce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * appropriate subtree if they wish to support the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @return an <code>IIOMetadataNode</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @see #getStandardTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    protected IIOMetadataNode getStandardChromaNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * Returns an <code>IIOMetadataNode</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * compression information of the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <code>javax_imageio_1.0</code> metadata format, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <code>null</code> if no such information is available.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * method is intended to be called by the utility routine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <code>getStandardTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * <p> The default implementation returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <p> Subclasses should override this method to produce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * appropriate subtree if they wish to support the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @return an <code>IIOMetadataNode</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @see #getStandardTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    protected IIOMetadataNode getStandardCompressionNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * Returns an <code>IIOMetadataNode</code> representing the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * format information of the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * <code>javax_imageio_1.0</code> metadata format, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <code>null</code> if no such information is available.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * method is intended to be called by the utility routine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * <code>getStandardTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * <p> The default implementation returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * <p> Subclasses should override this method to produce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * appropriate subtree if they wish to support the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @return an <code>IIOMetadataNode</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @see #getStandardTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    protected IIOMetadataNode getStandardDataNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Returns an <code>IIOMetadataNode</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * dimension information of the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * <code>javax_imageio_1.0</code> metadata format, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * <code>null</code> if no such information is available.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * method is intended to be called by the utility routine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * <code>getStandardTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * <p> The default implementation returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * <p> Subclasses should override this method to produce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * appropriate subtree if they wish to support the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @return an <code>IIOMetadataNode</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @see #getStandardTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    protected IIOMetadataNode getStandardDimensionNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * Returns an <code>IIOMetadataNode</code> representing the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * information of the standard <code>javax_imageio_1.0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * metadata format, or <code>null</code> if no such information is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * available.  This method is intended to be called by the utility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * routine <code>getStandardTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * <p> The default implementation returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <p> Subclasses should override this method to produce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * appropriate subtree if they wish to support the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @return an <code>IIOMetadataNode</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @see #getStandardTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    protected IIOMetadataNode getStandardDocumentNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * Returns an <code>IIOMetadataNode</code> representing the textual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * information of the standard <code>javax_imageio_1.0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * metadata format, or <code>null</code> if no such information is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * available.  This method is intended to be called by the utility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * routine <code>getStandardTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * <p> The default implementation returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <p> Subclasses should override this method to produce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * appropriate subtree if they wish to support the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @return an <code>IIOMetadataNode</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * @see #getStandardTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    protected IIOMetadataNode getStandardTextNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * Returns an <code>IIOMetadataNode</code> representing the tiling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * information of the standard <code>javax_imageio_1.0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * metadata format, or <code>null</code> if no such information is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * available.  This method is intended to be called by the utility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * routine <code>getStandardTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * <p> The default implementation returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * <p> Subclasses should override this method to produce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * appropriate subtree if they wish to support the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @return an <code>IIOMetadataNode</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @see #getStandardTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    protected IIOMetadataNode getStandardTileNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * Returns an <code>IIOMetadataNode</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * transparency information of the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * <code>javax_imageio_1.0</code> metadata format, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * <code>null</code> if no such information is available.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * method is intended to be called by the utility routine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * <code>getStandardTree</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * <p> The default implementation returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * <p> Subclasses should override this method to produce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * appropriate subtree if they wish to support the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * @return an <code>IIOMetadataNode</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    protected IIOMetadataNode getStandardTransparencyNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * Appends a new node to an existing node, if the new node is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * non-<code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    private void append(IIOMetadataNode root, IIOMetadataNode node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            root.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * A utility method to return a tree of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * <code>IIOMetadataNode</code>s representing the metadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * contained within this object according to the conventions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * the standard <code>javax_imageio_1.0</code> metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * <p> This method calls the various <code>getStandard*Node</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * methods to supply each of the subtrees rooted at the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * of the root node.  If any of those methods returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * <code>null</code>, the corresponding subtree will be omitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * If all of them return <code>null</code>, a tree consisting of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * single root node will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * @return an <code>IIOMetadataNode</code> representing the root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * of a metadata tree in the <code>javax_imageio_1.0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @see #getStandardChromaNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @see #getStandardCompressionNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @see #getStandardDataNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @see #getStandardDimensionNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @see #getStandardDocumentNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @see #getStandardTextNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @see #getStandardTileNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @see #getStandardTransparencyNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    protected final IIOMetadataNode getStandardTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        IIOMetadataNode root = new IIOMetadataNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                (IIOMetadataFormatImpl.standardMetadataFormatName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        append(root, getStandardChromaNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        append(root, getStandardCompressionNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        append(root, getStandardDataNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        append(root, getStandardDimensionNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        append(root, getStandardDocumentNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        append(root, getStandardTextNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        append(root, getStandardTileNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        append(root, getStandardTransparencyNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        return root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * Sets the internal state of this <code>IIOMetadata</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * from a tree of XML DOM <code>Node</code>s whose syntax is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * defined by the given metadata format.  The previous state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * discarded.  If the tree's structure or contents are invalid, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * <code>IIOInvalidTreeException</code> will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * <p> The default implementation calls <code>reset</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * followed by <code>mergeTree(formatName, root)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @param formatName the desired metadata format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @param root an XML DOM <code>Node</code> object forming the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * root of a tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @exception IllegalStateException if this object is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @exception IllegalArgumentException if <code>formatName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * is <code>null</code> or is not one of the names returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * <code>getMetadataFormatNames</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @exception IllegalArgumentException if <code>root</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @exception IIOInvalidTreeException if the tree cannot be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * successfully using the rules of the given format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @see #getMetadataFormatNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @see #getAsTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * @see #mergeTree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    public void setFromTree(String formatName, Node root)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        mergeTree(formatName, root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * Resets all the data stored in this object to default values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * usually to the state this object was in immediately after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * construction, though the precise semantics are plug-in specific.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * Note that there are many possible default values, depending on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * how the object was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @exception IllegalStateException if this object is read-only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * @see javax.imageio.ImageReader#getStreamMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * @see javax.imageio.ImageReader#getImageMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @see javax.imageio.ImageWriter#getDefaultStreamMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * @see javax.imageio.ImageWriter#getDefaultImageMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    public abstract void reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * Sets the <code>IIOMetadataController</code> to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * to provide settings for this <code>IIOMetadata</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * object when the <code>activateController</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * is called, overriding any default controller.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * argument is <code>null</code>, no controller will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * used, including any default.  To restore the default, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * <code>setController(getDefaultController())</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * <p> The default implementation sets the <code>controller</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * instance variable to the supplied value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * @param controller An appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * <code>IIOMetadataController</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @see IIOMetadataController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * @see #getController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @see #hasController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    public void setController(IIOMetadataController controller) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        this.controller = controller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * Returns whatever <code>IIOMetadataController</code> is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * installed.  This could be the default if there is one,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * <code>null</code>, or the argument of the most recent call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * to <code>setController</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * <p> The default implementation returns the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * <code>controller</code> instance variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @return the currently installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * <code>IIOMetadataController</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @see IIOMetadataController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @see #setController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @see #hasController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    public IIOMetadataController getController() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        return controller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Returns the default <code>IIOMetadataController</code>, if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * is one, regardless of the currently installed controller.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * there is no default controller, returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * <p> The default implementation returns the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * <code>defaultController</code> instance variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @return the default <code>IIOMetadataController</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * @see IIOMetadataController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * @see #setController(IIOMetadataController)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @see #getController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * @see #hasController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    public IIOMetadataController getDefaultController() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        return defaultController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * Returns <code>true</code> if there is a controller installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * for this <code>IIOMetadata</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * <p> The default implementation returns <code>true</code> if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * <code>getController</code> method returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * non-<code>null</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * @return <code>true</code> if a controller is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @see IIOMetadataController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @see #setController(IIOMetadataController)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @see #getController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @see #activateController()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public boolean hasController() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        return (getController() != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * Activates the installed <code>IIOMetadataController</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * this <code>IIOMetadata</code> object and returns the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * value.  When this method returns <code>true</code>, all values for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * <code>IIOMetadata</code> object will be ready for the next write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * operation.  If <code>false</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * returned, no settings in this object will have been disturbed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * (<i>i.e.</i>, the user canceled the operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * <p> Ordinarily, the controller will be a GUI providing a user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * interface for a subclass of <code>IIOMetadata</code> for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * particular plug-in.  Controllers need not be GUIs, however.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * <p> The default implementation calls <code>getController</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * and the calls <code>activate</code> on the returned object if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * <code>hasController</code> returns <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @return <code>true</code> if the controller completed normally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @exception IllegalStateException if there is no controller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * currently installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @see IIOMetadataController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @see #setController(IIOMetadataController)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @see #getController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * @see #getDefaultController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * @see #hasController
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    public boolean activateController() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        if (!hasController()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            throw new IllegalStateException("hasController() == false!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        return getController().activate(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
}