OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / classpath / external / relaxngDatatype / org / relaxng / datatype / helpers / StreamingValidatorImpl.java
1 package org.relaxng.datatype.helpers;\r
2 \r
3 import org.relaxng.datatype.*;\r
4 \r
5 /**\r
6  * Dummy implementation of {@link DatatypeStreamingValidator}.\r
7  * \r
8  * <p>\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
12  * \r
13  * <p>\r
14  * Typical usage would be:\r
15  * <PRE><XMP>\r
16  * class MyDatatype implements Datatype {\r
17  *     ....\r
18  *     public DatatypeStreamingValidator createStreamingValidator( ValidationContext context ) {\r
19  *         return new StreamingValidatorImpl(this,context);\r
20  *     }\r
21  *     ....\r
22  * }\r
23  * </XMP></PRE>\r
24  * \r
25  * @author <a href="mailto:kohsuke.kawaguchi@sun.com">Kohsuke KAWAGUCHI</a>\r
26  */\r
27 public final class StreamingValidatorImpl implements DatatypeStreamingValidator {\r
28         \r
29         /** This buffer accumulates characters. */\r
30         private final StringBuffer buffer = new StringBuffer();\r
31         \r
32         /** Datatype obejct that creates this streaming validator. */\r
33         private final Datatype baseType;\r
34         \r
35         /** The current context. */\r
36         private final ValidationContext context;\r
37         \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
41         }\r
42         \r
43         public boolean isValid() {\r
44                 return baseType.isValid(buffer.toString(),context);\r
45         }\r
46         \r
47         public void checkValid() throws DatatypeException {\r
48                 baseType.checkValid(buffer.toString(),context);\r
49         }\r
50         \r
51         public StreamingValidatorImpl( Datatype baseType, ValidationContext context ) {\r
52                 this.baseType = baseType;\r
53                 this.context = context;\r
54         }\r
55 }\r