001: /*
002: * JOSSO: Java Open Single Sign-On
003: *
004: * Copyright 2004-2008, Atricore, Inc.
005: *
006: * This is free software; you can redistribute it and/or modify it
007: * under the terms of the GNU Lesser General Public License as
008: * published by the Free Software Foundation; either version 2.1 of
009: * the License, or (at your option) any later version.
010: *
011: * This software is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this software; if not, write to the Free
018: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
020: */
021: package org.josso;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.josso.util.FactoryConfigurationError;
026:
027: /**
028: * Abstract factory to build ComponentKeeper instances. If you want to use your own factory , you have to :
029: *
030: * 1. Subclass this abstract factory and implement the newComponentKeeper() method.
031: * 2. Set the system property "org.josso.ComponentKeeperFactory" to your factory implementation's FQCN.
032: *
033: * The default factory, if no system property is specified is MBeanComponentKeeperFactoryImpl
034: *
035: * @author <a href="mailto:sgonzalez@josso.org">Sebastian Gonzalez Oyuela</a>
036: * @version $Id: ComponentKeeperFactory.java 508 2008-02-18 13:32:29Z sgonzalez $
037: */
038:
039: public abstract class ComponentKeeperFactory {
040:
041: private static final Log logger = LogFactory
042: .getLog(ComponentKeeperFactory.class);
043:
044: /**
045: * The system property that specifies the fully qualified class name of the specific ComponentKeeperFactory.
046: *
047: * The constant value is org.josso.ComponentKeeperFactory
048: */
049: public static final String COMPONENT_KEEKPER_FACTORY = "org.josso.ComponentKeeperFactory";
050:
051: /**
052: * The default factory class : org.josso.MBeanComponentKeeperFactoryImpl
053: */
054: private static String factoryClass = "org.josso.MBeanComponentKeeperFactoryImpl";
055: private String _resourceFileName;
056:
057: public static ComponentKeeperFactory getInstance() {
058:
059: if (System.getProperty(COMPONENT_KEEKPER_FACTORY) != null)
060: factoryClass = System
061: .getProperty(COMPONENT_KEEKPER_FACTORY);
062:
063: try {
064: return (ComponentKeeperFactory) Class.forName(factoryClass)
065: .newInstance();
066:
067: } catch (InstantiationException e) {
068: logger.error(e.getMessage(), e);
069: throw new FactoryConfigurationError(e);
070:
071: } catch (IllegalAccessException e) {
072: logger.error(e.getMessage(), e);
073: throw new FactoryConfigurationError(e);
074:
075: } catch (ClassNotFoundException e) {
076: logger.warn("Class not found : " + factoryClass);
077: throw new FactoryConfigurationError(e);
078: }
079:
080: }
081:
082: public static void setFactory(String f) {
083: factoryClass = f;
084: }
085:
086: public static String getFactory() {
087: return factoryClass;
088: }
089:
090: public abstract ComponentKeeper newComponentKeeper();
091:
092: public String getResourceFileName() {
093: return _resourceFileName;
094: }
095:
096: public void setResourceFileName(String resourceFileName) {
097: this._resourceFileName = resourceFileName;
098: }
099:
100: }
|