KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.relaxng.impl;
2
3 import org.relaxng.datatype.Datatype;
4 import org.relaxng.datatype.ValidationContext;
5
6 import java.util.Hashtable JavaDoc;
7
8 class ValueDataDerivType extends DataDerivType {
9   private final Datatype dt;
10   private PatternMemo noValue;
11   private Hashtable JavaDoc valueTable;
12
13   ValueDataDerivType(Datatype dt) {
14     this.dt = dt;
15   }
16
17   DataDerivType copy() {
18     return new ValueDataDerivType(dt);
19   }
20
21   PatternMemo dataDeriv(ValidatorPatternBuilder builder, Pattern p, String JavaDoc str, ValidationContext vc) {
22     Object JavaDoc value = dt.createValue(str, vc);
23     if (value == null) {
24       if (noValue == null)
25         noValue = super.dataDeriv(builder, p, str, vc);
26       return noValue;
27     }
28     else {
29       DatatypeValue dtv = new DatatypeValue(value, dt);
30       if (valueTable == null)
31         valueTable = new Hashtable JavaDoc();
32       PatternMemo tem = (PatternMemo)valueTable.get(dtv);
33       if (tem == null) {
34         tem = super.dataDeriv(builder, p, str, vc);
35         valueTable.put(dtv, tem);
36       }
37       return tem;
38     }
39   }
40
41   DataDerivType combine(DataDerivType ddt) {
42     if (ddt instanceof ValueDataDerivType) {
43       if (((ValueDataDerivType)ddt).dt == this.dt)
44         return this;
45       else
46         return InconsistentDataDerivType.getInstance();
47     }
48     else
49       return ddt.combine(this);
50   }
51
52   Datatype getDatatype() {
53     return dt;
54   }
55 }
56
Popular Tags