001: /*
002: * $Id: ModuleConfigFactory.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.config;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.apache.struts.util.RequestUtils;
026:
027: /**
028: * A factory interface for creating {@link ModuleConfig}s.
029: *
030: * @version $Rev: 471754 $ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
031: * $
032: * @see ModuleConfig
033: */
034: public abstract class ModuleConfigFactory {
035: /**
036: * The Java class to be used for <code>ModuleConfigFactory</code>
037: * instances.
038: */
039: protected static Class clazz = null;
040:
041: /**
042: * Commons Logging instance.
043: */
044: private static final Log LOG = LogFactory
045: .getLog(ModuleConfigFactory.class);
046:
047: /**
048: * The fully qualified class name to be used for <code>ModuleConfigFactory</code>
049: * instances.
050: */
051: protected static String factoryClass = "org.apache.struts.config.impl.DefaultModuleConfigFactory";
052:
053: /**
054: * Create and return a newly instansiated {@link ModuleConfig}. This
055: * method must be implemented by concrete subclasses.
056: *
057: * @param prefix Module prefix for Configuration
058: */
059: public abstract ModuleConfig createModuleConfig(String prefix);
060:
061: // ------------------------------------------------------ Static Properties
062:
063: /**
064: * The fully qualified class name that is used for <code>ModuleConfigFactory</code>
065: * instances.
066: *
067: * @return class name that is used for <code>ModuleConfigFactory</code>
068: * instances
069: */
070: public static String getFactoryClass() {
071: return (ModuleConfigFactory.factoryClass);
072: }
073:
074: /**
075: * Set the fully qualified class name that is used for
076: * <code>ModuleConfigFactory</code> instances.
077: *
078: * @param factoryClass name that is used for <code>ModuleConfigFactory</code>
079: * instances
080: */
081: public static void setFactoryClass(String factoryClass) {
082: ModuleConfigFactory.factoryClass = factoryClass;
083: ModuleConfigFactory.clazz = null;
084: }
085:
086: // --------------------------------------------------------- Static Methods
087:
088: /**
089: * Create and return a <code>ModuleConfigFactory</code> instance of the
090: * appropriate class, which can be used to create customized
091: * <code>ModuleConfig</code> instances. If no such factory can be
092: * created, return <code>null</code> instead.
093: */
094: public static ModuleConfigFactory createFactory() {
095: ModuleConfigFactory factory = null;
096:
097: try {
098: if (clazz == null) {
099: 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: }
|