1 /*
2  * Copyright (C) 2007 The Android Open Source Project
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.harmony.xml.dom;
18 
19 import org.w3c.dom.Node;
20 
21 /**
22  * Provides a straightforward implementation of the corresponding W3C DOM
23  * interface. The class is used internally only, thus only notable members that
24  * are not in the original interface are documented (the W3C docs are quite
25  * extensive). Hope that's ok.
26  * <p>
27  * Some of the fields may have package visibility, so other classes belonging to
28  * the DOM implementation can easily access them while maintaining the DOM tree
29  * structure.
30  * <p>
31  * This class represents a Node that has a parent Node, but no children.
32  */
33 public abstract class LeafNodeImpl extends NodeImpl {
34 
35     // Maintained by InnerNodeImpl.
36     InnerNodeImpl parent;
37 
38     // Maintained by InnerNodeImpl.
39     int index;
40 
LeafNodeImpl(DocumentImpl document)41     LeafNodeImpl(DocumentImpl document) {
42         super(document);
43     }
44 
getNextSibling()45     public Node getNextSibling() {
46         if (parent == null || index + 1 >= parent.children.size()) {
47             return null;
48         }
49 
50         return parent.children.get(index + 1);
51     }
52 
getParentNode()53     public Node getParentNode() {
54         return parent;
55     }
56 
getPreviousSibling()57     public Node getPreviousSibling() {
58         if (parent == null || index == 0) {
59             return null;
60         }
61 
62         return parent.children.get(index - 1);
63     }
64 
isParentOf(Node node)65     boolean isParentOf(Node node) {
66         return false;
67     }
68 
69 }
70