API Overview API Index Package Overview Direct link to this page
JDK 1.6
  org.relaxng.datatype.helpers. StreamingValidatorImpl View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

font color='#880088'>
package org.relaxng.datatype.helpers;

import org.relaxng.datatype.*;

/**
 * Dummy implementation of {@link DatatypeStreamingValidator}.
 * 
 * <p>
 * This implementation can be used as a quick hack when the performance
 * of streaming validation is not important. And this implementation
 * also shows you how to implement the DatatypeStreamingValidator interface.
 * 
 * <p>
 * Typical usage would be:
 * <PRE><XMP>
 * class MyDatatype implements Datatype {
 *     ....
 *     public DatatypeStreamingValidator createStreamingValidator( ValidationContext context ) {
 *         return new StreamingValidatorImpl(this,context);
 *     }
 *     ....
 * }
 * </XMP></PRE>
 * 
 * @author <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>
 */
public final class StreamingValidatorImpl implements DatatypeStreamingValidator {
	
	/** This buffer accumulates characters. */
	private final StringBuffer buffer = new StringBuffer();
	
	/** Datatype obejct that creates this streaming validator. */
	private final Datatype baseType;
	
	/** The current context. */
	private final ValidationContext context;
	
	public void addCharacters( char[] buf, int start, int len ) {
		// append characters to the current buffer.
		buffer.append(buf,start,len);
	}
	
	public boolean isValid() {
		return baseType.isValid(buffer.toString(),context);
	}
	
	public void checkValid() throws DatatypeException {
		baseType.checkValid(buffer.toString(),context);
	}
	
	public StreamingValidatorImpl( Datatype baseType, ValidationContext context ) {
		this.baseType = baseType;
		this.context = context;
	}
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar