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: MemorySessionsFactory.java 3308 2006-06-15 18:54:14Z gbevin $
08: */
09: package com.uwyn.rife.authentication.sessionvalidators;
10:
11: import com.uwyn.rife.authentication.SessionValidator;
12: import com.uwyn.rife.authentication.elements.exceptions.UnknownSessionValidatorClassException;
13: import com.uwyn.rife.ioc.HierarchicalProperties;
14: import com.uwyn.rife.ioc.exceptions.MandatoryPropertyMissingException;
15: import com.uwyn.rife.ioc.exceptions.PropertyValueException;
16:
17: /**
18: * Factory that instantiates session validators based on the class name
19: * specified in element properties.
20: *
21: * <p>
22: * Element properties used:
23: * <dl>
24: * <dt>{@value #PROPERTYNAME_MANAGER_CLASS}</dt>
25: * <dd>Name of the session manager class. If the class name is not fully
26: * qualified, the package name
27: * {@code com.uwyn.rife.authentication.sessionvalidators}
28: * will be assumed.</dd>
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 SessionValidator
34: * @since 1.6
35: */
36: public class SimpleSessionValidatorFactory implements
37: SessionValidatorFactory {
38: /** Element property that specifies the class name for session validators. */
39: public static final String PROPERTYNAME_MANAGER_CLASS = "sessionvalidator_class";
40:
41: public SessionValidator getValidator(
42: HierarchicalProperties properties)
43: throws PropertyValueException {
44: String className = properties.getValueTyped(
45: PROPERTYNAME_MANAGER_CLASS, String.class);
46: if (null == className) {
47: throw new MandatoryPropertyMissingException(
48: PROPERTYNAME_MANAGER_CLASS);
49: }
50: if (className.indexOf(".") < 0) {
51: className = SimpleSessionValidatorFactory.class
52: .getPackage().getName()
53: + "." + className;
54: }
55:
56: try {
57: Class<SessionValidator> clazz = (Class) Class
58: .forName(className);
59: return (SessionValidator) clazz.newInstance();
60: } catch (Exception e) {
61: throw new UnknownSessionValidatorClassException(className,
62: e);
63: }
64: }
65: }
|