KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > relaxng > impl > Pattern


1 package com.thaiopensource.relaxng.impl;
2
3 import org.xml.sax.SAXException JavaDoc;
4 import com.thaiopensource.relaxng.parse.ParsedPattern;
5
6 public abstract class Pattern implements ParsedPattern {
7   private final boolean nullable;
8   private final int hc;
9   private final int contentType;
10
11   static final int TEXT_HASH_CODE = 1;
12   static final int ERROR_HASH_CODE = 3;
13   static final int EMPTY_HASH_CODE = 5;
14   static final int NOT_ALLOWED_HASH_CODE = 7;
15   static final int CHOICE_HASH_CODE = 11;
16   static final int GROUP_HASH_CODE = 13;
17   static final int INTERLEAVE_HASH_CODE = 17;
18   static final int ONE_OR_MORE_HASH_CODE = 19;
19   static final int ELEMENT_HASH_CODE = 23;
20   static final int VALUE_HASH_CODE = 27;
21   static final int ATTRIBUTE_HASH_CODE = 29;
22   static final int DATA_HASH_CODE = 31;
23   static final int LIST_HASH_CODE = 37;
24   static final int AFTER_HASH_CODE = 41;
25
26   static int combineHashCode(int hc1, int hc2, int hc3) {
27     return hc1 * hc2 * hc3;
28   }
29
30   static int combineHashCode(int hc1, int hc2) {
31     return hc1 * hc2;
32   }
33
34   static final int EMPTY_CONTENT_TYPE = 0;
35   static final int ELEMENT_CONTENT_TYPE = 1;
36   static final int MIXED_CONTENT_TYPE = 2;
37   static final int DATA_CONTENT_TYPE = 3;
38
39   Pattern(boolean nullable, int contentType, int hc) {
40     this.nullable = nullable;
41     this.contentType = contentType;
42     this.hc = hc;
43   }
44
45   Pattern() {
46     this.nullable = false;
47     this.hc = hashCode();
48     this.contentType = EMPTY_CONTENT_TYPE;
49   }
50
51   void checkRecursion(int depth) throws SAXException JavaDoc { }
52
53   Pattern expand(SchemaPatternBuilder b) {
54     return this;
55   }
56
57   final boolean isNullable() {
58     return nullable;
59   }
60
61   boolean isNotAllowed() {
62     return false;
63   }
64
65   static final int START_CONTEXT = 0;
66   static final int ELEMENT_CONTEXT = 1;
67   static final int ELEMENT_REPEAT_CONTEXT = 2;
68   static final int ELEMENT_REPEAT_GROUP_CONTEXT = 3;
69   static final int ELEMENT_REPEAT_INTERLEAVE_CONTEXT = 4;
70   static final int ATTRIBUTE_CONTEXT = 5;
71   static final int LIST_CONTEXT = 6;
72   static final int DATA_EXCEPT_CONTEXT = 7;
73
74   void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha)
75     throws RestrictionViolationException {
76   }
77
78   // Know that other is not null
79
abstract boolean samePattern(Pattern other);
80
81   final int patternHashCode() {
82     return hc;
83   }
84
85   final int getContentType() {
86     return contentType;
87   }
88
89   boolean containsChoice(Pattern p) {
90     return this == p;
91   }
92
93   abstract void accept(PatternVisitor visitor);
94   abstract Object JavaDoc apply(PatternFunction f);
95
96   Pattern applyForPattern(PatternFunction f) {
97     return (Pattern)apply(f);
98   }
99
100   static boolean contentTypeGroupable(int ct1, int ct2) {
101     if (ct1 == EMPTY_CONTENT_TYPE || ct2 == EMPTY_CONTENT_TYPE)
102       return true;
103     if (ct1 == DATA_CONTENT_TYPE || ct2 == DATA_CONTENT_TYPE)
104       return false;
105     return true;
106   }
107
108 }
109
Popular Tags