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, Injector injector) {
42 super(fallbackActionLocator, injector);
43 }
44
45 protected Action doFindAction(final ICS ics, final String name) {
46
47 Action action = null;
48 action = groovyAction(name);
49
50 return action;
51 }
52
53
54
55
56
57
58
59
60 private Action groovyAction(final String name) {
61
62 if (StringUtils.isBlank(name))
63 return null;
64 Action action = null;
65 try {
66
67 final Object o = getGroovyLoader().load(name);
68
69 if (o instanceof Action) {
70 action = (Action) o;
71 } else {
72 if (LOG.isDebugEnabled())
73 LOG.debug(name + " is not a valid script.");
74 }
75 } catch (final RuntimeException e) {
76 throw e;
77 } catch (final Exception e) {
78 throw new RuntimeException(e);
79 }
80 return action;
81 }
82
83
84
85
86 public final GroovyLoader getGroovyLoader() {
87 return groovyLoader;
88 }
89
90
91
92
93 public final void setGroovyLoader(final GroovyLoader groovyLoader) {
94 this.groovyLoader = groovyLoader;
95 }
96
97 }