01: package org.kohsuke.rngom.binary;
02:
03: import org.kohsuke.rngom.binary.visitor.*;
04:
05: public class GroupPattern extends BinaryPattern {
06: GroupPattern(Pattern p1, Pattern p2) {
07: super (p1.isNullable() && p2.isNullable(), combineHashCode(
08: GROUP_HASH_CODE, p1.hashCode(), p2.hashCode()), p1, p2);
09: }
10:
11: Pattern expand(SchemaPatternBuilder b) {
12: Pattern ep1 = p1.expand(b);
13: Pattern ep2 = p2.expand(b);
14: if (ep1 != p1 || ep2 != p2)
15: return b.makeGroup(ep1, ep2);
16: else
17: return this ;
18: }
19:
20: void checkRestrictions(int context, DuplicateAttributeDetector dad,
21: Alphabet alpha) throws RestrictionViolationException {
22: switch (context) {
23: case START_CONTEXT:
24: throw new RestrictionViolationException(
25: "start_contains_group");
26: case DATA_EXCEPT_CONTEXT:
27: throw new RestrictionViolationException(
28: "data_except_contains_group");
29: }
30: super
31: .checkRestrictions(
32: context == ELEMENT_REPEAT_CONTEXT ? ELEMENT_REPEAT_GROUP_CONTEXT
33: : context, dad, alpha);
34: if (context != LIST_CONTEXT
35: && !contentTypeGroupable(p1.getContentType(), p2
36: .getContentType()))
37: throw new RestrictionViolationException("group_string");
38: }
39:
40: public void accept(PatternVisitor visitor) {
41: visitor.visitGroup(p1, p2);
42: }
43:
44: public Object apply(PatternFunction f) {
45: return f.caseGroup(this);
46: }
47: }
|