View Javadoc

1   /*
2    * $Id: ShowConfigAction.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.config_browser;
19  
20  import java.beans.PropertyDescriptor;
21  import java.util.Set;
22  import java.util.TreeSet;
23  
24  import ognl.OgnlRuntime;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  import com.opensymphony.xwork2.ObjectFactory;
30  import com.opensymphony.xwork2.config.entities.ActionConfig;
31  
32  /***
33   * ShowConfigAction
34   */
35  public class ShowConfigAction extends ActionNamesAction {
36  	
37  	private static final long serialVersionUID = -1630527489407671652L;
38  
39  	private static final PropertyDescriptor[] PDSAT = new PropertyDescriptor[0];
40  
41      private String namespace;
42      private String actionName;
43      private ActionConfig config;
44      private Set actionNames;
45      private String detailView = "results";
46      private PropertyDescriptor[] properties;
47      private static Log log = LogFactory.getLog(ShowConfigAction.class);
48  
49      public String getDetailView() {
50          return detailView;
51      }
52  
53      public void setDetailView(String detailView) {
54          this.detailView = detailView;
55      }
56  
57      public Set getActionNames() {
58          return actionNames;
59      }
60  
61      public String getNamespace() {
62          return namespace;
63      }
64  
65      public String stripPackage(Class clazz) {
66          return clazz.getName().substring(clazz.getName().lastIndexOf('.') + 1);
67      }
68  
69      public void setNamespace(String namespace) {
70          this.namespace = namespace;
71      }
72  
73      public String getActionName() {
74          return actionName;
75      }
76  
77      public void setActionName(String actionName) {
78          this.actionName = actionName;
79      }
80  
81      public ActionConfig getConfig() {
82          return config;
83      }
84  
85      public PropertyDescriptor[] getProperties() {
86          return properties;
87      }
88  
89      public String execute() throws Exception {
90          super.execute();
91          config = ConfigurationHelper.getActionConfig(namespace, actionName);
92          actionNames =
93                  new TreeSet(ConfigurationHelper.getActionNames(namespace));
94          try {
95              Class clazz = ObjectFactory.getObjectFactory().getClassInstance(getConfig().getClassName());
96              java.util.Collection pds = OgnlRuntime.getPropertyDescriptors(clazz).values();
97              properties = (PropertyDescriptor[]) pds.toArray(PDSAT);
98          } catch (Exception e) {
99              log.error("Unable to get properties for action " + actionName, e);
100             addActionError("Unable to retrieve action properties: " + e.toString());
101         }
102 
103         if (hasErrors()) //super might have set some :)
104             return ERROR;
105         else
106             return SUCCESS;
107     }
108 }
109