1 package org.apache.torque.generator.template.groovy;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import groovy.lang.Binding;
23 import groovy.lang.GroovyShell;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.torque.generator.GeneratorException;
28 import org.apache.torque.generator.configuration.ConfigurationException;
29 import org.apache.torque.generator.configuration.ConfigurationProvider;
30 import org.apache.torque.generator.control.ControllerState;
31 import org.apache.torque.generator.outlet.OutletResult;
32 import org.apache.torque.generator.qname.QualifiedName;
33 import org.apache.torque.generator.template.TemplateOutletImpl;
34
35
36
37
38
39 public class GroovyOutlet extends TemplateOutletImpl
40 {
41
42
43
44
45 public static final String TORQUE_GEN_CONTEXT_NAME = "torqueGen";
46
47
48 private static Log log = LogFactory.getLog(GroovyOutlet.class);
49
50
51
52
53
54
55
56
57
58
59
60
61
62 public GroovyOutlet(
63 QualifiedName name,
64 ConfigurationProvider configurationProvider,
65 String path)
66 throws ConfigurationException
67 {
68 super(name,
69 configurationProvider,
70 path,
71 null,
72 null);
73 }
74
75
76
77
78
79
80
81
82
83
84 @Override
85 public OutletResult execute(ControllerState controllerState)
86 throws GeneratorException
87
88 {
89 if (log.isDebugEnabled())
90 {
91 log.debug("Start executing GroovyOutlet " + getName());
92 }
93
94 try
95 {
96 Binding binding = new Binding();
97 GroovyShell shell = new GroovyShell(binding);
98
99 String result = (String) shell.evaluate(
100 getContent(controllerState));
101 return new OutletResult(result);
102 }
103 finally
104 {
105 if (log.isDebugEnabled())
106 {
107 log.debug("End executing GroovyOutlet " + getName());
108 }
109 }
110 }
111 }