##### Coverage Report - org.webmacro.engine.MacroBuildContext

Classes in this File | Line Coverage | Branch Coverage | Complexity
MacroBuildContext |
0% | 0/20
0% | 0/10
| 1.8333333333333333;1.833

1 |  |
     /*
2 |  |
      * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
3 |  |
      *
4 |  |
      * Redistribution and use in source and binary forms, with or without
5 |  |
      * modification, are permitted under the terms of either of the following
6 |  |
      * Open Source licenses:
7 |  |
      *
8 |  |
      * The GNU General Public License, version 2, or any later version, as
9 |  |
      * published by the Free Software Foundation
10 |  |
      * (http://www.fsf.org/copyleft/gpl.html);
11 |  |
      *
12 |  |
      *  or
13 |  |
      *
14 |  |
      * The Semiotek Public License (http://webmacro.org/LICENSE.)
15 |  |
      *
16 |  |
      * This software is provided "as is", with NO WARRANTY, not even the
17 |  |
      * implied warranties of fitness to purpose, or merchantability. You
18 |  |
      * assume all risks and liabilities associated with its use.
19 |  |
      *
20 |  |
      * See www.webmacro.org for more information on the WebMacro project.
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 |  |
      * A chained build context, for use in expanding macros.
33 |  |
      * When called upon to evaluate a reference which is one of the macros
34 |  |
      * formals, it evaluates the actual argument and returns that, otherwise
35 |  |
      * it chains back to the build context.
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 |  |