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

« back to all changes in this revision

Viewing changes to src/org/apache/xerces/impl/xs/traversers/XSDComplexTypeTraverser.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-2005 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
package org.apache.xerces.impl.xs.traversers;
58
17
 
70
29
import org.apache.xerces.impl.xs.XSModelGroupImpl;
71
30
import org.apache.xerces.impl.xs.XSParticleDecl;
72
31
import org.apache.xerces.impl.xs.XSWildcardDecl;
 
32
import org.apache.xerces.impl.xs.util.XInt;
 
33
import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 
34
import org.apache.xerces.util.DOMUtil;
 
35
import org.apache.xerces.xni.QName;
73
36
import org.apache.xerces.xs.XSAttributeUse;
74
37
import org.apache.xerces.xs.XSConstants;
75
38
import org.apache.xerces.xs.XSObjectList;
76
39
import org.apache.xerces.xs.XSTypeDefinition;
77
 
import org.apache.xerces.impl.xs.util.XInt;
78
 
import org.apache.xerces.impl.xs.util.XSObjectListImpl;
79
 
import org.apache.xerces.util.DOMUtil;
80
 
import org.apache.xerces.xni.QName;
81
40
import org.w3c.dom.Element;
82
41
 
83
42
/**
95
54
 *            ((group | all | choice | sequence)?,
96
55
 *            ((attribute | attributeGroup)*, anyAttribute?))))
97
56
 * </complexType>
98
 
 * @version $Id: XSDComplexTypeTraverser.java,v 1.41 2003/11/11 20:15:00 sandygao Exp $
 
57
 * 
 
58
 * @xerces.internal  
 
59
 * 
 
60
 * @version $Id: XSDComplexTypeTraverser.java 383214 2006-03-04 22:20:48Z nddelima $
99
61
 */
100
62
 
101
63
class  XSDComplexTypeTraverser extends XSDAbstractParticleTraverser {
102
 
 
 
64
    
103
65
    // size of stack to hold globals:
104
66
    private final static int GLOBAL_NUM = 11;
105
 
 
 
67
    
106
68
    // globals for building XSComplexTypeDecls
107
69
    private String fName = null;
108
70
    private String fTargetNamespace = null;
117
79
    private boolean fIsAbstract = false;
118
80
    private XSComplexTypeDecl fComplexTypeDecl = null;
119
81
    private XSAnnotationImpl [] fAnnotations = null;
120
 
 
 
82
    
121
83
    private XSParticleDecl fEmptyParticle = null;
122
 
 
 
84
    
123
85
    // our own little stack to retain state when getGlobalDecls is called:
124
86
    private Object [] fGlobalStore = null;
125
87
    private int fGlobalStorePos = 0;
126
 
 
 
88
    
127
89
    XSDComplexTypeTraverser (XSDHandler handler,
128
 
                             XSAttributeChecker gAttrCheck) {
 
90
            XSAttributeChecker gAttrCheck) {
129
91
        super(handler, gAttrCheck);
130
92
    }
131
 
 
132
 
 
 
93
    
 
94
    
133
95
    private static final boolean DEBUG=false;
134
 
 
 
96
    
135
97
    private SchemaDVFactory schemaFactory = SchemaDVFactory.getInstance();
136
 
 
 
98
    
137
99
    private class ComplexTypeRecoverableError extends Exception {
138
 
 
 
100
        
 
101
        private static final long serialVersionUID = 6802729912091130335L;
 
102
        
139
103
        Object[] errorSubstText=null;
140
104
        Element  errorElem = null;
141
105
        ComplexTypeRecoverableError() {
146
110
            errorSubstText=args;
147
111
            errorElem = e;
148
112
        }
149
 
 
 
113
        
150
114
    }
151
 
 
 
115
    
152
116
    /**
153
117
     * Traverse local complexType declarations
154
118
     *
158
122
     * @return XSComplexTypeDecl
159
123
     */
160
124
    XSComplexTypeDecl traverseLocal(Element complexTypeNode,
161
 
                                    XSDocumentInfo schemaDoc,
162
 
                                    SchemaGrammar grammar) {
163
 
 
164
 
 
 
125
            XSDocumentInfo schemaDoc,
 
126
            SchemaGrammar grammar) {
 
127
        
 
128
        
165
129
        Object[] attrValues = fAttrChecker.checkAttributes(complexTypeNode, false,
166
 
                                                           schemaDoc);
 
130
                schemaDoc);
167
131
        String complexTypeName = genAnonTypeName(complexTypeNode);
168
132
        contentBackup();
169
133
        XSComplexTypeDecl type = traverseComplexTypeDecl (complexTypeNode,
170
 
                                                          complexTypeName, attrValues, schemaDoc, grammar);
 
134
                complexTypeName, attrValues, schemaDoc, grammar);
171
135
        contentRestore();
172
136
        // need to add the type to the grammar for later constraint checking
173
137
        grammar.addComplexTypeDecl(type, fSchemaHandler.element2Locator(complexTypeNode));
174
138
        type.setIsAnonymous();
175
139
        fAttrChecker.returnAttrArray(attrValues, schemaDoc);
176
 
 
 
140
        
177
141
        return type;
178
142
    }
179
 
 
 
143
    
180
144
    /**
181
145
     * Traverse global complexType declarations
182
146
     *
186
150
     * @return XSComplexTypeDecXSComplexTypeDecl
187
151
     */
188
152
    XSComplexTypeDecl traverseGlobal (Element complexTypeNode,
189
 
                                      XSDocumentInfo schemaDoc,
190
 
                                      SchemaGrammar grammar) {
191
 
 
 
153
            XSDocumentInfo schemaDoc,
 
154
            SchemaGrammar grammar) {
 
155
        
192
156
        Object[] attrValues = fAttrChecker.checkAttributes(complexTypeNode, true,
193
 
                                                           schemaDoc);
 
157
                schemaDoc);
194
158
        String complexTypeName = (String)  attrValues[XSAttributeChecker.ATTIDX_NAME];
195
159
        contentBackup();
196
160
        XSComplexTypeDecl type = traverseComplexTypeDecl (complexTypeNode,
197
 
                                                          complexTypeName, attrValues, schemaDoc, grammar);
 
161
                complexTypeName, attrValues, schemaDoc, grammar);
198
162
        contentRestore();
199
163
        if (complexTypeName == null) {
200
164
            reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_COMPLEXTYPE, SchemaSymbols.ATT_NAME}, complexTypeNode);
204
168
        // need to add the type to the grammar for later constraint checking
205
169
        grammar.addComplexTypeDecl(type, fSchemaHandler.element2Locator(complexTypeNode));
206
170
        fAttrChecker.returnAttrArray(attrValues, schemaDoc);
207
 
 
 
171
        
208
172
        return type;
209
173
    }
210
 
 
211
 
 
 
174
    
 
175
    
