summaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/imageio/metadata/IIOMetadataFormatImpl.java
blob: efea723f9ab061ff9bf338369ad5a01bfb61de75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
/* IIOMetadataFormatImpl.java --
   Copyright (C) 2004  Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */


package javax.imageio.metadata;

import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.w3c.dom.TypeInfo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import javax.imageio.ImageTypeSpecifier;

public abstract class IIOMetadataFormatImpl implements IIOMetadataFormat
{
  /**
   * The standard metadata format name constant set to
   * "javax_imageio_1.0".
   */
  public static final String standardMetadataFormatName = "javax_imageio_1.0";

  private String rootName;

  // These maps assume that each element name is unique.

  private Map nodes = new HashMap();

  // A mapping from element name to child policy.
  private Map childPolicies = new HashMap();

  // A mapping from element name to the permissible number of
  // children.  Values in this map are length-two integer arrays; the
  // first index is the minimum bound, the second index is the maximum
  // bound.
  private Map childRanges = new HashMap();

  private String resourceBaseName;

  // Package-private so that it may be used in IIOMetadataNode.
  static class IIOMetadataNodeAttr extends IIOMetadataNode
    implements Attr
  {
    protected Element owner;
    protected String name;
    protected int dataType;
    protected boolean required;
    protected String defaultValue;

    public IIOMetadataNodeAttr (Element owner,
                                String name,
                                String defaultValue)
    {
      this (owner, name, IIOMetadataFormat.DATATYPE_STRING,
            true, defaultValue);
    }

    public IIOMetadataNodeAttr (Element owner,
                                String name,
                                int dataType,
                                boolean required,
                                String defaultValue)
    {
      this.owner = owner;
      this.name = name;
      this.dataType = dataType;
      this.required = required;
      this.defaultValue = defaultValue;
    }

    public String getName ()
    {
      return name;
    }

    public Element getOwnerElement ()
    {
      return owner;
    }

    public int getDataType ()
    {
      return dataType;
    }

    public TypeInfo getSchemaTypeInfo ()
    {
      return null;
    }

    public boolean getSpecified ()
    {
      return false;
    }

    public String getValue ()
    {
      return defaultValue;
    }

    public boolean isId()
    {
      return false;
    }

    public void setValue (String value)
    {
    }

    // new methods

    public boolean isRequired ()
    {
      return required;
    }
  }

  private class IIOMetadataNodeAttrEnumerated extends IIOMetadataNodeAttr
  {
    protected List enumeratedValues;

    public IIOMetadataNodeAttrEnumerated (Element owner,
                                          String name,
                                          int dataType,
                                          boolean required,
                                          String defaultValue,
                                          List enumeratedValues)
    {
      super (owner, name, dataType, required, defaultValue);
      this.enumeratedValues = new ArrayList (enumeratedValues);
    }

    public Object[] getEnumerations ()
    {
      return enumeratedValues.toArray ();
    }
  }

  private class IIOMetadataNodeAttrBounded extends IIOMetadataNodeAttr
  {
    protected String minValue;
    protected String maxValue;
    protected boolean minInclusive;
    protected boolean maxInclusive;

    public IIOMetadataNodeAttrBounded (Element owner,
                                       String name,
                                       int dataType,
                                       boolean required,
                                       String defaultValue,
                                       String minValue,
                                       String maxValue,
                                       boolean minInclusive,
                                       boolean maxInclusive)
    {
      super (owner, name, dataType, required, defaultValue);
      this.minValue = minValue;
      this.maxValue = maxValue;
      this.minInclusive = minInclusive;
      this.maxInclusive = maxInclusive;
    }

    public String getMinValue ()
    {
      return minValue;
    }

    public String getMaxValue ()
    {
      return maxValue;
    }
  }

  private class IIOMetadataNodeAttrList extends IIOMetadataNodeAttr
  {
    protected int listMinLength;
    protected int listMaxLength;

