~ubuntu-branches/ubuntu/karmic/libxerces2-java/karmic

« back to all changes in this revision

Viewing changes to src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-12-04 17:37:55 UTC
  • mfrom: (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20061204173755-hb6ybrrrk097zhx7
Tags: 2.8.1-1ubuntu1
* Merge with Debian unstable; remaining changes:
  - Build -gcj package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * The Apache Software License, Version 1.1
3
 
 *
4
 
 *
5
 
 * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
6
 
 * reserved.
7
 
 *
8
 
 * Redistribution and use in source and binary forms, with or without
9
 
 * modification, are permitted provided that the following conditions
10
 
 * are met:
11
 
 *
12
 
 * 1. Redistributions of source code must retain the above copyright
13
 
 *    notice, this list of conditions and the following disclaimer.
14
 
 *
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
18
 
 *    distribution.
19
 
 *
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.
26
 
 *
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.
31
 
 *
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.
35
 
 *
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
47
 
 * SUCH DAMAGE.
48
 
 * ====================================================================
49
 
 *
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.
 
3
 * 
 
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
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
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.
56
15
 */
57
16
 
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;
86
43
 
87
44
/**
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.
91
48
 *
 
49
 * @xerces.internal 
 
50
 *
92
51
 * @author Elena Litani, IBM
93
52
 * @author Rahul Srivastava, Sun Microsystems Inc.
94
53
 * @author Neeraj Bajaj, Sun Microsystems Inc.
95
54
 *
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 $
97
56
 */
98
57
abstract class XSDAbstractTraverser {
99
 
 
 
58
    
100
59
    protected static final String NO_NAME      = "(no name)";
101
 
 
 
60
    
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
109
 
 
 
68
    
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;
115
 
 
 
74
    
116
75
    //Shared data
117
76
    protected XSDHandler            fSchemaHandler = null;
118
77
    protected SymbolTable           fSymbolTable = null;
119
78
    protected XSAttributeChecker    fAttrChecker = null;
120
 
 
 
79
    protected boolean               fValidateAnnotations = false;
 
80
    
121
81
    // used to validate default/fixed attribute values
122
82
    ValidationState fValidationState = new ValidationState();
123
 
 
 
83
    
124
84
    XSDAbstractTraverser (XSDHandler handler,
125
 
                          XSAttributeChecker attrChecker) {
 
85
            XSAttributeChecker attrChecker) {
126
86
        fSchemaHandler = handler;
127
87
        fAttrChecker = attrChecker;
128
88
    }
129
 
 
130
 
    void reset(SymbolTable symbolTable) {
 
89
    
 
90
    void reset(SymbolTable symbolTable, boolean validateAnnotations) {
131
91
        fSymbolTable = symbolTable;
 
92
        fValidateAnnotations = validateAnnotations;
132
93
        fValidationState.setExtraChecking(false);
133
94
        fValidationState.setSymbolTable(symbolTable);
134
95
    }
135
 
 
 
96
    
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);
145
 
 
146
 
        String contents = null;
147
 
        for (Element child = DOMUtil.getFirstChildElement(annotationDecl);
148
 
            child != null;
149
 
            child = DOMUtil.getNextSiblingElement(child)) {
150
 
            String name = DOMUtil.getLocalName(child);
151
 
 
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();
 
106
        
 
107
        String contents = DOMUtil.getAnnotation(annotationDecl);
 
108
        Element child = DOMUtil.getFirstChildElement(annotationDecl);
 
109
        if (child != null) {
 
110
            do {
 
111
                String name = DOMUtil.getLocalName(child);
 
112
                
 
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);
161
118
                }
 
119
                
 
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);
 
125
                
 
126
                child = DOMUtil.getNextSiblingElement(child);
162
127
            }
163
 
 
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);
169
129
        }
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;
173
 
 
 
133
        
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
180
140
            StringBuffer localStrBuffer = new StringBuffer(64);
181
141
            localStrBuffer.append(" ");
