KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.thaiopensource.relaxng.impl;
2
3 import org.relaxng.datatype.ValidationContext;
4
5 import java.util.Hashtable JavaDoc;
6
7 import com.thaiopensource.xml.util.Name;
8
9 final class PatternMemo {
10   private final Pattern pattern;
11   private final ValidatorPatternBuilder builder;
12   private final boolean notAllowed;
13   private PatternMemo memoEndAttributes;
14   private PatternMemo memoTextOnly;
15   private PatternMemo memoEndTagDeriv;
16   private PatternMemo memoMixedTextDeriv;
17   private PatternMemo memoIgnoreMissingAttributes;
18   private Hashtable JavaDoc startTagOpenDerivMap;
19   private Hashtable JavaDoc startTagOpenRecoverDerivMap;
20   private Hashtable JavaDoc startAttributeDerivMap;
21   private DataDerivType memoDataDerivType;
22
23   PatternMemo(Pattern pattern, ValidatorPatternBuilder builder) {
24     this.pattern = pattern;
25     this.builder = builder;
26     this.notAllowed = pattern.isNotAllowed();
27   }
28
29   Pattern getPattern() {
30     return pattern;
31   }
32
33   ValidatorPatternBuilder getPatternBuilder() {
34     return builder;
35   }
36
37   boolean isNotAllowed() {
38     return notAllowed;
39   }
40
41   PatternMemo endAttributes() {
42     if (memoEndAttributes == null)
43       memoEndAttributes = applyForPatternMemo(builder.getEndAttributesFunction());
44     return memoEndAttributes;
45   }
46
47   PatternMemo endAttributes(PatternFunction f) {
48     if (memoEndAttributes == null)
49       memoEndAttributes = applyForPatternMemo(f);
50     return memoEndAttributes;
51   }
52
53   PatternMemo ignoreMissingAttributes() {
54     if (memoIgnoreMissingAttributes == null)
55       memoIgnoreMissingAttributes
56     = applyForPatternMemo(builder.getIgnoreMissingAttributesFunction());
57     return memoIgnoreMissingAttributes;
58   }
59
60   PatternMemo ignoreMissingAttributes(PatternFunction f) {
61     if (memoIgnoreMissingAttributes == null)
62       memoIgnoreMissingAttributes = applyForPatternMemo(f);
63     return memoIgnoreMissingAttributes;
64   }
65
66   PatternMemo textOnly() {
67     if (memoTextOnly == null)
68       memoTextOnly = applyForPatternMemo(builder.getTextOnlyFunction());
69     return memoTextOnly;
70   }
71
72   PatternMemo textOnly(PatternFunction f) {
73     if (memoTextOnly == null)
74       memoTextOnly = applyForPatternMemo(f);
75     return memoTextOnly;
76   }
77
78   PatternMemo endTagDeriv() {
79     if (memoEndTagDeriv == null)
80       memoEndTagDeriv = applyForPatternMemo(builder.getEndTagDerivFunction());
81     return memoEndTagDeriv;
82   }
83
84   PatternMemo endTagDeriv(PatternFunction f) {
85     if (memoEndTagDeriv == null)
86       memoEndTagDeriv = applyForPatternMemo(f);
87     return memoEndTagDeriv;
88   }
89
90
91   PatternMemo mixedTextDeriv() {
92     if (memoMixedTextDeriv == null)
93       memoMixedTextDeriv = applyForPatternMemo(builder.getMixedTextDerivFunction());
94     return memoMixedTextDeriv;
95   }
96
97   PatternMemo mixedTextDeriv(PatternFunction f) {
98     if (memoMixedTextDeriv == null)
99       memoMixedTextDeriv = applyForPatternMemo(f);
100     return memoMixedTextDeriv;
101   }
102
103   PatternMemo startTagOpenDeriv(Name name) {
104     return startTagOpenDeriv(name, null);
105   }
106
107   PatternMemo startTagOpenDeriv(StartTagOpenDerivFunction f) {
108     return startTagOpenDeriv(f.getName(), f);
109   }
110
111   private PatternMemo startTagOpenDeriv(Name name, StartTagOpenDerivFunction f) {
112     PatternMemo tem;
113     if (startTagOpenDerivMap == null)
114       startTagOpenDerivMap = new Hashtable JavaDoc();
115     else {
116       tem = (PatternMemo)startTagOpenDerivMap.get(name);
117       if (tem != null)
118     return tem;
119     }
120     if (f == null)
121       f = new StartTagOpenDerivFunction(name, builder);
122     tem = applyForPatternMemo(f);
123     startTagOpenDerivMap.put(name, tem);
124     return tem;
125   }
126
127   PatternMemo startTagOpenRecoverDeriv(Name name) {
128     return startTagOpenRecoverDeriv(name, null);
129   }
130
131   PatternMemo startTagOpenRecoverDeriv(StartTagOpenRecoverDerivFunction f) {
132     return startTagOpenRecoverDeriv(f.getName(), f);
133   }
134
135   private PatternMemo startTagOpenRecoverDeriv(Name name, StartTagOpenRecoverDerivFunction f) {
136     PatternMemo tem;
137     if (startTagOpenRecoverDerivMap == null)
138       startTagOpenRecoverDerivMap = new Hashtable JavaDoc();
139     else {
140       tem = (PatternMemo)startTagOpenRecoverDerivMap.get(name);
141       if (tem != null)
142     return tem;
143     }
144     if (f == null)
145       f = new StartTagOpenRecoverDerivFunction(name, builder);
146     tem = applyForPatternMemo(f);
147     startTagOpenRecoverDerivMap.put(name, tem);
148     return tem;
149   }
150
151   PatternMemo startAttributeDeriv(Name name) {
152     return startAttributeDeriv(name, null);
153   }
154
155   PatternMemo startAttributeDeriv(StartAttributeDerivFunction f) {
156     return startAttributeDeriv(f.getName(), f);
157   }
158
159   private PatternMemo startAttributeDeriv(Name name, StartAttributeDerivFunction f) {
160     PatternMemo tem;
161     if (startAttributeDerivMap == null)
162       startAttributeDerivMap = new Hashtable JavaDoc();
163     else {
164       tem = (PatternMemo)startAttributeDerivMap.get(name);
165       if (tem != null)
166     return tem;
167     }
168     if (f == null)
169       f = new StartAttributeDerivFunction(name, builder);
170     tem = applyForPatternMemo(f);
171     startAttributeDerivMap.put(name, tem);
172     return tem;
173   }
174
175   DataDerivType dataDerivType() {
176     if (memoDataDerivType == null)
177       memoDataDerivType = DataDerivTypeFunction.dataDerivType(builder, pattern).copy();
178     return memoDataDerivType;
179   }
180
181   PatternMemo dataDeriv(String JavaDoc str, ValidationContext vc) {
182     return dataDerivType().dataDeriv(builder, pattern, str, vc);
183   }
184
185   PatternMemo recoverAfter() {
186     // XXX memoize
187
return applyForPatternMemo(builder.getRecoverAfterFunction());
188   }
189
190   private PatternMemo applyForPatternMemo(PatternFunction f) {
191     return builder.getPatternMemo(pattern.applyForPattern(f));
192   }
193 }
194
Popular Tags