KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > relaxng > impl > SchemaPatternBuilder


1 package com.thaiopensource.relaxng.impl;
2
3 import org.relaxng.datatype.Datatype;
4 import org.xml.sax.Locator JavaDoc;
5
6 public class SchemaPatternBuilder extends PatternBuilder {
7   private boolean idTypes;
8   private final UnexpandedNotAllowedPattern unexpandedNotAllowed = new UnexpandedNotAllowedPattern();
9   private final TextPattern text = new TextPattern();
10   private final PatternInterner schemaInterner = new PatternInterner();
11
12   public SchemaPatternBuilder() { }
13
14   public boolean hasIdTypes() {
15     return idTypes;
16   }
17
18   Pattern makeElement(NameClass nameClass, Pattern content, Locator JavaDoc loc) {
19     Pattern p = new ElementPattern(nameClass, content, loc);
20     return schemaInterner.intern(p);
21   }
22
23   Pattern makeAttribute(NameClass nameClass, Pattern value, Locator JavaDoc loc) {
24     if (value == notAllowed)
25       return value;
26     Pattern p = new AttributePattern(nameClass, value, loc);
27     return schemaInterner.intern(p);
28   }
29
30   Pattern makeData(Datatype dt) {
31     noteDatatype(dt);
32     Pattern p = new DataPattern(dt);
33     return schemaInterner.intern(p);
34   }
35
36   Pattern makeDataExcept(Datatype dt, Pattern except, Locator JavaDoc loc) {
37     noteDatatype(dt);
38     Pattern p = new DataExceptPattern(dt, except, loc);
39     return schemaInterner.intern(p);
40   }
41
42   Pattern makeValue(Datatype dt, Object JavaDoc obj) {
43     noteDatatype(dt);
44     Pattern p = new ValuePattern(dt, obj);
45     return schemaInterner.intern(p);
46   }
47
48   Pattern makeText() {
49     return text;
50   }
51
52   Pattern makeOneOrMore(Pattern p) {
53     if (p == text)
54       return p;
55     return super.makeOneOrMore(p);
56   }
57
58   Pattern makeUnexpandedNotAllowed() {
59     return unexpandedNotAllowed;
60   }
61
62   Pattern makeError() {
63     Pattern p = new ErrorPattern();
64     return schemaInterner.intern(p);
65   }
66
67   Pattern makeChoice(Pattern p1, Pattern p2) {
68     if (p1 == notAllowed || p1 == p2)
69       return p2;
70     if (p2 == notAllowed)
71       return p1;
72     return super.makeChoice(p1, p2);
73   }
74
75   Pattern makeList(Pattern p, Locator JavaDoc loc) {
76     if (p == notAllowed)
77       return p;
78     Pattern p1 = new ListPattern(p, loc);
79     return schemaInterner.intern(p1);
80   }
81
82   Pattern makeMixed(Pattern p) {
83     return makeInterleave(text, p);
84   }
85
86   private void noteDatatype(Datatype dt) {
87     if (dt.getIdType() != Datatype.ID_TYPE_NULL)
88       idTypes = true;
89   }
90 }
91
Popular Tags