2
* The Apache Software License, Version 1.1
5
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in
17
* the documentation and/or other materials provided with the
20
* 3. The end-user documentation included with the redistribution,
21
* if any, must include the following acknowledgment:
22
* "This product includes software developed by the
23
* Apache Software Foundation (http://www.apache.org/)."
24
* Alternately, this acknowledgment may appear in the software itself,
25
* if and wherever such third-party acknowledgments normally appear.
27
* 4. The names "Xerces" and "Apache Software Foundation" must
28
* not be used to endorse or promote products derived from this
29
* software without prior written permission. For written
30
* permission, please contact apache@apache.org.
32
* 5. Products derived from this software may not be called "Apache",
33
* nor may "Apache" appear in their name, without prior written
34
* permission of the Apache Software Foundation.
36
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48
* ====================================================================
50
* This software consists of voluntary contributions made by many
51
* individuals on behalf of the Apache Software Foundation and was
52
* originally based on software copyright (c) 2001, International
53
* Business Machines, Inc., http://www.apache.org. For more
54
* information on the Apache Software Foundation, please see
55
* <http://www.apache.org/>.
2
* Copyright 2001-2006 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
58
17
package org.apache.xerces.impl.xs.traversers;
72
31
import org.apache.xerces.impl.xs.XSElementDecl;
73
32
import org.apache.xerces.impl.xs.XSParticleDecl;
74
33
import org.apache.xerces.impl.xs.XSWildcardDecl;
75
import org.apache.xerces.xs.XSObjectList;
76
import org.apache.xerces.xs.XSTypeDefinition;
77
34
import org.apache.xerces.impl.xs.util.XInt;
78
35
import org.apache.xerces.impl.xs.util.XSObjectListImpl;
79
36
import org.apache.xerces.util.DOMUtil;
80
37
import org.apache.xerces.util.NamespaceSupport;
81
38
import org.apache.xerces.util.SymbolTable;
82
39
import org.apache.xerces.xni.QName;
40
import org.apache.xerces.xs.XSObjectList;
41
import org.apache.xerces.xs.XSTypeDefinition;
83
42
import org.w3c.dom.Element;
84
import org.w3c.dom.Node;
85
import org.w3c.dom.Text;
88
45
* Class <code>XSDAbstractTraverser</code> serves as the base class for all
89
* other <code>XSD???Traverser</code>s. It holds the common data and provide
46
* other <code>XSD???Traverser</code>s. It holds the common data and provides
90
47
* a unified way to initialize these data.
92
51
* @author Elena Litani, IBM
93
52
* @author Rahul Srivastava, Sun Microsystems Inc.
94
53
* @author Neeraj Bajaj, Sun Microsystems Inc.
96
* @version $Id: XSDAbstractTraverser.java,v 1.35 2003/11/11 20:15:00 sandygao Exp $
55
* @version $Id: XSDAbstractTraverser.java 442081 2006-09-11 03:19:57Z mrglavas $
98
57
abstract class XSDAbstractTraverser {
100
59
protected static final String NO_NAME = "(no name)";
102
61
// Flags for checkOccurrences to indicate any special
103
62
// restrictions on minOccurs and maxOccurs relating to "all".
104
63
// NOT_ALL_CONTEXT - not processing an <all>
106
65
// GROUP_REF_WITH_ALL - processing <group> reference that contained <all>
107
66
// CHILD_OF_GROUP - processing a child of a model group definition
108
67
// PROCESSING_ALL_GP - processing an <all> group itself
110
69
protected static final int NOT_ALL_CONTEXT = 0;
111
70
protected static final int PROCESSING_ALL_EL = 1;
112
71
protected static final int GROUP_REF_WITH_ALL = 2;
113
72
protected static final int CHILD_OF_GROUP = 4;
114
73
protected static final int PROCESSING_ALL_GP = 8;
117
76
protected XSDHandler fSchemaHandler = null;
118
77
protected SymbolTable fSymbolTable = null;
119
78
protected XSAttributeChecker fAttrChecker = null;
79
protected boolean fValidateAnnotations = false;
121
81
// used to validate default/fixed attribute values
122
82
ValidationState fValidationState = new ValidationState();
124
84
XSDAbstractTraverser (XSDHandler handler,
125
XSAttributeChecker attrChecker) {
85
XSAttributeChecker attrChecker) {
126
86
fSchemaHandler = handler;
127
87
fAttrChecker = attrChecker;
130
void reset(SymbolTable symbolTable) {
90
void reset(SymbolTable symbolTable, boolean validateAnnotations) {
131
91
fSymbolTable = symbolTable;
92
fValidateAnnotations = validateAnnotations;
132
93
fValidationState.setExtraChecking(false);
133
94
fValidationState.setSymbolTable(symbolTable);
136
97
// traverse the annotation declaration
137
98
// REVISIT: how to pass the parentAttrs? as DOM attributes?
138
99
// as name/value pairs (string)? in parsed form?
139
100
// @return XSAnnotationImpl object
140
101
XSAnnotationImpl traverseAnnotationDecl(Element annotationDecl, Object[] parentAttrs,
141
boolean isGlobal, XSDocumentInfo schemaDoc) {
102
boolean isGlobal, XSDocumentInfo schemaDoc) {
142
103
// General Attribute Checking
143
104
Object[] attrValues = fAttrChecker.checkAttributes(annotationDecl, isGlobal, schemaDoc);
144
105
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
146
String contents = null;
147
for (Element child = DOMUtil.getFirstChildElement(annotationDecl);
149
child = DOMUtil.getNextSiblingElement(child)) {
150
String name = DOMUtil.getLocalName(child);
152
// the only valid children of "annotation" are
153
// "appinfo" and "documentation"
154
if (!((name.equals(SchemaSymbols.ELT_APPINFO)) ||
155
(name.equals(SchemaSymbols.ELT_DOCUMENTATION)))) {
156
reportSchemaError("src-annotation", new Object[]{name}, child);
157
} else { // the annotation, as we currently know it, is a Text child
158
Node textContent = child.getFirstChild();
159
if(textContent != null && textContent.getNodeType() == Node.TEXT_NODE) {
160
contents = ((Text)textContent).getData();
107
String contents = DOMUtil.getAnnotation(annotationDecl);
108
Element child = DOMUtil.getFirstChildElement(annotationDecl);
111
String name = DOMUtil.getLocalName(child);
113
// the only valid children of "annotation" are
114
// "appinfo" and "documentation"
115
if (!((name.equals(SchemaSymbols.ELT_APPINFO)) ||
116
(name.equals(SchemaSymbols.ELT_DOCUMENTATION)))) {
117
reportSchemaError("src-annotation", new Object[]{name}, child);
120
// General Attribute Checking
121
// There is no difference between global or local appinfo/documentation,
122
// so we assume it's always global.
123
attrValues = fAttrChecker.checkAttributes(child, true, schemaDoc);
124
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
126
child = DOMUtil.getNextSiblingElement(child);
164
// General Attribute Checking
165
// There is no difference between global or local appinfo/documentation,
166
// so we assume it's always global.
167
attrValues = fAttrChecker.checkAttributes(child, true, schemaDoc);
168
fAttrChecker.returnAttrArray(attrValues, schemaDoc);
128
while (child != null);
170
130
// if contents was null, must have been some kind of error;
171
131
// nothing to contribute to PSVI
172
132
if (contents == null) return null;
174
134
// find the grammar; fSchemaHandler must be known!
175
135
SchemaGrammar grammar = fSchemaHandler.getGrammar(schemaDoc.fTargetNamespace);
176
136
// fish out local attributes passed from parent
193
153
prefix = rawname.substring(0,colonIndex);
194
154
localpart = rawname.substring(colonIndex+1);
196
String uri = schemaDoc.fNamespaceSupport.getURI(prefix.intern());
156
String uri = schemaDoc.fNamespaceSupport.getURI(fSymbolTable.addSymbol(prefix));
197
157
if (!annotationDecl.getAttributeNS(uri, localpart).equals("")) {
198
158
i++; // skip the next value, too
201
161
localStrBuffer.append(rawname)
203
String value = (String)annotationLocalAttrs.elementAt(i++);
204
// search for pesky "s and >s within attr value:
205
value = processAttValue(value);
206
localStrBuffer.append(value)
209
// and now splice it into place; immediately after the annotation token, for simplicity's sake
210
StringBuffer contentBuffer = new StringBuffer(contents.length() + localStrBuffer.length());
211
int annotationTokenEnd = contents.indexOf(SchemaSymbols.ELT_ANNOTATION);
212
// annotation must occur somewhere or we're in big trouble...
213
if(annotationTokenEnd == -1) return null;
214
annotationTokenEnd += SchemaSymbols.ELT_ANNOTATION.length();
215
contentBuffer.append(contents.substring(0,annotationTokenEnd));
216
contentBuffer.append(localStrBuffer.toString());
217
contentBuffer.append(contents.substring(annotationTokenEnd, contents.length()));
218
return new XSAnnotationImpl(contentBuffer.toString(), grammar);
220
return new XSAnnotationImpl(contents, grammar);
163
String value = (String)annotationLocalAttrs.elementAt(i++);
164
// search for pesky "s and <s within attr value:
165
value = processAttValue(value);
166
localStrBuffer.append(value)
169
// and now splice it into place; immediately after the annotation token, for simplicity's sake
170
StringBuffer contentBuffer = new StringBuffer(contents.length() + localStrBuffer.length());
171
int annotationTokenEnd = contents.indexOf(SchemaSymbols.ELT_ANNOTATION);
172
// annotation must occur somewhere or we're in big trouble...
173
if(annotationTokenEnd == -1) return null;
174
annotationTokenEnd += SchemaSymbols.ELT_ANNOTATION.length();
175
contentBuffer.append(contents.substring(0,annotationTokenEnd));
176
contentBuffer.append(localStrBuffer.toString());
177
contentBuffer.append(contents.substring(annotationTokenEnd, contents.length()));
178
final String annotation = contentBuffer.toString();
179
if (fValidateAnnotations) {
180
schemaDoc.addAnnotation(new XSAnnotationInfo(annotation, annotationDecl));
182
return new XSAnnotationImpl(annotation, grammar);
184
if (fValidateAnnotations) {
185
schemaDoc.addAnnotation(new XSAnnotationInfo(contents, annotationDecl));
187
return new XSAnnotationImpl(contents, grammar);
192
XSAnnotationImpl traverseSyntheticAnnotation(Element annotationParent, String initialContent,
193
Object[] parentAttrs, boolean isGlobal, XSDocumentInfo schemaDoc) {
195
String contents = initialContent;
197
// find the grammar; fSchemaHandler must be known!
198
SchemaGrammar grammar = fSchemaHandler.getGrammar(schemaDoc.fTargetNamespace);
199
// fish out local attributes passed from parent
200
Vector annotationLocalAttrs = (Vector)parentAttrs[XSAttributeChecker.ATTIDX_NONSCHEMA];
201
// optimize for case where there are no local attributes
202
if (annotationLocalAttrs != null && !annotationLocalAttrs.isEmpty()) {
203
StringBuffer localStrBuffer = new StringBuffer(64);
204
localStrBuffer.append(" ");
205
// Vector should contain rawname value pairs
207
while (i < annotationLocalAttrs.size()) {
208
String rawname = (String)annotationLocalAttrs.elementAt(i++);
209
int colonIndex = rawname.indexOf(':');
210
String prefix, localpart;
211
if (colonIndex == -1) {
216
prefix = rawname.substring(0,colonIndex);
217
localpart = rawname.substring(colonIndex+1);
219
String uri = schemaDoc.fNamespaceSupport.getURI(fSymbolTable.addSymbol(prefix));
220
localStrBuffer.append(rawname)
222
String value = (String)annotationLocalAttrs.elementAt(i++);
223
// search for pesky "s and <s within attr value:
224
value = processAttValue(value);
225
localStrBuffer.append(value)
228
// and now splice it into place; immediately after the annotation token, for simplicity's sake
229
StringBuffer contentBuffer = new StringBuffer(contents.length() + localStrBuffer.length());
230
int annotationTokenEnd = contents.indexOf(SchemaSymbols.ELT_ANNOTATION);
231
// annotation must occur somewhere or we're in big trouble...
232
if(annotationTokenEnd == -1) return null;
233
annotationTokenEnd += SchemaSymbols.ELT_ANNOTATION.length();
234
contentBuffer.append(contents.substring(0,annotationTokenEnd));
235
contentBuffer.append(localStrBuffer.toString());
236
contentBuffer.append(contents.substring(annotationTokenEnd, contents.length()));
237
final String annotation = contentBuffer.toString();
238
if (fValidateAnnotations) {
239
schemaDoc.addAnnotation(new XSAnnotationInfo(annotation, annotationParent));
241
return new XSAnnotationImpl(annotation, grammar);
243
if (fValidateAnnotations) {
244
schemaDoc.addAnnotation(new XSAnnotationInfo(contents, annotationParent));
246
return new XSAnnotationImpl(contents, grammar);
225
250
// the QName simple type used to resolve qnames
226
251
private static final XSSimpleType fQNameDV = (XSSimpleType)SchemaGrammar.SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_QNAME);
227
252
// Temp data structures to be re-used in traversing facets
228
253
private StringBuffer fPattern = new StringBuffer();
229
254
private final XSFacets xsFacets = new XSFacets();
231
256
class FacetInfo {
232
257
XSFacets facetdata;
233
258
Element nodeAfterFacets;
234
259
short fPresentFacets;
235
260
short fFixedFacets;
238
263
FacetInfo traverseFacets(Element content,
239
XSSimpleType baseValidator,
240
XSDocumentInfo schemaDoc) {
264
XSSimpleType baseValidator,
265
XSDocumentInfo schemaDoc) {
242
267
short facetsPresent = 0 ;
243
268
short facetsFixed = 0; // facets that have fixed="true"
285
310
enumNSDecls.addElement(nsDecls);
286
311
Element child = DOMUtil.getFirstChildElement( content );
289
// traverse annotation if any
291
if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
292
enumAnnotations.add(enumAnnotations.getLength()-1,traverseAnnotationDecl(child, attrs, false, schemaDoc));
293
child = DOMUtil.getNextSiblingElement(child);
295
if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
296
reportSchemaError("s4s-elt-must-match.1", new Object[]{"enumeration", "(annotation?)", DOMUtil.getLocalName(child)}, child);
314
DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
315
// traverse annotation if any
316
enumAnnotations.add(enumAnnotations.getLength()-1,traverseAnnotationDecl(child, attrs, false, schemaDoc));
317
child = DOMUtil.getNextSiblingElement(child);
320
String text = DOMUtil.getSyntheticAnnotation(content);
322
enumAnnotations.add(enumAnnotations.getLength()-1, traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc));
326
reportSchemaError("s4s-elt-must-match.1", new Object[]{"enumeration", "(annotation?)", DOMUtil.getLocalName(child)}, child);
300
329
else if (facet.equals(SchemaSymbols.ELT_PATTERN)) {
301
330
attrs = fAttrChecker.checkAttributes(content, false, schemaDoc);
309
338
fPattern.append((String)attrs[XSAttributeChecker.ATTIDX_VALUE]);
311
340
Element child = DOMUtil.getFirstChildElement( content );
313
// traverse annotation if any
314
if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
315
if (patternAnnotations == null){
316
patternAnnotations = new XSObjectListImpl();
318
patternAnnotations.add(traverseAnnotationDecl(child, attrs, false, schemaDoc));
319
child = DOMUtil.getNextSiblingElement(child);
321
if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
322
reportSchemaError("s4s-elt-must-match.1", new Object[]{"pattern", "(annotation?)", DOMUtil.getLocalName(child)}, child);
342
DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
343
// traverse annotation if any
344
if (patternAnnotations == null){
345
patternAnnotations = new XSObjectListImpl();
347
patternAnnotations.add(traverseAnnotationDecl(child, attrs, false, schemaDoc));
348
child = DOMUtil.getNextSiblingElement(child);
351
String text = DOMUtil.getSyntheticAnnotation(content);
353
if (patternAnnotations == null){
354
patternAnnotations = new XSObjectListImpl();
356
patternAnnotations.add(traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc));
360
reportSchemaError("s4s-elt-must-match.1", new Object[]{"pattern", "(annotation?)", DOMUtil.getLocalName(child)}, child);
328
364
if (facet.equals(SchemaSymbols.ELT_MINLENGTH)) {
371
407
facetsFixed |= currentFacet;
373
409
switch (currentFacet) {
374
case XSSimpleType.FACET_MINLENGTH:
375
xsFacets.minLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
377
case XSSimpleType.FACET_MAXLENGTH:
378
xsFacets.maxLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
380
case XSSimpleType.FACET_MAXEXCLUSIVE:
381
xsFacets.maxExclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
383
case XSSimpleType.FACET_MAXINCLUSIVE:
384
xsFacets.maxInclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
386
case XSSimpleType.FACET_MINEXCLUSIVE:
387
xsFacets.minExclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
389
case XSSimpleType.FACET_MININCLUSIVE:
390
xsFacets.minInclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
392
case XSSimpleType.FACET_TOTALDIGITS:
393
xsFacets.totalDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
395
case XSSimpleType.FACET_FRACTIONDIGITS:
396
xsFacets.fractionDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
398
case XSSimpleType.FACET_WHITESPACE:
399
xsFacets.whiteSpace = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).shortValue();
401
case XSSimpleType.FACET_LENGTH:
402
xsFacets.length = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
410
case XSSimpleType.FACET_MINLENGTH:
411
xsFacets.minLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
413
case XSSimpleType.FACET_MAXLENGTH:
414
xsFacets.maxLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
416
case XSSimpleType.FACET_MAXEXCLUSIVE:
417
xsFacets.maxExclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
419
case XSSimpleType.FACET_MAXINCLUSIVE:
420
xsFacets.maxInclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
422
case XSSimpleType.FACET_MINEXCLUSIVE:
423
xsFacets.minExclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
425
case XSSimpleType.FACET_MININCLUSIVE:
426
xsFacets.minInclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
428
case XSSimpleType.FACET_TOTALDIGITS:
429
xsFacets.totalDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
431
case XSSimpleType.FACET_FRACTIONDIGITS:
432
xsFacets.fractionDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
434
case XSSimpleType.FACET_WHITESPACE:
435
xsFacets.whiteSpace = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).shortValue();
437
case XSSimpleType.FACET_LENGTH:
438
xsFacets.length = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
407
443
Element child = DOMUtil.getFirstChildElement( content );
444
XSAnnotationImpl annotation = null;
446
DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
447
// traverse annotation if any
448
annotation = traverseAnnotationDecl(child, attrs, false, schemaDoc);
449
child = DOMUtil.getNextSiblingElement(child);
452
String text = DOMUtil.getSyntheticAnnotation(content);
454
annotation = traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc);
457
switch (currentFacet) {
458
case XSSimpleType.FACET_MINLENGTH:
459
xsFacets.minLengthAnnotation = annotation;
461
case XSSimpleType.FACET_MAXLENGTH:
462
xsFacets.maxLengthAnnotation = annotation;
464
case XSSimpleType.FACET_MAXEXCLUSIVE:
465
xsFacets.maxExclusiveAnnotation = annotation;
467
case XSSimpleType.FACET_MAXINCLUSIVE:
468
xsFacets.maxInclusiveAnnotation = annotation;
470
case XSSimpleType.FACET_MINEXCLUSIVE:
471
xsFacets.minExclusiveAnnotation = annotation;
473
case XSSimpleType.FACET_MININCLUSIVE:
474
xsFacets.minInclusiveAnnotation = annotation;
476
case XSSimpleType.FACET_TOTALDIGITS:
477
xsFacets.totalDigitsAnnotation = annotation;
479
case XSSimpleType.FACET_FRACTIONDIGITS:
480
xsFacets.fractionDigitsAnnotation = annotation;
482
case XSSimpleType.FACET_WHITESPACE:
483
xsFacets.whiteSpaceAnnotation = annotation;
485
case XSSimpleType.FACET_LENGTH:
486
xsFacets.lengthAnnotation = annotation;
408
489
if (child != null) {
409
// traverse annotation if any
410
if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
411
XSAnnotationImpl annotation = traverseAnnotationDecl(child, attrs, false, schemaDoc);
412
switch (currentFacet) {
413
case XSSimpleType.FACET_MINLENGTH:
414
xsFacets.minLengthAnnotation = annotation;
416
case XSSimpleType.FACET_MAXLENGTH:
417
xsFacets.maxLengthAnnotation = annotation;
419
case XSSimpleType.FACET_MAXEXCLUSIVE:
420
xsFacets.maxExclusiveAnnotation = annotation;
422
case XSSimpleType.FACET_MAXINCLUSIVE:
423
xsFacets.maxInclusiveAnnotation = annotation;
425
case XSSimpleType.FACET_MINEXCLUSIVE:
426
xsFacets.minExclusiveAnnotation = annotation;
428
case XSSimpleType.FACET_MININCLUSIVE:
429
xsFacets.minInclusiveAnnotation = annotation;
431
case XSSimpleType.FACET_TOTALDIGITS:
432
xsFacets.totalDigitsAnnotation = annotation;
434
case XSSimpleType.FACET_FRACTIONDIGITS:
435
xsFacets.fractionDigitsAnnotation = annotation;
437
case XSSimpleType.FACET_WHITESPACE:
438
xsFacets.whiteSpaceAnnotation = annotation;
440
case XSSimpleType.FACET_LENGTH:
441
xsFacets.lengthAnnotation = annotation;
446
child = DOMUtil.getNextSiblingElement(child);
448
if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
449
reportSchemaError("s4s-elt-must-match.1", new Object[]{facet, "(annotation?)", DOMUtil.getLocalName(child)}, child);
490
reportSchemaError("s4s-elt-must-match.1", new Object[]{facet, "(annotation?)", DOMUtil.getLocalName(child)}, child);
453
493
fAttrChecker.returnAttrArray (attrs, schemaDoc);
500
540
// Traverse a set of attribute and attribute group elements
501
541
// Needed by complexType and attributeGroup traversal
502
542
// This method will return the first non-attribute/attrgrp found
504
544
Element traverseAttrsAndAttrGrps(Element firstAttr, XSAttributeGroupDecl attrGrp,
505
XSDocumentInfo schemaDoc, SchemaGrammar grammar,
506
XSComplexTypeDecl enclosingCT) {
545
XSDocumentInfo schemaDoc, SchemaGrammar grammar,
546
XSComplexTypeDecl enclosingCT) {
508
548
Element child=null;
509
549
XSAttributeGroupDecl tempAttrGrp = null;
510
550
XSAttributeUseImpl tempAttrUse = null;
511
551
String childName;
513
553
for (child=firstAttr; child!=null; child=DOMUtil.getNextSiblingElement(child)) {
514
554
childName = DOMUtil.getLocalName(child);
515
555
if (childName.equals(SchemaSymbols.ELT_ATTRIBUTE)) {
516
556
tempAttrUse = fSchemaHandler.fAttributeTraverser.traverseLocal(child,
520
560
if (tempAttrUse == null) break;
521
561
if (attrGrp.getAttributeUse(tempAttrUse.fAttrDecl.getNamespace(),
522
tempAttrUse.fAttrDecl.getName())==null) {
562
tempAttrUse.fAttrDecl.getName())==null) {
523
563
String idName = attrGrp.addAttributeUse(tempAttrUse);
524
564
if (idName != null) {
525
565
String code = (enclosingCT == null) ? "ag-props-correct.3" : "ct-props-correct.5";
602
642
child = DOMUtil.getNextSiblingElement(child);
611
651
void reportSchemaError (String key, Object[] args, Element ele) {
612
652
fSchemaHandler.reportSchemaError(key, args, ele);
616
656
* Element/Attribute traversers call this method to check whether
617
657
* the type is NOTATION without enumeration facet
619
659
void checkNotationType(String refName, XSTypeDefinition typeDecl, Element elem) {
620
660
if (typeDecl.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE &&
621
((XSSimpleType)typeDecl).getVariety() == XSSimpleType.VARIETY_ATOMIC &&
622
((XSSimpleType)typeDecl).getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) {
661
((XSSimpleType)typeDecl).getVariety() == XSSimpleType.VARIETY_ATOMIC &&
662
((XSSimpleType)typeDecl).getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) {
623
663
if ((((XSSimpleType)typeDecl).getDefinedFacets() & XSSimpleType.FACET_ENUMERATION) == 0) {
624
664
reportSchemaError("enumeration-required-notation", new Object[]{typeDecl.getName(), refName, DOMUtil.getLocalName(elem)}, elem);
629
669
// Checks constraints for minOccurs, maxOccurs
630
670
protected XSParticleDecl checkOccurrences(XSParticleDecl particle,
631
String particleName, Element parent,
671
String particleName, Element parent,
635
675
int min = particle.fMinOccurs;
636
676
int max = particle.fMaxOccurs;
637
677
boolean defaultMin = (defaultVals & (1 << XSAttributeChecker.ATTIDX_MINOCCURS)) != 0;
638
678
boolean defaultMax = (defaultVals & (1 << XSAttributeChecker.ATTIDX_MAXOCCURS)) != 0;
640
680
boolean processingAllEl = ((allContextFlags & PROCESSING_ALL_EL) != 0);
641
681
boolean processingAllGP = ((allContextFlags & PROCESSING_ALL_GP) != 0);
642
682
boolean groupRefWithAll = ((allContextFlags & GROUP_REF_WITH_ALL) != 0);
643
683
boolean isGroupChild = ((allContextFlags & CHILD_OF_GROUP) != 0);
645
685
// Neither minOccurs nor maxOccurs may be specified
646
686
// for the child of a model group definition.
647
687
if (isGroupChild) {
689
729
particle.fMaxOccurs = min;
690
730
particle.fMaxOccurs = max;
695
// this is not terribly performant!
696
735
private static String processAttValue(String original) {
736
final int length = original.length();
697
737
// normally, nothing will happen
698
StringBuffer newVal = new StringBuffer(original.length());
699
for(int i=0; i<original.length(); i++) {
700
char currChar = original.charAt(i);
701
if(currChar == '"') {
738
for (int i = 0; i < length; ++i) {
739
char currChar = original.charAt(i);
740
if (currChar == '"' || currChar == '<' || currChar == '&' ||
741
currChar == 0x09 || currChar == 0x0A || currChar == 0x0D) {
742
return escapeAttValue(original, i);
748
// this is not terribly performant!
749
private static String escapeAttValue(String original, int from) {
751
final int length = original.length();
752
StringBuffer newVal = new StringBuffer(length);
753
newVal.append(original.substring(0, from));
754
for (i = from; i < length; ++i) {
755
char currChar = original.charAt(i);
756
if (currChar == '"') {
702
757
newVal.append(""");
703
} else if (currChar == '>') {
704
newVal.append(">");
705
} else if (currChar == '&') {
759
else if (currChar == '<') {
760
newVal.append("<");
762
else if (currChar == '&') {
706
763
newVal.append("&");
765
// Must escape 0x09, 0x0A and 0x0D if they appear in attribute
766
// value so that they may be round-tripped. They would otherwise
767
// be transformed to a 0x20 during attribute value normalization.
768
else if (currChar == 0x09) {
769
newVal.append("	");
771
else if (currChar == 0x0A) {
772
newVal.append("
");
774
else if (currChar == 0x0D) {
775
newVal.append("
");
708
778
newVal.append(currChar);