212
176
    private XSComplexTypeDecl traverseComplexTypeDecl(Element complexTypeDecl,
213
 
                                                      String complexTypeName,
214
 
                                                      Object[] attrValues,
215
 
                                                      XSDocumentInfo schemaDoc,
216
 
                                                      SchemaGrammar grammar) {
217
 
 
 
177
            String complexTypeName,
 
178
            Object[] attrValues,
 
179
            XSDocumentInfo schemaDoc,
 
180
            SchemaGrammar grammar) {
 
181
        
218
182
        fComplexTypeDecl = new XSComplexTypeDecl();
219
183
        fAttrGrp = new XSAttributeGroupDecl();
220
184
        Boolean abstractAtt  = (Boolean) attrValues[XSAttributeChecker.ATTIDX_ABSTRACT];
221
185
        XInt    blockAtt     = (XInt)    attrValues[XSAttributeChecker.ATTIDX_BLOCK];
222
186
        Boolean mixedAtt     = (Boolean) attrValues[XSAttributeChecker.ATTIDX_MIXED];
223
187
        XInt    finalAtt     = (XInt)    attrValues[XSAttributeChecker.ATTIDX_FINAL];
224
 
 
 
188
        
225
189
        fName = complexTypeName;
226
190
        fComplexTypeDecl.setName(fName);
227
191
        fTargetNamespace = schemaDoc.fTargetNamespace;
228
 
 
 
192
        
229
193
        fBlock = blockAtt == null ? schemaDoc.fBlockDefault : blockAtt.shortValue();
230
194
        fFinal = finalAtt == null ? schemaDoc.fFinalDefault : finalAtt.shortValue();
231
195
        //discard valid Block/Final 'Default' values that are invalid for Block/Final
232
196
        fBlock &= (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION);
233
197
        fFinal &= (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION);
234
 
 
235
 
        if (abstractAtt != null && abstractAtt.booleanValue())
236
 
            fIsAbstract = true;
237
 
 
238
 
 
 
198
        
 
199
        fIsAbstract = (abstractAtt != null && abstractAtt.booleanValue());
 
200
        fAnnotations = null;
 
201
        
239
202
        Element child = null;
240
 
 
 
203
        
241
204
        try {
242
205
            // ---------------------------------------------------------------
243
206
            // First, handle any ANNOTATION declaration and get next child
244
207
            // ---------------------------------------------------------------
245
208
            child = DOMUtil.getFirstChildElement(complexTypeDecl);
246
 
 
247
 
            if (child != null) {
248
 
                // traverse annotation if any
 
209
            if(child != null) {
249
210
                if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
250
211
                    addAnnotation(traverseAnnotationDecl(child, attrValues, false, schemaDoc));
251
212
                    child = DOMUtil.getNextSiblingElement(child);
252
213
                }
 
214
                else {
 
215
                    String text = DOMUtil.getSyntheticAnnotation(complexTypeDecl);
 
216
                    if (text != null) {
 
217
                        addAnnotation(traverseSyntheticAnnotation(complexTypeDecl, text, attrValues, false, schemaDoc));
 
218
                    }
 
219
                }
253
220
                if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) {
254
221
                    throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
255
 
                           new Object[]{fName,SchemaSymbols.ELT_ANNOTATION},
256
 
                           child);
 
222
                            new Object[]{fName,SchemaSymbols.ELT_ANNOTATION},
 
223
                            child);
 
224
                }
 
225
            }
 
226
            else {
 
227
                String text = DOMUtil.getSyntheticAnnotation(complexTypeDecl);
 
228
                if (text != null) {
 
229
                    addAnnotation(traverseSyntheticAnnotation(complexTypeDecl, text, attrValues, false, schemaDoc));
257
230
                }
258
231
            }
259
232
            // ---------------------------------------------------------------
263
236
                //
264
237
                // EMPTY complexType with complexContent
265
238
                //
266
 
 
 
239
                
267
240
                // set the base to the anyType
268
241
                fBaseType = SchemaGrammar.fAnyType;
269
242
                processComplexContent(child, mixedAtt.booleanValue(), false,
270
 
                                      schemaDoc, grammar);
 
243
                        schemaDoc, grammar);
271
244
            }
272
245
            else if (DOMUtil.getLocalName(child).equals
273
 
                     (SchemaSymbols.ELT_SIMPLECONTENT)) {
 
246
                    (SchemaSymbols.ELT_SIMPLECONTENT)) {
274
247
                //
275
248
                // SIMPLE CONTENT
276
249
                //
279
252
                if (elemTmp != null) {
280
253
                    String siblingName = DOMUtil.getLocalName(elemTmp);
281
254
                    throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
282
 
                                                          new Object[]{fName,siblingName},
283
 
                                                          elemTmp);
 
255
                            new Object[]{fName,siblingName},
 
256
                            elemTmp);
284
257
                }
285
258
            }
286
259
            else if (DOMUtil.getLocalName(child).equals
287
 
                     (SchemaSymbols.ELT_COMPLEXCONTENT)) {
 
260
                    (SchemaSymbols.ELT_COMPLEXCONTENT)) {
288
261
                traverseComplexContent(child, mixedAtt.booleanValue(),
289
 
                                       schemaDoc, grammar);
 
262
                        schemaDoc, grammar);
290
263
                Element elemTmp = DOMUtil.getNextSiblingElement(child);
291
264
                if (elemTmp != null) {
292
265
                    String siblingName = DOMUtil.getLocalName(elemTmp);
293
266
                    throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
294
 
                                                          new Object[]{fName,siblingName},
295
 
                                                          elemTmp);
 
267
                            new Object[]{fName,siblingName},
 
268
                            elemTmp);
296
269
                }
297
270
            }
298
271
            else {
301
274
                // GROUP, ALL, SEQUENCE or CHOICE, followed by optional attributes
302
275
                // Note that it's possible that only attributes are specified.
303
276
                //
304
 
 
 
277
                
305
278
                // set the base to the anyType
306
279
                fBaseType = SchemaGrammar.fAnyType;
307
280
                processComplexContent(child, mixedAtt.booleanValue(), false,
308
 
                                      schemaDoc, grammar);
 
281
                        schemaDoc, grammar);
309
282
            }
310
 
 
 
283
            
311
284
        }
312
285
        catch (ComplexTypeRecoverableError e) {
313
286
            handleComplexTypeError(e.getMessage(), e.errorSubstText,
314
 
                                   e.errorElem);
 
287
                    e.errorElem);
315
288
        }
316
 
 
 
289
        
317
290
        if (DEBUG) {
318
291
            System.out.println(fName);
319
292
        }
320
293
        fComplexTypeDecl.setValues(fName, fTargetNamespace, fBaseType,
321
294
                fDerivedBy, fFinal, fBlock, fContentType, fIsAbstract,
322
295
                fAttrGrp, fXSSimpleType, fParticle, new XSObjectListImpl(fAnnotations, 
323
 
                fAnnotations == null? 0 : fAnnotations.length));
 
296
                        fAnnotations == null? 0 : fAnnotations.length));
324
297
        return fComplexTypeDecl;
325
298
    }
326
 
 
327
 
 
 
299
    
 
300
    
328
301
    private void traverseSimpleContent(Element simpleContentElement,
329
 
                                       XSDocumentInfo schemaDoc,
330
 
                                       SchemaGrammar grammar)
 
302
            XSDocumentInfo schemaDoc,
 
303
            SchemaGrammar grammar)
331
304
    throws ComplexTypeRecoverableError {
332
 
 
333
 
 
 
305
        
 
306
        
334
307
        Object[] simpleContentAttrValues = fAttrChecker.checkAttributes(simpleContentElement, false,
335
 
                                                           schemaDoc);
336
 
 
 
308
                schemaDoc);
 
309
        
337
310
        // -----------------------------------------------------------------------
338
311
        // Set content type
339
312
        // -----------------------------------------------------------------------
