View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * @deprecated since 2.0.0
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);  // first child
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  }