jdk/src/share/classes/javax/imageio/metadata/IIOMetadataFormatImpl.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 19168 ff364494f2b8
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, 2004, 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 java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.MissingResourceException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.imageio.ImageTypeSpecifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.imageio.plugins.common.StandardMetadataFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A concrete class providing a reusable implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>IIOMetadataFormat</code> interface.  In addition, a static
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * instance representing the standard, plug-in neutral
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>javax_imageio_1.0</code> format is provided by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>getStandardFormatInstance</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p> In order to supply localized descriptions of elements and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * attributes, a <code>ResourceBundle</code> with a base name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <code>this.getClass().getName() + "Resources"</code> should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * supplied via the usual mechanism used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>ResourceBundle.getBundle</code>.  Briefly, the subclasser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * supplies one or more additional classes according to a naming
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * convention (by default, the fully-qualified name of the subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * extending <code>IIMetadataFormatImpl</code>, plus the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * "Resources", plus the country, language, and variant codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * separated by underscores).  At run time, calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <code>getElementDescription</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>getAttributeDescription</code> will attempt to load such
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * classes dynamically according to the supplied locale, and will use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * either the element name, or the element name followed by a '/'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * character followed by the attribute name as a key.  This key will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * be supplied to the <code>ResourceBundle</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <code>getString</code> method, and the resulting localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * description of the node or attribute is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p> The subclass may supply a different base name for the resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * bundles using the <code>setResourceBaseName</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <p> A subclass may choose its own localization mechanism, if so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * desired, by overriding the supplied implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <code>getElementDescription</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <code>getAttributeDescription</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @see ResourceBundle#getBundle(String,Locale)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
public abstract class IIOMetadataFormatImpl implements IIOMetadataFormat {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * A <code>String</code> constant containing the standard format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * name, <code>"javax_imageio_1.0"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final String standardMetadataFormatName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        "javax_imageio_1.0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static IIOMetadataFormat standardFormat = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private String resourceBaseName = this.getClass().getName() + "Resources";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private String rootName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // Element name (String) -> Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private HashMap elementMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    class Element {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        String elementName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        int childPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        int minChildren = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        int maxChildren = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // Child names (Strings)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        List childList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // Parent names (Strings)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        List parentList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // List of attribute names in the order they were added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        List attrList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // Attr name (String) -> Attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        Map attrMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        ObjectValue objectValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    class Attribute {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        String attrName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        int valueType = VALUE_ARBITRARY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        int dataType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        boolean required;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        String defaultValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        List enumeratedValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        String minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        String maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        // list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        int listMinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        int listMaxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    class ObjectValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        int valueType = VALUE_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        Class classType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        Object defaultValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // Meaningful only if valueType == VALUE_ENUMERATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        List enumeratedValues = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // Meaningful only if valueType == VALUE_RANGE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        Comparable minValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        Comparable maxValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // Meaningful only if valueType == VALUE_LIST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        int arrayMinLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int arrayMaxLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Constructs a blank <code>IIOMetadataFormatImpl</code> instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * with a given root element name and child policy (other than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <code>CHILD_POLICY_REPEAT</code>).  Additional elements, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * their attributes and <code>Object</code> reference information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * may be added using the various <code>add</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param rootName the name of the root element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param childPolicy one of the <code>CHILD_POLICY_*</code> constants,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * other than <code>CHILD_POLICY_REPEAT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @exception IllegalArgumentException if <code>rootName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @exception IllegalArgumentException if <code>childPolicy</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * not one of the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public IIOMetadataFormatImpl(String rootName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                 int childPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (rootName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            throw new IllegalArgumentException("rootName == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (childPolicy < CHILD_POLICY_EMPTY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            childPolicy > CHILD_POLICY_MAX ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            childPolicy == CHILD_POLICY_REPEAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            throw new IllegalArgumentException("Invalid value for childPolicy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        this.rootName = rootName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        Element root = new Element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        root.elementName = rootName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        root.childPolicy = childPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        elementMap.put(rootName, root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Constructs a blank <code>IIOMetadataFormatImpl</code> instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * with a given root element name and a child policy of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * <code>CHILD_POLICY_REPEAT</code>.  Additional elements, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * their attributes and <code>Object</code> reference information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * may be added using the various <code>add</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param rootName the name of the root element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param minChildren the minimum number of children of the node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param maxChildren the maximum number of children of the node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @exception IllegalArgumentException if <code>rootName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @exception IllegalArgumentException if <code>minChildren</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * is negative or larger than <code>maxChildren</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public IIOMetadataFormatImpl(String rootName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                 int minChildren,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                 int maxChildren) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (rootName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            throw new IllegalArgumentException("rootName == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (minChildren < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            throw new IllegalArgumentException("minChildren < 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (minChildren > maxChildren) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            throw new IllegalArgumentException("minChildren > maxChildren!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Element root = new Element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        root.elementName = rootName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        root.childPolicy = CHILD_POLICY_REPEAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        root.minChildren = minChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        root.maxChildren = maxChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        this.rootName = rootName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        elementMap.put(rootName, root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Sets a new base name for locating <code>ResourceBundle</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * containing descriptions of elements and attributes for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <p> Prior to the first time this method is called, the base
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * name will be equal to <code>this.getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * "Resources"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19168
diff changeset
   237
     * @param resourceBaseName a <code>String</code> containing the new
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * base name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <code>resourceBaseName</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see #getResourceBaseName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    protected void setResourceBaseName(String resourceBaseName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (resourceBaseName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            throw new IllegalArgumentException("resourceBaseName == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        this.resourceBaseName = resourceBaseName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Returns the currently set base name for locating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <code>ResourceBundle</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return a <code>String</code> containing the base name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see #setResourceBaseName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    protected String getResourceBaseName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return resourceBaseName;
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
     * Utility method for locating an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param mustAppear if <code>true</code>, throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <code>IllegalArgumentException</code> if no such node exists;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * if <code>false</code>, just return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private Element getElement(String elementName, boolean mustAppear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (mustAppear && (elementName == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            throw new IllegalArgumentException("element name is null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        Element element = (Element)elementMap.get(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (mustAppear && (element == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            throw new IllegalArgumentException("No such element: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                               elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private Element getElement(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return getElement(elementName, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    // Utility method for locating an attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    private Attribute getAttribute(String elementName, String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        Attribute attr = (Attribute)element.attrMap.get(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            throw new IllegalArgumentException("No such attribute \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                               attrName + "\"!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    // Setup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Adds a new element type to this metadata document format with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * child policy other than <code>CHILD_POLICY_REPEAT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param elementName the name of the new element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param parentName the name of the element that will be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * parent of the new element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @param childPolicy one of the <code>CHILD_POLICY_*</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * constants, other than <code>CHILD_POLICY_REPEAT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * indicating the child policy of the new element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @exception IllegalArgumentException if <code>parentName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @exception IllegalArgumentException if <code>childPolicy</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * is not one of the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    protected void addElement(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                              String parentName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                              int childPolicy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        Element parent = getElement(parentName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (childPolicy < CHILD_POLICY_EMPTY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            childPolicy > CHILD_POLICY_MAX ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            childPolicy == CHILD_POLICY_REPEAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                ("Invalid value for childPolicy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        Element element = new Element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        element.elementName = elementName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        element.childPolicy = childPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        parent.childList.add(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        element.parentList.add(parentName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        elementMap.put(elementName, element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Adds a new element type to this metadata document format with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * child policy of <code>CHILD_POLICY_REPEAT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @param elementName the name of the new element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @param parentName the name of the element that will be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * parent of the new element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @param minChildren the minimum number of children of the node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @param maxChildren the maximum number of children of the node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @exception IllegalArgumentException if <code>parentName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @exception IllegalArgumentException if <code>minChildren</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * is negative or larger than <code>maxChildren</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    protected void addElement(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                              String parentName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                              int minChildren,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                              int maxChildren) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        Element parent = getElement(parentName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (minChildren < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            throw new IllegalArgumentException("minChildren < 0!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if (minChildren > maxChildren) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            throw new IllegalArgumentException("minChildren > maxChildren!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        Element element = new Element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        element.elementName = elementName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        element.childPolicy = CHILD_POLICY_REPEAT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        element.minChildren = minChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        element.maxChildren = maxChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        parent.childList.add(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        element.parentList.add(parentName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        elementMap.put(elementName, element);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Adds an existing element to the list of legal children for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * given parent node type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @param parentName the name of the element that will be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * new parent of the element.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19168
diff changeset
   384
     * @param elementName the name of the element to be added as a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @exception IllegalArgumentException if <code>parentName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    protected void addChildElement(String elementName, String parentName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        Element parent = getElement(parentName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        parent.childList.add(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        element.parentList.add(parentName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Removes an element from the format.  If no element with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * given name was present, nothing happens and no exception is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @param elementName the name of the element to be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    protected void removeElement(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        Element element = getElement(elementName, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        if (element != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            Iterator iter = element.parentList.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                String parentName = (String)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                Element parent = getElement(parentName, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    parent.childList.remove(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            elementMap.remove(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * Adds a new attribute to a previously defined element that may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * be set to an arbitrary value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @param attrName the name of the attribute being added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @param dataType the data type (string format) of the attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * one of the <code>DATATYPE_*</code> constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @param required <code>true</code> if the attribute must be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @param defaultValue the default value for the attribute, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @exception IllegalArgumentException if <code>attrName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @exception IllegalArgumentException if <code>dataType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * not one of the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    protected void addAttribute(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                String attrName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                                int dataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                                boolean required,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                String defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if (attrName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            throw new IllegalArgumentException("attrName == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (dataType < DATATYPE_STRING || dataType > DATATYPE_DOUBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            throw new IllegalArgumentException("Invalid value for dataType!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        Attribute attr = new Attribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        attr.attrName = attrName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        attr.valueType = VALUE_ARBITRARY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        attr.dataType = dataType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        attr.required = required;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        attr.defaultValue = defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        element.attrList.add(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        element.attrMap.put(attrName, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Adds a new attribute to a previously defined element that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * be defined by a set of enumerated values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @param attrName the name of the attribute being added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @param dataType the data type (string format) of the attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * one of the <code>DATATYPE_*</code> constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @param required <code>true</code> if the attribute must be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @param defaultValue the default value for the attribute, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * @param enumeratedValues a <code>List</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * <code>String</code>s containing the legal values for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @exception IllegalArgumentException if <code>attrName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @exception IllegalArgumentException if <code>dataType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * not one of the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * <code>enumeratedValues</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * <code>enumeratedValues</code> does not contain at least one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * <code>enumeratedValues</code> contains an element that is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * <code>String</code> or is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    protected void addAttribute(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                                String attrName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                                int dataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                boolean required,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                                String defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                                List<String> enumeratedValues) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (attrName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            throw new IllegalArgumentException("attrName == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (dataType < DATATYPE_STRING || dataType > DATATYPE_DOUBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            throw new IllegalArgumentException("Invalid value for dataType!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (enumeratedValues == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            throw new IllegalArgumentException("enumeratedValues == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (enumeratedValues.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            throw new IllegalArgumentException("enumeratedValues is empty!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        Iterator iter = enumeratedValues.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            Object o = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if (o == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    ("enumeratedValues contains a null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            if (!(o instanceof String)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    ("enumeratedValues contains a non-String value!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        Attribute attr = new Attribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        attr.attrName = attrName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        attr.valueType = VALUE_ENUMERATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        attr.dataType = dataType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        attr.required = required;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        attr.defaultValue = defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        attr.enumeratedValues = enumeratedValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        element.attrList.add(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        element.attrMap.put(attrName, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * Adds a new attribute to a previously defined element that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * be defined by a range of values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @param attrName the name of the attribute being added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @param dataType the data type (string format) of the attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * one of the <code>DATATYPE_*</code> constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @param required <code>true</code> if the attribute must be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @param defaultValue the default value for the attribute, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @param minValue the smallest (inclusive or exclusive depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * on the value of <code>minInclusive</code>) legal value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * attribute, as a <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @param maxValue the largest (inclusive or exclusive depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * on the value of <code>minInclusive</code>) legal value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * attribute, as a <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @param minInclusive <code>true</code> if <code>minValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * is inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @param maxInclusive <code>true</code> if <code>maxValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * is inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @exception IllegalArgumentException if <code>attrName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @exception IllegalArgumentException if <code>dataType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * not one of the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    protected void addAttribute(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                                String attrName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                                int dataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                                boolean required,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                String defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                String minValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                                String maxValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                                boolean minInclusive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                boolean maxInclusive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if (attrName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            throw new IllegalArgumentException("attrName == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        if (dataType < DATATYPE_STRING || dataType > DATATYPE_DOUBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            throw new IllegalArgumentException("Invalid value for dataType!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        Attribute attr = new Attribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        attr.attrName = attrName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        attr.valueType = VALUE_RANGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        if (minInclusive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            attr.valueType |= VALUE_RANGE_MIN_INCLUSIVE_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (maxInclusive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            attr.valueType |= VALUE_RANGE_MAX_INCLUSIVE_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        attr.dataType = dataType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        attr.required = required;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        attr.defaultValue = defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        attr.minValue = minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        attr.maxValue = maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        element.attrList.add(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        element.attrMap.put(attrName, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * Adds a new attribute to a previously defined element that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * be defined by a list of values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @param attrName the name of the attribute being added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @param dataType the data type (string format) of the attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * one of the <code>DATATYPE_*</code> constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @param required <code>true</code> if the attribute must be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @param listMinLength the smallest legal number of list items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @param listMaxLength the largest legal number of list items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @exception IllegalArgumentException if <code>attrName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @exception IllegalArgumentException if <code>dataType</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * not one of the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * <code>listMinLength</code> is negative or larger than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * <code>listMaxLength</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    protected void addAttribute(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                                String attrName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                int dataType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                                boolean required,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                int listMinLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                                int listMaxLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        if (attrName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            throw new IllegalArgumentException("attrName == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        if (dataType < DATATYPE_STRING || dataType > DATATYPE_DOUBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            throw new IllegalArgumentException("Invalid value for dataType!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        if (listMinLength < 0 || listMinLength > listMaxLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            throw new IllegalArgumentException("Invalid list bounds!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        Attribute attr = new Attribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        attr.attrName = attrName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        attr.valueType = VALUE_LIST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        attr.dataType = dataType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        attr.required = required;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        attr.listMinLength = listMinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        attr.listMaxLength = listMaxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        element.attrList.add(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        element.attrMap.put(attrName, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * Adds a new attribute to a previously defined element that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * be defined by the enumerated values <code>TRUE</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * <code>FALSE</code>, with a datatype of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * <code>DATATYPE_BOOLEAN</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @param attrName the name of the attribute being added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @param hasDefaultValue <code>true</code> if a default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * should be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @param defaultValue the default value for the attribute as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * <code>boolean</code>, ignored if <code>hasDefaultValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * is <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @exception IllegalArgumentException if <code>attrName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    protected void addBooleanAttribute(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                                       String attrName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                                       boolean hasDefaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                                       boolean defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        List values = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        values.add("TRUE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        values.add("FALSE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        String dval = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        if (hasDefaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            dval = defaultValue ? "TRUE" : "FALSE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        addAttribute(elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                     attrName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                     DATATYPE_BOOLEAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                     true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                     dval,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                     values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * Removes an attribute from a previously defined element.  If no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * attribute with the given name was present in the given element,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * nothing happens and no exception is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @param attrName the name of the attribute being removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * is <code>null</code>, or is not a legal element name for this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    protected void removeAttribute(String elementName, String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        element.attrList.remove(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        element.attrMap.remove(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * Allows an <code>Object</code> reference of a given class type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * to be stored in nodes implementing the named element.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * value of the <code>Object</code> is unconstrained other than by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * its class type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * <p> If an <code>Object</code> reference was previously allowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * the previous settings are overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @param classType a <code>Class</code> variable indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * legal class type for the object value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * @param required <code>true</code> if an object value must be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @param defaultValue the default value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * <code>Object</code> reference, or <code>null</code>.
19168
ff364494f2b8 8022455: Fix doclint warnings in javax.imageio
prr
parents: 5506
diff changeset
   732
     * @param <T> the type of the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * is <code>null</code>, or is not a legal element name for this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    protected <T> void addObjectValue(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                                      Class<T> classType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                                      boolean required,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                      T defaultValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        ObjectValue obj = new ObjectValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        obj.valueType = VALUE_ARBITRARY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        obj.classType = classType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        obj.defaultValue = defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        element.objectValue = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * Allows an <code>Object</code> reference of a given class type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * to be stored in nodes implementing the named element.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * value of the <code>Object</code> must be one of the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * given by <code>enumeratedValues</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * <p> If an <code>Object</code> reference was previously allowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * the previous settings are overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @param classType a <code>Class</code> variable indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * legal class type for the object value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * @param required <code>true</code> if an object value must be present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * @param defaultValue the default value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * <code>Object</code> reference, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * @param enumeratedValues a <code>List</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * <code>Object</code>s containing the legal values for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * object reference.
19168
ff364494f2b8 8022455: Fix doclint warnings in javax.imageio
prr
parents: 5506
diff changeset
   769
     * @param <T> the type of the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * is <code>null</code>, or is not a legal element name for this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * <code>enumeratedValues</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * <code>enumeratedValues</code> does not contain at least one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * <code>enumeratedValues</code> contains an element that is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * an instance of the class type denoted by <code>classType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * or is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    protected <T> void addObjectValue(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                                      Class<T> classType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                                      boolean required,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                                      T defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                                      List<? extends T> enumeratedValues)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if (enumeratedValues == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            throw new IllegalArgumentException("enumeratedValues == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        if (enumeratedValues.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            throw new IllegalArgumentException("enumeratedValues is empty!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        Iterator iter = enumeratedValues.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            Object o = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            if (o == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                throw new IllegalArgumentException("enumeratedValues contains a null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            if (!classType.isInstance(o)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                throw new IllegalArgumentException("enumeratedValues contains a value not of class classType!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        ObjectValue obj = new ObjectValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        obj.valueType = VALUE_ENUMERATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        obj.classType = classType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        obj.defaultValue = defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        obj.enumeratedValues = enumeratedValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        element.objectValue = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * Allows an <code>Object</code> reference of a given class type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * to be stored in nodes implementing the named element.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * value of the <code>Object</code> must be within the range given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * by <code>minValue</code> and <code>maxValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * Furthermore, the class type must implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * <code>Comparable</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * <p> If an <code>Object</code> reference was previously allowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * the previous settings are overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * @param classType a <code>Class</code> variable indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * legal class type for the object value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * @param defaultValue the default value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @param minValue the smallest (inclusive or exclusive depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * on the value of <code>minInclusive</code>) legal value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * object value, as a <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * @param maxValue the largest (inclusive or exclusive depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * on the value of <code>minInclusive</code>) legal value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * object value, as a <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * @param minInclusive <code>true</code> if <code>minValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * is inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * @param maxInclusive <code>true</code> if <code>maxValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * is inclusive.
19168
ff364494f2b8 8022455: Fix doclint warnings in javax.imageio
prr
parents: 5506
diff changeset
   841
     * @param <T> the type of the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * is <code>null</code>, or is not a legal element name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    protected <T extends Object & Comparable<? super T>> void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        addObjectValue(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                       Class<T> classType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                       T defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                       Comparable<? super T> minValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                       Comparable<? super T> maxValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                       boolean minInclusive,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                       boolean maxInclusive)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        ObjectValue obj = new ObjectValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        obj.valueType = VALUE_RANGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if (minInclusive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            obj.valueType |= VALUE_RANGE_MIN_INCLUSIVE_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        if (maxInclusive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            obj.valueType |= VALUE_RANGE_MAX_INCLUSIVE_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        obj.classType = classType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        obj.defaultValue = defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        obj.minValue = minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        obj.maxValue = maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        element.objectValue = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * Allows an <code>Object</code> reference of a given class type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * to be stored in nodes implementing the named element.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * value of the <code>Object</code> must an array of objects of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * class type given by <code>classType</code>, with at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * <code>arrayMinLength</code> and at most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * <code>arrayMaxLength</code> elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * <p> If an <code>Object</code> reference was previously allowed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * the previous settings are overwritten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @param classType a <code>Class</code> variable indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * legal class type for the object value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @param arrayMinLength the smallest legal length for the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @param arrayMaxLength the largest legal length for the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @exception IllegalArgumentException if <code>elementName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * not a legal element name for this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    protected void addObjectValue(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                                  Class<?> classType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                                  int arrayMinLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                                  int arrayMaxLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        ObjectValue obj = new ObjectValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        obj.valueType = VALUE_LIST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        obj.classType = classType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        obj.arrayMinLength = arrayMinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        obj.arrayMaxLength = arrayMaxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        element.objectValue = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * Disallows an <code>Object</code> reference from being stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * nodes implementing the named element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * @exception IllegalArgumentException if <code>elementName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * not a legal element name for this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    protected void removeObjectValue(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        element.objectValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    // Utility method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    // Methods from IIOMetadataFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    // Root
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    public String getRootName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        return rootName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    // Multiplicity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    public abstract boolean canNodeAppear(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                                          ImageTypeSpecifier imageType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    public int getElementMinChildren(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        if (element.childPolicy != CHILD_POLICY_REPEAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            throw new IllegalArgumentException("Child policy not CHILD_POLICY_REPEAT!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        return element.minChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    public int getElementMaxChildren(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        if (element.childPolicy != CHILD_POLICY_REPEAT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            throw new IllegalArgumentException("Child policy not CHILD_POLICY_REPEAT!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        return element.maxChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    private String getResource(String key, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        if (locale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            locale = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
         * If an applet supplies an implementation of IIOMetadataFormat and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
         * resource bundles, then the resource bundle will need to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
         * accessed via the applet class loader. So first try the context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
         * class loader to locate the resource bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
         * If that throws MissingResourceException, then try the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
         * system class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        ClassLoader loader = (ClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                new java.security.PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                   public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                       return Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        ResourceBundle bundle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            bundle = ResourceBundle.getBundle(resourceBaseName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                                              locale, loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        } catch (MissingResourceException mre) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                bundle = ResourceBundle.getBundle(resourceBaseName, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            } catch (MissingResourceException mre1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            return bundle.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        } catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * Returns a <code>String</code> containing a description of the
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19168
diff changeset
   994
     * named element, or <code>null</code>.  The description will be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * localized for the supplied <code>Locale</code> if possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * <p> The default implementation will first locate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * <code>ResourceBundle</code> using the current resource base
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * name set by <code>setResourceBaseName</code> and the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * <code>Locale</code>, using the fallback mechanism described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * the comments for <code>ResourceBundle.getBundle</code>.  If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * <code>ResourceBundle</code> is found, the element name will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * used as a key to its <code>getString</code> method, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * result returned.  If no <code>ResourceBundle</code> is found,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * or no such key is present, <code>null</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * <p> If <code>locale</code> is <code>null</code>, the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * default <code>Locale</code> returned by <code>Locale.getLocale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @param locale the <code>Locale</code> for which localization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * will be attempted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * @return the element description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * is <code>null</code>, or is not a legal element name for this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @see #setResourceBaseName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    public String getElementDescription(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                                        Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        return getResource(elementName, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    // Children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public int getChildPolicy(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        return element.childPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    public String[] getChildNames(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        if (element.childPolicy == CHILD_POLICY_EMPTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        return (String[])element.childList.toArray(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    // Attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    public String[] getAttributeNames(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        List names = element.attrList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        String[] result = new String[names.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        return (String[])names.toArray(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    public int getAttributeValueType(String elementName, String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        Attribute attr = getAttribute(elementName, attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        return attr.valueType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    public int getAttributeDataType(String elementName, String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        Attribute attr = getAttribute(elementName, attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        return attr.dataType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    public boolean isAttributeRequired(String elementName, String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        Attribute attr = getAttribute(elementName, attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        return attr.required;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    public String getAttributeDefaultValue(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                                           String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        Attribute attr = getAttribute(elementName, attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        return attr.defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    public String[] getAttributeEnumerations(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                                             String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        Attribute attr = getAttribute(elementName, attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        if (attr.valueType != VALUE_ENUMERATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                ("Attribute not an enumeration!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        List values = attr.enumeratedValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        Iterator iter = values.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        String[] result = new String[values.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        return (String[])values.toArray(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    public String getAttributeMinValue(String elementName, String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        Attribute attr = getAttribute(elementName, attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        if (attr.valueType != VALUE_RANGE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            attr.valueType != VALUE_RANGE_MIN_INCLUSIVE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            attr.valueType != VALUE_RANGE_MAX_INCLUSIVE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            attr.valueType != VALUE_RANGE_MIN_MAX_INCLUSIVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            throw new IllegalArgumentException("Attribute not a range!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        return attr.minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    public String getAttributeMaxValue(String elementName, String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        Attribute attr = getAttribute(elementName, attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        if (attr.valueType != VALUE_RANGE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            attr.valueType != VALUE_RANGE_MIN_INCLUSIVE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            attr.valueType != VALUE_RANGE_MAX_INCLUSIVE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            attr.valueType != VALUE_RANGE_MIN_MAX_INCLUSIVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            throw new IllegalArgumentException("Attribute not a range!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        return attr.maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    public int getAttributeListMinLength(String elementName, String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        Attribute attr = getAttribute(elementName, attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        if (attr.valueType != VALUE_LIST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            throw new IllegalArgumentException("Attribute not a list!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        return attr.listMinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    public int getAttributeListMaxLength(String elementName, String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        Attribute attr = getAttribute(elementName, attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        if (attr.valueType != VALUE_LIST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            throw new IllegalArgumentException("Attribute not a list!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        return attr.listMaxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * Returns a <code>String</code> containing a description of the
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19168
diff changeset
  1132
     * named attribute, or <code>null</code>.  The description will be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * localized for the supplied <code>Locale</code> if possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * <p> The default implementation will first locate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * <code>ResourceBundle</code> using the current resource base
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * name set by <code>setResourceBaseName</code> and the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * <code>Locale</code>, using the fallback mechanism described in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * the comments for <code>ResourceBundle.getBundle</code>.  If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * <code>ResourceBundle</code> is found, the element name followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * by a "/" character followed by the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * (<code>elementName + "/" + attrName</code>) will be used as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * key to its <code>getString</code> method, and the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * returned.  If no <code>ResourceBundle</code> is found, or no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * such key is present, <code>null</code> will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * <p> If <code>locale</code> is <code>null</code>, the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * default <code>Locale</code> returned by <code>Locale.getLocale</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * @param elementName the name of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @param attrName the name of the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * @param locale the <code>Locale</code> for which localization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * will be attempted, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @return the attribute description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * @exception IllegalArgumentException if <code>elementName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * is <code>null</code>, or is not a legal element name for this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * @exception IllegalArgumentException if <code>attrName</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * <code>null</code> or is not a legal attribute name for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * @see #setResourceBaseName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    public String getAttributeDescription(String elementName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                                          String attrName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                                          Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        if (attrName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            throw new IllegalArgumentException("attrName == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        Attribute attr = (Attribute)element.attrMap.get(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            throw new IllegalArgumentException("No such attribute!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        String key = elementName + "/" + attrName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        return getResource(key, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    private ObjectValue getObjectValue(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        ObjectValue objv = (ObjectValue)element.objectValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        if (objv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            throw new IllegalArgumentException("No object within element " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                                               elementName + "!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        return objv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    public int getObjectValueType(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        Element element = getElement(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        ObjectValue objv = (ObjectValue)element.objectValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        if (objv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            return VALUE_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        return objv.valueType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    public Class<?> getObjectClass(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        ObjectValue objv = getObjectValue(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        return objv.classType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    public Object getObjectDefaultValue(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        ObjectValue objv = getObjectValue(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        return objv.defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    public Object[] getObjectEnumerations(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        ObjectValue objv = getObjectValue(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        if (objv.valueType != VALUE_ENUMERATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            throw new IllegalArgumentException("Not an enumeration!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        List vlist = objv.enumeratedValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        Object[] values = new Object[vlist.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        return vlist.toArray(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    public Comparable<?> getObjectMinValue(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        ObjectValue objv = getObjectValue(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        if ((objv.valueType & VALUE_RANGE) != VALUE_RANGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            throw new IllegalArgumentException("Not a range!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        return objv.minValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    public Comparable<?> getObjectMaxValue(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        ObjectValue objv = getObjectValue(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        if ((objv.valueType & VALUE_RANGE) != VALUE_RANGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            throw new IllegalArgumentException("Not a range!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        return objv.maxValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    public int getObjectArrayMinLength(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        ObjectValue objv = getObjectValue(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        if (objv.valueType != VALUE_LIST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            throw new IllegalArgumentException("Not a list!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        return objv.arrayMinLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    public int getObjectArrayMaxLength(String elementName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        ObjectValue objv = getObjectValue(elementName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        if (objv.valueType != VALUE_LIST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            throw new IllegalArgumentException("Not a list!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        return objv.arrayMaxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    // Standard format descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    private synchronized static void createStandardFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        if (standardFormat == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            standardFormat = new StandardMetadataFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * Returns an <code>IIOMetadataFormat</code> object describing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * standard, plug-in neutral <code>javax.imageio_1.0</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * metadata document format described in the comment of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * <code>javax.imageio.metadata</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * @return a predefined <code>IIOMetadataFormat</code> instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    public static IIOMetadataFormat getStandardFormatInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        createStandardFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        return standardFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
}