~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xerces-2_9_1/src/org/apache/xerces/impl/xs/XSComplexTypeDecl.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 * contributor license agreements.  See the NOTICE file distributed with
 
4
 * this work for additional information regarding copyright ownership.
 
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 * (the "License"); you may not use this file except in compliance with
 
7
 * the License.  You may obtain a copy of the License at
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
11
 * Unless required by applicable law or agreed to in writing, software
 
12
 * distributed under the License is distributed on an "AS IS" BASIS,
 
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 * See the License for the specific language governing permissions and
 
15
 * limitations under the License.
 
16
 */
 
17
 
 
18
package org.apache.xerces.impl.xs;
 
19
 
 
20
import org.apache.xerces.impl.dv.XSSimpleType;
 
21
import org.apache.xerces.xs.*;
 
22
import org.apache.xerces.impl.xs.models.XSCMValidator;
 
23
import org.apache.xerces.impl.xs.models.CMBuilder;
 
24
import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 
25
import org.apache.xerces.impl.dv.xs.XSSimpleTypeDecl;
 
26
import org.w3c.dom.TypeInfo;
 
27
 
 
28
/**
 
29
 * The XML representation for a complexType
 
30
 * schema component is a <complexType> element information item
 
31
 *
 
32
 * @xerces.internal 
 
33
 *
 
34
 * @author Elena Litani, IBM
 
35
 * @author Sandy Gao, IBM
 
36
 * @version $Id: XSComplexTypeDecl.java,v 1.2 2009/12/10 03:18:27 matthewoliver Exp $
 
37
 */
 
