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