KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > utils > HelperNodeList


1
2 /*
3  * Copyright 1999-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package com.sun.org.apache.xml.internal.security.utils;
19
20
21
22 import java.util.ArrayList JavaDoc;
23
24 import org.w3c.dom.Document JavaDoc;
25 import org.w3c.dom.Node JavaDoc;
26 import org.w3c.dom.NodeList JavaDoc;
27
28
29 /**
30  *
31  *
32  * @author Christian Geuer-Pollmann
33  *
34  */

35 public class HelperNodeList implements NodeList JavaDoc {
36
37    /** {@link java.util.logging} logging facility */
38     static java.util.logging.Logger JavaDoc log =
39     java.util.logging.Logger.getLogger(HelperNodeList.class.getName());
40
41    /** Field nodes */
42    ArrayList JavaDoc nodes = new ArrayList JavaDoc(20);
43
44    boolean _allNodesMustHaveSameParent = false;
45
46    /**
47     *
48     */

49    public HelperNodeList() {
50       this(false);
51    }
52
53    
54    /**
55     * @param allNodesMustHaveSameParent
56     */

57    public HelperNodeList(boolean allNodesMustHaveSameParent) {
58       this._allNodesMustHaveSameParent = allNodesMustHaveSameParent;
59    }
60
61    /**
62     * Method item
63     *
64     * @param index
65     * @return node with inde i
66     */

67    public Node JavaDoc item(int index) {
68
69       // if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "item(" + index + ") of " + this.getLength() + " nodes");
70

71       return (Node JavaDoc) nodes.get(index);
72    }
73
74    /**
75     * Method getLength
76     *
77     * @return length of the list
78     */

79    public int getLength() {
80       return nodes.size();
81    }
82
83    /**
84     * Method appendChild
85     *
86     * @param node
87     * @throws IllegalArgumentException
88     */

89    public void appendChild(Node JavaDoc node) throws IllegalArgumentException JavaDoc {
90       if (this._allNodesMustHaveSameParent && this.getLength() > 0) {
91          if (this.item(0).getParentNode() != node.getParentNode()) {
92             throw new IllegalArgumentException JavaDoc("Nodes have not the same Parent");
93          }
94       }
95       nodes.add(node);
96    }
97
98    /**
99     * @return the document that contains this nodelist
100     */

101    public Document JavaDoc getOwnerDocument() {
102       if (this.getLength() == 0) {
103          return null;
104       }
105       return XMLUtils.getOwnerDocument(this.item(0));
106    }
107 }
108
Popular Tags