01: package org.relaxng.datatype.helpers;
02:
03: import org.relaxng.datatype.*;
04:
05: /**
06: * Dummy implementation of {@link DatatypeStreamingValidator}.
07: *
08: * <p>
09: * This implementation can be used as a quick hack when the performance
10: * of streaming validation is not important. And this implementation
11: * also shows you how to implement the DatatypeStreamingValidator interface.
12: *
13: * <p>
14: * Typical usage would be:
15: * <PRE><XMP>
16: * class MyDatatype implements Datatype {
17: * ....
18: * public DatatypeStreamingValidator createStreamingValidator( ValidationContext context ) {
19: * return new StreamingValidatorImpl(this,context);
20: * }
21: * ....
22: * }
23: * </XMP></PRE>
24: *
25: * @author <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
26: */
27: public final class StreamingValidatorImpl implements
28: DatatypeStreamingValidator {
29:
30: /** This buffer accumulates characters. */
31: private final StringBuffer buffer = new StringBuffer();
32:
33: /** Datatype obejct that creates this streaming validator. */
34: private final Datatype baseType;
35:
36: /** The current context. */
37: private final ValidationContext context;
38:
39: public void addCharacters(char[] buf, int start, int len) {
40: // append characters to the current buffer.
41: buffer.append(buf, start, len);
42: }
43:
44: public boolean isValid() {
45: return baseType.isValid(buffer.toString(), context);
46: }
47:
48: public void checkValid() throws DatatypeException {
49: baseType.checkValid(buffer.toString(), context);
50: }
51:
52: public StreamingValidatorImpl(Datatype baseType,
53: ValidationContext context) {
54: this.baseType = baseType;
55: this.context = context;
56: }
57: }
|