182
142
            // Vector should contain rawname value pairs
183
 
            int i=0;
184
 
            while(i<annotationLocalAttrs.size()) {
 
143
            int i = 0;
 
144
            while (i < annotationLocalAttrs.size()) {
185
145
                String rawname = (String)annotationLocalAttrs.elementAt(i++);
186
146
                int colonIndex = rawname.indexOf(':');
187
147
                String prefix, localpart;
193
153
                    prefix = rawname.substring(0,colonIndex);
194
154
                    localpart = rawname.substring(colonIndex+1);
195
155
                }
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
199
159
                    continue;
200
160
                }
201
161
                localStrBuffer.append(rawname)
202
 
                    .append("=\"");
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)
207
 
                    .append("\" ");
208
 
            }
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);
219
 
        } else {
220
 
            return new XSAnnotationImpl(contents, grammar);
221
 
        }
222
 
 
223
 
    }
224
 
 
 
162
                .append("=\"");
 
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)
 
167
                .append("\" ");
 
168
            }
 
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));
 
181
            }
 
182
            return new XSAnnotationImpl(annotation, grammar);
 
183
        } else {
 
184
            if (fValidateAnnotations) {
 
185
                schemaDoc.addAnnotation(new XSAnnotationInfo(contents, annotationDecl));
 
186
            }
 
187
            return new XSAnnotationImpl(contents, grammar);
 
188
        }
 
189
        
 
190
    }
 
191
    
 
192
    XSAnnotationImpl traverseSyntheticAnnotation(Element annotationParent, String initialContent,
 
193
            Object[] parentAttrs, boolean isGlobal, XSDocumentInfo schemaDoc) {
 
194
        
 
195
        String contents = initialContent;
 
196
        
 
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
 
206
            int i = 0;
 
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) {
 
212
                    prefix = "";
 
213
                    localpart = rawname;
 
214
                }
 
215
                else {
 
216
                    prefix = rawname.substring(0,colonIndex);
 
217
                    localpart = rawname.substring(colonIndex+1);
 
218
                }
 
219
                String uri = schemaDoc.fNamespaceSupport.getURI(fSymbolTable.addSymbol(prefix));
 
220
                localStrBuffer.append(rawname)
 
221
                .append("=\"");
 
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)
 
226
                .append("\" ");
 
227
            }
 
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));
 
240
            }
 
241
            return new XSAnnotationImpl(annotation, grammar);
 
242
        } else {
 
243
            if (fValidateAnnotations) {
 
244
                schemaDoc.addAnnotation(new XSAnnotationInfo(contents, annotationParent));
 
245
            }
 
246
            return new XSAnnotationImpl(contents, grammar);
 
247
        }
 
248
    }
 
249
    
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();
230
 
 
 
255
    
231
256
    class FacetInfo {
232
257
        XSFacets facetdata;
233
258
        Element nodeAfterFacets;
234
259
        short fPresentFacets;
235
260
        short fFixedFacets;
236
261
    }
237
 
 
 
262
    
238
263
    FacetInfo traverseFacets(Element content,
239
 
                             XSSimpleType baseValidator,
240
 
                             XSDocumentInfo schemaDoc) {
241
 
 
 
264
            XSSimpleType baseValidator,
 
265
            XSDocumentInfo schemaDoc) {
 
266
        
242
267
        short facetsPresent = 0 ;
243
268
        short facetsFixed = 0; // facets that have fixed="true"        
244
269
        String facet;
257
282
                attrs = fAttrChecker.checkAttributes(content, false, schemaDoc, hasQName);
258
283
                String enumVal = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
259
284
                NamespaceSupport nsDecls = (NamespaceSupport)attrs[XSAttributeChecker.ATTIDX_ENUMNSDECLS];
260
 
 
 
285
                
261
286
                // for NOTATION types, need to check whether there is a notation
262
287
                // declared with the same name as the enumeration value.
263
288
                if (baseValidator.getVariety() == XSSimpleType.VARIETY_ATOMIC &&
264
 
                    baseValidator.getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) {
 
289
                        baseValidator.getPrimitiveKind() == XSSimpleType.PRIMITIVE_NOTATION) {
265
290
                    // need to use the namespace context returned from checkAttributes
266
291
                    schemaDoc.fValidationContext.setNamespaceSupport(nsDecls);
267
292
                    try{
284
309
                if (hasQName)
285
310
                    enumNSDecls.addElement(nsDecls);
286
311
                Element child = DOMUtil.getFirstChildElement( content );
287
 
 
288
 
                if (child != null) {
289
 
                     // traverse annotation if any
290
 
                     
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);
294
 
                     }
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);
297
 
                     }
