View Javadoc

1   /*
2    * $Id: ShowConfigAction.java 651946 2008-04-27 13:41:38Z apetrelli $
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  
22  package org.apache.struts2.config_browser;
23  
24  import java.beans.PropertyDescriptor;
25  import java.util.Set;
26  import java.util.TreeSet;
27  
28  import com.opensymphony.xwork2.ObjectFactory;
29  import com.opensymphony.xwork2.config.entities.ActionConfig;
30  import com.opensymphony.xwork2.inject.Inject;
31  import com.opensymphony.xwork2.util.logging.Logger;
32  import com.opensymphony.xwork2.util.logging.LoggerFactory;
33  import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
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 Logger LOG = LoggerFactory.getLogger(ShowConfigAction.class);
51      
52      private ObjectFactory objectFactory;
53      private ReflectionProvider reflectionProvider;
54  
55      public String getDetailView() {
56          return detailView;
57      }
58  
59      public void setDetailView(String detailView) {
60          this.detailView = detailView;
61      }
62  
63      public Set getActionNames() {
64          return actionNames;
65      }
66  
67      public String getNamespace() {
68          return namespace;
69      }
70      
71      @Inject
72      public void setObjectFactory(ObjectFactory fac) {
73          this.objectFactory = fac;
74      }
75      
76      @Inject
77      public void setReflectionProvider(ReflectionProvider prov) {
78          this.reflectionProvider = prov;
79      }
80  
81      public String stripPackage(Class clazz) {
82          return clazz.getName().substring(clazz.getName().lastIndexOf('.') + 1);
83      }
84  
85      public void setNamespace(String namespace) {
86          this.namespace = namespace;
87      }
88  
89      public String getActionName() {
90          return actionName;
91      }
92  
93      public void setActionName(String actionName) {
94          this.actionName = actionName;
95      }
96  
97      public ActionConfig getConfig() {
98          return config;
99      }
100 
101     public PropertyDescriptor[] getProperties() {
102         return properties;
103     }
104 
105     public String execute() throws Exception {
106         super.execute();
107         config = configHelper.getActionConfig(namespace, actionName);
108         actionNames =
109                 new TreeSet(configHelper.getActionNames(namespace));
110         try {
111             Class clazz = objectFactory.getClassInstance(getConfig().getClassName());
112             properties = reflectionProvider.getPropertyDescriptors(clazz);
113         } catch (Exception e) {
114             LOG.error("Unable to get properties for action " + actionName, e);
115             addActionError("Unable to retrieve action properties: " + e.toString());
116         }
117 
118         if (hasErrors()) //super might have set some :)
119             return ERROR;
120         else
121             return SUCCESS;
122     }
123 }
124