/ldaptive/core/trunk/src/main/java/org/ldaptive/pool/CompareValidator.java
http://vt-middleware.googlecode.com/ · Java · 99 lines · 47 code · 14 blank · 38 comment · 2 complexity · 592fc4ba9ce20c8db026ce032d3420d2 MD5 · raw file
- /*
- $Id: CompareValidator.java 2352 2012-04-11 14:00:33Z dfisher $
- Copyright (C) 2003-2012 Virginia Tech.
- All rights reserved.
- SEE LICENSE FOR MORE INFORMATION
- Author: Middleware Services
- Email: middleware@vt.edu
- Version: $Revision: 2352 $
- Updated: $Date: 2012-04-11 16:00:33 +0200 (Wed, 11 Apr 2012) $
- */
- package org.ldaptive.pool;
- import org.ldaptive.CompareOperation;
- import org.ldaptive.CompareRequest;
- import org.ldaptive.Connection;
- import org.ldaptive.LdapAttribute;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- /**
- * Validates a connection is healthy by performing a compare operation.
- *
- * @author Middleware Services
- * @version $Revision: 2352 $ $Date: 2012-04-11 16:00:33 +0200 (Wed, 11 Apr 2012) $
- */
- public class CompareValidator implements Validator<Connection>
- {
- /** Logger for this class. */
- protected final Logger logger = LoggerFactory.getLogger(getClass());
- /** Compare request to perform validation with. */
- private CompareRequest compareRequest;
- /** Creates a new compare validator. */
- public CompareValidator()
- {
- compareRequest = new CompareRequest();
- compareRequest.setDn("");
- compareRequest.setAttribute(new LdapAttribute("objectClass", "top"));
- }
- /**
- * Creates a new compare validator.
- *
- * @param cr to use for compares
- */
- public CompareValidator(final CompareRequest cr)
- {
- compareRequest = cr;
- }
- /**
- * Returns the compare request.
- *
- * @return compare request
- */
- public CompareRequest getCompareRequest()
- {
- return compareRequest;
- }
- /**
- * Sets the compare request.
- *
- * @param cr compare request
- */
- public void setCompareRequest(final CompareRequest cr)
- {
- compareRequest = cr;
- }
- /** {@inheritDoc} */
- @Override
- public boolean validate(final Connection c)
- {
- boolean success = false;
- if (c != null) {
- try {
- final CompareOperation compare = new CompareOperation(c);
- success = compare.execute(compareRequest).getResult();
- } catch (Exception e) {
- logger.debug(
- "validation failed for compare request {}",
- compareRequest,
- e);
- }
- }
- return success;
- }
- }