1 /**
2 *
3 */
4 package siouxsie.mvc.test;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9 import siouxsie.mvc.IScreen;
10 import siouxsie.mvc.IValueStackAware;
11
12 import com.opensymphony.xwork2.ActionContext;
13 import com.opensymphony.xwork2.config.Configuration;
14 import com.opensymphony.xwork2.config.ConfigurationManager;
15 import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
16 import com.opensymphony.xwork2.util.ValueStack;
17 import com.opensymphony.xwork2.util.ValueStackFactory;
18
19 /**
20 * @author Arnaud Cogoluegnes
21 * @version $Id: ScreenCreator.java 143 2008-06-03 20:37:37Z acogo $
22 */
23 public class ScreenCreator {
24
25 private static final Log LOG = LogFactory.getLog(ScreenCreator.class);
26
27 public IScreen create(LaunchConfiguration config) {
28 ConfigurationManager confManager = new ConfigurationManager();
29 confManager.addContainerProvider(new XWorkConfigurationProvider());
30 confManager.addContainerProvider(new TestContainerProvider());
31 Configuration conf = confManager.getConfiguration();
32 ValueStack vs = conf.getContainer().getInstance(ValueStackFactory.class).createValueStack();
33 ActionContext context = new ActionContext(vs.getContext());
34 ActionContext.setContext(context);
35
36 vs.push(config.getContext());
37
38 IScreen screen = null;
39 try {
40 screen = config.getScreenClass().newInstance();
41 } catch (InstantiationException e) {
42 LOG.error("could not create screen",e);
43 } catch (IllegalAccessException e) {
44 LOG.error("could not create screen",e);
45 }
46
47 if(screen instanceof IValueStackAware) {
48 ((IValueStackAware) screen).setValueStack(vs);
49 }
50
51 conf.getContainer().inject(screen);
52
53 screen.buildGUI();
54
55 screen.initGUI();
56
57 return screen;
58
59 }
60
61 }