KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.relaxng.impl;
2
3 import org.xml.sax.Locator JavaDoc;
4 import org.xml.sax.SAXException JavaDoc;
5
6 class ListPattern extends Pattern {
7   private final Pattern p;
8   private final Locator JavaDoc locator;
9
10   ListPattern(Pattern p, Locator JavaDoc locator) {
11     super(false,
12       DATA_CONTENT_TYPE,
13       combineHashCode(LIST_HASH_CODE, p.hashCode()));
14     this.p = p;
15     this.locator = locator;
16   }
17
18   Pattern expand(SchemaPatternBuilder b) {
19     Pattern ep = p.expand(b);
20     if (ep != p)
21       return b.makeList(ep, locator);
22     else
23       return this;
24   }
25
26   void checkRecursion(int depth) throws SAXException JavaDoc {
27     p.checkRecursion(depth);
28   }
29
30   boolean samePattern(Pattern other) {
31     return (other instanceof ListPattern
32         && p == ((ListPattern)other).p);
33   }
34
35   void accept(PatternVisitor visitor) {
36     visitor.visitList(p);
37   }
38
39   Object JavaDoc apply(PatternFunction f) {
40     return f.caseList(this);
41   }
42
43   void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
44     throws RestrictionViolationException {
45     switch (context) {
46     case DATA_EXCEPT_CONTEXT:
47       throw new RestrictionViolationException("data_except_contains_list");
48     case START_CONTEXT:
49       throw new RestrictionViolationException("start_contains_list");
50     case LIST_CONTEXT:
51       throw new RestrictionViolationException("list_contains_list");
52     }
53     try {
54       p.checkRestrictions(LIST_CONTEXT, dad, null);
55     }
56     catch (RestrictionViolationException e) {
57       e.maybeSetLocator(locator);
58       throw e;
59     }
60   }
61   
62   Pattern getOperand() {
63     return p;
64   }
65 }
66
Popular Tags