1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.controller.action.support;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.springframework.util.Assert;
23
24 import COM.FutureTense.Cache.CacheManager;
25 import COM.FutureTense.Interfaces.ICS;
26
27 import com.fatwire.gst.foundation.controller.action.Action;
28 import com.fatwire.gst.foundation.controller.action.ActionLocator;
29 import com.fatwire.gst.foundation.controller.action.Factory;
30 import com.fatwire.gst.foundation.controller.action.Injector;
31
32
33
34
35
36
37
38
39
40
41
42
43 public abstract class AbstractActionLocator implements ActionLocator {
44
45 protected static final Log LOG = LogFactory.getLog(AbstractActionLocator.class.getPackage().getName());
46
47
48
49 private ActionLocator fallbackActionLocator;
50 private Injector injector;
51
52 public AbstractActionLocator() {
53 super();
54 }
55
56 public AbstractActionLocator(Injector injector) {
57 super();
58 if (injector == null)
59 throw new IllegalArgumentException("injector should not be null");
60 this.injector = injector;
61 }
62
63 public AbstractActionLocator(ActionLocator fallbackActionLocator, Injector injector) {
64 super();
65 this.fallbackActionLocator = fallbackActionLocator;
66 this.injector = injector;
67 }
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 public final Action getAction(final ICS ics, final String name) {
87 Action action = null;
88 action = doFindAction(ics, name);
89
90
91
92
93
94
95
96 if (action == null) {
97 ActionLocator fabal = getFallbackActionLocator();
98 if (fabal == null)
99 throw new IllegalStateException(
100 "The doFindAction() method returned null and there is no fallback ActionLocator defined. This is an incorrect setup.");
101 if (LOG.isTraceEnabled())
102 LOG.trace("No Action found in action locator " + getClass().getName()
103 + ". Trying with fallback action locator: " + fabal.getClass().getName());
104 action = fabal.getAction(ics, name);
105 } else {
106 if (LOG.isTraceEnabled()) {
107 LOG.trace("Action '" + name + "' maps to action " + action.getClass().getName());
108 }
109 injectDependencies(ics, action);
110 if (StringUtils.isNotBlank(name)) {
111 CacheManager.RecordItem(ics, "gsf-action:" + name);
112 } else if (action != null) {
113 CacheManager.RecordItem(ics, "gsf-action:" + action.getClass().getName());
114 }
115 }
116 return action;
117
118 }
119
120
121
122
123
124
125
126
127
128
129 protected abstract Action doFindAction(final ICS ics, final String name);
130
131
132
133
134
135 protected final void injectDependencies(final ICS ics, final Action action) {
136
137 Injector injector = getInjector();
138 injector.inject(ics, action);
139
140 }
141
142 public Injector getInjector() {
143
144 return injector;
145 }
146
147
148
149
150 public ActionLocator getFallbackActionLocator() {
151 return fallbackActionLocator;
152 }
153
154
155
156
157 public void setFallbackActionLocator(final ActionLocator fallbackActionLocator) {
158 Assert.notNull(fallbackActionLocator);
159 this.fallbackActionLocator = fallbackActionLocator;
160 }
161
162 public void setInjector(Injector injector) {
163 this.injector = injector;
164 }
165
166 }