~ubuntu-branches/ubuntu/utopic/jing-trang/utopic

« back to all changes in this revision

Viewing changes to mod/pattern/src/main/com/thaiopensource/relaxng/pattern/DataDerivTypeFunction.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
class DataDerivTypeFunction extends AbstractPatternFunction<DataDerivType> {
 
4
  private final ValidatorPatternBuilder builder;
 
5
 
 
6
  DataDerivTypeFunction(ValidatorPatternBuilder builder) {
 
7
    this.builder = builder;
 
8
  }
 
9
 
 
10
  static DataDerivType dataDerivType(ValidatorPatternBuilder builder, Pattern pattern) {
 
11
    return pattern.apply(builder.getDataDerivTypeFunction());
 
12
  }
 
13
 
 
14
  public DataDerivType caseOther(Pattern p) {
 
15
    return new SingleDataDerivType();
 
16
  }
 
17
 
 
18
  public DataDerivType caseRef(RefPattern p) {
 
19
    return apply(p.getPattern());
 
20
  }
 
21
 
 
22
  public DataDerivType caseAfter(AfterPattern p) {
 
23
    Pattern p1 = p.getOperand1();
 
24
    DataDerivType ddt = apply(p.getOperand1());
 
25
    if (!p1.isNullable())
 
26
      return ddt;
 
27
    return ddt.combine(new BlankDataDerivType());
 
28
  }
 
29
 
 
30
  private DataDerivType caseBinary(BinaryPattern p) {
 
31
    return apply(p.getOperand1()).combine(apply(p.getOperand2()));
 
32
  }
 
33
 
 
34
  public DataDerivType caseChoice(ChoicePattern p) {
 
35
    return caseBinary(p);
 
36
  }
 
37
 
 
38
  public DataDerivType caseGroup(GroupPattern p) {
 
39
    return caseBinary(p);
 
40
  }
 
41
 
 
42
  public DataDerivType caseInterleave(InterleavePattern p) {
 
43
    return caseBinary(p);
 
44
  }
 
45
 
 
46
  public DataDerivType caseOneOrMore(OneOrMorePattern p) {
 
47
    return apply(p.getOperand());
 
48
  }
 
49
 
 
50
  public DataDerivType caseList(ListPattern p) {
 
51
    return InconsistentDataDerivType.getInstance();
 
52
  }
 
53
 
 
54
  public DataDerivType caseValue(ValuePattern p) {
 
55
    return new ValueDataDerivType(p.getDatatype(), p.getDatatypeName());
 
56
  }
 
57
 
 
58
  public DataDerivType caseData(DataPattern p) {
 
59
    if (p.allowsAnyString())
 
60
      return new SingleDataDerivType();
 
61
    return new DataDataDerivType(p);
 
62
  }
 
63
 
 
64
  public DataDerivType caseDataExcept(DataExceptPattern p) {
 
65
    if (p.allowsAnyString())
 
66
      return apply(p.getExcept());
 
67
    return new DataDataDerivType(p).combine(apply(p.getExcept()));
 
68
  }
 
69
 
 
70
  private DataDerivType apply(Pattern p) {
 
71
    return builder.getPatternMemo(p).dataDerivType();
 
72
  }
 
73
}