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.xml.sax.SAXException;
06:
07: public class OneOrMorePattern extends Pattern {
08: Pattern p;
09:
10: OneOrMorePattern(Pattern p) {
11: super (p.isNullable(), p.getContentType(), combineHashCode(
12: ONE_OR_MORE_HASH_CODE, p.hashCode()));
13: this .p = p;
14: }
15:
16: Pattern expand(SchemaPatternBuilder b) {
17: Pattern ep = p.expand(b);
18: if (ep != p)
19: return b.makeOneOrMore(ep);
20: else
21: return this ;
22: }
23:
24: void checkRecursion(int depth) throws SAXException {
25: p.checkRecursion(depth);
26: }
27:
28: void checkRestrictions(int context, DuplicateAttributeDetector dad,
29: Alphabet alpha) throws RestrictionViolationException {
30: switch (context) {
31: case START_CONTEXT:
32: throw new RestrictionViolationException(
33: "start_contains_one_or_more");
34: case DATA_EXCEPT_CONTEXT:
35: throw new RestrictionViolationException(
36: "data_except_contains_one_or_more");
37: }
38:
39: p.checkRestrictions(
40: context == ELEMENT_CONTEXT ? ELEMENT_REPEAT_CONTEXT
41: : context, dad, alpha);
42: if (context != LIST_CONTEXT
43: && !contentTypeGroupable(p.getContentType(), p
44: .getContentType()))
45: throw new RestrictionViolationException(
46: "one_or_more_string");
47: }
48:
49: boolean samePattern(Pattern other) {
50: return (other instanceof OneOrMorePattern && p == ((OneOrMorePattern) other).p);
51: }
52:
53: public void accept(PatternVisitor visitor) {
54: visitor.visitOneOrMore(p);
55: }
56:
57: public Object apply(PatternFunction f) {
58: return f.caseOneOrMore(this );
59: }
60:
61: Pattern getOperand() {
62: return p;
63: }
64: }
|