    public IIOMetadataNodeAttrList (Element owner,
                                    String name,
                                    int dataType,
                                    boolean required,
                                    int listMinLength,
                                    int listMaxLength)
    {
      super (owner, name, dataType, required, null);
      this.listMinLength = listMinLength;
      this.listMaxLength = listMaxLength;
    }

    public int getListMinLength ()
    {
      return listMinLength;
    }

    public int getListMaxLength ()
    {
      return listMaxLength;
    }
  }

  private class NodeObject
  {
    protected Element owner;
    protected Class classType;
    protected boolean required;
    protected Object defaultValue;
    protected int valueType;

    public NodeObject (Element owner,
                       Class classType,
                       boolean required,
                       Object defaultValue)
    {
      this.owner = owner;
      this.classType = classType;
      this.required = required;
      this.defaultValue = defaultValue;
      valueType = IIOMetadataFormat.VALUE_ARBITRARY;
    }

    public int getValueType ()
    {
      return valueType;
    }

    public Class getClassType ()
    {
      return classType;
    }

    public Element getOwnerElement ()
    {
      return owner;
    }

    public Object getDefaultValue ()
    {
      return defaultValue;
    }

    public boolean isRequired ()
    {
      return required;
    }
  }

  private class NodeObjectEnumerated extends NodeObject
  {
    protected List enumeratedValues;

    public NodeObjectEnumerated (Element owner,
                                 Class classType,
                                 boolean required,
                                 Object defaultValue,
                                 List enumeratedValues)
    {
      super (owner, classType, false, defaultValue);
      this.enumeratedValues = enumeratedValues;
      valueType = IIOMetadataFormat.VALUE_ENUMERATION;
    }

    public Object[] getEnumerations ()
    {
      return enumeratedValues.toArray();
    }
  }

  private class NodeObjectBounded extends NodeObject
  {
    protected Comparable minValue;
    protected Comparable maxValue;
    protected boolean minInclusive;
    protected boolean maxInclusive;

    public NodeObjectBounded (Element owner,
                              Class classType,
                              Object defaultValue,
                              Comparable minValue,
                              Comparable maxValue,
                              boolean minInclusive,
                              boolean maxInclusive)
    {
      super (owner, classType, false, defaultValue);
      this.minValue = minValue;
      this.maxValue = maxValue;
      this.minInclusive = minInclusive;
      this.maxInclusive = maxInclusive;
      if (minInclusive)
        {
          if (maxInclusive)
            valueType = IIOMetadataFormat.VALUE_RANGE_MIN_MAX_INCLUSIVE;
          else
            valueType = IIOMetadataFormat.VALUE_RANGE_MIN_INCLUSIVE;
        }
      else
        {
          if (maxInclusive)
            valueType = IIOMetadataFormat.VALUE_RANGE_MAX_INCLUSIVE;
          else
            valueType = IIOMetadataFormat.VALUE_RANGE;
        }
    }

    public Comparable getMinValue ()
    {
      return minValue;
    }

    public Comparable getMaxValue ()
    {
      return maxValue;
    }
  }

  private class NodeObjectArray extends NodeObject
  {
    protected Integer arrayMinLength;
    protected Integer arrayMaxLength;

    public NodeObjectArray (Element owner,
                            Class classType,
                            int arrayMinLength,
                            int arrayMaxLength)
    {
      super (owner, classType, false, null);
      this.arrayMinLength = new Integer (arrayMinLength);
      this.arrayMaxLength = new Integer (arrayMaxLength);
      valueType = IIOMetadataFormat.VALUE_LIST;
    }

    public Comparable getArrayMinLength ()
    {
      return arrayMinLength;
    }

    public Comparable getArrayMaxLength ()
    {
      return arrayMaxLength;
    }
  }

