01: package org.kohsuke.rngom.digested;
02:
03: import org.kohsuke.rngom.ast.builder.Annotations;
04: import org.kohsuke.rngom.ast.builder.BuildException;
05: import org.kohsuke.rngom.ast.builder.Include;
06: import org.kohsuke.rngom.ast.builder.IncludedGrammar;
07: import org.kohsuke.rngom.ast.builder.Scope;
08: import org.kohsuke.rngom.ast.om.Location;
09: import org.kohsuke.rngom.ast.om.ParsedPattern;
10: import org.kohsuke.rngom.parse.IllegalSchemaException;
11: import org.kohsuke.rngom.parse.Parseable;
12:
13: import java.util.HashSet;
14: import java.util.Set;
15:
16: /**
17: * @author Kohsuke Kawaguchi (kk@kohsuke.org)
18: */
19: final class IncludeImpl extends GrammarBuilderImpl implements Include {
20:
21: private Set overridenPatterns = new HashSet();
22: private boolean startOverriden = false;
23:
24: public IncludeImpl(DGrammarPattern p, Scope parent,
25: DSchemaBuilderImpl sb) {
26: super (p, parent, sb);
27: }
28:
29: public void define(String name, Combine combine,
30: ParsedPattern pattern, Location loc, Annotations anno)
31: throws BuildException {
32: super .define(name, combine, pattern, loc, anno);
33: if (name == START)
34: startOverriden = true;
35: else
36: overridenPatterns.add(name);
37: }
38:
39: public void endInclude(Parseable current, String uri, String ns,
40: Location loc, Annotations anno) throws BuildException,
41: IllegalSchemaException {
42: current.parseInclude(uri, sb, new IncludedGrammarImpl(grammar,
43: parent, sb), ns);
44: }
45:
46: private class IncludedGrammarImpl extends GrammarBuilderImpl
47: implements IncludedGrammar {
48: public IncludedGrammarImpl(DGrammarPattern p, Scope parent,
49: DSchemaBuilderImpl sb) {
50: super (p, parent, sb);
51: }
52:
53: public void define(String name, Combine combine,
54: ParsedPattern pattern, Location loc, Annotations anno)
55: throws BuildException {
56: // check for overridden pattern
57: if (name == START) {
58: if (startOverriden)
59: return;
60: } else {
61: if (overridenPatterns.contains(name))
62: return;
63: }
64: // otherwise define
65: super .define(name, combine, pattern, loc, anno);
66: }
67:
68: public ParsedPattern endIncludedGrammar(Location loc,
69: Annotations anno) throws BuildException {
70: return null;
71: }
72: }
73: }
|