01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com> and
03: * Steven Grimm <koreth[remove] at midwinter 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: DatabaseRememberFactory.java 3643 2007-01-12 15:29:45Z gbevin $
08: */
09: package com.uwyn.rife.authentication.remembermanagers;
10:
11: import com.uwyn.rife.database.Datasource;
12: import com.uwyn.rife.database.DbQueryManagerCache;
13: import com.uwyn.rife.database.DbQueryManagerFactory;
14: import com.uwyn.rife.ioc.HierarchicalProperties;
15: import com.uwyn.rife.ioc.exceptions.MandatoryPropertyMissingException;
16: import com.uwyn.rife.ioc.exceptions.PropertyValueException;
17:
18: /**
19: * Factory for {@link DatabaseRemember} manager instances that creates singletons
20: * based on the {@code Datasource}.
21: *
22: * @author Steven Grimm (koreth[remove] at midwinter dot com)
23: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
24: * @version $Revision: 3643 $
25: * @since 1.0
26: */
27: public class DatabaseRememberFactory extends DbQueryManagerFactory
28: implements RememberManagerFactory {
29: /** The package name of the datasource-specific implementations */
30: public static final String MANAGER_PACKAGE_NAME = DatabaseRememberFactory.class
31: .getPackage().getName()
32: + ".databasedrivers.";
33:
34: private static DbQueryManagerCache mCache = new DbQueryManagerCache();
35:
36: /**
37: * Return an instance of {@code DatabaseRemember} for the provided
38: * {@code Datasource}.
39: *
40: * @param datasource the datasource that will be used to create the manager
41: * @return the requested {@code DatabaseRemember} instance
42: * @since 1.0
43: */
44: public static DatabaseRemember getInstance(Datasource datasource) {
45: return (DatabaseRemember) getInstance(MANAGER_PACKAGE_NAME,
46: mCache, datasource);
47: }
48:
49: public DatabaseRemember getRememberManager(
50: HierarchicalProperties properties)
51: throws PropertyValueException {
52: Datasource datasource = properties.getValueTyped("datasource",
53: Datasource.class);
54: if (null == datasource) {
55: throw new MandatoryPropertyMissingException("datasource");
56: }
57:
58: return getInstance(datasource);
59: }
60: }
|