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: DatabaseSessionValidatorFactory.java 3643 2007-01-12 15:29:45Z gbevin $
08: */
09: package com.uwyn.rife.authentication.sessionvalidators;
10:
11: import com.uwyn.rife.authentication.SessionValidator;
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 DatabaseSessionValidator} 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 DatabaseSessionValidatorFactory extends
30: DbQueryManagerFactory implements SessionValidatorFactory {
31: /** The package name of the datasource-specific implementations */
32: public static final String MANAGER_PACKAGE_NAME = DatabaseSessionValidatorFactory.class
33: .getPackage().getName()
34: + ".databasedrivers.";
35:
36: private static DbQueryManagerCache mCache = new DbQueryManagerCache();
37:
38: /**
39: * Return an instance of {@code DatabaseSessionValidator} 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 DatabaseSessionValidator} instance
44: * @since 1.0
45: */
46: private static DatabaseSessionValidator getInstance(
47: Datasource datasource) {
48: return (DatabaseSessionValidator) getInstance(
49: MANAGER_PACKAGE_NAME, mCache, datasource);
50: }
51:
52: /**
53: * Return an instance of {@code DatabaseSessionValidator} for the provided
54: * {@code Datasource} and identifier.
55: *
56: * @param datasource the datasource that will be used to create the manager
57: * @param identifier the identifier that will be used to differentiate the
58: * manager when different ones are needed for the same datasource
59: * @return the requested {@code DatabaseSessionValidator} instance
60: * @since 1.0
61: */
62: private static DatabaseSessionValidator getInstance(
63: Datasource datasource, String identifier) {
64: return (DatabaseSessionValidator) getInstance(
65: MANAGER_PACKAGE_NAME, mCache, datasource, identifier);
66: }
67:
68: public SessionValidator getValidator(
69: HierarchicalProperties properties)
70: throws PropertyValueException {
71: Datasource datasource = properties.getValueTyped("datasource",
72: Datasource.class);
73: if (null == datasource) {
74: throw new MandatoryPropertyMissingException("datasource");
75: }
76:
77: String credentialsmanager_id = properties
78: .getValueString("credentialsmanager_id");
79:
80: if (credentialsmanager_id != null)
81: return getInstance(datasource, credentialsmanager_id);
82: else
83: return getInstance(datasource);
84: }
85: }
|