/vt-ldap/tags/vt-ldap-3.2/src/main/java/edu/vt/middleware/ldap/pool/AbstractLdapFactory.java

http://vt-middleware.googlecode.com/ · Java · 175 lines · 86 code · 28 blank · 61 comment · 15 complexity · 1fada735265083f2285c3a7675ac531b MD5 · raw file

  1. /*
  2. $Id: AbstractLdapFactory.java 930 2009-10-26 20:44:26Z dfisher $
  3. Copyright (C) 2003-2009 Virginia Tech.
  4. All rights reserved.
  5. SEE LICENSE FOR MORE INFORMATION
  6. Author: Middleware Services
  7. Email: middleware@vt.edu
  8. Version: $Revision: 930 $
  9. Updated: $Date: 2009-10-26 21:44:26 +0100 (Mon, 26 Oct 2009) $
  10. */
  11. package edu.vt.middleware.ldap.pool;
  12. import edu.vt.middleware.ldap.BaseLdap;
  13. import org.apache.commons.logging.Log;
  14. import org.apache.commons.logging.LogFactory;
  15. /**
  16. * <code>AbstractLdapFactory</code> provides a basic implementation of an ldap
  17. * factory.
  18. *
  19. * @param <T> type of ldap object
  20. *
  21. * @author Middleware Services
  22. * @version $Revision: 930 $ $Date: 2009-10-26 21:44:26 +0100 (Mon, 26 Oct 2009) $
  23. */
  24. public abstract class AbstractLdapFactory<T extends BaseLdap>
  25. implements LdapFactory<T>
  26. {
  27. /** Log for this class. */
  28. protected final Log logger = LogFactory.getLog(this.getClass());
  29. /** For activating ldap objects. */
  30. protected LdapActivator<T> activator;
  31. /** For passivating ldap objects. */
  32. protected LdapPassivator<T> passivator;
  33. /** For validating ldap objects. */
  34. protected LdapValidator<T> validator;
  35. /**
  36. * Sets the ldap activator for this factory.
  37. *
  38. * @param la ldap activator
  39. */
  40. public void setLdapActivator(final LdapActivator<T> la)
  41. {
  42. this.activator = la;
  43. }
  44. /**
  45. * Returns the ldap activator for this factory.
  46. *
  47. * @return ldap activator
  48. */
  49. public LdapActivator<T> getLdapActivator()
  50. {
  51. return this.activator;
  52. }
  53. /**
  54. * Sets the ldap passivator for this factory.
  55. *
  56. * @param lp ldap passivator
  57. */
  58. public void setLdapPassivator(final LdapPassivator<T> lp)
  59. {
  60. this.passivator = lp;
  61. }
  62. /**
  63. * Returns the ldap passivator for this factory.
  64. *
  65. * @return ldap passivator
  66. */
  67. public LdapPassivator<T> getLdapPassivator()
  68. {
  69. return this.passivator;
  70. }
  71. /**
  72. * Sets the ldap validator for this factory.
  73. *
  74. * @param lv ldap validator
  75. */
  76. public void setLdapValidator(final LdapValidator<T> lv)
  77. {
  78. this.validator = lv;
  79. }
  80. /**
  81. * Returns the ldap validator for this factory.
  82. *
  83. * @return ldap validator
  84. */
  85. public LdapValidator<T> getLdapValidator()
  86. {
  87. return this.validator;
  88. }
  89. /** {@inheritDoc} */
  90. public abstract T create();
  91. /** {@inheritDoc} */
  92. public abstract void destroy(final T t);
  93. /** {@inheritDoc} */
  94. public boolean activate(final T t)
  95. {
  96. boolean success = false;
  97. if (this.activator == null) {
  98. success = true;
  99. if (this.logger.isTraceEnabled()) {
  100. this.logger.trace("no activator configured");
  101. }
  102. } else {
  103. success = this.activator.activate(t);
  104. if (this.logger.isTraceEnabled()) {
  105. this.logger.trace("activation for " + t + " = " + success);
  106. }
  107. }
  108. return success;
  109. }
  110. /** {@inheritDoc} */
  111. public boolean passivate(final T t)
  112. {
  113. boolean success = false;
  114. if (this.passivator == null) {
  115. success = true;
  116. if (this.logger.isTraceEnabled()) {
  117. this.logger.trace("no passivator configured");
  118. }
  119. } else {
  120. success = this.passivator.passivate(t);
  121. if (this.logger.isTraceEnabled()) {
  122. this.logger.trace("passivation for " + t + " = " + success);
  123. }
  124. }
  125. return success;
  126. }
  127. /** {@inheritDoc} */
  128. public boolean validate(final T t)
  129. {
  130. boolean success = false;
  131. if (this.validator == null) {
  132. success = true;
  133. if (this.logger.isWarnEnabled()) {
  134. this.logger.warn("validate called, but no validator configured");
  135. }
  136. } else {
  137. success = this.validator.validate(t);
  138. if (this.logger.isTraceEnabled()) {
  139. this.logger.trace("validation for " + t + " = " + success);
  140. }
  141. }
  142. return success;
  143. }
  144. }