KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > config_browser > ShowConfigAction


1 package com.opensymphony.webwork.config_browser;
2
3 import com.opensymphony.xwork.ObjectFactory;
4 import com.opensymphony.xwork.config.entities.ActionConfig;
5 import ognl.OgnlRuntime;
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9 import java.beans.PropertyDescriptor JavaDoc;
10 import java.util.Set JavaDoc;
11 import java.util.TreeSet JavaDoc;
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 JavaDoc[] PDSAT = new PropertyDescriptor JavaDoc[0];
20
21     private String JavaDoc namespace;
22     private String JavaDoc actionName;
23     private ActionConfig config;
24     private Set JavaDoc actionNames;
25     private String JavaDoc detailView = "results";
26     private PropertyDescriptor JavaDoc[] properties;
27     private static Log log = LogFactory.getLog(ShowConfigAction.class);
28
29     public String JavaDoc getDetailView() {
30         return detailView;
31     }
32
33     public void setDetailView(String JavaDoc detailView) {
34         this.detailView = detailView;
35     }
36
37     public Set JavaDoc getActionNames() {
38         return actionNames;
39     }
40
41     public String JavaDoc getNamespace() {
42         return namespace;
43     }
44
45     public String JavaDoc stripPackage(Class JavaDoc clazz) {
46         return clazz.getName().substring(clazz.getName().lastIndexOf('.') + 1);
47     }
48
49     public void setNamespace(String JavaDoc namespace) {
50         this.namespace = namespace;
51     }
52
53     public String JavaDoc getActionName() {
54         return actionName;
55     }
56
57     public void setActionName(String JavaDoc actionName) {
58         this.actionName = actionName;
59     }
60
61     public ActionConfig getConfig() {
62         return config;
63     }
64
65     public PropertyDescriptor JavaDoc[] getProperties() {
66         return properties;
67     }
68
69     public String JavaDoc execute() throws Exception JavaDoc {
70         super.execute();
71         config = ConfigurationHelper.getActionConfig(namespace, actionName);
72         actionNames =
73                 new TreeSet JavaDoc(ConfigurationHelper.getActionNames(namespace));
74         try {
75             Class JavaDoc clazz = ObjectFactory.getObjectFactory().getClassInstance(getConfig().getClassName());
76             java.util.Collection JavaDoc pds = OgnlRuntime.getPropertyDescriptors(clazz).values();
77             properties = (PropertyDescriptor JavaDoc[]) pds.toArray(PDSAT);
78         } catch (Exception JavaDoc e) {
79             log.error("Unable to get properties for action " + actionName, e);
80             addActionError("Unable to retrieve action properties: " + e.toString());
81         }
82
83         if (hasErrors()) //super might have set some :)
84
return ERROR;
85         else
86             return SUCCESS;
87     }
88 }
89
90
Popular Tags