KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.relaxng.impl;
2
3 class DataDerivTypeFunction extends AbstractPatternFunction {
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 (DataDerivType)pattern.apply(builder.getDataDerivTypeFunction());
12   }
13
14   public Object JavaDoc caseOther(Pattern p) {
15     return new SingleDataDerivType();
16   }
17
18   public Object JavaDoc caseAfter(AfterPattern p) {
19     Pattern p1 = p.getOperand1();
20     DataDerivType ddt = apply(p.getOperand1());
21     if (!p1.isNullable())
22       return ddt;
23     return ddt.combine(new BlankDataDerivType());
24   }
25
26   private Object JavaDoc caseBinary(BinaryPattern p) {
27     return apply(p.getOperand1()).combine(apply(p.getOperand2()));
28   }
29
30   public Object JavaDoc caseChoice(ChoicePattern p) {
31     return caseBinary(p);
32   }
33
34   public Object JavaDoc caseGroup(GroupPattern p) {
35     return caseBinary(p);
36   }
37
38   public Object JavaDoc caseInterleave(InterleavePattern p) {
39     return caseBinary(p);
40   }
41
42   public Object JavaDoc caseOneOrMore(OneOrMorePattern p) {
43     return apply(p.getOperand());
44   }
45
46   public Object JavaDoc caseList(ListPattern p) {
47     return InconsistentDataDerivType.getInstance();
48   }
49
50   public Object JavaDoc caseValue(ValuePattern p) {
51     return new ValueDataDerivType(p.getDatatype());
52   }
53
54   public Object JavaDoc caseData(DataPattern p) {
55     if (p.allowsAnyString())
56       return new SingleDataDerivType();
57     return new DataDataDerivType(p.getDatatype());
58   }
59
60   public Object JavaDoc caseDataExcept(DataExceptPattern p) {
61     if (p.allowsAnyString())
62       return apply(p.getExcept());
63     return new DataDataDerivType(p.getDatatype()).combine(apply(p.getExcept()));
64   }
65
66   private DataDerivType apply(Pattern p) {
67     return builder.getPatternMemo(p).dataDerivType();
68   }
69 }
70
Popular Tags