You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InternalColumnValidator.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. Copyright (c) 2018 James Ahlborn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.impl;
  14. import java.io.IOException;
  15. import com.healthmarketscience.jackcess.Column;
  16. import com.healthmarketscience.jackcess.util.ColumnValidator;
  17. /**
  18. * Base class for ColumnValidator instances handling "internal" validation
  19. * functionality, which are wrappers around any "external" behavior.
  20. *
  21. * @author James Ahlborn
  22. */
  23. abstract class InternalColumnValidator implements ColumnValidator
  24. {
  25. private ColumnValidator _delegate;
  26. protected InternalColumnValidator(ColumnValidator delegate)
  27. {
  28. _delegate = delegate;
  29. }
  30. ColumnValidator getExternal() {
  31. ColumnValidator extValidator = _delegate;
  32. while(extValidator instanceof InternalColumnValidator) {
  33. extValidator = ((InternalColumnValidator)extValidator)._delegate;
  34. }
  35. return extValidator;
  36. }
  37. void setExternal(ColumnValidator extValidator) {
  38. InternalColumnValidator intValidator = this;
  39. while(intValidator._delegate instanceof InternalColumnValidator) {
  40. intValidator = (InternalColumnValidator)intValidator._delegate;
  41. }
  42. intValidator._delegate = extValidator;
  43. }
  44. public final Object validate(Column col, Object val) throws IOException {
  45. val = _delegate.validate(col, val);
  46. return internalValidate(col, val);
  47. }
  48. protected abstract Object internalValidate(Column col, Object val)
  49. throws IOException;
  50. }