340
313
        fContentType = XSComplexTypeDecl.CONTENTTYPE_SIMPLE;
341
314
        fParticle = null;
342
 
 
 
315
        
343
316
        Element simpleContent = DOMUtil.getFirstChildElement(simpleContentElement);
344
 
        if (simpleContent != null) {
345
 
            // traverse annotation if any
346
 
            if (DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)) {
347
 
                addAnnotation(traverseAnnotationDecl(simpleContent, simpleContentAttrValues, false, schemaDoc));
348
 
                simpleContent = DOMUtil.getNextSiblingElement(simpleContent);
 
317
        if (simpleContent != null && DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)) {
 
318
            addAnnotation(traverseAnnotationDecl(simpleContent, simpleContentAttrValues, false, schemaDoc));
 
319
            simpleContent = DOMUtil.getNextSiblingElement(simpleContent);
 
320
        }
 
321
        else {
 
322
            String text = DOMUtil.getSyntheticAnnotation(simpleContentElement);
 
323
            if (text != null) {
 
324
                addAnnotation(traverseSyntheticAnnotation(simpleContentElement, text, simpleContentAttrValues, false, schemaDoc));
349
325
            }
350
326
        }
351
 
 
 
327
        
352
328
        // If there are no children, return
353
329
        if (simpleContent==null) {
354
330
            fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
355
331
            throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.2",
356
 
                            new Object[]{fName,SchemaSymbols.ELT_SIMPLECONTENT},
357
 
                            simpleContentElement);
 
332
                    new Object[]{fName,SchemaSymbols.ELT_SIMPLECONTENT},
 
333
                    simpleContentElement);
358
334
        }
359
 
 
 
335
        
360
336
        // -----------------------------------------------------------------------
361
337
        // The content should be either "restriction" or "extension"
362
338
        // -----------------------------------------------------------------------
368
344
        else {
369
345
            fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
370
346
            throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
371
 
                            new Object[]{fName,simpleContentName},
372
 
                            simpleContent);
 
347
                    new Object[]{fName,simpleContentName},
 
348
                    simpleContent);
373
349
        }
374
350
        Element elemTmp = DOMUtil.getNextSiblingElement(simpleContent);
375
351
        if (elemTmp != null) {
376
352
            fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
377
353
            String siblingName = DOMUtil.getLocalName(elemTmp);
378
354
            throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
379
 
                            new Object[]{fName,siblingName},
380
 
                            elemTmp);
 
355
                    new Object[]{fName,siblingName},
 
356
                    elemTmp);
381
357
        }
382
 
 
 
358
        
383
359
        Object [] derivationTypeAttrValues = fAttrChecker.checkAttributes(simpleContent, false,
384
 
                                                  schemaDoc);
 
360
                schemaDoc);
385
361
        QName baseTypeName = (QName)  derivationTypeAttrValues[XSAttributeChecker.ATTIDX_BASE];
386
 
 
387
 
 
 
362
        
 
363
        
388
364
        // -----------------------------------------------------------------------
389
365
        // Need a base type.
390
366
        // -----------------------------------------------------------------------
392
368
            fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
393
369
            fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
394
370
            throw new ComplexTypeRecoverableError("s4s-att-must-appear",
395
 
                            new Object[]{simpleContentName, "base"}, simpleContent);
 
371
                    new Object[]{simpleContentName, "base"}, simpleContent);
396
372
        }
397
 
 
 
373
        
398
374
        XSTypeDefinition type = (XSTypeDefinition)fSchemaHandler.getGlobalDecl(schemaDoc,
399
 
                                      XSDHandler.TYPEDECL_TYPE, baseTypeName,
400
 
                                      simpleContent);
 
375
                XSDHandler.TYPEDECL_TYPE, baseTypeName,
 
376
                simpleContent);
401
377
        if (type==null) {
402
378
            fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
403
379
            fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
404
380
            throw new ComplexTypeRecoverableError();
405
381
        }
406
 
 
 
382
        
407
383
        fBaseType = type;
408
 
 
 
384
        
409
385
        XSSimpleType baseValidator = null;
410
386
        XSComplexTypeDecl baseComplexType = null;
411
387
        int baseFinalSet = 0;
412
 
 
 
388
        
413
389
        // If the base type is complex, it must have simpleContent
414
390
        if ((type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE)) {
415
 
 
 
391
            
416
392
            baseComplexType = (XSComplexTypeDecl)type;
417
393
            baseFinalSet = baseComplexType.getFinal();
418
394
            // base is a CT with simple content (both restriction and extension are OK)
421
397
            }
422
398
            // base is a CT with mixed/emptiable content (only restriction is OK)
423
399
            else if (fDerivedBy == XSConstants.DERIVATION_RESTRICTION &&
424
 
                     baseComplexType.getContentType() == XSComplexTypeDecl.CONTENTTYPE_MIXED &&
425
 
                     ((XSParticleDecl)baseComplexType.getParticle()).emptiable()) {
 
400
                    baseComplexType.getContentType() == XSComplexTypeDecl.CONTENTTYPE_MIXED &&
 
401
                    ((XSParticleDecl)baseComplexType.getParticle()).emptiable()) {
426
402
            }
427
403
            else {
428
404
                fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
429
405
                fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
430
406
                throw new ComplexTypeRecoverableError("src-ct.2.1",
431
 
                                new Object[]{fName, baseComplexType.getName()}, simpleContent);
 
407
                        new Object[]{fName, baseComplexType.getName()}, simpleContent);
432
408
            }
433
409
        }
434
410
        else {
438
414
                fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
439
415
                fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
440
416
                throw new ComplexTypeRecoverableError("src-ct.2.1",
441
 
                                new Object[]{fName, baseValidator.getName()}, simpleContent);
 
417
                        new Object[]{fName, baseValidator.getName()}, simpleContent);
442
418
            }
443
419
            baseFinalSet=baseValidator.getFinal();
444
420
        }
445
 
 
 
421
        
446
422
        // -----------------------------------------------------------------------
447
423
        // Check that the base permits the derivation
448
424
        // -----------------------------------------------------------------------
450
426
            fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
451
427
            fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
452
428
            String errorKey = (fDerivedBy==XSConstants.DERIVATION_EXTENSION) ?
453
 
                              "cos-ct-extends.1.1" : "derivation-ok-restriction.1";
 
429
                    "cos-ct-extends.1.1" : "derivation-ok-restriction.1";
454
430
            throw new ComplexTypeRecoverableError(errorKey,
455
 
                                new Object[]{fName, fBaseType.getName()}, simpleContent);
 
431
                    new Object[]{fName, fBaseType.getName()}, simpleContent);
456
432
        }
457
 
 
 
433
        
458
434
        // -----------------------------------------------------------------------
459
435
        // Skip over any potential annotations
460
436
        // -----------------------------------------------------------------------
 
437
        Element scElement = simpleContent;
461
438
        simpleContent = DOMUtil.getFirstChildElement(simpleContent);
462
439
        if (simpleContent != null) {
463
440
            // traverse annotation if any
464
 
 
 
441
            
465
442
            if (DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)) {
466
443
                addAnnotation(traverseAnnotationDecl(simpleContent, derivationTypeAttrValues, false, schemaDoc));
467
444
                simpleContent = DOMUtil.getNextSiblingElement(simpleContent);
468
445
            }
469
 
 
 
