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: DatabaseSessionsFactory.java 3643 2007-01-12 15:29:45Z gbevin $
08: */
09: package com.uwyn.rife.authentication.sessionmanagers;
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 DatabaseSessions} 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 DatabaseSessionsFactory extends DbQueryManagerFactory
28: implements SessionManagerFactory {
29: /** The package name of the datasource-specific implementations */
30: public static final String MANAGER_PACKAGE_NAME = DatabaseSessionsFactory.class
31: .getPackage().getName()
32: + ".databasedrivers.";
33:
34: private static DbQueryManagerCache mCache = new DbQueryManagerCache();
35:
36: /**
37: * Return an instance of {@code DatabaseSessions} 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 DatabaseSessions} instance
42: * @since 1.0
43: */
44: public static DatabaseSessions getInstance(Datasource datasource) {
45: return (DatabaseSessions) getInstance(MANAGER_PACKAGE_NAME,
46: mCache, datasource);
47: }
48:
49: public DatabaseSessions getManager(HierarchicalProperties properties)
50: throws PropertyValueException {
51: Datasource datasource = properties.getValueTyped("datasource",
52: Datasource.class);
53: if (null == datasource) {
54: throw new MandatoryPropertyMissingException("datasource");
55: }
56:
57: return getInstance(datasource);
58: }
59: }
|