/*
* Copyright 2001-2008 Geert Bevin <gbevin[remove] at uwyn dot com> and
* Steven Grimm <koreth[remove] at midwinter dot com>
* Licensed under the Apache License, Version 2.0 (the "License")
* $Id: DatabaseSessionValidatorFactory.java 3918 2008-04-14 17:35:35Z gbevin $
*/
package com.uwyn.rife.authentication.sessionvalidators;
import com.uwyn.rife.authentication.SessionValidator;
import com.uwyn.rife.database.Datasource;
import com.uwyn.rife.database.DbQueryManagerCache;
import com.uwyn.rife.database.DbQueryManagerFactory;
import com.uwyn.rife.ioc.HierarchicalProperties;
import com.uwyn.rife.ioc.exceptions.MandatoryPropertyMissingException;
import com.uwyn.rife.ioc.exceptions.PropertyValueException;
/**
* Factory for {@link DatabaseSessionValidator} manager instances that creates singletons
* based on the {@code Datasource} and an optional differentiating
* identifier.
*
* @author Steven Grimm (koreth[remove] at midwinter dot com)
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
* @version $Revision: 3918 $
* @since 1.0
*/
public class DatabaseSessionValidatorFactory extends DbQueryManagerFactory implements SessionValidatorFactory
{
/** The package name of the datasource-specific implementations */
public static final String MANAGER_PACKAGE_NAME = DatabaseSessionValidatorFactory.class.getPackage().getName()+".databasedrivers.";
private static DbQueryManagerCache mCache = new DbQueryManagerCache();
/**
* Return an instance of {@code DatabaseSessionValidator} for the provided
* {@code Datasource}.
*
* @param datasource the datasource that will be used to create the manager
* @return the requested {@code DatabaseSessionValidator} instance
* @since 1.0
*/
private static DatabaseSessionValidator getInstance(Datasource datasource)
{
return (DatabaseSessionValidator)getInstance(MANAGER_PACKAGE_NAME, mCache, datasource);
}
/**
* Return an instance of {@code DatabaseSessionValidator} for the provided
* {@code Datasource} and identifier.
*
* @param datasource the datasource that will be used to create the manager
* @param identifier the identifier that will be used to differentiate the
* manager when different ones are needed for the same datasource
* @return the requested {@code DatabaseSessionValidator} instance
* @since 1.0
*/
private static DatabaseSessionValidator getInstance(Datasource datasource, String identifier)
{
return (DatabaseSessionValidator)getInstance(MANAGER_PACKAGE_NAME, mCache, datasource, identifier);
}
public SessionValidator getValidator(HierarchicalProperties properties)
throws PropertyValueException
{
Datasource datasource = properties.getValueTyped("datasource", Datasource.class);
if (null == datasource)
{
throw new MandatoryPropertyMissingException("datasource");
}
String credentialsmanager_id = properties.getValueString("credentialsmanager_id");
if (credentialsmanager_id != null)
return getInstance(datasource, credentialsmanager_id);
else
return getInstance(datasource);
}
}