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: DatabaseUsersFactory.java 3643 2007-01-12 15:29:45Z gbevin $
08: */
09: package com.uwyn.rife.authentication.credentialsmanagers;
10:
11: import com.uwyn.rife.authentication.CredentialsManager;
12: import com.uwyn.rife.database.Datasource;
13: import com.uwyn.rife.database.DbQueryManagerCache;
14: import com.uwyn.rife.database.DbQueryManagerFactory;
15: import com.uwyn.rife.ioc.HierarchicalProperties;
16: import com.uwyn.rife.ioc.exceptions.MandatoryPropertyMissingException;
17: import com.uwyn.rife.ioc.exceptions.PropertyValueException;
18:
19: /**
20: * Factory for {@link DatabaseUsers} manager instances that creates singletons
21: * based on the {@code Datasource} and an optional differentiating
22: * identifier.
23: *
24: * @author Steven Grimm (koreth[remove] at midwinter dot com)
25: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
26: * @version $Revision: 3643 $
27: * @since 1.0
28: */
29: public class DatabaseUsersFactory extends DbQueryManagerFactory
30: implements CredentialsManagerFactory {
31: /** The package name of the datasource-specific implementations */
32: public static final String MANAGER_PACKAGE_NAME = DatabaseUsersFactory.class
33: .getPackage().getName()
34: + ".databasedrivers.";
35:
36: private static DbQueryManagerCache mCache = new DbQueryManagerCache();
37:
38: /**
39: * Return an instance of {@code DatabaseUsers} for the provided
40: * {@code Datasource}.
41: *
42: * @param datasource the datasource that will be used to create the manager
43: * @return the requested {@code DatabaseUsers} instance
44: * @since 1.0
45: */
46: public static DatabaseUsers getInstance(Datasource datasource) {
47: return getInstance(datasource, null);
48: }
49:
50: /**
51: * Return an instance of {@code DatabaseUsers} for the provided
52: * {@code Datasource} and identifier.
53: *
54: * @param datasource the datasource that will be used to create the manager
55: * @param identifier the identifier that will be used to differentiate the
56: * manager when different ones are needed for the same datasource
57: * @return the requested {@code DatabaseUsers} instance
58: * @since 1.0
59: */
60: public static DatabaseUsers getInstance(Datasource datasource,
61: String identifier) {
62: if (null == identifier)
63: identifier = "";
64:
65: return (DatabaseUsers) getInstance(MANAGER_PACKAGE_NAME,
66: mCache, datasource, identifier);
67: }
68:
69: public CredentialsManager getCredentialsManager(
70: HierarchicalProperties properties)
71: throws PropertyValueException {
72: if (!properties.contains("datasource")) {
73: throw new MandatoryPropertyMissingException("datasource");
74: }
75:
76: return getInstance(properties.getValueTyped("datasource",
77: Datasource.class), properties.getValueString(
78: "credentialsmanager_id", ""));
79: }
80: }
|