001 package com.thaiopensource.relaxng.impl; 002 003 import org.relaxng.datatype.Datatype; 004 import org.relaxng.datatype.ValidationContext; 005 006 import java.util.Hashtable; 007 008 class ValueDataDerivType extends DataDerivType { 009 private final Datatype dt; 010 private PatternMemo noValue; 011 private Hashtable valueTable; 012 013 ValueDataDerivType(Datatype dt) { 014 this.dt = dt; 015 } 016 017 DataDerivType copy() { 018 return new ValueDataDerivType(dt); 019 } 020 021 PatternMemo dataDeriv(ValidatorPatternBuilder builder, Pattern p, String str, ValidationContext vc) { 022 Object value = dt.createValue(str, vc); 023 if (value == null) { 024 if (noValue == null) 025 noValue = super.dataDeriv(builder, p, str, vc); 026 return noValue; 027 } 028 else { 029 DatatypeValue dtv = new DatatypeValue(value, dt); 030 if (valueTable == null) 031 valueTable = new Hashtable(); 032 PatternMemo tem = (PatternMemo)valueTable.get(dtv); 033 if (tem == null) { 034 tem = super.dataDeriv(builder, p, str, vc); 035 valueTable.put(dtv, tem); 036 } 037 return tem; 038 } 039 } 040 041 DataDerivType combine(DataDerivType ddt) { 042 if (ddt instanceof ValueDataDerivType) { 043 if (((ValueDataDerivType)ddt).dt == this.dt) 044 return this; 045 else 046 return InconsistentDataDerivType.getInstance(); 047 } 048 else 049 return ddt.combine(this); 050 } 051 052 Datatype getDatatype() { 053 return dt; 054 } 055 }