KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.relaxng.impl;
2
3 class InterleavePattern extends BinaryPattern {
4   InterleavePattern(Pattern p1, Pattern p2) {
5     super(p1.isNullable() && p2.isNullable(),
6       combineHashCode(INTERLEAVE_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.makeInterleave(ep1, ep2);
15     else
16       return this;
17   }
18   void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
19     throws RestrictionViolationException {
20     switch (context) {
21     case START_CONTEXT:
22       throw new RestrictionViolationException("start_contains_interleave");
23     case DATA_EXCEPT_CONTEXT:
24       throw new RestrictionViolationException("data_except_contains_interleave");
25     case LIST_CONTEXT:
26       throw new RestrictionViolationException("list_contains_interleave");
27     }
28     if (context == ELEMENT_REPEAT_CONTEXT)
29       context = ELEMENT_REPEAT_INTERLEAVE_CONTEXT;
30     Alphabet a1;
31     if (alpha != null && alpha.isEmpty())
32       a1 = alpha;
33     else
34       a1 = new Alphabet();
35     p1.checkRestrictions(context, dad, a1);
36     if (a1.isEmpty())
37       p2.checkRestrictions(context, dad, a1);
38     else {
39       Alphabet a2 = new Alphabet();
40       p2.checkRestrictions(context, dad, a2);
41       a1.checkOverlap(a2);
42       if (alpha != null) {
43     if (alpha != a1)
44       alpha.addAlphabet(a1);
45     alpha.addAlphabet(a2);
46       }
47     }
48     if (!contentTypeGroupable(p1.getContentType(), p2.getContentType()))
49       throw new RestrictionViolationException("interleave_string");
50     if (p1.getContentType() == MIXED_CONTENT_TYPE
51     && p2.getContentType() == MIXED_CONTENT_TYPE)
52       throw new RestrictionViolationException("interleave_text_overlap");
53   }
54
55   void accept(PatternVisitor visitor) {
56     visitor.visitInterleave(p1, p2);
57   }
58   Object JavaDoc apply(PatternFunction f) {
59     return f.caseInterleave(this);
60   }
61 }
62
Popular Tags