View Javadoc

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