446
            else {
 
447
                String text = DOMUtil.getSyntheticAnnotation(scElement);
 
448
                if (text != null) {
 
449
                    addAnnotation(traverseSyntheticAnnotation(scElement, text, derivationTypeAttrValues, false, schemaDoc));
 
450
                }
 
451
            }
 
452
            
470
453
            if (simpleContent !=null &&
471
 
                DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)){
 
454
                    DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_ANNOTATION)){
472
455
                fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
473
456
                fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
474
457
                throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
475
 
                       new Object[]{fName,SchemaSymbols.ELT_ANNOTATION},
476
 
                       simpleContent);
477
 
            }
478
 
        }
479
 
 
 
458
                        new Object[]{fName,SchemaSymbols.ELT_ANNOTATION},
 
459
                        simpleContent);
 
460
            }
 
461
        }
 
462
        else {
 
463
            String text = DOMUtil.getSyntheticAnnotation(scElement);
 
464
            if (text != null) {
 
465
                addAnnotation(traverseSyntheticAnnotation(scElement, text, derivationTypeAttrValues, false, schemaDoc));
 
466
            }
 
467
        }
 
468
        
480
469
        // -----------------------------------------------------------------------
481
470
        // Process a RESTRICTION
482
471
        // -----------------------------------------------------------------------
483
472
        if (fDerivedBy == XSConstants.DERIVATION_RESTRICTION) {
484
 
 
 
473
            
485
474
            // -----------------------------------------------------------------------
486
475
            // There may be a simple type definition in the restriction element
487
476
            // The data type validator will be based on it, if specified
488
477
            // -----------------------------------------------------------------------
489
478
            if (simpleContent !=null &&
490
 
            DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_SIMPLETYPE )) {
491
 
 
 
479
                    DOMUtil.getLocalName(simpleContent).equals(SchemaSymbols.ELT_SIMPLETYPE )) {
 
480
                
492
481
                XSSimpleType dv = fSchemaHandler.fSimpleTypeTraverser.traverseLocal(
493
 
                      simpleContent, schemaDoc, grammar);
 
482
                        simpleContent, schemaDoc, grammar);
494
483
                if (dv == null) {
495
484
                    fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
496
485
                    fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
498
487
                }
499
488
                //check that this datatype validator is validly derived from the base
500
489
                //according to derivation-ok-restriction 5.1.2.1
501
 
 
 
490
                
502
491
                if (baseValidator != null &&
503
 
                    !XSConstraints.checkSimpleDerivationOk(dv, baseValidator,
504
 
                                                           baseValidator.getFinal())) {
 
492
                        !XSConstraints.checkSimpleDerivationOk(dv, baseValidator,
 
493
                                baseValidator.getFinal())) {
505
494
                    fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
506
495
                    fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
507
496
                    throw new ComplexTypeRecoverableError("derivation-ok-restriction.5.2.2.1",
508
 
                           new Object[]{fName, dv.getName(), baseValidator.getName()},
509
 
                           simpleContent);
 
497
                            new Object[]{fName, dv.getName(), baseValidator.getName()},
 
498
                            simpleContent);
510
499
                }
511
500
                baseValidator = dv;
512
501
                simpleContent = DOMUtil.getNextSiblingElement(simpleContent);
513
502
            }
514
 
 
 
503
            
515
504
            // this only happens when restricting a mixed/emptiable CT
516
505
            // but there is no <simpleType>, which is required
517
506
            if (baseValidator == null) {
518
507
                fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
519
508
                fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
520
509
                throw new ComplexTypeRecoverableError("src-ct.2.2",
521
 
                                new Object[]{fName}, simpleContent);
 
510
                        new Object[]{fName}, simpleContent);
522
511
            }
523
 
 
 
512
            
524
513
            // -----------------------------------------------------------------------
525
514
            // Traverse any facets
526
515
            // -----------------------------------------------------------------------
528
517
            XSFacets facetData = null;
529
518
            short presentFacets = 0 ;
530
519
            short fixedFacets = 0 ;
531
 
 
 
520
            
532
521
            if (simpleContent!=null) {
533
522
                FacetInfo fi = traverseFacets(simpleContent, baseValidator, schemaDoc);
534
523
                attrNode = fi.nodeAfterFacets;
536
525
                presentFacets = fi.fPresentFacets;
537
526
                fixedFacets = fi.fFixedFacets;
538
527
            }
539
 
 
 
528
            
540
529
            fXSSimpleType = schemaFactory.createTypeRestriction(null,schemaDoc.fTargetNamespace,(short)0,baseValidator,null);
541
530
            try{
542
531
                fValidationState.setNamespaceSupport(schemaDoc.fNamespaceSupport);
544
533
            }catch(InvalidDatatypeFacetException ex){
545
534
                reportSchemaError(ex.getKey(), ex.getArgs(), simpleContent);
546
535
            }
547
 
 
 
536
            
548
537
            // -----------------------------------------------------------------------
549
538
            // Traverse any attributes
550
539
            // -----------------------------------------------------------------------
553
542
                    fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
554
543
                    fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
555
544
                    throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
556
 
                             new Object[]{fName,DOMUtil.getLocalName(attrNode)},
557
 
                             attrNode);
 
545
                            new Object[]{fName,DOMUtil.getLocalName(attrNode)},
 
546
                            attrNode);
558
547
                }
559
548
                Element node=traverseAttrsAndAttrGrps(attrNode,fAttrGrp,
560
 
                                                      schemaDoc,grammar,fComplexTypeDecl);
 
549
                        schemaDoc,grammar,fComplexTypeDecl);
561
550
                if (node!=null) {
562
551
                    fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
563
552
                    fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
564
553
                    throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
565
 
                             new Object[]{fName,DOMUtil.getLocalName(node)},
566
 
                             node);
 
554
                            new Object[]{fName,DOMUtil.getLocalName(node)},
 
555
                            node);
567
556
                }
568
557
            }
569
 
 
 
558
            
570
559
            try {
571
560
                mergeAttributes(baseComplexType.getAttrGrp(), fAttrGrp, fName, false, simpleContentElement);
572
561
            } catch (ComplexTypeRecoverableError e) {
576
565
            }
577
566
            // Prohibited uses must be removed after merge for RESTRICTION
578
567
            fAttrGrp.removeProhibitedAttrs();
579
 
 
 
568
            
580
569
            Object[] errArgs=fAttrGrp.validRestrictionOf(fName, baseComplexType.getAttrGrp());
581
570
            if (errArgs != null) {
582
571
                fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
583
572
                fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
584
573
                throw new ComplexTypeRecoverableError((String)errArgs[errArgs.length-1],
585
 
                             errArgs, attrNode);
 
574
                        errArgs, attrNode);
586
575
            }
587
 
 
 
576
            
588
577
        }
589
578
        // -----------------------------------------------------------------------
590
579
        // Process a EXTENSION
600
589
                    fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
601
590
                    fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
602
591
                    throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
603
 
                                                          new Object[]{fName,DOMUtil.getLocalName(attrNode)},
604
 
                                                          attrNode);
 
592
                            new Object[]{fName,DOMUtil.getLocalName(attrNode)},
 
593
                            attrNode);
605
594
                }
606
595
                Element node=traverseAttrsAndAttrGrps(attrNode,fAttrGrp,
607
 
                                                      schemaDoc,grammar,fComplexTypeDecl);
608
 
 
 
