1 package org.apache.velocity.runtime.parser.node;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Map;
23 import org.apache.velocity.exception.VelocityException;
24 import org.apache.velocity.runtime.log.Log;
25
26
27
28
29
30
31
32
33
34 public class MapSetExecutor
35 extends SetExecutor
36 {
37 private final String property;
38
39 public MapSetExecutor(final Log log, final Class clazz, final String property)
40 {
41 this.log = log;
42 this.property = property;
43 discover(clazz);
44 }
45
46 protected void discover (final Class clazz)
47 {
48 Class [] interfaces = clazz.getInterfaces();
49 for (int i = 0 ; i < interfaces.length; i++)
50 {
51 if (interfaces[i].equals(Map.class))
52 {
53 try
54 {
55 if (property != null)
56 {
57 setMethod(Map.class.getMethod("put", new Class [] { Object.class, Object.class }));
58 }
59 }
60
61
62
63 catch( RuntimeException e )
64 {
65 throw e;
66 }
67 catch(Exception e)
68 {
69 String msg = "Exception while looking for put('" + property + "') method";
70 log.error(msg, e);
71 throw new VelocityException(msg, e);
72 }
73 break;
74 }
75 }
76 }
77
78 public Object execute(final Object o, final Object arg)
79 {
80 return ((Map) o).put(property, arg);
81 }
82 }