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 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | 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 | 2 | myArgs = new ArgDescriptor[]{ |
51 | |
new LValueArg(PARAM_TARGET), |
52 | |
new AssignmentArg(), |
53 | |
new RValueArg(PARAM_RESULT) |
54 | |
}; |
55 | |
|
56 | |
private static final DirectiveDescriptor |
57 | 2 | myDescr = new DirectiveDescriptor("param", null, myArgs, null); |
58 | |
|
59 | |
public static DirectiveDescriptor getDescriptor () |
60 | |
{ |
61 | 6 | return myDescr; |
62 | |
} |
63 | |
|
64 | |
public Object build (DirectiveBuilder builder, |
65 | |
BuildContext bc) |
66 | |
throws BuildException |
67 | |
{ |
68 | 0 | Variable target = null; |
69 | 0 | Object result = null; |
70 | |
try |
71 | |
{ |
72 | 0 | target = (Variable) builder.getArg(PARAM_TARGET, bc); |
73 | 0 | result = builder.getArg(PARAM_RESULT, bc); |
74 | |
} |
75 | 0 | catch (ClassCastException e) |
76 | |
{ |
77 | 0 | throw new NotVariableBuildException(myDescr.name, e); |
78 | 0 | } |
79 | 0 | if (!target.isSimpleName()) |
80 | 0 | throw new NotSimpleVariableBuildException(myDescr.name); |
81 | |
try |
82 | |
{ |
83 | 0 | target.setValue(bc, result); |
84 | |
} |
85 | 0 | catch (PropertyException e) |
86 | |
{ |
87 | 0 | throw new BuildException("#param: Exception setting variable " |
88 | |
+ target.toString(), e); |
89 | 0 | } |
90 | 0 | return new SetDirective(target, result); |
91 | |
} |
92 | |
|
93 | |
public void write (FastWriter out, Context context) |
94 | |
throws PropertyException, IOException |
95 | |
{ |
96 | 0 | } |
97 | |
|
98 | |
} |
99 | |
|