01: package org.kohsuke.rngom.binary;
02:
03: import org.kohsuke.rngom.binary.visitor.PatternFunction;
04: import org.kohsuke.rngom.binary.visitor.PatternVisitor;
05: import org.relaxng.datatype.Datatype;
06:
07: public class DataPattern extends StringPattern {
08: private Datatype dt;
09:
10: DataPattern(Datatype dt) {
11: super (combineHashCode(DATA_HASH_CODE, dt.hashCode()));
12: this .dt = dt;
13: }
14:
15: boolean samePattern(Pattern other) {
16: if (other.getClass() != this .getClass())
17: return false;
18: return dt.equals(((DataPattern) other).dt);
19: }
20:
21: public void accept(PatternVisitor visitor) {
22: visitor.visitData(dt);
23: }
24:
25: public Object apply(PatternFunction f) {
26: return f.caseData(this );
27: }
28:
29: Datatype getDatatype() {
30: return dt;
31: }
32:
33: boolean allowsAnyString() {
34: return false;
35: // return dt instanceof Datatype2 && ((Datatype2)dt).alwaysValid();
36: }
37:
38: void checkRestrictions(int context, DuplicateAttributeDetector dad,
39: Alphabet alpha) throws RestrictionViolationException {
40: switch (context) {
41: case START_CONTEXT:
42: throw new RestrictionViolationException(
43: "start_contains_data");
44: }
45: }
46: }
|