298
 
               }
 
312
                
 
313
                if (child != null &&
 
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);
 
318
                }
 
319
                else {
 
320
                    String text = DOMUtil.getSyntheticAnnotation(content);
 
321
                    if (text != null) {
 
322
                        enumAnnotations.add(enumAnnotations.getLength()-1, traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc));
 
323
                    }
 
324
                }
 
325
                if (child !=null) {
 
326
                    reportSchemaError("s4s-elt-must-match.1", new Object[]{"enumeration", "(annotation?)", DOMUtil.getLocalName(child)}, child);
 
327
                }
299
328
            }
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]);
310
339
                }
311
340
                Element child = DOMUtil.getFirstChildElement( content );
312
 
                if (child != null) {
313
 
                         // traverse annotation if any
314
 
                         if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
315
 
                             if (patternAnnotations == null){
316
 
                                 patternAnnotations = new XSObjectListImpl();
317
 
                             }
318
 
                             patternAnnotations.add(traverseAnnotationDecl(child, attrs, false, schemaDoc));
319
 
                             child = DOMUtil.getNextSiblingElement(child);
320
 
                         }
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);
323
 
                         }
324
 
                }
325
 
                
 
341
                if (child != null &&
 
342
                        DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
 
343
                    // traverse annotation if any
 
344
                    if (patternAnnotations == null){
 
345
                        patternAnnotations = new XSObjectListImpl();
 
346
                    }
 
347
                    patternAnnotations.add(traverseAnnotationDecl(child, attrs, false, schemaDoc));
 
348
                    child = DOMUtil.getNextSiblingElement(child);
 
349
                }
 
350
                else {
 
351
                    String text = DOMUtil.getSyntheticAnnotation(content);
 
352
                    if (text != null) {
 
353
                        if (patternAnnotations == null){
 
354
                            patternAnnotations = new XSObjectListImpl();
 
355
                        }
 
356
                        patternAnnotations.add(traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc));
 
357
                    }
 
358
                }
 
359
                if (child !=null) {
 
360
                    reportSchemaError("s4s-elt-must-match.1", new Object[]{"pattern", "(annotation?)", DOMUtil.getLocalName(child)}, child);
 
361
                }
326
362
            }