  /**
   * Construct a blank IIOMetadataFormatImpl with the given root name
   * and child policy.
   *
   * @param rootName the root element name
   * @param childPolicy the child policy of the root element
   *
   * @exception IllegalArgumentException if rootName is null
   * @exception IllegalArgumentException if childPolicy is
   * CHILD_POLICY_REPEAT or if childPolicy is not a CHILD_POLICY
   * constant
   */
  public IIOMetadataFormatImpl (String rootName, int childPolicy)
  {
    if (rootName == null)
      throw new IllegalArgumentException ("null argument");

    if (childPolicy < IIOMetadataFormat.CHILD_POLICY_ALL
        || childPolicy > IIOMetadataFormat.CHILD_POLICY_SOME
        || childPolicy == IIOMetadataFormat.CHILD_POLICY_REPEAT)
      throw new IllegalArgumentException ("wrong child policy");

    nodes.put (rootName, new IIOMetadataNode (rootName));
    childPolicies.put (rootName, new Integer (childPolicy));
    this.rootName = rootName;
  }

  /**
   * Construct a blank IIOMetadataFormatImpl with the given root name,
   * a child policy of CHILD_POLICY_REPEAT and the given minimum and
   * maximum limits on the number of root element children.
   *
   * @param rootName the root element name
   * @param minChildren the minimum number of children that this node
   * can have
   * @param maxChildren the maximum number of children that this node
   * can have
   *
   * @exception IllegalArgumentException if rootName is null
   * @exception IllegalArgumentException if minChildren is less than
   * zero or greater than maxChildren
   */
  public IIOMetadataFormatImpl (String rootName,
                                int minChildren,
                                int maxChildren)
  {
    if (rootName == null)
      throw new IllegalArgumentException ("null argument");

    if (minChildren < 0 || maxChildren < minChildren)
      throw new IllegalArgumentException ("invalid min or max children argument");

    nodes.put (rootName, new IIOMetadataNode (rootName));
    childPolicies.put (rootName, new Integer (IIOMetadataFormat.CHILD_POLICY_REPEAT));
    childRanges.put (rootName, new int [] { minChildren, maxChildren });
    this.rootName = rootName;
  }