596
                        schemaDoc,grammar,fComplexTypeDecl);
 
597
                
609
598
                if (node!=null) {
610
599
                    fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
611
600
                    fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
612
601
                    throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
613
 
                                                          new Object[]{fName,DOMUtil.getLocalName(node)},
614
 
                                                          node);
 
602
                            new Object[]{fName,DOMUtil.getLocalName(node)},
 
603
                            node);
615
604
                }
616
605
                // Remove prohibited uses.   Should be done prior to any merge.
617
606
                fAttrGrp.removeProhibitedAttrs();
618
607
            }
619
 
 
 
608
            
620
609
            if (baseComplexType != null) {
621
610
                try {
622
611
                    mergeAttributes(baseComplexType.getAttrGrp(), fAttrGrp, fName, true, simpleContentElement);
632
621
        fAttrChecker.returnAttrArray(simpleContentAttrValues, schemaDoc);
633
622
        fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
634
623
    }
635
 
 
 
624
    
636
625
    private void traverseComplexContent(Element complexContentElement,
637
 
                                        boolean mixedOnType, XSDocumentInfo schemaDoc,
638
 
                                        SchemaGrammar grammar)
 
626
            boolean mixedOnType, XSDocumentInfo schemaDoc,
 
627
            SchemaGrammar grammar)
639
628
    throws ComplexTypeRecoverableError {
640
 
 
641
 
 
 
629
        
 
630
        
642
631
        Object[] complexContentAttrValues = fAttrChecker.checkAttributes(complexContentElement, false,
643
 
                                                           schemaDoc);
644
 
 
645
 
 
 
632
                schemaDoc);
 
633
        
 
634
        
646
635
        // -----------------------------------------------------------------------
647
636
        // Determine if this is mixed content
648
637
        // -----------------------------------------------------------------------
651
640
        if (mixedAtt != null) {
652
641
            mixedContent = mixedAtt.booleanValue();
653
642
        }
654
 
 
655
 
 
 
643
        
 
644
        
656
645
        // -----------------------------------------------------------------------
657
646
        // Since the type must have complex content, set the simple type validators
658
647
        // to null
659
648
        // -----------------------------------------------------------------------
660
649
        fXSSimpleType = null;
661
 
 
 
650
        
662
651
        Element complexContent = DOMUtil.getFirstChildElement(complexContentElement);
663
 
        if (complexContent != null) {
664
 
            // traverse annotation if any
665
 
            if (DOMUtil.getLocalName(complexContent).equals(SchemaSymbols.ELT_ANNOTATION)) {
666
 
                addAnnotation(traverseAnnotationDecl(complexContent, complexContentAttrValues, false, schemaDoc));
667
 
                complexContent = DOMUtil.getNextSiblingElement(complexContent);
 
652
        if (complexContent != null && DOMUtil.getLocalName(complexContent).equals(SchemaSymbols.ELT_ANNOTATION)) {
 
653
            addAnnotation(traverseAnnotationDecl(complexContent, complexContentAttrValues, false, schemaDoc));
 
654
            complexContent = DOMUtil.getNextSiblingElement(complexContent);
 
655
        }
 
656
        else {
 
657
            String text = DOMUtil.getSyntheticAnnotation(complexContentElement);
 
658
            if (text != null) {
 
659
                addAnnotation(traverseSyntheticAnnotation(complexContentElement, text, complexContentAttrValues, false, schemaDoc));
668
660
            }
669
661
        }
670
 
 
 
662
        
671
663
        // If there are no children, return
672
664
        if (complexContent==null) {
673
665
            fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
674
666
            throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.2",
675
 
                      new Object[]{fName,SchemaSymbols.ELT_COMPLEXCONTENT},
676
 
                      complexContentElement);
 
667
                    new Object[]{fName,SchemaSymbols.ELT_COMPLEXCONTENT},
 
668
                    complexContentElement);
677
669
        }
678
 
 
 
670
        
679
671
        // -----------------------------------------------------------------------
680
672
        // The content should be either "restriction" or "extension"
681
673
        // -----------------------------------------------------------------------
687
679
        else {
688
680
            fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
689
681
            throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
690
 
                      new Object[]{fName, complexContentName}, complexContent);
 
682
                    new Object[]{fName, complexContentName}, complexContent);
691
683
        }
692
684
        Element elemTmp = DOMUtil.getNextSiblingElement(complexContent);
693
685
        if (elemTmp != null) {
694
686
            fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
695
687
            String siblingName = DOMUtil.getLocalName(elemTmp);
696
688
            throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
697
 
                      new Object[]{fName, siblingName}, elemTmp);
 
689
                    new Object[]{fName, siblingName}, elemTmp);
698
690
        }
699
 
 
 
691
        
700
692
        Object[] derivationTypeAttrValues = fAttrChecker.checkAttributes(complexContent, false,
701
 
                                                  schemaDoc);
 
693
                schemaDoc);
702
694
        QName baseTypeName = (QName)  derivationTypeAttrValues[XSAttributeChecker.ATTIDX_BASE];
703
 
 
704
 
 
 
695
        
 
696
        
705
697
        // -----------------------------------------------------------------------
706
698
        // Need a base type.  Check that it's a complex type
707
699
        // -----------------------------------------------------------------------
709
701
            fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
710
702
            fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
711
703
            throw new ComplexTypeRecoverableError("s4s-att-must-appear",
712
 
                      new Object[]{complexContentName, "base"}, complexContent);
 
704
                    new Object[]{complexContentName, "base"}, complexContent);
713
705
        }
714
 
 
 
706
        
715
707
        XSTypeDefinition type = (XSTypeDefinition)fSchemaHandler.getGlobalDecl(schemaDoc,
716
 
                                                                   XSDHandler.TYPEDECL_TYPE,
717
 
                                                                   baseTypeName,
718
 
                                                                   complexContent);
719
 
 
 
708
                XSDHandler.TYPEDECL_TYPE,
 
709
                baseTypeName,
 
710
                complexContent);
 
711
        
720
712
        if (type==null) {
721
713
            fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
722
714
            fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
723
715
            throw new ComplexTypeRecoverableError();
724
716
        }
725
 
 
 
717
        
726
718
        if (! (type instanceof XSComplexTypeDecl)) {
727
719
            fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
728
720
            fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
729
721
            throw new ComplexTypeRecoverableError("src-ct.1",
730
 
                      new Object[]{fName, type.getName()}, complexContent);
 
722
                    new Object[]{fName, type.getName()}, complexContent);
731
723
        }
732
724
        XSComplexTypeDecl baseType = (XSComplexTypeDecl)type;
733
725
        fBaseType = baseType;
734
 
 
 
726
        
735
727
        // -----------------------------------------------------------------------
736
728
        // Check that the base permits the derivation
737
729
        // -----------------------------------------------------------------------
739
731
            fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
740
732
            fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
741
733
            String errorKey = (fDerivedBy==XSConstants.DERIVATION_EXTENSION) ?
742
 
                              "cos-ct-extends.1.1" : "derivation-ok-restriction.1";
 
734
                    "cos-ct-extends.1.1" : "derivation-ok-restriction.1";
743
735
            throw new ComplexTypeRecoverableError(errorKey,
744
 
                                new Object[]{fName, fBaseType.getName()}, complexContent);
 
736
                    new Object[]{fName, fBaseType.getName()}, complexContent);
