jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/HelperNodeList.java
author mullan
Mon, 26 Sep 2011 17:20:45 -0700
changeset 10694 cf59e2badd14
parent 1337 e8d6cef36199
child 18780 f47b920867e7
permissions -rw-r--r--
7088502: Security libraries don't build with javac -Werror Summary: Changes to files in src/share/classes/com/sun/org/apache/xml/internal/security and its subpackages to remove warnings Reviewed-by: mullan Contributed-by: kurchi.subhra.hazra@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.security.utils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
import java.util.ArrayList;
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    24
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class HelperNodeList implements NodeList {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
   /** Field nodes */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    38
   List<Node> nodes = new ArrayList<Node>(20);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
   boolean _allNodesMustHaveSameParent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
   public HelperNodeList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
      this(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    * @param allNodesMustHaveSameParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
   public HelperNodeList(boolean allNodesMustHaveSameParent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
      this._allNodesMustHaveSameParent = allNodesMustHaveSameParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    * Method item
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    * @param index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    * @return node with inde i
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
   public Node item(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    64
      // log.log(java.util.logging.Level.FINE, "item(" + index + ") of " + this.getLength() + " nodes");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    66
      return nodes.get(index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    * Method getLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    *  @return length of the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
   public int getLength() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
      return nodes.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    * Method appendChild
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    * @param node
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    * @throws IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
   public void appendChild(Node node) throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      if (this._allNodesMustHaveSameParent && this.getLength() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         if (this.item(0).getParentNode() != node.getParentNode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            throw new IllegalArgumentException("Nodes have not the same Parent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      nodes.add(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    * @return the document that contains this nodelist
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
   public Document getOwnerDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
      if (this.getLength() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
      return XMLUtils.getOwnerDocument(this.item(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}