1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.model;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Stack;
28
29
30
31
32 @Deprecated
33 public class MixedTreeModel {
34
35 private static final Logger LOG = LoggerFactory.getLogger(MixedTreeModel.class);
36
37 private Node root;
38 private Node current;
39 private Stack<Boolean> junctions = new Stack<Boolean>();
40
41 public void beginBuildNode() {
42 Node newNode = new Node();
43 if (root == null) {
44 root = newNode;
45 current = root;
46 } else {
47 current.add(newNode);
48 current = newNode;
49 }
50 }
51
52 public void endBuildNode() {
53 current = current.getParent();
54 }
55
56 public void onEncodeBegin() {
57 if (LOG.isDebugEnabled()) {
58 LOG.debug("current=" + current);
59 }
60 if (current == null) {
61 current = root;
62 junctions.push(hasCurrentNodeNextSibling());
63 } else {
64 if (current.getChildren().size() > 0) {
65 current = current.getChildAt(0);
66 junctions.push(hasCurrentNodeNextSibling());
67 } else {
68 Node searchParent = current;
69 do {
70 junctions.pop();
71 Node nextSibling = searchParent.nextSibling();
72 if (nextSibling != null) {
73 current = nextSibling;
74 junctions.push(hasCurrentNodeNextSibling());
75 return;
76 }
77 searchParent = searchParent.getParent();
78 } while (searchParent != null);
79 current = null;
80 }
81 }
82 }
83
84 public boolean hasCurrentNodeNextSibling() {
85 return current.hasNextSibling();
86 }
87
88 public List<Boolean> getJunctions() {
89 Boolean top = junctions.pop();
90 List<Boolean> result = new ArrayList<Boolean>(junctions);
91 junctions.push(top);
92 return result;
93 }
94
95 public TreePath getPath() {
96 return current.getPath();
97 }
98 }