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