01: package com.opensymphony.webwork.config_browser;
02:
03: import com.opensymphony.xwork.ObjectFactory;
04: import com.opensymphony.xwork.config.entities.ActionConfig;
05: import ognl.OgnlRuntime;
06: import org.apache.commons.logging.Log;
07: import org.apache.commons.logging.LogFactory;
08:
09: import java.beans.PropertyDescriptor;
10: import java.util.Set;
11: import java.util.TreeSet;
12:
13: /**
14: * ShowConfigAction
15: *
16: * @author Jason Carreira Created Aug 11, 2003 9:42:12 PM
17: */
18: public class ShowConfigAction extends ActionNamesAction {
19: private static final PropertyDescriptor[] PDSAT = new PropertyDescriptor[0];
20:
21: private String namespace;
22: private String actionName;
23: private ActionConfig config;
24: private Set actionNames;
25: private String detailView = "results";
26: private PropertyDescriptor[] properties;
27: private static Log log = LogFactory.getLog(ShowConfigAction.class);
28:
29: public String getDetailView() {
30: return detailView;
31: }
32:
33: public void setDetailView(String detailView) {
34: this .detailView = detailView;
35: }
36:
37: public Set getActionNames() {
38: return actionNames;
39: }
40:
41: public String getNamespace() {
42: return namespace;
43: }
44:
45: public String stripPackage(Class clazz) {
46: return clazz.getName().substring(
47: clazz.getName().lastIndexOf('.') + 1);
48: }
49:
50: public void setNamespace(String namespace) {
51: this .namespace = namespace;
52: }
53:
54: public String getActionName() {
55: return actionName;
56: }
57:
58: public void setActionName(String actionName) {
59: this .actionName = actionName;
60: }
61:
62: public ActionConfig getConfig() {
63: return config;
64: }
65:
66: public PropertyDescriptor[] getProperties() {
67: return properties;
68: }
69:
70: public String execute() throws Exception {
71: super .execute();
72: config = ConfigurationHelper.getActionConfig(namespace,
73: actionName);
74: actionNames = new TreeSet(ConfigurationHelper
75: .getActionNames(namespace));
76: try {
77: Class clazz = ObjectFactory.getObjectFactory()
78: .getClassInstance(getConfig().getClassName());
79: java.util.Collection pds = OgnlRuntime
80: .getPropertyDescriptors(clazz).values();
81: properties = (PropertyDescriptor[]) pds.toArray(PDSAT);
82: } catch (Exception e) {
83: log.error("Unable to get properties for action "
84: + actionName, e);
85: addActionError("Unable to retrieve action properties: "
86: + e.toString());
87: }
88:
89: if (hasErrors()) //super might have set some :)
90: return ERROR;
91: else
92: return SUCCESS;
93: }
94: }
|