745
737
        }
746
 
 
 
738
        
747
739
        // -----------------------------------------------------------------------
748
740
        // Skip over any potential annotations
749
741
        // -----------------------------------------------------------------------
750
742
        complexContent = DOMUtil.getFirstChildElement(complexContent);
751
 
 
 
743
        
752
744
        if (complexContent != null) {
753
745
            // traverse annotation if any
754
746
            if (DOMUtil.getLocalName(complexContent).equals(SchemaSymbols.ELT_ANNOTATION)) {
755
747
                addAnnotation(traverseAnnotationDecl(complexContent, derivationTypeAttrValues, false, schemaDoc));
756
748
                complexContent = DOMUtil.getNextSiblingElement(complexContent);
757
749
            }
 
750
            else {
 
751
                String text = DOMUtil.getSyntheticAnnotation(complexContent);
 
752
                if (text != null) {
 
753
                    addAnnotation(traverseSyntheticAnnotation(complexContent, text, derivationTypeAttrValues, false, schemaDoc));
 
754
                }
 
755
            }
758
756
            if (complexContent !=null &&
759
 
                DOMUtil.getLocalName(complexContent).equals(SchemaSymbols.ELT_ANNOTATION)){
 
757
                    DOMUtil.getLocalName(complexContent).equals(SchemaSymbols.ELT_ANNOTATION)){
760
758
                fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
761
759
                fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
762
760
                throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
763
 
                       new Object[]{fName,SchemaSymbols.ELT_ANNOTATION}, complexContent);
 
761
                        new Object[]{fName,SchemaSymbols.ELT_ANNOTATION}, complexContent);
 
762
            }
 
763
        }
 
764
        else {
 
765
            String text = DOMUtil.getSyntheticAnnotation(complexContent);
 
766
            if (text != null) {
 
767
                addAnnotation(traverseSyntheticAnnotation(complexContent, text, derivationTypeAttrValues, false, schemaDoc));
764
768
            }
765
769
        }
766
770
        // -----------------------------------------------------------------------
769
773
        // -----------------------------------------------------------------------
770
774
        try {
771
775
            processComplexContent(complexContent, mixedContent, true, schemaDoc,
772
 
                              grammar);
 
776
                    grammar);
773
777
        } catch (ComplexTypeRecoverableError e) {
774
778
            fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
775
779
            fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
776
780
            throw e;
777
781
        }
778
 
 
 
782
        
779
783
        // -----------------------------------------------------------------------
780
784
        // Compose the final content and attribute uses
781
785
        // -----------------------------------------------------------------------
782
786
        XSParticleDecl baseContent = (XSParticleDecl)baseType.getParticle();
783
787
        if (fDerivedBy==XSConstants.DERIVATION_RESTRICTION) {
784
 
 
 
788
            
785
789
            // This is an RESTRICTION
786
 
 
 
790
            
787
791
            // N.B. derivation-ok-restriction.5.3 is checked under schema
788
792
            // full checking.   That's because we need to wait until locals are
789
793
            // traversed so that occurrence information is correct.
790
 
 
791
 
 
 
794
            
 
795
            
792
796
            if (fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED &&
793
 
                baseType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_MIXED) {
 
797
                    baseType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_MIXED) {
794
798
                fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
795
799
                fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
796
800
                throw new ComplexTypeRecoverableError("derivation-ok-restriction.5.4.1.2",
797
 
                                          new Object[]{fName, baseType.getName()},
798
 
                                                       complexContent);
 
801
                        new Object[]{fName, baseType.getName()},
 
802
                        complexContent);
799
803
            }
800
 
 
 
804
            
801
805
            try {
802
806
                mergeAttributes(baseType.getAttrGrp(), fAttrGrp, fName, false, complexContent);
803
807
            } catch (ComplexTypeRecoverableError e) {
807
811
            }
808
812
            // Remove prohibited uses.   Must be done after merge for RESTRICTION.
809
813
            fAttrGrp.removeProhibitedAttrs();
810
 
 
 
814
            
811
815
            if (baseType != SchemaGrammar.fAnyType) {
812
816
                Object[] errArgs = fAttrGrp.validRestrictionOf(fName, baseType.getAttrGrp());
813
817
                if (errArgs != null) {
814
818
                    fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
815
819
                    fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
816
820
                    throw new ComplexTypeRecoverableError((String)errArgs[errArgs.length-1],
817
 
                                                          errArgs, complexContent);
 
821
                            errArgs, complexContent);
818
822
                }
819
823
            }
820
824
        }
821
825
        else {
822
 
 
 
826
            
823
827
            // This is an EXTENSION
824
 
 
 
828
            
825
829
            // Create the particle
826
830
            if (fParticle == null) {
827
831
                fContentType = baseType.getContentType();
835
839
                // Check if the contentType of the base is consistent with the new type
836
840
                // cos-ct-extends.1.4.3.2
837
841
                if (fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT &&
838
 
                    baseType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_ELEMENT) {
 
842
                        baseType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_ELEMENT) {
839
843
                    fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
840
844
                    fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
841
845
                    throw new ComplexTypeRecoverableError("cos-ct-extends.1.4.3.2.2.1.a",
842
846
                            new Object[]{fName}, complexContent);
843
847
                }
844
848
                else if (fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED &&
845
 
                         baseType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_MIXED) {
 
849
                        baseType.getContentType() != XSComplexTypeDecl.CONTENTTYPE_MIXED) {
846
850
                    fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
847
851
                    fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
848
852
                    throw new ComplexTypeRecoverableError("cos-ct-extends.1.4.3.2.2.1.b",
849
853
                            new Object[]{fName}, complexContent);
850
854
                }
851
 
 
 
855
                
852
856
                // if the content of either type is an "all" model group, error.
853
857
                if (fParticle.fType == XSParticleDecl.PARTICLE_MODELGROUP &&
854
858
                        ((XSModelGroupImpl)fParticle.fValue).fCompositor == XSModelGroupImpl.MODELGROUP_ALL ||
866
870
                group.fParticles = new XSParticleDecl[2];
867
871
                group.fParticles[0] = (XSParticleDecl)baseType.getParticle();
868
872
                group.fParticles[1] = fParticle;
 
873
                group.fAnnotations = XSObjectListImpl.EMPTY_LIST;
869
874
                // the particle to contain the above sequence
870
875
                XSParticleDecl particle = new XSParticleDecl();
871
876
                particle.fType = XSParticleDecl.PARTICLE_MODELGROUP;
872
877
                particle.fValue = group;
873
 
 
 
878
                particle.fAnnotations = fParticle.getAnnotations(); 
 
879
                
874
880
                fParticle = particle;
875
881
            }
876
 
 
 
882
            
877
883
            // Remove prohibited uses.   Must be done before merge for EXTENSION.
878
884
            fAttrGrp.removeProhibitedAttrs();
879
885
            try {
880
 
            mergeAttributes(baseType.getAttrGrp(), fAttrGrp, fName, true, complexContent);
 
886
                mergeAttributes(baseType.getAttrGrp(), fAttrGrp, fName, true, complexContent);
881
887
            } catch (ComplexTypeRecoverableError e) {
882
888
                fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
883
889
                fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
884
890
                throw e;
885
891
            }
886
 
 
 
892
            
887
893
        }
888
 
 
 
894
        
889
895
        // and *finally* we can legitimately return the attributes!
890
896
        fAttrChecker.returnAttrArray(complexContentAttrValues, schemaDoc);
891
897
        fAttrChecker.returnAttrArray(derivationTypeAttrValues, schemaDoc);
892
 
 
 
898
        
893
899
    } // end of traverseComplexContent