38
public class XSComplexTypeDecl implements XSComplexTypeDefinition, TypeInfo {
 
39
 
 
40
    // name of the complexType
 
41
    String fName = null;
 
42
 
 
43
    // target namespace of the complexType
 
44
    String fTargetNamespace = null;
 
45
 
 
46
    // base type of the complexType
 
47
    XSTypeDefinition fBaseType = null;
 
48
 
 
49
    // derivation method of the complexType
 
50
    short fDerivedBy = XSConstants.DERIVATION_RESTRICTION;
 
51
 
 
52
    // final set of the complexType
 
53
    short fFinal = XSConstants.DERIVATION_NONE;
 
54
 
 
55
    // block set (prohibited substitution) of the complexType
 
56
    short fBlock = XSConstants.DERIVATION_NONE;
 
57
 
 
58
    // flags: whether is abstract; whether contains ID type;
 
59
    //        whether it's an anonymous tpye
 
60
    short fMiscFlags = 0;
 
61
 
 
62
    // the attribute group that holds the attribute uses and attribute wildcard
 
63
    XSAttributeGroupDecl fAttrGrp = null;
 
64
 
 
65
    // the content type of the complexType
 
66
    short fContentType = CONTENTTYPE_EMPTY;
 
67
 
 
68
    // if the content type is simple, then the corresponding simpleType
 
69
    XSSimpleType fXSSimpleType = null;
 
70
 
 
71
    // if the content type is element or mixed, the particle
 
72
    XSParticleDecl fParticle = null;
 
73
 
 
74
    // if there is a particle, the content model corresponding to that particle
 
75
    XSCMValidator fCMValidator = null;
 
76
 
 
77
    // the content model that's sufficient for computing UPA
 
78
    XSCMValidator fUPACMValidator = null;
 
79
 
 
80
    // list of annotations affiliated with this type
 
81
    XSObjectListImpl fAnnotations = null;
 
82
 
 
83
    // DOM Level 3 TypeInfo Derivation Method constants
 
84
    static final int DERIVATION_ANY = 0;
 
85
    static final int DERIVATION_RESTRICTION = 1;
 
86
    static final int DERIVATION_EXTENSION = 2;
 
87
    static final int DERIVATION_UNION = 4;
 
88
    static final int DERIVATION_LIST = 8;
 
89
    
 
90
    public XSComplexTypeDecl() {
 
91
        // do-nothing constructor for now.
 
92
    }
 
93
 
 
94
    public void setValues(String name, String targetNamespace,
 
95
            XSTypeDefinition baseType, short derivedBy, short schemaFinal, 
 
96
            short block, short contentType,
 
97
            boolean isAbstract, XSAttributeGroupDecl attrGrp, 
 
98
            XSSimpleType simpleType, XSParticleDecl particle,
 
99
            XSObjectListImpl annotations) {
 
100
        fTargetNamespace = targetNamespace;
 
101
        fBaseType = baseType;
 
102
        fDerivedBy = derivedBy;
 
103
        fFinal = schemaFinal;
 
104
        fBlock = block;
 
105
        fContentType = contentType;
 
106
        if(isAbstract)
 
107
            fMiscFlags |= CT_IS_ABSTRACT;
 
108
        fAttrGrp = attrGrp;
 
109
        fXSSimpleType = simpleType;
 
110
        fParticle = particle;
 
111
        fAnnotations = annotations;
 
112
   }
 
113
 
 
114
   public void setName(String name) {
 
115
        fName = name;
 
116
   }
 
117
 
 
118
    public short getTypeCategory() {
 
119
        return COMPLEX_TYPE;
 
120
    }
 
121
 
 
122
    public String getTypeName() {
 
123
        return fName;
 
124
    }
 
125
 
 
126
    public short getFinalSet(){
 
127
        return fFinal;
 
128
    }
 
129
 
 
130
    public String getTargetNamespace(){
 
131
        return fTargetNamespace;
 
132
    }
 
133
 
 
134
    // flags for the misc flag
 
135
    private static final short CT_IS_ABSTRACT = 1;
 
136
    private static final short CT_HAS_TYPE_ID = 2;
 
137
    private static final short CT_IS_ANONYMOUS = 4;
 
138
 
 
139
    // methods to get/set misc flag
 
140
 
 
141
    public boolean containsTypeID () {
 
142
        return((fMiscFlags & CT_HAS_TYPE_ID) != 0);
 
143
    }
 
144
 
 
145
    public void setIsAbstractType() {
 
146
        fMiscFlags |= CT_IS_ABSTRACT;
 
147
    }
 
148
    public void setContainsTypeID() {
 
149
        fMiscFlags |= CT_HAS_TYPE_ID;
 
150
    }
 
151
    public void setIsAnonymous() {
 
152
        fMiscFlags |= CT_IS_ANONYMOUS;
 
153
    }
 
154
 
 
155
    public XSCMValidator getContentModel(CMBuilder cmBuilder) {
 
156
        return getContentModel(cmBuilder, false);
 
157
    }
 
158
 
 
159
    public synchronized XSCMValidator getContentModel(CMBuilder cmBuilder, boolean forUPA) {
 
160
        if (fCMValidator == null) {
 
161
            if (forUPA) {
 
162
                if (fUPACMValidator == null) {
 
163
                    fUPACMValidator = cmBuilder.getContentModel(this, true);
 
164
 
 
165
                    if (fUPACMValidator != null && !fUPACMValidator.isCompactedForUPA()) {
 
166
                        fCMValidator = fUPACMValidator;
 
167
                    }
 
168
                }
 
169
                return fUPACMValidator;
 
170
            }
 
171
            else {
 
172
                fCMValidator = cmBuilder.getContentModel(this, false);
 
173
            }
 
174
        }
 
175
 
 
176
        return fCMValidator;
 
177
    }
 
178
 
 
179
    // some utility methods:
 
180
 
 
181
    // return the attribute group for this complex type
 
182
    public XSAttributeGroupDecl getAttrGrp() {
 
183
        return fAttrGrp;
 
184
    }
 
185
 
 
186
    public String toString() {
 
187
        StringBuffer str = new StringBuffer();
 
188
        appendTypeInfo(str);
 
189
        return str.toString();
 
190
    }
 
191
 
 
192
    void appendTypeInfo(StringBuffer str) {
 
193
        String contentType[] = {"EMPTY", "SIMPLE", "ELEMENT", "MIXED"};
 
194
        String derivedBy[] = {"EMPTY", "EXTENSION", "RESTRICTION"};
 
195
 
 
196
        str.append("Complex type name='").append(fTargetNamespace).append(",").append(getTypeName()).append("', ");
 
197
        if (fBaseType != null) {
 
198
            str.append(" base type name='").append(fBaseType.getName()).append("', ");
 
199
        }
 
200
        str.append(" content type='").append(contentType[fContentType]).append("', ");
 
201
        str.append(" isAbstract='").append(getAbstract()).append("', ");
 
202
        str.append(" hasTypeId='").append(containsTypeID()).append("', ");
 
203
        str.append(" final='").append(fFinal).append("', ");
 
204
        str.append(" block='").append(fBlock).append("', ");
 
205
        if (fParticle != null) {
 
206
            str.append(" particle='").append(fParticle.toString()).append("', ");
 
207
        }
 
208
        str.append(" derivedBy='").append(derivedBy[fDerivedBy]).append("'. ");
 
209
 
 
210
    }
 
211
 
 
212
    public boolean derivedFromType(XSTypeDefinition ancestor, short derivationMethod) {
 
213
        // ancestor is null, retur false
 
214
        if (ancestor == null)
 
215
            return false;
 
216
        // ancestor is anyType, return true
 
217
        if (ancestor == SchemaGrammar.fAnyType)
 
218
            return true;
 
219
        // recursively get base, and compare it with ancestor
 
220
        XSTypeDefinition type = this;
 
221
        while (type != ancestor &&                     // compare with ancestor
 
222
               type != SchemaGrammar.fAnySimpleType &&  // reached anySimpleType
 
223
               type != SchemaGrammar.fAnyType) {        // reached anyType
 
224
            type = type.getBaseType();
 
225
        }
 
226
 
 
227
        return type == ancestor;
 
228
    }
 
229
 
 
230
    public boolean derivedFrom(String ancestorNS, String ancestorName, short derivationMethod) {
 
231
        // ancestor is null, retur false
 
232
        if (ancestorName == null)
 
233
            return false;
 
234
        // ancestor is anyType, return true
 
235
        if (ancestorNS != null &&
 
236
            ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) &&
 
237
            ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)) {
 
238
            return true;
 
239
        }
 
