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 caseOther(Pattern p) { 15 return new SingleDataDerivType(); 16 } 17 18 public Object 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 caseBinary(BinaryPattern p) { 27 return apply(p.getOperand1()).combine(apply(p.getOperand2())); 28 } 29 30 public Object caseChoice(ChoicePattern p) { 31 return caseBinary(p); 32 } 33 34 public Object caseGroup(GroupPattern p) { 35 return caseBinary(p); 36 } 37 38 public Object caseInterleave(InterleavePattern p) { 39 return caseBinary(p); 40 } 41 42 public Object caseOneOrMore(OneOrMorePattern p) { 43 return apply(p.getOperand()); 44 } 45 46 public Object caseList(ListPattern p) { 47 return InconsistentDataDerivType.getInstance(); 48 } 49 50 public Object caseValue(ValuePattern p) { 51 return new ValueDataDerivType(p.getDatatype()); 52 } 53 54 public Object caseData(DataPattern p) { 55 if (p.allowsAnyString()) 56 return new SingleDataDerivType(); 57 return new DataDataDerivType(p.getDatatype()); 58 } 59 60 public Object 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 |