KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > config > ModuleConfigFactory


1 /*
2  * $Id: ModuleConfigFactory.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.struts.config;
20
21 import org.apache.struts.util.RequestUtils;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 /**
26  * A factory interface for creating {@link ModuleConfig}s.
27  *
28  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
29  *
30  * @see ModuleConfig
31  */

32 public abstract class ModuleConfigFactory {
33     
34     /**
35      * Create and return a newly instansiated {@link ModuleConfig}.
36      * This method must be implemented by concrete subclasses.
37      *
38      * @param prefix Module prefix for Configuration
39      */

40     public abstract ModuleConfig createModuleConfig(String JavaDoc prefix);
41
42
43     // ------------------------------------------------------ Static Properties
44
/**
45      * The fully qualified class name that is used for
46      * <code>ModuleConfigFactory</code> instances.
47      * @return class name that is used for
48      * <code>ModuleConfigFactory</code> instances
49      */

50     public static String JavaDoc getFactoryClass() {
51         return (ModuleConfigFactory.factoryClass);
52     }
53
54     /**
55      * Set the fully qualified class name that is used for
56      * <code>ModuleConfigFactory</code> instances.
57      * @param factoryClass name that is used for
58      * <code>ModuleConfigFactory</code> instances
59      */

60     public static void setFactoryClass(String JavaDoc factoryClass) {
61         ModuleConfigFactory.factoryClass = factoryClass;
62         ModuleConfigFactory.clazz = null;
63     }
64
65     // --------------------------------------------------------- Static Methods
66

67
68     /**
69      * Create and return a <code>ModuleConfigFactory</code> instance of the
70      * appropriate class, which can be used to create customized
71      * <code>ModuleConfig</code> instances. If no such factory can be
72      * created, return <code>null</code> instead.
73      */

74     public static ModuleConfigFactory createFactory() {
75
76         ModuleConfigFactory factory = null;
77
78         try {
79             if (clazz == null) {
80                 clazz = RequestUtils.applicationClass(factoryClass);
81             }
82
83             factory = (ModuleConfigFactory) clazz.newInstance();
84
85         } catch (ClassNotFoundException JavaDoc e) {
86             LOG.error("ModuleConfigFactory.createFactory()", e);
87         } catch (InstantiationException JavaDoc e) {
88             LOG.error("ModuleConfigFactory.createFactory()", e);
89         } catch (IllegalAccessException JavaDoc e) {
90             LOG.error("ModuleConfigFactory.createFactory()", e);
91         }
92
93         return factory;
94
95     }
96
97
98     /**
99      * The Java class to be used for
100      * <code>ModuleConfigFactory</code> instances.
101      */

102     protected static Class JavaDoc clazz = null;
103
104     /**
105      * Commons Logging instance.
106      */

107     private static final Log LOG = LogFactory.getLog(ModuleConfigFactory.class);
108
109
110     /**
111      * The fully qualified class name to be used for
112      * <code>ModuleConfigFactory</code> instances.
113      */

114     protected static String JavaDoc factoryClass =
115         "org.apache.struts.config.impl.DefaultModuleConfigFactory";
116
117
118 }
119
Popular Tags