1 package org.relaxng.datatype.helpers;
\r
3 import org.relaxng.datatype.*;
\r
6 * Dummy implementation of {@link DatatypeStreamingValidator}.
\r
9 * This implementation can be used as a quick hack when the performance
\r
10 * of streaming validation is not important. And this implementation
\r
11 * also shows you how to implement the DatatypeStreamingValidator interface.
\r
14 * Typical usage would be:
\r
16 * class MyDatatype implements Datatype {
\r
18 * public DatatypeStreamingValidator createStreamingValidator( ValidationContext context ) {
\r
19 * return new StreamingValidatorImpl(this,context);
\r
25 * @author <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
\r
27 public final class StreamingValidatorImpl implements DatatypeStreamingValidator {
\r
29 /** This buffer accumulates characters. */
\r
30 private final StringBuffer buffer = new StringBuffer();
\r
32 /** Datatype obejct that creates this streaming validator. */
\r
33 private final Datatype baseType;
\r
35 /** The current context. */
\r
36 private final ValidationContext context;
\r
38 public void addCharacters( char[] buf, int start, int len ) {
\r
39 // append characters to the current buffer.
\r
40 buffer.append(buf,start,len);
\r
43 public boolean isValid() {
\r
44 return baseType.isValid(buffer.toString(),context);
\r
47 public void checkValid() throws DatatypeException {
\r
48 baseType.checkValid(buffer.toString(),context);
\r
51 public StreamingValidatorImpl( Datatype baseType, ValidationContext context ) {
\r
52 this.baseType = baseType;
\r
53 this.context = context;
\r