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