01: package org.kohsuke.rngom.ast.util;
02:
03: import org.kohsuke.rngom.ast.builder.BuildException;
04: import org.kohsuke.rngom.ast.builder.SchemaBuilder;
05: import org.kohsuke.rngom.ast.om.ParsedPattern;
06: import org.kohsuke.rngom.binary.SchemaBuilderImpl;
07: import org.kohsuke.rngom.binary.SchemaPatternBuilder;
08: import org.kohsuke.rngom.parse.IllegalSchemaException;
09: import org.kohsuke.rngom.parse.host.ParsedPatternHost;
10: import org.kohsuke.rngom.parse.host.SchemaBuilderHost;
11: import org.relaxng.datatype.DatatypeLibraryFactory;
12: import org.xml.sax.ErrorHandler;
13:
14: /**
15: * Wraps a {@link SchemaBuilder} and does all the semantic checks
16: * required by the RELAX NG spec.
17: *
18: * <h2>Usage</h2>
19: * <p>
20: * Whereas you normally write it as follows:
21: * <pre>
22: * YourParsedPattern r = (YourParsedPattern)parseable.parse(sb);
23: * </pre>
24: * write this as follows:
25: * <pre>
26: * YourParsedPattern r = (YourParsedPattern)parseable.parse(new CheckingSchemaBuilder(sb,eh));
27: * </pre>
28: *
29: * <p>
30: * The checking is done by using the <tt>rngom.binary</tt> package, so if you are using
31: * that package for parsing schemas, then there's no need to use this.
32: *
33: * @author
34: * Kohsuke Kawaguchi (kk@kohsuke.org)
35: */
36: public class CheckingSchemaBuilder extends SchemaBuilderHost {
37: /**
38: *
39: * @param sb
40: * Your {@link SchemaBuilder} that parses RELAX NG schemas.
41: * @param eh
42: * All the errors found will be sent to this handler.
43: */
44: public CheckingSchemaBuilder(SchemaBuilder sb, ErrorHandler eh) {
45: super (new SchemaBuilderImpl(eh), sb);
46: }
47:
48: public CheckingSchemaBuilder(SchemaBuilder sb, ErrorHandler eh,
49: DatatypeLibraryFactory dlf) {
50: super (
51: new SchemaBuilderImpl(eh, dlf,
52: new SchemaPatternBuilder()), sb);
53: }
54:
55: public ParsedPattern expandPattern(ParsedPattern p)
56: throws BuildException, IllegalSchemaException {
57:
58: // just return the result from the user-given SchemaBuilder
59: ParsedPatternHost r = (ParsedPatternHost) super
60: .expandPattern(p);
61: return r.rhs;
62: }
63: }
|