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.credentialsmanagers;
10:
11: import com.uwyn.rife.authentication.CredentialsManager;
12: import com.uwyn.rife.authentication.elements.exceptions.UnknownCredentialsManagerFactoryClassException;
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 CredentialsManager 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 {@code CredentialsManager}
25: * objects. If not fully qualified, the package name
26: * {@code com.uwyn.rife.authentication.credentialsmanagers} will be
27: * assumed.</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 DatabaseUsersFactory
34: * @see MemoryUsersFactory
35: * @since 1.6
36: */
37: public abstract class CredentialsManagerFactoryFactory {
38: /** Name of the element property that controls the factory class to instantiate. */
39: public static final String PROPERTYNAME_FACTORY_CLASS = "credentialsmanagerfactory_class";
40:
41: private static SingletonFactory<CredentialsManagerFactory> mFactories = new SingletonFactory(
42: CredentialsManagerFactory.class);
43:
44: /**
45: * Returns a {@code CredentialsManagerFactory} 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 CredentialsManagerFactory getInstance(
53: HierarchicalProperties properties)
54: throws PropertyValueException {
55: try {
56: return mFactories.getInstance(properties,
57: PROPERTYNAME_FACTORY_CLASS,
58: CredentialsManagerFactoryFactory.class);
59: } catch (MandatoryPropertyMissingException e) {
60: throw e;
61: } catch (Exception e) {
62: throw new UnknownCredentialsManagerFactoryClassException(e
63: .getMessage(), e);
64: }
65: }
66:
67: /**
68: * Returns a {@code CredentialsManagerFactory} 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 CredentialsManager getManager(
76: HierarchicalProperties properties)
77: throws PropertyValueException {
78: CredentialsManagerFactory factory = getInstance(properties);
79: return factory.getCredentialsManager(properties);
80: }
81: }
|