001 package com.thaiopensource.relaxng.impl;
002
003 import org.xml.sax.Locator;
004 import org.xml.sax.SAXException;
005
006 class ListPattern extends Pattern {
007 private final Pattern p;
008 private final Locator locator;
009
010 ListPattern(Pattern p, Locator locator) {
011 super(false,
012 DATA_CONTENT_TYPE,
013 combineHashCode(LIST_HASH_CODE, p.hashCode()));
014 this.p = p;
015 this.locator = locator;
016 }
017
018 Pattern expand(SchemaPatternBuilder b) {
019 Pattern ep = p.expand(b);
020 if (ep != p)
021 return b.makeList(ep, locator);
022 else
023 return this;
024 }
025
026 void checkRecursion(int depth) throws SAXException {
027 p.checkRecursion(depth);
028 }
029
030 boolean samePattern(Pattern other) {
031 return (other instanceof ListPattern
032 && p == ((ListPattern)other).p);
033 }
034
035 void accept(PatternVisitor visitor) {
036 visitor.visitList(p);
037 }
038
039 Object apply(PatternFunction f) {
040 return f.caseList(this);
041 }
042
043 void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
044 throws RestrictionViolationException {
045 switch (context) {
046 case DATA_EXCEPT_CONTEXT:
047 throw new RestrictionViolationException("data_except_contains_list");
048 case START_CONTEXT:
049 throw new RestrictionViolationException("start_contains_list");
050 case LIST_CONTEXT:
051 throw new RestrictionViolationException("list_contains_list");
052 }
053 try {
054 p.checkRestrictions(LIST_CONTEXT, dad, null);
055 }
056 catch (RestrictionViolationException e) {
057 e.maybeSetLocator(locator);
058 throw e;
059 }
060 }
061
062 Pattern getOperand() {
063 return p;
064 }
065 }