327
363
            else {
328
364
                if (facet.equals(SchemaSymbols.ELT_MINLENGTH)) {
358
394
                else {
359
395
                    break;   // a non-facet
360
396
                }
361
 
 
 
397
                
362
398
                attrs = fAttrChecker.checkAttributes(content, false, schemaDoc);
363
 
 
 
399
                
364
400
                // check for duplicate facets
365
401
                if ((facetsPresent & currentFacet) != 0) {
366
402
                    reportSchemaError("src-single-facet-value", new Object[]{facet}, content);
371
407
                        facetsFixed |= currentFacet;
372
408
                    }
373
409
                    switch (currentFacet) {
374
 
                        case XSSimpleType.FACET_MINLENGTH:
375
 
                            xsFacets.minLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
376
 
                            break;
377
 
                        case XSSimpleType.FACET_MAXLENGTH:
378
 
                            xsFacets.maxLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
379
 
                            break;
380
 
                        case XSSimpleType.FACET_MAXEXCLUSIVE:
381
 
                            xsFacets.maxExclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
382
 
                            break;
383
 
                        case XSSimpleType.FACET_MAXINCLUSIVE:
384
 
                            xsFacets.maxInclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
385
 
                            break;
386
 
                        case XSSimpleType.FACET_MINEXCLUSIVE:
387
 
                            xsFacets.minExclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
388
 
                            break;
389
 
                        case XSSimpleType.FACET_MININCLUSIVE:
390
 
                            xsFacets.minInclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
391
 
                            break;
392
 
                        case XSSimpleType.FACET_TOTALDIGITS:
393
 
                            xsFacets.totalDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
394
 
                            break;
395
 
                        case XSSimpleType.FACET_FRACTIONDIGITS:
396
 
                            xsFacets.fractionDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
397
 
                            break;
398
 
                        case XSSimpleType.FACET_WHITESPACE:
399
 
                            xsFacets.whiteSpace = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).shortValue();
400
 
                            break;
401
 
                        case XSSimpleType.FACET_LENGTH:
402
 
                            xsFacets.length = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
403
 
                            break;
 
410
                    case XSSimpleType.FACET_MINLENGTH:
 
411
                        xsFacets.minLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
 
412
                    break;
 
413
                    case XSSimpleType.FACET_MAXLENGTH:
 
414
                        xsFacets.maxLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
 
415
                    break;
 
416
                    case XSSimpleType.FACET_MAXEXCLUSIVE:
 
417
                        xsFacets.maxExclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
 
418
                    break;
 
419
                    case XSSimpleType.FACET_MAXINCLUSIVE:
 
420
                        xsFacets.maxInclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
 
421
                    break;
 
422
                    case XSSimpleType.FACET_MINEXCLUSIVE:
 
423
                        xsFacets.minExclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
 
424
                    break;
 
425
                    case XSSimpleType.FACET_MININCLUSIVE:
 
426
                        xsFacets.minInclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE];
 
427
                    break;
 
428
                    case XSSimpleType.FACET_TOTALDIGITS:
 
429
                        xsFacets.totalDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
 
430
                    break;
 
431
                    case XSSimpleType.FACET_FRACTIONDIGITS:
 
432
                        xsFacets.fractionDigits = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
 
433
                    break;
 
434
                    case XSSimpleType.FACET_WHITESPACE:
 
435
                        xsFacets.whiteSpace = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).shortValue();
 
436
                    break;
 
437
                    case XSSimpleType.FACET_LENGTH:
 
438
                        xsFacets.length = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue();
 
439
                    break;
404
440
                    }
405
441
                }
406
 
 
 
442
                
407
443
                Element child = DOMUtil.getFirstChildElement( content );
 
444
                XSAnnotationImpl annotation = null;
 
445
                if (child != 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);
 
450
                }
 
451
                else {
 
452
                    String text = DOMUtil.getSyntheticAnnotation(content);
 
453
                    if (text != null) {
 
454
                        annotation = traverseSyntheticAnnotation(content, text, attrs, false, schemaDoc);
 
455
                    }
 
456
               }
 
457
                switch (currentFacet) {
 
458
                case XSSimpleType.FACET_MINLENGTH:
 
459
                    xsFacets.minLengthAnnotation = annotation;
 
460
                break;
 
461
                case XSSimpleType.FACET_MAXLENGTH:
 
462
                    xsFacets.maxLengthAnnotation = annotation;
 
463
                break;
 
464
                case XSSimpleType.FACET_MAXEXCLUSIVE:
 
465
                    xsFacets.maxExclusiveAnnotation = annotation;
 
466
                break;
 
467
                case XSSimpleType.FACET_MAXINCLUSIVE:
 
468
                    xsFacets.maxInclusiveAnnotation = annotation;
 
469
                break;
 
470
                case XSSimpleType.FACET_MINEXCLUSIVE:
 
471
                    xsFacets.minExclusiveAnnotation = annotation;
 
472
                break;
 
473
                case XSSimpleType.FACET_MININCLUSIVE:
 
474
                    xsFacets.minInclusiveAnnotation = annotation;
 
475
                break;
 
476
                case XSSimpleType.FACET_TOTALDIGITS:
 
477
                    xsFacets.totalDigitsAnnotation = annotation;
 
478
                break;
 
479
                case XSSimpleType.FACET_FRACTIONDIGITS:
 
480
                    xsFacets.fractionDigitsAnnotation = annotation;
 
481
                break;
 
482
                case XSSimpleType.FACET_WHITESPACE:
 
483
                    xsFacets.whiteSpaceAnnotation = annotation;
 
484
                break;
 
485
                case XSSimpleType.FACET_LENGTH:
 
486
                    xsFacets.lengthAnnotation = annotation;
 
487
                break;
 
488
                }
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;
415
 
                                break;