894
 
 
895
 
 
 
900
    
 
901
    
896
902
    // This method merges attribute uses from the base, into the derived set.
897
903
    // The first duplicate attribute, if any, is returned.
898
904
    // LM: may want to merge with attributeGroup processing.
899
905
    private void mergeAttributes(XSAttributeGroupDecl fromAttrGrp,
900
 
                                 XSAttributeGroupDecl toAttrGrp,
901
 
                                 String typeName,
902
 
                                 boolean extension,
903
 
                                 Element elem)
 
906
            XSAttributeGroupDecl toAttrGrp,
 
907
            String typeName,
 
908
            boolean extension,
 
909
            Element elem)
904
910
    throws ComplexTypeRecoverableError {
905
 
 
 
911
        
906
912
        XSObjectList attrUseS = fromAttrGrp.getAttributeUses();
907
913
        XSAttributeUseImpl  duplicateAttrUse =  null, oneAttrUse = null;
908
914
        int attrCount = attrUseS.getLength();
909
915
        for (int i=0; i<attrCount; i++) {
910
916
            oneAttrUse = (XSAttributeUseImpl)attrUseS.item(i);
911
917
            XSAttributeUse existingAttrUse = toAttrGrp.getAttributeUse(oneAttrUse.fAttrDecl.getNamespace(),
912
 
                                                        oneAttrUse.fAttrDecl.getName());
 
918
                    oneAttrUse.fAttrDecl.getName());
913
919
            if (existingAttrUse == null) {
914
 
 
 
920
                
915
921
                String idName = toAttrGrp.addAttributeUse(oneAttrUse);
916
922
                if (idName != null) {
917
923
                    throw new ComplexTypeRecoverableError("ct-props-correct.5",
918
 
                          new Object[]{typeName, idName, oneAttrUse.fAttrDecl.getName()},
919
 
                          elem);
 
924
                            new Object[]{typeName, idName, oneAttrUse.fAttrDecl.getName()},
 
925
                            elem);
920
926
                }
921
927
            }
922
928
            else {
923
929
                if (extension) {
924
930
                    throw new ComplexTypeRecoverableError("ct-props-correct.4",
925
 
                          new Object[]{typeName, oneAttrUse.fAttrDecl.getName()},
926
 
                          elem);
 
931
                            new Object[]{typeName, oneAttrUse.fAttrDecl.getName()},
 
932
                            elem);
927
933
                }
928
934
            }
929
935
        }
935
941
            else if (fromAttrGrp.fAttributeWC != null) {
936
942
                toAttrGrp.fAttributeWC = toAttrGrp.fAttributeWC.performUnionWith(fromAttrGrp.fAttributeWC, toAttrGrp.fAttributeWC.fProcessContents);
937
943
            }
938
 
 
 
944
            
939
945
        }
940
946
    }
941
 
 
 
947
    
942
948
    private void processComplexContent(Element complexContentChild,
943
 
                                       boolean isMixed, boolean isDerivation,
944
 
                                       XSDocumentInfo schemaDoc, SchemaGrammar grammar)
 
949
            boolean isMixed, boolean isDerivation,
 
950
            XSDocumentInfo schemaDoc, SchemaGrammar grammar)
945
951
    throws ComplexTypeRecoverableError {
946
 
 
 
952
        
947
953
        Element attrNode = null;
948
954
        XSParticleDecl particle = null;
949
 
 
 
955
        
950
956
        // whether there is a particle with empty model group
951
957
        boolean emptyParticle = false;
952
958
        if (complexContentChild != null) {
954
960
            // GROUP, ALL, SEQUENCE or CHOICE, followed by attributes, if specified.
955
961
            // Note that it's possible that only attributes are specified.
956
962
            // -------------------------------------------------------------
957
 
 
958
 
 
 
963
            
 
964
            
959
965
            String childName = DOMUtil.getLocalName(complexContentChild);
960
 
 
 
966
            
961
967
            if (childName.equals(SchemaSymbols.ELT_GROUP)) {
962
 
 
 
968
                
963
969
                particle = fSchemaHandler.fGroupTraverser.traverseLocal(complexContentChild,
964
 
                                                                        schemaDoc, grammar);
 
970
                        schemaDoc, grammar);
965
971
                attrNode = DOMUtil.getNextSiblingElement(complexContentChild);
966
972
            }
967
973
            else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) {
968
974
                particle = traverseSequence(complexContentChild,schemaDoc,grammar,
969
 
                                            NOT_ALL_CONTEXT,fComplexTypeDecl);
 
975
                        NOT_ALL_CONTEXT,fComplexTypeDecl);
970
976
                if (particle != null) {
971
977
                    XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue;
972
978
                    if (group.fParticleCount == 0)
976
982
            }
977
983
            else if (childName.equals(SchemaSymbols.ELT_CHOICE)) {
978
984
                particle = traverseChoice(complexContentChild,schemaDoc,grammar,
979
 
                                          NOT_ALL_CONTEXT,fComplexTypeDecl);
 
985
                        NOT_ALL_CONTEXT,fComplexTypeDecl);
980
986
                if (particle != null && particle.fMinOccurs == 0) {
981
987
                    XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue;
982
988
                    if (group.fParticleCount == 0)
986
992
            }
987
993
            else if (childName.equals(SchemaSymbols.ELT_ALL)) {
988
994
                particle = traverseAll(complexContentChild,schemaDoc,grammar,
989
 
                                       PROCESSING_ALL_GP,fComplexTypeDecl);
 
995
                        PROCESSING_ALL_GP,fComplexTypeDecl);
990
996
                if (particle != null) {
991
997
                    XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue;
992
998
                    if (group.fParticleCount == 0)
999
1005
                attrNode = complexContentChild;
1000
1006
            }
1001
1007
        }
1002
 
 
 
1008
        
1003
1009
        // if the particle is empty because there is no non-annotation chidren,
1004
1010
        // we need to make the particle itself null (so that the effective
1005
1011
        // content is empty).
1018
1024
            // child != null means we might have seen an element with
1019
1025
            // minOccurs == maxOccurs == 0
1020
1026
        }
1021
 
 
 
1027
        
1022
1028
        if (particle == null && isMixed) {
1023
1029
            if (fEmptyParticle == null) {
1024
1030
                XSModelGroupImpl group = new XSModelGroupImpl();
1025
1031
                group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
1026
1032
                group.fParticleCount = 0;
1027
1033
                group.fParticles = null;
 
1034
                group.fAnnotations = XSObjectListImpl.EMPTY_LIST;
1028
1035
                fEmptyParticle = new XSParticleDecl();
1029
1036
                fEmptyParticle.fType = XSParticleDecl.PARTICLE_MODELGROUP;
1030
1037
                fEmptyParticle.fValue = group;
 
1038
                fEmptyParticle.fAnnotations = XSObjectListImpl.EMPTY_LIST;
1031
1039
            }
1032
1040
            particle = fEmptyParticle;
1033
1041
        }
1034
1042
        fParticle = particle;
1035
 
 
 
1043
        
1036
1044
        // -----------------------------------------------------------------------
1037
1045
        // Set the content type
