1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.healthmarketscience.jackcess.impl;
18
19 import java.io.IOException;
20
21 import com.healthmarketscience.jackcess.Column;
22 import com.healthmarketscience.jackcess.util.ColumnValidator;
23 import com.healthmarketscience.jackcess.util.SimpleColumnValidator;
24
25
26
27
28
29
30
31 abstract class InternalColumnValidator implements ColumnValidator
32 {
33 private ColumnValidator _delegate;
34
35 protected InternalColumnValidator(ColumnValidator delegate)
36 {
37 _delegate = delegate;
38 }
39
40 ColumnValidator getExternal() {
41 ColumnValidator extValidator = _delegate;
42 while(extValidator instanceof InternalColumnValidator) {
43 extValidator = ((InternalColumnValidator)extValidator)._delegate;
44 }
45 return extValidator;
46 }
47
48 void setExternal(ColumnValidator extValidator) {
49 InternalColumnValidator intValidator = this;
50 while(intValidator._delegate instanceof InternalColumnValidator) {
51 intValidator = (InternalColumnValidator)intValidator._delegate;
52 }
53 intValidator._delegate = extValidator;
54 }
55
56 @Override
57 public final Object validate(Column col, Object val) throws IOException {
58 val = _delegate.validate(col, val);
59 return internalValidate(col, val);
60 }
61
62 @Override
63 public String toString() {
64 StringBuilder sb = new StringBuilder().append("{");
65 if(_delegate instanceof InternalColumnValidator) {
66 ((InternalColumnValidator)_delegate).appendToString(sb);
67 } else if(_delegate != SimpleColumnValidator.INSTANCE) {
68 sb.append("custom=").append(_delegate);
69 }
70 if(sb.length() > 1) {
71 sb.append(";");
72 }
73 appendToString(sb);
74 sb.append("}");
75 return sb.toString();
76 }
77
78 protected abstract void appendToString(StringBuilder sb);
79
80 protected abstract Object internalValidate(Column col, Object val)
81 throws IOException;
82 }