1 package com.thaiopensource.relaxng.impl; 2 3 class GroupPattern extends BinaryPattern { 4 GroupPattern(Pattern p1, Pattern p2) { 5 super(p1.isNullable() && p2.isNullable(), 6 combineHashCode(GROUP_HASH_CODE, p1.hashCode(), p2.hashCode()), 7 p1, 8 p2); 9 } 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, Alphabet alpha) throws RestrictionViolationException { 21 switch (context) { 22 case START_CONTEXT: 23 throw new RestrictionViolationException("start_contains_group"); 24 case DATA_EXCEPT_CONTEXT: 25 throw new RestrictionViolationException("data_except_contains_group"); 26 } 27 super.checkRestrictions(context == ELEMENT_REPEAT_CONTEXT 28 ? ELEMENT_REPEAT_GROUP_CONTEXT 29 : context, 30 dad, 31 alpha); 32 if (context != LIST_CONTEXT 33 && !contentTypeGroupable(p1.getContentType(), p2.getContentType())) 34 throw new RestrictionViolationException("group_string"); 35 } 36 37 void accept(PatternVisitor visitor) { 38 visitor.visitGroup(p1, p2); 39 } 40 Object apply(PatternFunction f) { 41 return f.caseGroup(this); 42 } 43 } 44 | Popular Tags |