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 ValuePattern extends StringPattern {
08: Object obj;
09: Datatype dt;
10:
11: ValuePattern(Datatype dt, Object obj) {
12: super (combineHashCode(VALUE_HASH_CODE, obj.hashCode()));
13: this .dt = dt;
14: this .obj = obj;
15: }
16:
17: boolean samePattern(Pattern other) {
18: if (getClass() != other.getClass())
19: return false;
20: if (!(other instanceof ValuePattern))
21: return false;
22: return (dt.equals(((ValuePattern) other).dt) && dt.sameValue(
23: obj, ((ValuePattern) other).obj));
24: }
25:
26: public void accept(PatternVisitor visitor) {
27: visitor.visitValue(dt, obj);
28: }
29:
30: public Object apply(PatternFunction f) {
31: return f.caseValue(this );
32: }
33:
34: void checkRestrictions(int context, DuplicateAttributeDetector dad,
35: Alphabet alpha) throws RestrictionViolationException {
36: switch (context) {
37: case START_CONTEXT:
38: throw new RestrictionViolationException(
39: "start_contains_value");
40: }
41: }
42:
43: Datatype getDatatype() {
44: return dt;
45: }
46:
47: Object getValue() {
48: return obj;
49: }
50:
51: }
|