240
 
 
241
        // recursively get base, and compare it with ancestor
 
242
        XSTypeDefinition type = this;
 
243
        while (!(ancestorName.equals(type.getName()) &&
 
244
                 ((ancestorNS == null && type.getNamespace() == null) ||
 
245
                  (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) &&   // compare with ancestor
 
246
               type != SchemaGrammar.fAnySimpleType &&  // reached anySimpleType
 
247
               type != SchemaGrammar.fAnyType) {        // reached anyType
 
248
            type = (XSTypeDefinition)type.getBaseType();
 
249
        }
 
250
 
 
251
        return type != SchemaGrammar.fAnySimpleType &&
 
252
        type != SchemaGrammar.fAnyType;
 
253
    }
 
254
 
 
255
    /**
 
256
     * Checks if a type is derived from another given the the name, namespace
 
257
     * and derivation method. See:
 
258
     * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#TypeInfo-isDerivedFrom
 
259
     * 
 
260
     * @param ancestorNS
 
261
     *            The namspace of the ancestor type declaration
 
262
     * @param ancestorName
 
263
     *            The name of the ancestor type declaration
 
264
     * @param derivationMethod
 
265
     *            The derivation method
 
266
     * 
 
267
     * @return boolean True if the ancestor type is derived from the reference
 
268
     *         type by the specifiied derivation method.
 
269
     */
 
270
    public boolean isDOMDerivedFrom(String ancestorNS, String ancestorName,
 
271
            int derivationMethod) {
 
272
        // ancestor is null, retur false
 
273
        if (ancestorName == null)
 
274
            return false;
 
275
        
 
276
        // ancestor is anyType, return true
 
277
        if (ancestorNS != null
 
278
                && ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)
 
279
                && ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)
 
280
                && (derivationMethod == DERIVATION_RESTRICTION 
 
281
                && derivationMethod == DERIVATION_EXTENSION)) {
 
282
            return true;
 
283
        }
 
284
        
 
285
        // restriction
 
286
        if ((derivationMethod & DERIVATION_RESTRICTION) != 0) {
 
287
            if (isDerivedByRestriction(ancestorNS, ancestorName,
 
288
                    derivationMethod, this)) {
 
289
                return true;
 
290
            }
 
291
        }
 
292
        
 
293
        // extension
 
294
        if ((derivationMethod & DERIVATION_EXTENSION) != 0) {
 
295
            if (isDerivedByExtension(ancestorNS, ancestorName,
 
296
                    derivationMethod, this)) {
 
297
                return true;
 
298
            }
 
299
        }
 
300
        
 
301
        // list or union
 
