author | mkos |
Sun, 30 Dec 2012 00:00:00 +0100 | |
changeset 22678 | ac1ea46be942 |
parent 12009 | 4abb694f273a |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22678
ac1ea46be942
8029237: Update copyright year to match last edit in jaxws repository for 2012
mkos
parents:
12009
diff
changeset
|
2 |
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
/* |
|
26 |
* Copyright (C) 2004-2011 |
|
27 |
* |
|
28 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
29 |
* of this software and associated documentation files (the "Software"), to deal |
|
30 |
* in the Software without restriction, including without limitation the rights |
|
31 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
32 |
* copies of the Software, and to permit persons to whom the Software is |
|
33 |
* furnished to do so, subject to the following conditions: |
|
34 |
* |
|
35 |
* The above copyright notice and this permission notice shall be included in |
|
36 |
* all copies or substantial portions of the Software. |
|
37 |
* |
|
38 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
39 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
40 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
41 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
42 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
43 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
44 |
* THE SOFTWARE. |
|
45 |
*/ |
|
46 |
package com.sun.xml.internal.rngom.binary; |
|
47 |
||
48 |
import com.sun.xml.internal.rngom.ast.om.ParsedPattern; |
|
49 |
import com.sun.xml.internal.rngom.binary.visitor.PatternFunction; |
|
50 |
import com.sun.xml.internal.rngom.binary.visitor.PatternVisitor; |
|
51 |
import org.xml.sax.SAXException; |
|
52 |
||
53 |
public abstract class Pattern implements ParsedPattern { |
|
54 |
private boolean nullable; |
|
55 |
private int hc; |
|
56 |
private int contentType; |
|
57 |
||
58 |
static final int TEXT_HASH_CODE = 1; |
|
59 |
static final int ERROR_HASH_CODE = 3; |
|
60 |
static final int EMPTY_HASH_CODE = 5; |
|
61 |
static final int NOT_ALLOWED_HASH_CODE = 7; |
|
62 |
static final int CHOICE_HASH_CODE = 11; |
|
63 |
static final int GROUP_HASH_CODE = 13; |
|
64 |
static final int INTERLEAVE_HASH_CODE = 17; |
|
65 |
static final int ONE_OR_MORE_HASH_CODE = 19; |
|
66 |
static final int ELEMENT_HASH_CODE = 23; |
|
67 |
static final int VALUE_HASH_CODE = 27; |
|
68 |
static final int ATTRIBUTE_HASH_CODE = 29; |
|
69 |
static final int DATA_HASH_CODE = 31; |
|
70 |
static final int LIST_HASH_CODE = 37; |
|
71 |
static final int AFTER_HASH_CODE = 41; |
|
72 |
||
73 |
static int combineHashCode(int hc1, int hc2, int hc3) { |
|
74 |
return hc1 * hc2 * hc3; |
|
75 |
} |
|
76 |
||
77 |
static int combineHashCode(int hc1, int hc2) { |
|
78 |
return hc1 * hc2; |
|
79 |
} |
|
80 |
||
81 |
static final int EMPTY_CONTENT_TYPE = 0; |
|
82 |
static final int ELEMENT_CONTENT_TYPE = 1; |
|
83 |
static final int MIXED_CONTENT_TYPE = 2; |
|
84 |
static final int DATA_CONTENT_TYPE = 3; |
|
85 |
||
86 |
Pattern(boolean nullable, int contentType, int hc) { |
|
87 |
this.nullable = nullable; |
|
88 |
this.contentType = contentType; |
|
89 |
this.hc = hc; |
|
90 |
} |
|
91 |
||
92 |
Pattern() { |
|
93 |
this.nullable = false; |
|
94 |
this.hc = hashCode(); |
|
95 |
this.contentType = EMPTY_CONTENT_TYPE; |
|
96 |
} |
|
97 |
||
98 |
void checkRecursion(int depth) throws SAXException { } |
|
99 |
||
100 |
Pattern expand(SchemaPatternBuilder b) { |
|
101 |
return this; |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* Returns true if the pattern is nullable. |
|
106 |
* |
|
107 |
* <p> |
|
108 |
* A pattern is nullable when it can match the empty sequence. |
|
109 |
*/ |
|
110 |
public final boolean isNullable() { |
|
111 |
return nullable; |
|
112 |
} |
|
113 |
||
114 |
boolean isNotAllowed() { |
|
115 |
return false; |
|
116 |
} |
|
117 |
||
118 |
static final int START_CONTEXT = 0; |
|
119 |
static final int ELEMENT_CONTEXT = 1; |
|
120 |
static final int ELEMENT_REPEAT_CONTEXT = 2; |
|
121 |
static final int ELEMENT_REPEAT_GROUP_CONTEXT = 3; |
|
122 |
static final int ELEMENT_REPEAT_INTERLEAVE_CONTEXT = 4; |
|
123 |
static final int ATTRIBUTE_CONTEXT = 5; |
|
124 |
static final int LIST_CONTEXT = 6; |
|
125 |
static final int DATA_EXCEPT_CONTEXT = 7; |
|
126 |
||
127 |
void checkRestrictions(int context, DuplicateAttributeDetector dad, Alphabet alpha) |
|
128 |
throws RestrictionViolationException { |
|
129 |
} |
|
130 |
||
131 |
// Know that other is not null |
|
132 |
abstract boolean samePattern(Pattern other); |
|
133 |
||
134 |
final int patternHashCode() { |
|
135 |
return hc; |
|
136 |
} |
|
137 |
||
138 |
final int getContentType() { |
|
139 |
return contentType; |
|
140 |
} |
|
141 |
||
142 |
boolean containsChoice(Pattern p) { |
|
143 |
return this == p; |
|
144 |
} |
|
145 |
||
146 |
public abstract void accept(PatternVisitor visitor); |
|
147 |
public abstract Object apply(PatternFunction f); |
|
148 |
||
149 |
// DPattern applyForPattern(PatternFunction f) { |
|
150 |
// return (DPattern)apply(f); |
|
151 |
// } |
|
152 |
||
153 |
static boolean contentTypeGroupable(int ct1, int ct2) { |
|
154 |
if (ct1 == EMPTY_CONTENT_TYPE || ct2 == EMPTY_CONTENT_TYPE) |
|
155 |
return true; |
|
156 |
if (ct1 == DATA_CONTENT_TYPE || ct2 == DATA_CONTENT_TYPE) |
|
157 |
return false; |
|
158 |
return true; |
|
159 |
} |
|
160 |
||
161 |
} |