1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
package org.webmacro.engine; |
25 | |
|
26 | |
import org.webmacro.PropertyException; |
27 | |
|
28 | |
import java.util.HashMap; |
29 | |
import java.util.Map; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class MacroBuildContext extends BuildContext |
38 | |
{ |
39 | |
|
40 | |
private BuildContext chainedContext, rootContext; |
41 | |
private MacroDefinition macro; |
42 | |
private Object[] args; |
43 | 0 | private Map macroArgs = new HashMap(); |
44 | |
|
45 | |
public MacroBuildContext (MacroDefinition macroP, |
46 | |
Object[] argsP, |
47 | |
BuildContext bc) |
48 | |
{ |
49 | 0 | super(bc.getBroker()); |
50 | 0 | this.chainedContext = bc; |
51 | 0 | this.args = argsP; |
52 | 0 | this.macro = macroP; |
53 | 0 | String[] argNames = macro.getArgNames(); |
54 | 0 | for (int i = 0; i < argNames.length; i++) |
55 | 0 | macroArgs.put(argNames[i], args[i]); |
56 | |
|
57 | 0 | rootContext = chainedContext; |
58 | 0 | while (rootContext instanceof MacroBuildContext) |
59 | 0 | rootContext = ((MacroBuildContext) rootContext).chainedContext; |
60 | 0 | } |
61 | |
|
62 | |
public BuildContext getRootContext () |
63 | |
{ |
64 | 0 | return rootContext; |
65 | |
} |
66 | |
|
67 | |
public void putMacro (String name, MacroDefinition macro) |
68 | |
{ |
69 | 0 | rootContext.putMacro(name, macro); |
70 | 0 | } |
71 | |
|
72 | |
public MacroDefinition getMacro (String name) |
73 | |
{ |
74 | 0 | return rootContext.getMacro(name); |
75 | |
} |
76 | |
|
77 | |
public boolean containsKey (Object name) |
78 | |
{ |
79 | 0 | return macroArgs.containsKey(name) || chainedContext.containsKey(name); |
80 | |
} |
81 | |
|
82 | |
protected Object internalGet (Object name) throws PropertyException |
83 | |
{ |
84 | 0 | if (macroArgs.containsKey(name)) |
85 | 0 | return macroArgs.get(name); |
86 | |
else |
87 | |
{ |
88 | 0 | return rootContext.get(name); |
89 | |
} |
90 | |
} |
91 | |
} |
92 | |
|