1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.javagen.agile.core.context;
17
18 import org.javagen.agile.core.model.Model;
19
20 /***
21 * Builds a context by pushing the nodes on a stack from root to leaf so that leaf
22 * values take precedence. Also pushes the current model and current models name.
23 *
24 * @author Richard Easterling
25 */
26 public class DefaultContextLoader implements ContextLoader {
27
28 public void pushAll(ContextHolderStack stack, Model modelTree) {
29 pushModelTreeFromRoot(stack, modelTree);
30 }
31
32 public void popAll(ContextHolderStack stack, Model modelTree) {
33 popModelTreeToRoot(stack, modelTree);
34 }
35
36 public static void pushModelTreeFromRoot(ContextHolderStack stack, Model node) {
37 if (node==null)
38 return;
39 pushModelTreeFromRoot(stack, node.getParentModel());
40 node.put(Keys.MODEL.toString(), node);
41 node.put(Keys.MODEL_NAME.toString(), node.getName());
42 stack.push(node);
43 }
44
45 public static void popModelTreeToRoot(ContextHolderStack stack, Model parent) {
46 while(parent!=null) {
47 stack.pop();
48 parent = parent.getParentModel();
49 }
50 }
51
52 }