1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.groovy.action;
18
19 import org.apache.commons.lang.StringUtils;
20
21 import COM.FutureTense.Interfaces.ICS;
22
23 import com.fatwire.gst.foundation.controller.action.Action;
24 import com.fatwire.gst.foundation.controller.action.ActionLocator;
25 import com.fatwire.gst.foundation.controller.action.Injector;
26 import com.fatwire.gst.foundation.controller.action.support.AbstractActionLocator;
27 import com.fatwire.gst.foundation.groovy.GroovyLoader;
28
29
30
31
32
33 public class GroovyActionLocator extends AbstractActionLocator {
34 private GroovyLoader groovyLoader;
35
36 public GroovyActionLocator() {
37 super();
38
39 }
40
41 public GroovyActionLocator(ActionLocator fallbackActionLocator,
42 Injector injector) {
43 super(fallbackActionLocator, injector);
44 }
45
46 protected Action doFindAction(final ICS ics, final String name) {
47
48 Action action = null;
49 action = groovyAction(ics, name);
50
51 return action;
52 }
53
54
55
56
57
58
59
60
61
62 private Action groovyAction(final ICS ics, final String name) {
63
64 if (StringUtils.isBlank(name))
65 return null;
66 Action action = null;
67 try {
68
69 final Object o = getGroovyLoader().load(ics, name);
70
71 if (o instanceof Action) {
72 action = (Action) o;
73 } else {
74 if (LOG.isDebugEnabled())
75 LOG.debug(name + " is not a valid script.");
76 }
77 } catch (final RuntimeException e) {
78 throw e;
79 } catch (final Exception e) {
80 throw new RuntimeException(e);
81 }
82 return action;
83 }
84
85
86
87
88 public final GroovyLoader getGroovyLoader() {
89 return groovyLoader;
90 }
91
92
93
94
95
96 public final void setGroovyLoader(final GroovyLoader groovyLoader) {
97 this.groovyLoader = groovyLoader;
98 }
99
100 }