~ubuntu-branches/debian/wheezy/jing-trang/wheezy

« back to all changes in this revision

Viewing changes to mod/pattern/src/main/com/thaiopensource/relaxng/pattern/ListPattern.java

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Thibault
  • Date: 2009-09-01 15:53:03 UTC
  • Revision ID: james.westby@ubuntu.com-20090901155303-2kweef05h5v9j3ni
Tags: upstream-20090818
ImportĀ upstreamĀ versionĀ 20090818

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.thaiopensource.relaxng.pattern;
 
2
 
 
3
import org.xml.sax.Locator;
 
4
import org.xml.sax.SAXException;
 
5
 
 
6
class ListPattern extends Pattern {
 
7
  private final Pattern p;
 
8
  private final Locator locator;
 
9
 
 
10
  ListPattern(Pattern p, Locator 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 {
 
27
    p.checkRecursion(depth);
 
28
  }
 
29
 
 
30
  boolean samePattern(Pattern other) {
 
31
    return (other instanceof ListPattern
 
32
            && p == ((ListPattern)other).p);
 
33
  }
 
34
 
 
35
  <T> T apply(PatternFunction<T> f) {
 
36
    return f.caseList(this);
 
37
  }
 
38
 
 
39
  void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
 
40
    throws RestrictionViolationException {
 
41
    switch (context) {
 
42
    case DATA_EXCEPT_CONTEXT:
 
43
      throw new RestrictionViolationException("data_except_contains_list");
 
44
    case START_CONTEXT:
 
45
      throw new RestrictionViolationException("start_contains_list");
 
46
    case LIST_CONTEXT:
 
47
      throw new RestrictionViolationException("list_contains_list");
 
48
    }
 
49
    try {
 
50
      p.checkRestrictions(LIST_CONTEXT, dad, null);
 
51
    }
 
52
    catch (RestrictionViolationException e) {
 
53
      e.maybeSetLocator(locator);
 
54
      throw e;
 
55
    }
 
56
  }
 
57
  
 
58
  Pattern getOperand() {
 
59
    return p;
 
60
  }
 
61
}