class DirContextPoolableObjectFactory extends BaseKeyedPoolableObjectFactory {

    public boolean validateObject(Object key, Object obj) {
        Assert.notNull(this.dirContextValidator,
                "DirContextValidator may not be null");
        Assert.isTrue(key instanceof DirContextType,
                "key must be a DirContextType");
        Assert.isTrue(obj instanceof DirContext,
                "The Object to validate must be of type '" + DirContext.class
                        + "'");

        try {
            final DirContextType contextType = (DirContextType) key;
            final DirContext dirContext = (DirContext) obj;
            return this.dirContextValidator.validateDirContext(contextType,
                    dirContext);
        } catch (Exception e) {
            this.logger.warn("Failed to validate '" + obj
                    + "' due to an unexpected exception.", e);
            return false;
        }
    }

}