416
 
                            case XSSimpleType.FACET_MAXLENGTH:
417
 
                                xsFacets.maxLengthAnnotation = annotation;
418
 
                                break;
419
 
                            case XSSimpleType.FACET_MAXEXCLUSIVE:
420
 
                                xsFacets.maxExclusiveAnnotation = annotation;
421
 
                                break;
422
 
                            case XSSimpleType.FACET_MAXINCLUSIVE:
423
 
                                xsFacets.maxInclusiveAnnotation = annotation;
424
 
                                break;
425
 
                            case XSSimpleType.FACET_MINEXCLUSIVE:
426
 
                                xsFacets.minExclusiveAnnotation = annotation;
427
 
                                break;
428
 
                            case XSSimpleType.FACET_MININCLUSIVE:
429
 
                                xsFacets.minInclusiveAnnotation = annotation;
430
 
                                break;
431
 
                            case XSSimpleType.FACET_TOTALDIGITS:
432
 
                                xsFacets.totalDigitsAnnotation = annotation;
433
 
                                break;
434
 
                            case XSSimpleType.FACET_FRACTIONDIGITS:
435
 
                                xsFacets.fractionDigitsAnnotation = annotation;
436
 
                                break;
437
 
                            case XSSimpleType.FACET_WHITESPACE:
438
 
                                xsFacets.whiteSpaceAnnotation = annotation;
439
 
                                break;
440
 
                            case XSSimpleType.FACET_LENGTH:
441
 
                                xsFacets.lengthAnnotation = annotation;
442
 
                                break;
443
 
                        }
444
 
                        
445
 
                        
446
 
                        child = DOMUtil.getNextSiblingElement(child);
447
 
                    }
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);
450
 
                    }
 
490
                    reportSchemaError("s4s-elt-must-match.1", new Object[]{facet, "(annotation?)", DOMUtil.getLocalName(child)}, child);
451
491
                }
452
492
            }
453
493
            fAttrChecker.returnAttrArray (attrs, schemaDoc);
464
504
            xsFacets.pattern = fPattern.toString();
465
505
            xsFacets.patternAnnotations = patternAnnotations;
466
506
        }
467
 
 
 
507
        
468
508
        fPattern.setLength(0);
469
 
 
 
509
        
470
510
        FacetInfo fi = new FacetInfo();
471
511
        fi.facetdata = xsFacets;
472
512
        fi.nodeAfterFacets = content;
474
514
        fi.fFixedFacets = facetsFixed;
475
515
        return fi;
476
516
    }
477
 
 
478
 
 
 
517
    
 
518
    
479
519
    // return whether QName/NOTATION is part of the given type
480
520
    private boolean containsQName(XSSimpleType type) {
481
521
        if (type.getVariety() == XSSimpleType.VARIETY_ATOMIC) {
495
535
        }
496
536
        return false;
497
537
    }
498
 
 
 
538
    
499
539
    //
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
503
543
    //