302
        if ((((derivationMethod & DERIVATION_LIST) != 0) || ((derivationMethod & DERIVATION_UNION) != 0))
 
303
                && ((derivationMethod & DERIVATION_RESTRICTION) == 0)
 
304
                && ((derivationMethod & DERIVATION_EXTENSION) == 0)) {
 
305
 
 
306
            if (ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)
 
307
                    && ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)) {
 
308
                ancestorName = SchemaSymbols.ATTVAL_ANYSIMPLETYPE;
 
309
            }
 
310
 
 
311
            if(!(fName.equals(SchemaSymbols.ATTVAL_ANYTYPE) 
 
312
                            && fTargetNamespace.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA))){
 
313
                if (fBaseType != null && fBaseType instanceof XSSimpleTypeDecl) {
 
314
                    
 
315
                    return ((XSSimpleTypeDecl) fBaseType).isDOMDerivedFrom(ancestorNS,
 
316
                            ancestorName, derivationMethod);
 
317
                } else if (fBaseType != null
 
318
                        && fBaseType instanceof XSComplexTypeDecl) {
 
319
                    return ((XSComplexTypeDecl) fBaseType).isDOMDerivedFrom(
 
320
                            ancestorNS, ancestorName, derivationMethod);
 
321
                }
 
322
            }
 
323
        }
 
324
        
 
325
        // If the value of the parameter is 0 i.e. no bit (corresponding to
 
326
        // restriction, list, extension or union) is set to 1 for the 
 
327
        // derivationMethod parameter.   
 
328
        if (((derivationMethod  & DERIVATION_EXTENSION) == 0)
 
329
                && (((derivationMethod & DERIVATION_RESTRICTION) == 0)
 
330
                        && ((derivationMethod & DERIVATION_LIST) == 0) 
 
331
                        && ((derivationMethod & DERIVATION_UNION) == 0))) {
 
332
            return isDerivedByAny(ancestorNS, ancestorName, derivationMethod, this);
 
333
        }
 
334
 
 
335
        return false;
 
336
    }
 
337
    
 
338
    /**
 
339
     * Checks if a type is derived from another by any combination of
 
340
     * restriction, list ir union. See:
 
341
     * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#TypeInfo-isDerivedFrom
 
342
     * 
 
343
     * @param ancestorNS
 
344
     *            The namspace of the ancestor type declaration
 
345
     * @param ancestorName
 
346
     *            The name of the ancestor type declaration
 
347
     * @param derivationMethod
 
348
     *            A short indication the method of derivation
 
349
     * @param type
 
350
     *            The reference type definition
 
351
     * 
 
352
     * @return boolean True if the type is derived by any method for the
 
353
     *         reference type
 
354
     */
 
