1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.webmacro.directive;
24
25 import org.webmacro.Context;
26 import org.webmacro.FastWriter;
27 import org.webmacro.PropertyException;
28 import org.webmacro.engine.BuildContext;
29 import org.webmacro.engine.BuildException;
30 import org.webmacro.engine.Variable;
31
32 import java.io.IOException;
33
34 /***
35 * The #param directive is provided for backward compatibility.
36 * Invoking
37 * #param $a="stuff"
38 * is equivalent to
39 * #attribute $a="stuff"
40 * #set $a="stuff"
41 */
42
43 public class ParamDirective extends Directive
44 {
45
46 private static final int PARAM_TARGET = 1;
47 private static final int PARAM_RESULT = 2;
48
49 private static final ArgDescriptor[]
50 myArgs = new ArgDescriptor[]{
51 new LValueArg(PARAM_TARGET),
52 new AssignmentArg(),
53 new RValueArg(PARAM_RESULT)
54 };
55
56 private static final DirectiveDescriptor
57 myDescr = new DirectiveDescriptor("param", null, myArgs, null);
58
59 public static DirectiveDescriptor getDescriptor ()
60 {
61 return myDescr;
62 }
63
64 public Object build (DirectiveBuilder builder,
65 BuildContext bc)
66 throws BuildException
67 {
68 Variable target = null;
69 Object result = null;
70 try
71 {
72 target = (Variable) builder.getArg(PARAM_TARGET, bc);
73 result = builder.getArg(PARAM_RESULT, bc);
74 if (!target.isSimpleName())
75 throw new NotSimpleVariableBuildException(myDescr.name);
76
77 target.setValue(bc, result);
78 }
79 catch (ClassCastException e)
80 {
81 throw new NotVariableBuildException(myDescr.name, e);
82 }
83 catch (PropertyException e)
84 {
85 throw new BuildException("#param: Exception setting variable "
86 + target.toString(), e);
87 }
88 return new SetDirective(target, result);
89 }
90
91 public void write (FastWriter out, Context context)
92 throws PropertyException, IOException
93 {
94 }
95
96 }
97