  protected void addAttribute (String elementName,
                               String attrName,
                               int dataType,
                               boolean required,
                               String defaultValue)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    node.setAttributeNode (new IIOMetadataNodeAttr (node,
                                                    attrName,
                                                    dataType,
                                                    required,
                                                    defaultValue));
  }

  protected void addAttribute (String elementName,
                               String attrName,
                               int dataType,
                               boolean required,
                               String defaultValue,
                               List<String> enumeratedValues)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    node.setAttributeNode (new IIOMetadataNodeAttrEnumerated (node,
                                                              attrName,
                                                              dataType,
                                                              required,
                                                              defaultValue,
                                                              enumeratedValues));
  }

  protected void addAttribute (String elementName,
                               String attrName,
                               int dataType,
                               boolean required,
                               String defaultValue,
                               String minValue,
                               String maxValue,
                               boolean minInclusive,
                               boolean maxInclusive)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    node.setAttributeNode (new IIOMetadataNodeAttrBounded (node,
                                                           attrName,
                                                           dataType,
                                                           required,
                                                           defaultValue,
                                                           minValue,
                                                           maxValue,
                                                           minInclusive,
                                                           maxInclusive));
  }

  protected void addAttribute (String elementName,
                               String attrName,
                               int dataType,
                               boolean required,
                               int listMinLength,
                               int listMaxLength)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    node.setAttributeNode (new IIOMetadataNodeAttrList (node,
                                                        attrName,
                                                        dataType,
                                                        required,
                                                        listMinLength,
                                                        listMaxLength));
  }

  protected void addBooleanAttribute (String elementName,
                                      String attrName,
                                      boolean hasDefaultValue,
                                      boolean defaultValue)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);

    List enumeratedValues = new ArrayList();
    enumeratedValues.add ("TRUE");
    enumeratedValues.add ("FALSE");

    node.setAttributeNode (new IIOMetadataNodeAttrEnumerated (node,
                                                              attrName,
                                                              IIOMetadataFormat.DATATYPE_BOOLEAN,
                                                              hasDefaultValue,
                                                              defaultValue ? "TRUE" : "FALSE",
                                                              enumeratedValues));
  }

  protected void addChildElement (String elementName, String parentName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (parentName);

    node.appendChild (new IIOMetadataNode (elementName));
    childPolicies.put (elementName, new Integer (IIOMetadataFormat.CHILD_POLICY_REPEAT));
  }

  protected void addElement (String elementName, String parentName, int childPolicy)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (parentName);

    node.appendChild (new IIOMetadataNode (elementName));
    childPolicies.put (elementName, new Integer (childPolicy));
  }

  protected void addElement (String elementName, String parentName,
                             int minChildren, int maxChildren)
  {
    addChildElement (elementName, parentName);
    childRanges.put (elementName, new int [] { minChildren, maxChildren });
  }

  private void addNodeObject (IIOMetadataNode node, NodeObject o)
  {
    node.setUserObject (o);
  }

  private NodeObject getNodeObject (IIOMetadataNode node)
  {
    return (NodeObject) node.getUserObject ();
  }

  private void removeNodeObject (IIOMetadataNode node)
  {
    node.setUserObject (null);
  }

  protected <T> void addObjectValue (String elementName, Class<T> classType,
                                     boolean required, T defaultValue)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    addNodeObject (node, new NodeObject (node,
                                         classType,
                                         required,
                                         defaultValue));
  }

  protected <T> void addObjectValue (String elementName, Class<T> classType,
                                     boolean required, T defaultValue,
                                     List<? extends T> enumeratedValues)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    addNodeObject (node, new NodeObjectEnumerated (node,
                                                   classType,
                                                   required,
                                                   defaultValue,
                                                   enumeratedValues));
  }

  protected <T extends Object & Comparable<? super T>>
  void addObjectValue (String elementName, Class<T> classType,
                       T defaultValue,
                       Comparable<? super T> minValue,
                       Comparable<? super T> maxValue,
                       boolean minInclusive,
                       boolean maxInclusive)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    addNodeObject (node, new NodeObjectBounded (node,
                                                classType,
                                                defaultValue,
                                                minValue,
                                                maxValue,
                                                minInclusive,
                                                maxInclusive));
  }

  protected void addObjectValue (String elementName, Class<?> classType,
                                 int arrayMinLength, int arrayMaxLength)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    addNodeObject (node, new NodeObjectArray (node,
                                              classType,
                                              arrayMinLength,
                                              arrayMaxLength));
  }

  public String getRootName ()
  {
    return rootName;
  }

  protected String getResourceBaseName ()
  {
    return resourceBaseName;
  }

  public static IIOMetadataFormat getStandardFormatInstance ()
  {
    // FIXME: populate this with the standard metadata format
    return new IIOMetadataFormatImpl (standardMetadataFormatName,
                                      IIOMetadataFormat.CHILD_POLICY_ALL)
      {
        public boolean canNodeAppear (String elementName,
                                      ImageTypeSpecifier specifier)
        {
          return true;
        }
      };
  }

  public abstract boolean canNodeAppear (String elementName,
                                         ImageTypeSpecifier specifier);

  protected void removeAttribute (String elementName,
                                  String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    node.removeAttribute (attrName);
  }

  protected void removeElement (String elementName)
  {
    nodes.remove (elementName);
  }

  protected void removeObjectValue (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    removeNodeObject (node);
  }

  protected void setResourceBaseName (String resourceBaseName)
  {
    this.resourceBaseName = resourceBaseName;
  }

  public int getAttributeDataType (String elementName, String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) node.getAttributeNode (attrName);
    return attr.getDataType ();
  }

  public String getAttributeDefaultValue (String elementName, String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) node.getAttributeNode (attrName);
    return attr.getValue();
  }

  public String getAttributeDescription (String elementName, String attrName, Locale locale)
  {
    return getDescription (elementName + "/" + attrName, locale);
  }

  public String[] getAttributeEnumerations (String elementName, String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    IIOMetadataNodeAttrEnumerated attr =
      (IIOMetadataNodeAttrEnumerated) node.getAttributeNode (attrName);

    Object[] attrEnums = attr.getEnumerations();

    String[] attrNames = new String[attrEnums.length];

    for (int i = 0; i < attrEnums.length; i++)
      {
        attrNames[i] = (String) attrEnums[i];
      }

    return attrNames;
  }

  public int getAttributeListMaxLength (String elementName, String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    IIOMetadataNodeAttrList attr =
      (IIOMetadataNodeAttrList) node.getAttributeNode (attrName);
    return attr.getListMaxLength();
  }

  public int getAttributeListMinLength (String elementName, String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    IIOMetadataNodeAttrList attr =
      (IIOMetadataNodeAttrList) node.getAttributeNode (attrName);
    return attr.getListMinLength();
  }

  public String getAttributeMaxValue (String elementName, String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    IIOMetadataNodeAttrBounded attr =
      (IIOMetadataNodeAttrBounded) node.getAttributeNode (attrName);
    return attr.getMaxValue();
  }

  public String getAttributeMinValue (String elementName, String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    IIOMetadataNodeAttrBounded attr =
      (IIOMetadataNodeAttrBounded) node.getAttributeNode (attrName);
    return attr.getMinValue();
  }

  public String[] getAttributeNames (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);

    NamedNodeMap attrNodes = node.getAttributes();

    String[] attrNames = new String[attrNodes.getLength()];

    for (int i = 0; i < attrNodes.getLength(); i++)
      {
        attrNames[i] = attrNodes.item (i).getLocalName();
      }

    return attrNames;
  }

  public int getAttributeValueType (String elementName, String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) node.getAttributeNode (attrName);
    return attr.getDataType();
  }

  public String[] getChildNames (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);

    NodeList childNodes = node.getChildNodes();

    String[] childNames = new String[childNodes.getLength()];

    for (int i = 0; i < childNodes.getLength(); i++)
      {
        childNames[i] = childNodes.item (i).getLocalName();
      }

    return childNames;
  }

  public int getChildPolicy (String elementName)
  {
    return ((Integer) childPolicies.get (elementName)).intValue();
  }

  private String getDescription (String resourceName, Locale locale)
  {
    if (resourceBaseName == null)
      return null;

    Locale l = locale;

    if (l == null)
      l = Locale.getDefault();

    ResourceBundle bundle = ResourceBundle.getBundle (resourceBaseName, locale);

    String desc = null;

    if (bundle == null)
      {
        try
          {
            desc = bundle.getString (resourceName);
          }
        catch (MissingResourceException e)
          {
            desc = null;
          }
      }

    return desc;
  }

  public String getElementDescription (String elementName, Locale locale)
  {
    return getDescription (elementName, locale);
  }

  public int getElementMaxChildren (String elementName)
  {
    return ((int[]) childRanges.get (elementName))[1];
  }

  public int getElementMinChildren (String elementName)
  {
    return ((int[]) childRanges.get (elementName))[0];
  }

  public int getObjectArrayMaxLength (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    return ((Integer) ((NodeObjectArray) getNodeObject (node)).getArrayMaxLength ()).intValue();
  }

  public int getObjectArrayMinLength (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    return ((Integer) ((NodeObjectArray) getNodeObject (node)).getArrayMinLength ()).intValue();
  }

  public Class<?> getObjectClass (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    return getNodeObject (node).getClassType ();
  }

  public Object getObjectDefaultValue (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    return getNodeObject (node).getDefaultValue ();
  }

  public Object[] getObjectEnumerations (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    return ((NodeObjectEnumerated) getNodeObject (node)).getEnumerations ();
  }

  public Comparable<?> getObjectMaxValue (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    return ((NodeObjectBounded) getNodeObject (node)).getMaxValue ();
  }

  public Comparable<?> getObjectMinValue (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    return ((NodeObjectBounded) getNodeObject (node)).getMinValue ();
  }

  public int getObjectValueType (String elementName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    NodeObject n = getNodeObject (node);

    if (n == null)
      return IIOMetadataFormat.VALUE_NONE;
    else
      return n.getValueType ();
  }

  public boolean isAttributeRequired (String elementName, String attrName)
  {
    IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
    return ((IIOMetadataNodeAttr) node.getAttributeNode (attrName)).isRequired();
  }
}