1038
1046
        // -----------------------------------------------------------------------
1042
1050
            fContentType = XSComplexTypeDecl.CONTENTTYPE_MIXED;
1043
1051
        else
1044
1052
            fContentType = XSComplexTypeDecl.CONTENTTYPE_ELEMENT;
1045
 
 
1046
 
 
 
1053
        
 
1054
        
1047
1055
        // -------------------------------------------------------------
1048
1056
        // Now, process attributes
1049
1057
        // -------------------------------------------------------------
1050
1058
        if (attrNode != null) {
1051
1059
            if (!isAttrOrAttrGroup(attrNode)) {
1052
1060
                throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
1053
 
                                                      new Object[]{fName,DOMUtil.getLocalName(attrNode)},
1054
 
                                                      attrNode);
 
1061
                        new Object[]{fName,DOMUtil.getLocalName(attrNode)},
 
1062
                        attrNode);
1055
1063
            }
1056
1064
            Element node =
1057
 
            traverseAttrsAndAttrGrps(attrNode,fAttrGrp,schemaDoc,grammar,fComplexTypeDecl);
 
1065
                traverseAttrsAndAttrGrps(attrNode,fAttrGrp,schemaDoc,grammar,fComplexTypeDecl);
1058
1066
            if (node!=null) {
1059
1067
                throw new ComplexTypeRecoverableError("s4s-elt-invalid-content.1",
1060
 
                                                      new Object[]{fName,DOMUtil.getLocalName(node)},
1061
 
                                                      node);
 
1068
                        new Object[]{fName,DOMUtil.getLocalName(node)},
 
1069
                        node);
1062
1070
            }
1063
1071
            // Only remove prohibited attribute uses if this isn't a derived type
1064
1072
            // Derivation-specific code worries about this elsewhere
1066
1074
                fAttrGrp.removeProhibitedAttrs();
1067
1075
            }
1068
1076
        }
1069
 
 
1070
 
 
1071
 
 
 
1077
        
 
1078
        
 
1079
        
1072
1080
    } // end processComplexContent
1073
 
 
1074
 
 
 
1081
    
 
1082
    
1075
1083
    private boolean isAttrOrAttrGroup(Element e) {
1076
1084
        String elementName = DOMUtil.getLocalName(e);
1077
 
 
 
1085
        
1078
1086
        if (elementName.equals(SchemaSymbols.ELT_ATTRIBUTE) ||
1079
 
            elementName.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP) ||
1080
 
            elementName.equals(SchemaSymbols.ELT_ANYATTRIBUTE))
 
1087
                elementName.equals(SchemaSymbols.ELT_ATTRIBUTEGROUP) ||
 
1088
                elementName.equals(SchemaSymbols.ELT_ANYATTRIBUTE))
1081
1089
            return true;
1082
1090
        else
1083
1091
            return false;
1084
1092
    }
1085
 
 
 
1093
    
1086
1094
    private void traverseSimpleContentDecl(Element simpleContentDecl) {
1087
1095
    }
1088
 
 
 
1096
    
1089
1097
    private void traverseComplexContentDecl(Element complexContentDecl,
1090
 
                                            boolean mixedOnComplexTypeDecl) {
 
1098
            boolean mixedOnComplexTypeDecl) {
1091
1099
    }
1092
 
 
 
1100
    
1093
1101
    /*
1094
1102
     * Generate a name for an anonymous type
1095
1103
     */
1096
1104
    private String genAnonTypeName(Element complexTypeDecl) {
1097
 
 
 
1105
        
1098
1106
        // Generate a unique name for the anonymous type by concatenating together the
1099
1107
        // names of parent nodes
1100
1108
        // The name is quite good for debugging/error purposes, but we may want to
1101
1109
        // revisit how this is done for performance reasons (LM).
1102
 
        String typeName;
 
1110
        StringBuffer typeName = new StringBuffer("#AnonType_");
1103
1111
        Element node = DOMUtil.getParent(complexTypeDecl);
1104
 
        typeName="#AnonType_";
1105
1112
        while (node != null && (node != DOMUtil.getRoot(DOMUtil.getDocument(node)))) {
1106
 
            typeName = typeName+node.getAttribute(SchemaSymbols.ATT_NAME);
 
1113
            typeName.append(node.getAttribute(SchemaSymbols.ATT_NAME));
1107
1114
            node = DOMUtil.getParent(node);
1108
1115
        }
1109
 
        return typeName;
 
1116
        return typeName.toString();
1110
1117
    }
1111
 
 
1112
 
 
 
1118
    
 
1119
    
1113
1120
    private void handleComplexTypeError(String messageId,Object[] args,
1114
 
                                        Element e) {
1115
 
 
 
1121
            Element e) {
 
1122
        
1116
1123
        if (messageId!=null) {
1117
1124
            reportSchemaError(messageId, args, e);
1118
1125
        }
1119
 
 
 
1126
        
1120
1127
        //
1121
1128
        //  Mock up the typeInfo structure so that there won't be problems during
1122
1129
        //  validation
1127
1134
        // REVISIT: do we need to remove all attribute uses already added into
1128
1135
        // the attribute group? maybe it's ok to leave them there. -SG
1129
1136
        fAttrGrp.fAttributeWC = getErrorWildcard();
1130
 
 
 
1137
        
1131
1138
        return;
1132
 
 
 
1139
        
1133
1140
    }
1134
 
 
 
1141
    
1135
1142
    private XSParticleDecl getErrorContent() {
1136
1143
        XSParticleDecl particle = new XSParticleDecl();
1137
1144
        particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
1146
1153
        XSParticleDecl errorContent = new XSParticleDecl();
1147
1154
        errorContent.fType = XSParticleDecl.PARTICLE_MODELGROUP;
1148
1155
        errorContent.fValue = group;
1149
 
 
 
1156
        
1150
1157
        return errorContent;
1151
1158
    }
1152
 
 
 
1159
    
1153
1160
    private XSWildcardDecl getErrorWildcard() {
1154
1161
        XSWildcardDecl errorWildcard = new XSWildcardDecl();
1155
1162
        errorWildcard.fProcessContents = XSWildcardDecl.PC_SKIP;
1156
1163
        return errorWildcard;
1157
1164
    }
1158
 
 
 
1165
    
1159
1166
    private void contentBackup() {
1160
1167
        if(fGlobalStore == null) {
1161
1168
            fGlobalStore = new Object [GLOBAL_NUM];
1179
1186
        fGlobalStore[fGlobalStorePos++] = fXSSimpleType;
1180
1187
        fGlobalStore[fGlobalStorePos++] = fAnnotations;
1181
1188
    }
1182
 
 
 
1189
    
1183
1190
    private void contentRestore() {
1184
1191
        fAnnotations = (XSAnnotationImpl [])fGlobalStore[--fGlobalStorePos];
1185
1192
        fXSSimpleType = (XSSimpleType)fGlobalStore[--fGlobalStorePos];
1197
1204
        fIsAbstract = ((Boolean)fGlobalStore[--fGlobalStorePos]).booleanValue();
1198
1205
        fComplexTypeDecl = (XSComplexTypeDecl)fGlobalStore[--fGlobalStorePos];
1199
1206
    }
1200
 
 
 
1207
    
1201
1208
    private void addAnnotation(XSAnnotationImpl annotation) {
1202
1209
        if(annotation == null)
1203
1210
            return;