KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > saaj > NodeListImpl


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

16 package org.apache.axis2.saaj;
17
18 import org.w3c.dom.Node JavaDoc;
19 import org.w3c.dom.NodeList JavaDoc;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24
25 /**
26  * @author Ashutosh Shahi
27  *
28  * TODO To change the template for this generated type comment go to
29  * Window - Preferences - Java - Code Style - Code Templates
30  */

31 public class NodeListImpl implements NodeList JavaDoc {
32     
33     List JavaDoc mNodes;
34     
35     public static final NodeList JavaDoc EMPTY_NODELIST = new NodeListImpl(Collections.EMPTY_LIST);
36     
37     /**
38      * Constructor and Setter is intensionally made package access only.
39      *
40      */

41     NodeListImpl() {
42         mNodes = new ArrayList JavaDoc();
43     }
44     
45     NodeListImpl(List JavaDoc nodes) {
46         this();
47         mNodes.addAll(nodes);
48     }
49
50     void addNode(org.w3c.dom.Node JavaDoc node) {
51         mNodes.add(node);
52     }
53
54     void addNodeList(org.w3c.dom.NodeList JavaDoc nodes) {
55         for (int i = 0; i < nodes.getLength(); i++) {
56             mNodes.add(nodes.item(i));
57         }
58     }
59     
60     /**
61      * Interface Implemented
62      *
63      * @param index
64      * @return
65      */

66     public Node JavaDoc item(int index) {
67         if (mNodes != null && mNodes.size() > index) {
68             return (Node JavaDoc) mNodes.get(index);
69         } else {
70             return null;
71         }
72     }
73
74     public int getLength() {
75         return mNodes.size();
76     }
77
78 }
79
Popular Tags