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