355
    private boolean isDerivedByAny(String ancestorNS, String ancestorName,
 
356
            int derivationMethod, XSTypeDefinition type) {
 
357
        XSTypeDefinition oldType = null;
 
358
        boolean derivedFrom = false;
 
359
        while (type != null && type != oldType) {
 
360
            
 
361
            // If the ancestor type is reached or is the same as this type.
 
362
            if ((ancestorName.equals(type.getName()))
 
363
                    && ((ancestorNS == null && type.getNamespace() == null) 
 
364
                        || (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) {
 
365
                derivedFrom = true;
 
366
                break;
 
367
            }
 
368
            
 
369
            // Check if this type is derived from the base by restriction or
 
370
            // extension
 
371
            if (isDerivedByRestriction(ancestorNS, ancestorName,
 
372
                    derivationMethod, type)) {
 
373
                return true;
 
374
            } else if (!isDerivedByExtension(ancestorNS, ancestorName,
 
375
                    derivationMethod, type)) {
 
376
                return true;
 
377
            }
 
378
            oldType = type;
 
379
            type = type.getBaseType();
 
380
        }
 
381
        
 
382
        return derivedFrom;
 
383
    }
 
384
    
 
385
    /**
 
386
     * Checks if a type is derived from another by restriction. See:
 
387
     * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#TypeInfo-isDerivedFrom
 
388
     * 
 
389
     * @param ancestorNS
 
390
     *            The namspace of the ancestor type declaration
 
391
     * @param ancestorName
 
392
     *            The name of the ancestor type declaration
 
393
     * @param derivationMethod
 
394
     *            A short indication the method of derivation *
 
395
     * @param type
 
396
     *            The reference type definition
 
397
     * 
 
398
     * @return boolean True if the type is derived by restriciton for the
 
399
     *         reference type
 
400
     */
 
401
    private boolean isDerivedByRestriction(String ancestorNS,
 
402
            String ancestorName, int derivationMethod, XSTypeDefinition type) {
 
403
        
 
404
        XSTypeDefinition oldType = null;
 
405
        while (type != null && type != oldType) {
 
406
            
 
407
            // ancestor is anySimpleType, return false
 
408
            if (ancestorNS != null
 
409
                    && ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)
 
410
                    && ancestorName.equals(SchemaSymbols.ATTVAL_ANYSIMPLETYPE)) {
 
411
                return false;
 
412
            }
 
413
            
 
414
            // if the name and namespace of this type is the same as the
 
415
            // ancestor return true
 
416
            if ((ancestorName.equals(type.getName()))
 
417
                    && (ancestorNS != null && ancestorNS.equals(type.getNamespace())) 
 
418
                            || ((type.getNamespace() == null && ancestorNS == null))) {
 
419
                
 
420
                return true;
 
421
            }
 
422
            
 
423
            // If the base type is a complexType with simpleContent
 
424
            if (type instanceof XSSimpleTypeDecl) {
 
425
                if (ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)
 
426
                        && ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)) {
 
427
                    ancestorName = SchemaSymbols.ATTVAL_ANYSIMPLETYPE;
 
428
                }
 
429
                return ((XSSimpleTypeDecl) type).isDOMDerivedFrom(ancestorNS,
 
430
                        ancestorName, derivationMethod);
 
431
            } else {
 
432
                // If the base type is a complex type
 
433
                // Every derivation step till the base type should be
 
434
                // restriction. If not return false
 
435
                if (((XSComplexTypeDecl) type).getDerivationMethod() != XSConstants.DERIVATION_RESTRICTION) {
 
436
                    return false;
 
437
                }
 
438
            }
 
439
            oldType = type;
 
440
            type = type.getBaseType();
 
441
            
 
442
        }
 
443
        
 
444
        return false;
 
445
    }
 
446
    
 
447
    /**
 
448
     * Checks if a type is derived from another by extension. See:
 
449
     * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#TypeInfo-isDerivedFrom
 
450
     * 
 
451
     * @param ancestorNS
 
452
     *            The namspace of the ancestor type declaration
 
453
     * @param ancestorName
 
454
     *            The name of the ancestor type declaration
 
455
     * @param derivationMethod
 
456
     *            A short indication the method of derivation
 
457
     * @param type
 
458
     *            The reference type definition
 
459
     * 
 
460
     * @return boolean True if the type is derived by extension for the
 
461
     *         reference type
 
462
     */
 
463
    private boolean isDerivedByExtension(String ancestorNS,
 
464
            String ancestorName, int derivationMethod, XSTypeDefinition type) {
 
465
        
 
466
        boolean extension = false;
 
467
        XSTypeDefinition oldType = null;
 
468
        while (type != null && type != oldType) {
 
469
            // If ancestor is anySimpleType return false.
 
470
            if (ancestorNS != null
 
471
                    && ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)
 
472
                    && ancestorName.equals(SchemaSymbols.ATTVAL_ANYSIMPLETYPE)
 
473
                    && SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(type.getNamespace())
 
474
                            && SchemaSymbols.ATTVAL_ANYTYPE.equals(type.getName())) {
 
475
                break;
 
476
            }
 
477
            
 
478
            if ((ancestorName.equals(type.getName()))
 
479
                    && ((ancestorNS == null && type.getNamespace() == null) 
 
480
                        || (ancestorNS != null && ancestorNS.equals(type.getNamespace())))) {
 
481
                // returns true if atleast one derivation step was extension
 
482
                return extension;
 
483
            }
 
484
            
 
485
            // If the base type is a complexType with simpleContent
 
486
            if (type instanceof XSSimpleTypeDecl) {
 
487
                if (ancestorNS.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)
 
488
                        && ancestorName.equals(SchemaSymbols.ATTVAL_ANYTYPE)) {
 
489
                    ancestorName = SchemaSymbols.ATTVAL_ANYSIMPLETYPE;
 
490
                }
 
491
                
 
492
                // derivationMethod extension will always return false for a
 
493
                // simpleType,
 
494
                // we treat it like a restriction
 
495
                if ((derivationMethod & DERIVATION_EXTENSION) != 0) {
 
496
                    return extension
 
497
                    & ((XSSimpleTypeDecl) type).isDOMDerivedFrom(
 
498
                            ancestorNS, ancestorName,
 
499
                            (derivationMethod & DERIVATION_RESTRICTION));
 
500
                } else {
 
501
                    return extension
 
502
                    & ((XSSimpleTypeDecl) type).isDOMDerivedFrom(
 
503
                            ancestorNS, ancestorName, derivationMethod);
 
504
                }
 
505
                
 
506
            } else {
 
507
                // If the base type is a complex type
 
508
                // At least one derivation step upto the ancestor type should be
 
509
                // extension.
 
510
                if (((XSComplexTypeDecl) type).getDerivationMethod() == XSConstants.DERIVATION_EXTENSION) {
 
511
                    extension = extension | true;
 
512
                }
 
513
            }
 
