01: package com.opensymphony.webwork.config_browser;
02:
03: import com.opensymphony.xwork.ActionSupport;
04: import com.opensymphony.xwork.ActionContext;
05: import com.opensymphony.xwork.validator.ActionValidatorManagerFactory;
06: import com.opensymphony.webwork.util.ClassLoaderUtils;
07:
08: import java.util.Collections;
09: import java.util.List;
10:
11: /**
12: * ListValidatorsAction loads the validations for a given class and context
13: *
14: * @author Jason Carreira
15: * @author Rainer Hermanns
16: * Date: May 31, 2004 5:06:16 PM
17: */
18: public class ListValidatorsAction extends ActionSupport {
19: private String clazz;
20: private String context;
21: List validators = Collections.EMPTY_LIST;
22:
23: public String getClazz() {
24: return clazz;
25: }
26:
27: public void setClazz(String clazz) {
28: this .clazz = clazz;
29: }
30:
31: public String stripPackage(Class clazz) {
32: return clazz.getName().substring(
33: clazz.getName().lastIndexOf('.') + 1);
34: }
35:
36: public String stripPackage(String clazz) {
37: return clazz.substring(clazz.lastIndexOf('.') + 1);
38: }
39:
40: public String getContext() {
41: return context;
42: }
43:
44: public void setContext(String context) {
45: this .context = context;
46: }
47:
48: public List getValidators() {
49: return validators;
50: }
51:
52: public String execute() throws Exception {
53: loadValidators();
54: return super .execute();
55: }
56:
57: protected void loadValidators() {
58: Class value = getClassInstance();
59: if (value != null) {
60: validators = ActionValidatorManagerFactory.getInstance()
61: .getValidators(value, context);
62: }
63: }
64:
65: private Class getClassInstance() {
66: try {
67: return ClassLoaderUtils.loadClass(clazz, ActionContext
68: .getContext().getClass());
69: } catch (Exception e) {
70: LOG.error("Class '" + clazz + "' not found...", e);
71: }
72: return null;
73: }
74: }
|