1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.fatwire.gst.foundation.controller.action.support;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.commons.logging.Log;
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.facade.logging.LogUtil;
27
28
29
30
31
32
33
34
35
36 public class ClassActionLocator extends AbstractActionLocator {
37 private static final Log LOG = LogUtil.getLog(ClassActionLocator.class);
38 private static final String CLASS_PREFIX = "class:";
39
40 public ClassActionLocator(ActionLocator fallbackActionLocator, Injector injector) {
41 super(fallbackActionLocator, injector);
42
43 }
44
45 public ClassActionLocator() {
46 super();
47 }
48
49 @Override
50 protected Action doFindAction(ICS ics, String name) {
51 if (StringUtils.startsWith(name, CLASS_PREFIX)) {
52 String c = StringUtils.trim(StringUtils.substringAfter(name, CLASS_PREFIX));
53 if (StringUtils.isEmpty(c)) {
54 LOG.warn("Passed in classname with the " + CLASS_PREFIX + " is null or empty.");
55 } else {
56 try {
57 Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(c);
58 if (Action.class.isAssignableFrom(clazz)) {
59 LOG.debug("Creating Action for class " + clazz);
60 Action action = (Action) clazz.newInstance();
61 return action;
62 } else {
63 throw new RuntimeException("Class " + c + " is not an Action.");
64 }
65
66 } catch (ClassNotFoundException e) {
67 throw new RuntimeException("Class " + c + " cannot be found.", e);
68 } catch (InstantiationException e) {
69 throw new RuntimeException("Class " + c + " " + e.getMessage(), e);
70 } catch (IllegalAccessException e) {
71 throw new RuntimeException("Class " + c + " " + e.getMessage(), e);
72 }
73 }
74
75 }
76 return null;
77 }
78
79 }