514
            oldType = type;
 
515
            type = type.getBaseType();
 
516
        }
 
517
        
 
518
        return false;
 
519
    }
 
520
    
 
521
    
 
522
    
 
523
    public void reset(){
 
524
        fName = null;
 
525
        fTargetNamespace = null;
 
526
        fBaseType = null;
 
527
        fDerivedBy = XSConstants.DERIVATION_RESTRICTION;
 
528
        fFinal = XSConstants.DERIVATION_NONE;
 
529
        fBlock = XSConstants.DERIVATION_NONE;
 
530
 
 
531
        fMiscFlags = 0;
 
532
 
 
533
        // reset attribute group
 
534
        fAttrGrp.reset();
 
535
        fContentType = CONTENTTYPE_EMPTY;
 
536
        fXSSimpleType = null;
 
537
        fParticle = null;
 
538
        fCMValidator = null;
 
539
        fUPACMValidator = null;
 
540
        if(fAnnotations != null) {
 
541
            // help out the garbage collector
 
542
            fAnnotations.clear();
 
543
        }
 
544
        fAnnotations = null;
 
545
    }
 
546
 
 
547
    /**
 
548
     * Get the type of the object, i.e ELEMENT_DECLARATION.
 
549
     */
 
550
    public short getType() {
 
551
        return XSConstants.TYPE_DEFINITION;
 
552
    }
 
553
 
 
554
    /**
 
555
     * The <code>name</code> of this <code>XSObject</code> depending on the
 
556
     * <code>XSObject</code> type.
 
557
     */
 
558
    public String getName() {
 
559
        return getAnonymous() ? null : fName;
 
560
    }
 
561
 
 
562
    /**
 
563
     * A boolean that specifies if the type definition is anonymous.
 
564
     * Convenience attribute. This is a field is not part of
 
565
     * XML Schema component model.
 
566
     */
 
567
    public boolean getAnonymous() {
 
568
        return((fMiscFlags & CT_IS_ANONYMOUS) != 0);
 
569
    }
 
570
 
 
571
    /**
 
572
     * The namespace URI of this node, or <code>null</code> if it is
 
573
     * unspecified.  defines how a namespace URI is attached to schema
 
574
     * components.
 
575
     */
 
576
    public String getNamespace() {
 
577
        return fTargetNamespace;
 
578
    }
 
579
 
 
580
    /**
 
581
     * {base type definition} Either a simple type definition or a complex
 
582
     * type definition.
 
583
     */
 
584
    public XSTypeDefinition getBaseType() {
 
585
        return fBaseType;
 
586
    }
 
587
 
 
588
    /**
 
589
     * {derivation method} Either extension or restriction. The valid constant
 
590
     * value for this <code>XSConstants</code> EXTENTION, RESTRICTION.
 
591
     */
 
592
    public short getDerivationMethod() {
 
593
        return fDerivedBy;
 
594
    }
 
595
 
 
596
    /**
 
597
     * {final} For complex type definition it is a subset of {extension,
 
598
     * restriction}. For simple type definition it is a subset of
 
599
     * {extension, list, restriction, union}.
 
600
     * @param derivation  Extension, restriction, list, union constants
 
601
     *   (defined in <code>XSConstants</code>).
 
602
     * @return True if derivation is in the final set, otherwise false.
 
603
     */
 
604
    public boolean isFinal(short derivation) {
 
605
        return (fFinal & derivation) != 0;
 
606
    }
 
