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