KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > message > NodeListImpl


1 /*
2  * Copyright 2001-2004 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
17 package org.apache.axis.message;
18
19 import org.w3c.dom.Node JavaDoc;
20 import org.w3c.dom.NodeList JavaDoc;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.List JavaDoc;
26
27 /**
28  * A simple implementation for Nodelist Support in AXIS
29  *
30  * @author Heejune Ahn (cityboy@tmax.co.kr)
31  *
32  */

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

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

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