607
 
 
608
    /**
 
609
     * {final} For complex type definition it is a subset of {extension, restriction}.
 
610
     *
 
611
     * @return A bit flag that represents:
 
612
     *         {extension, restriction) or none for complexTypes;
 
613
     *         {extension, list, restriction, union} or none for simpleTypes;
 
614
     */
 
615
    public short getFinal() {
 
616
        return fFinal;
 
617
    }
 
618
 
 
619
    /**
 
620
     * {abstract} A boolean. Complex types for which {abstract} is true must
 
621
     * not be used as the {type definition} for the validation of element
 
622
     * information items.
 
623
     */
 
624
    public boolean getAbstract() {
 
625
        return((fMiscFlags & CT_IS_ABSTRACT) != 0);
 
626
    }
 
627
 
 
628
    /**
 
629
     *  {attribute uses} A set of attribute uses.
 
630
     */
 
631
    public XSObjectList getAttributeUses() {
 
632
        return fAttrGrp.getAttributeUses();
 
633
    }
 
634
 
 
635
    /**
 
636
     * {attribute wildcard} Optional. A wildcard.
 
637
     */
 
638
    public XSWildcard getAttributeWildcard() {
 
639
        return fAttrGrp.getAttributeWildcard();
 
640
    }
 
641
 
 
642
    /**
 
643
     * {content type} One of empty, a simple type definition (see
 
644
     * <code>simpleType</code>, or mixed, element-only (see
 
645
     * <code>cmParticle</code>).
 
646
     */
 
647
    public short getContentType() {
 
648
        return fContentType;
 
649
    }
 
650
 
 
651
    /**
 
652
     * A simple type definition corresponding to simple content model,
 
653
     * otherwise <code>null</code>
 
654
     */
 
655
    public XSSimpleTypeDefinition getSimpleType() {
 
656
        return fXSSimpleType;
 
657
    }
 
658
 
 
659
    /**
 
660
     * A particle for mixed or element-only content model, otherwise
 
661
     * <code>null</code>
 
662
     */
 
663
    public XSParticle getParticle() {
 
664
        return fParticle;
 
665
    }
 
666
 
 
667
    /**
 
668
     * {prohibited substitutions} A subset of {extension, restriction}.
 
669
     * @param prohibited  extention or restriction constants (defined in
 
670
     *   <code>XSConstants</code>).
 
671
     * @return True if prohibited is a prohibited substitution, otherwise
 
672
     *   false.
 
673
     */
 
674
    public boolean isProhibitedSubstitution(short prohibited) {
 
675
        return (fBlock & prohibited) != 0;
 
676
    }
 
677
 
 
678
    /**
 
679
     * {prohibited substitutions}
 
680
     *
 
681
     * @return A bit flag corresponding to prohibited substitutions
 
682
     */
 
683
    public short getProhibitedSubstitutions() {
 
684
        return fBlock;
 
685
    }
 
686
 
 
687
    /**
 
688
     * Optional. Annotation.
 
689
     */
 
690
    public XSObjectList getAnnotations() {
 
691
        return (fAnnotations != null) ? fAnnotations : XSObjectListImpl.EMPTY_LIST;
 
692
    }
 
693
    
 
694
        /**
 
695
         * @see org.apache.xerces.xs.XSObject#getNamespaceItem()
 
696
         */
 
697
        public XSNamespaceItem getNamespaceItem() {
 
698
        // REVISIT: implement
 
699
                return null;
 
700
        }
 
701
 
 
702
    /* (non-Javadoc)
 
703
     * @see org.apache.xerces.xs.XSComplexTypeDefinition#getAttributeUse(java.lang.String, java.lang.String)
 
704
     */
 
705
    public XSAttributeUse getAttributeUse(String namespace, String name) {
 
706
         return fAttrGrp.getAttributeUse(namespace, name);
 
707
    }
 
708
 
 
709
    public String getTypeNamespace() {
 
710
        return getNamespace();
 
711
    }
 
712
 
 
713
    public boolean isDerivedFrom(String typeNamespaceArg, String typeNameArg, int derivationMethod) {
 
714
        return isDOMDerivedFrom(typeNamespaceArg, typeNameArg, derivationMethod);
 
715
    }
 
716
 
 
717
} // class XSComplexTypeDecl