504
544
    Element traverseAttrsAndAttrGrps(Element firstAttr, XSAttributeGroupDecl attrGrp,
505
 
                                     XSDocumentInfo schemaDoc, SchemaGrammar grammar,
506
 
                                     XSComplexTypeDecl enclosingCT) {
507
 
 
 
545
            XSDocumentInfo schemaDoc, SchemaGrammar grammar,
 
546
            XSComplexTypeDecl enclosingCT) {
 
547
        
508
548
        Element child=null;
509
549
        XSAttributeGroupDecl tempAttrGrp = null;
510
550
        XSAttributeUseImpl tempAttrUse = null;
511
551
        String childName;
512
 
 
 
552
        
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,
517
 
                                                                               schemaDoc,
518
 
                                                                               grammar,
519
 
                                                                               enclosingCT);
 
557
                        schemaDoc,
 
558
                        grammar,
 
559
                        enclosingCT);
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";
537
577
            else if (childName.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP)) {
538
578
                //REVISIT: do we need to save some state at this point??
539
579
                tempAttrGrp = fSchemaHandler.fAttributeGroupTraverser.traverseLocal(
540
 
                       child, schemaDoc, grammar);
 
580
                        child, schemaDoc, grammar);
541
581
                if(tempAttrGrp == null ) break;
542
582
                XSObjectList attrUseS = tempAttrGrp.getAttributeUses();
543
583
                XSAttributeUseImpl existingAttrUse = null, oneAttrUse;
545
585
                for (int i=0; i<attrCount; i++) {
546
586
                    oneAttrUse = (XSAttributeUseImpl)attrUseS.item(i);
547
587
                    if (existingAttrUse == attrGrp.getAttributeUse(oneAttrUse.fAttrDecl.getNamespace(),
548
 
                    oneAttrUse.fAttrDecl.getName())) {
 
588
                            oneAttrUse.fAttrDecl.getName())) {
549
589
                        String idName = attrGrp.addAttributeUse(oneAttrUse);
550
590
                        if (idName != null) {
551
591
                            String code = (enclosingCT == null) ? "ag-props-correct.3" : "ct-props-correct.5";
560
600
                        reportSchemaError(code, new Object[]{name, oneAttrUse.fAttrDecl.getName()}, child);
561
601
                    }
562
602
                }
563
 
 
 
603
                
564
604
                if (tempAttrGrp.fAttributeWC != null) {
565
605
                    if (attrGrp.fAttributeWC == null) {
566
606
                        attrGrp.fAttributeWC = tempAttrGrp.fAttributeWC;
568
608
                    // perform intersection of attribute wildcard
569
609
                    else {
570
610
                        attrGrp.fAttributeWC = attrGrp.fAttributeWC.
571
 
                                               performIntersectionWith(tempAttrGrp.fAttributeWC, attrGrp.fAttributeWC.fProcessContents);
 
611
                        performIntersectionWith(tempAttrGrp.fAttributeWC, attrGrp.fAttributeWC.fProcessContents);
572
612
                        if (attrGrp.fAttributeWC == null) {
573
613
                            String code = (enclosingCT == null) ? "src-attribute_group.2" : "src-ct.4";
574
614
                            String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName();
580
620
            else
581
621
                break;
582
622
        } // for
583
 
 
 
623
        
584
624
        if (child != null) {
585
625
            childName = DOMUtil.getLocalName(child);
586
626
            if (childName.equals(SchemaSymbols.ELT_ANYATTRIBUTE)) {
587
627
                XSWildcardDecl tempAttrWC = fSchemaHandler.fWildCardTraverser.
588
 
                                            traverseAnyAttribute(child, schemaDoc, grammar);
 
628
                traverseAnyAttribute(child, schemaDoc, grammar);
589
629
                if (attrGrp.fAttributeWC == null) {
590
630
                    attrGrp.fAttributeWC = tempAttrWC;
591
631
                }
592
632
                // perform intersection of attribute wildcard
593
633
                else {
594
634
                    attrGrp.fAttributeWC = tempAttrWC.
595
 
                                           performIntersectionWith(attrGrp.fAttributeWC, tempAttrWC.fProcessContents);
 
635
                    performIntersectionWith(attrGrp.fAttributeWC, tempAttrWC.fProcessContents);
596
636
                    if (attrGrp.fAttributeWC == null) {
597
637
                        String code = (enclosingCT == null) ? "src-attribute_group.2" : "src-ct.4";
598
638
                        String name = (enclosingCT == null) ? attrGrp.fName : enclosingCT.getName();
602
642
                child = DOMUtil.getNextSiblingElement(child);
603
643
            }
604
644
        }
605
 
 
 
645
        
606
646
        // Success
607
647
        return child;
608
 
 
 
648
        
609
649
    }
610
 
 
 
650
    
611
651
    void reportSchemaError (String key, Object[] args, Element ele) {
612
652
        fSchemaHandler.reportSchemaError(key, args, ele);
613
653
    }
614
 
 
 
654
    
615
655
    /**
616
656
     * Element/Attribute traversers call this method to check whether
617
657
     * the type is NOTATION without enumeration facet
618
658
     */
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);
625
665
            }
626
666
        }
627
667
    }
