001 package com.thaiopensource.relaxng.impl; 002 003 import com.thaiopensource.datatype.Datatype2; 004 import org.relaxng.datatype.Datatype; 005 006 class DataPattern extends StringPattern { 007 private final Datatype dt; 008 009 DataPattern(Datatype dt) { 010 super(combineHashCode(DATA_HASH_CODE, dt.hashCode())); 011 this.dt = dt; 012 } 013 014 boolean samePattern(Pattern other) { 015 if (other.getClass() != this.getClass()) 016 return false; 017 return dt.equals(((DataPattern)other).dt); 018 } 019 020 void accept(PatternVisitor visitor) { 021 visitor.visitData(dt); 022 } 023 024 Object apply(PatternFunction f) { 025 return f.caseData(this); 026 } 027 028 Datatype getDatatype() { 029 return dt; 030 } 031 032 boolean allowsAnyString() { 033 return dt instanceof Datatype2 && ((Datatype2)dt).alwaysValid(); 034 } 035 036 void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha) 037 throws RestrictionViolationException { 038 switch (context) { 039 case START_CONTEXT: 040 throw new RestrictionViolationException("start_contains_data"); 041 } 042 } 043 }