01: /*
02: * Copyright 2001-2007 Steven Grimm <koreth[remove] at midwinter dot com> and
03: * Geert Bevin <gbevin[remove] at uwyn dot com>
04: * Distributed under the terms of either:
05: * - the common development and distribution license (CDDL), v1.0; or
06: * - the GNU Lesser General Public License, v2.1 or later
07: * $Id$
08: */
09: package com.uwyn.rife.authentication.remembermanagers;
10:
11: import com.uwyn.rife.authentication.RememberManager;
12: import com.uwyn.rife.authentication.elements.exceptions.UnknownRememberManagerFactoryClassException;
13: import com.uwyn.rife.ioc.HierarchicalProperties;
14: import com.uwyn.rife.ioc.exceptions.MandatoryPropertyMissingException;
15: import com.uwyn.rife.ioc.exceptions.PropertyValueException;
16: import com.uwyn.rife.tools.SingletonFactory;
17:
18: /**
19: * Creates RememberManager factories based on configuration options.
20: *
21: * <p>Element properties used:
22: * <dl>
23: * <dt>{@value #PROPERTYNAME_FACTORY_CLASS}</dt>
24: * <dd>The name of the class that will be used to instantiate RememberManager
25: * objects. If not fully qualified, the package name
26: * {@code com.uwyn.rife.authentication.remembermanagers} will be
27: * assumed. If not specified at all, no remember manager will be created.</dd>
28: * </dl>
29: *
30: * @author Steven Grimm (koreth[remove] at midwinter dot com)
31: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
32: * @version $Revision: $
33: * @see RememberManagerFactory
34: * @see DatabaseRememberFactory
35: * @since 1.6
36: */
37: public abstract class RememberManagerFactoryFactory {
38: /** Name of the element property that controls the factory class to instantiate. */
39: public static final String PROPERTYNAME_FACTORY_CLASS = "remembermanagerfactory_class";
40:
41: private static SingletonFactory<RememberManagerFactory> mFactories = new SingletonFactory(
42: RememberManagerFactory.class);
43:
44: /**
45: * Returns a {@code RememberManagerFactory} instance.
46: *
47: * @param properties the properties that will setup the manager
48: * @throws PropertyValueException when an error occurred during the retrieval
49: * of the property values
50: * @since 1.6
51: */
52: public static RememberManagerFactory getInstance(
53: HierarchicalProperties properties)
54: throws PropertyValueException {
55: try {
56: return mFactories.getInstance(properties,
57: PROPERTYNAME_FACTORY_CLASS,
58: RememberManagerFactoryFactory.class);
59: } catch (MandatoryPropertyMissingException e) {
60: throw e;
61: } catch (Exception e) {
62: throw new UnknownRememberManagerFactoryClassException(e
63: .getMessage(), e);
64: }
65: }
66:
67: /**
68: * Returns a {@code RememberManager} instance using the configured factory.
69: *
70: * @param properties the properties that will setup the manager
71: * @throws PropertyValueException when an error occurred during the retrieval
72: * of the property values
73: * @since 1.6
74: */
75: public static RememberManager getManager(
76: HierarchicalProperties properties)
77: throws PropertyValueException {
78: /*
79: * Remember managers are optional; if one isn't specified it's
80: * not an error condition.
81: */
82: if (!properties.contains(PROPERTYNAME_FACTORY_CLASS)) {
83: return null;
84: }
85:
86: RememberManagerFactory factory = getInstance(properties);
87: return factory.getRememberManager(properties);
88: }
89: }
|