628
 
 
 
668
    
629
669
    // Checks constraints for minOccurs, maxOccurs
630
670
    protected XSParticleDecl checkOccurrences(XSParticleDecl particle,
631
 
                                              String particleName, Element parent,
632
 
                                              int allContextFlags,
633
 
                                              long defaultVals) {
634
 
 
 
671
            String particleName, Element parent,
 
672
            int allContextFlags,
 
673
            long defaultVals) {
 
674
        
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;
639
 
 
 
679
        
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);
644
 
 
 
684
        
645
685
        // Neither minOccurs nor maxOccurs may be specified
646
686
        // for the child of a model group definition.
647
687
        if (isGroupChild) {
656
696
                max = 1;
657
697
            }
658
698
        }
659
 
 
 
699
        
660
700
        // If minOccurs=maxOccurs=0, no component is specified
661
701
        if (min == 0 && max== 0) {
662
702
            particle.fType = XSParticleDecl.PARTICLE_EMPTY;
663
703
            return null;
664
704
        }
665
 
 
 
705
        
666
706
        // For the elements referenced in an <all>, minOccurs attribute
667
707
        // must be zero or one, and maxOccurs attribute must be one.
668
708
        // For a complex type definition that contains an <all> or a
671
711
        if (processingAllEl) {
672
712
            if (max != 1) {
673
713
                reportSchemaError("cos-all-limited.2", new Object[]{new Integer(max),
674
 
                                  ((XSElementDecl)particle.fValue).getName()}, parent);
 
714
                        ((XSElementDecl)particle.fValue).getName()}, parent);
675
715
                max = 1;
676
716
                if (min > 1)
677
717
                    min = 1;
685
725
                max = 1;
686
726
            }
687
727
        }
688
 
 
 
728
        
689
729
        particle.fMaxOccurs = min;
690
730
        particle.fMaxOccurs = max;
691
 
 
 
731
        
692
732
        return particle;
693
733
    }
694
 
 
695
 
    // this is not terribly performant!
 
734
    
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);
 
743
            }
 
744
        }
 
745
        return original;
 
746
    }
 
747
    
 
748
    // this is not terribly performant!
 
749
    private static String escapeAttValue(String original, int from) {
 
750
        int i;
 
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("&quot;");
703
 
            } else if (currChar == '>') {
704
 
                newVal.append("&gt;");
705
 
            } else if (currChar == '&') {
 
758
            } 
 
759
            else if (currChar == '<') {
 
760
                newVal.append("&lt;");
 
761
            }
 
762
            else if (currChar == '&') {
706
763
                newVal.append("&amp;");
707
 
            } else {
 
764
            }
 
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("&#x9;");
 
770
            }
 
771
            else if (currChar == 0x0A) {
 
772
                newVal.append("&#xA;");
 
773
            }
 
774
            else if (currChar == 0x0D) {
 
775
                newVal.append("&#xD;");
 
776
            }
 
777
            else {
708
778
                newVal.append(currChar);
709
779
            }
710
780
        }