KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.relaxng.impl;
2
3 import org.xml.sax.Locator JavaDoc;
4 import org.xml.sax.SAXException JavaDoc;
5
6 class ElementPattern extends Pattern {
7   private Pattern p;
8   private final NameClass origNameClass;
9   private NameClass nameClass;
10   private boolean expanded = false;
11   private boolean checkedRestrictions = false;
12   private final Locator JavaDoc loc;
13
14   ElementPattern(NameClass nameClass, Pattern p, Locator JavaDoc loc) {
15     super(false,
16       ELEMENT_CONTENT_TYPE,
17       combineHashCode(ELEMENT_HASH_CODE,
18               nameClass.hashCode(),
19               p.hashCode()));
20     this.nameClass = nameClass;
21     this.origNameClass = nameClass;
22     this.p = p;
23     this.loc = loc;
24   }
25
26   void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
27     throws RestrictionViolationException {
28     if (alpha != null)
29       alpha.addElement(origNameClass);
30     if (checkedRestrictions)
31       return;
32     switch (context) {
33     case DATA_EXCEPT_CONTEXT:
34       throw new RestrictionViolationException("data_except_contains_element");
35     case LIST_CONTEXT:
36       throw new RestrictionViolationException("list_contains_element");
37     case ATTRIBUTE_CONTEXT:
38       throw new RestrictionViolationException("attribute_contains_element");
39     }
40     checkedRestrictions = true;
41     try {
42       p.checkRestrictions(ELEMENT_CONTEXT, new DuplicateAttributeDetector(), null);
43     }
44     catch (RestrictionViolationException e) {
45       checkedRestrictions = false;
46       e.maybeSetLocator(loc);
47       throw e;
48     }
49   }
50
51   Pattern expand(SchemaPatternBuilder b) {
52     if (!expanded) {
53       expanded = true;
54       p = p.expand(b);
55       if (p.isNotAllowed())
56     nameClass = new NullNameClass();
57     }
58     return this;
59   }
60
61   boolean samePattern(Pattern other) {
62     if (!(other instanceof ElementPattern))
63       return false;
64     ElementPattern ep = (ElementPattern)other;
65     return nameClass.equals(ep.nameClass) && p == ep.p;
66   }
67
68   void checkRecursion(int depth) throws SAXException JavaDoc {
69     p.checkRecursion(depth + 1);
70   }
71
72   void accept(PatternVisitor visitor) {
73     visitor.visitElement(nameClass, p);
74   }
75
76   Object JavaDoc apply(PatternFunction f) {
77     return f.caseElement(this);
78   }
79
80   void setContent(Pattern p) {
81     this.p = p;
82   }
83
84   Pattern getContent() {
85     return p;
86   }
87
88   NameClass getNameClass() {
89     return nameClass;
90   }
91
92   Locator JavaDoc getLocator() {
93     return loc;
94   }
95 }
96
Popular Tags