KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.relaxng.impl;
2
3 class ChoicePattern extends BinaryPattern {
4   ChoicePattern(Pattern p1, Pattern p2) {
5     super(p1.isNullable() || p2.isNullable(),
6       combineHashCode(CHOICE_HASH_CODE, p1.hashCode(), p2.hashCode()),
7       p1,
8       p2);
9   }
10   Pattern expand(SchemaPatternBuilder b) {
11     Pattern ep1 = p1.expand(b);
12     Pattern ep2 = p2.expand(b);
13     if (ep1 != p1 || ep2 != p2)
14       return b.makeChoice(ep1, ep2);
15     else
16       return this;
17   }
18
19   boolean containsChoice(Pattern p) {
20     return p1.containsChoice(p) || p2.containsChoice(p);
21   }
22
23   void accept(PatternVisitor visitor) {
24     visitor.visitChoice(p1, p2);
25   }
26
27   Object JavaDoc apply(PatternFunction f) {
28     return f.caseChoice(this);
29   }
30
31   void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
32     throws RestrictionViolationException {
33     if (dad != null)
34       dad.startChoice();
35     p1.checkRestrictions(context, dad, alpha);
36     if (dad != null)
37       dad.alternative();
38     p2.checkRestrictions(context, dad, alpha);
39     if (dad != null)
40       dad.endChoice();
41   }
42
43 }
44
45
Popular Tags