1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.config;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.struts.util.RequestUtils;
26
27 /**
28 * A factory interface for creating {@link ModuleConfig}s.
29 *
30 * @version $Rev: 471754 $ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
31 * $
32 * @see ModuleConfig
33 */
34 public abstract class ModuleConfigFactory {
35 /**
36 * The Java class to be used for <code>ModuleConfigFactory</code>
37 * instances.
38 */
39 protected static Class clazz = null;
40
41 /**
42 * Commons Logging instance.
43 */
44 private static final Log LOG = LogFactory.getLog(ModuleConfigFactory.class);
45
46 /**
47 * The fully qualified class name to be used for <code>ModuleConfigFactory</code>
48 * instances.
49 */
50 protected static String factoryClass =
51 "org.apache.struts.config.impl.DefaultModuleConfigFactory";
52
53 /**
54 * Create and return a newly instansiated {@link ModuleConfig}. This
55 * method must be implemented by concrete subclasses.
56 *
57 * @param prefix Module prefix for Configuration
58 */
59 public abstract ModuleConfig createModuleConfig(String prefix);
60
61
62
63 /**
64 * The fully qualified class name that is used for <code>ModuleConfigFactory</code>
65 * instances.
66 *
67 * @return class name that is used for <code>ModuleConfigFactory</code>
68 * instances
69 */
70 public static String getFactoryClass() {
71 return (ModuleConfigFactory.factoryClass);
72 }
73
74 /**
75 * Set the fully qualified class name that is used for
76 * <code>ModuleConfigFactory</code> instances.
77 *
78 * @param factoryClass name that is used for <code>ModuleConfigFactory</code>
79 * instances
80 */
81 public static void setFactoryClass(String factoryClass) {
82 ModuleConfigFactory.factoryClass = factoryClass;
83 ModuleConfigFactory.clazz = null;
84 }
85
86
87
88 /**
89 * Create and return a <code>ModuleConfigFactory</code> instance of the
90 * appropriate class, which can be used to create customized
91 * <code>ModuleConfig</code> instances. If no such factory can be
92 * created, return <code>null</code> instead.
93 */
94 public static ModuleConfigFactory createFactory() {
95 ModuleConfigFactory factory = null;
96
97 try {
98 if (clazz == null) {
99 clazz = RequestUtils.applicationClass(factoryClass);
100 }
101
102 factory = (ModuleConfigFactory) clazz.newInstance();
103 } catch (ClassNotFoundException e) {
104 LOG.error("ModuleConfigFactory.createFactory()", e);
105 } catch (InstantiationException e) {
106 LOG.error("ModuleConfigFactory.createFactory()", e);
107 } catch (IllegalAccessException e) {
108 LOG.error("ModuleConfigFactory.createFactory()", e);
109 }
110
111 return factory;
112 }
113 }