FileDocCategorySizeDatePackage
SchemaGrammar.javaAPI DocJava SE 6 API49741Tue Jun 10 00:22:44 BST 2008com.sun.org.apache.xerces.internal.impl.xs

SchemaGrammar

public class SchemaGrammar extends Object implements XSGrammar, XSNamespaceItem
This class is to hold all schema component declaration that are declared within one namespace. The Grammar class this class extends contains what little commonality there is between XML Schema and DTD grammars. It's useful to distinguish grammar objects from other kinds of object when they exist in pools or caches.
xerces.internal
author
Sandy Gao, IBM
author
Elena Litani, IBM
version
$Id: SchemaGrammar.java,v 1.2.6.1 2005/09/09 07:30:49 sunithareddy Exp $

Fields Summary
String
fTargetNamespace
SymbolHash
fGlobalAttrDecls
SymbolHash
fGlobalAttrGrpDecls
SymbolHash
fGlobalElemDecls
SymbolHash
fGlobalGroupDecls
SymbolHash
fGlobalNotationDecls
SymbolHash
fGlobalIDConstraintDecls
SymbolHash
fGlobalTypeDecls
XSDDescription
fGrammarDescription
XSAnnotationImpl[]
fAnnotations
int
fNumAnnotations
private SymbolTable
fSymbolTable
private SAXParser
fSAXParser
private DOMParser
fDOMParser
private static final int
BASICSET_COUNT
private static final int
FULLSET_COUNT
private static final int
GRAMMAR_XS
private static final int
GRAMMAR_XSI
Vector
fImported
private static final int
INITIAL_SIZE
private static final int
INC_SIZE
private int
fCTCount
private XSComplexTypeDecl[]
fComplexTypeDecls
private SimpleLocator[]
fCTLocators
private static final int
REDEFINED_GROUP_INIT_SIZE
private int
fRGCount
private XSGroupDecl[]
fRedefinedGroupDecls
private SimpleLocator[]
fRGLocators
boolean
fFullChecked
private int
fSubGroupCount
private XSElementDecl[]
fSubGroups
public static final XSComplexTypeDecl
fAnyType
public static final BuiltinSchemaGrammar
SG_SchemaNS
public static final Schema4Annotations
SG_Schema4Annotations
public static final XSSimpleType
fAnySimpleType
public static final BuiltinSchemaGrammar
SG_XSI
private static final short
MAX_COMP_IDX
private static final boolean[]
GLOBAL_COMP
private XSNamedMap[]
fComponents
private Vector
fDocuments
private Vector
fLocations
Constructors Summary
protected SchemaGrammar()


    //
    // Constructors
    //

    // needed to make BuiltinSchemaGrammar work.
      
public SchemaGrammar(String targetNamespace, XSDDescription grammarDesc, SymbolTable symbolTable)
Default constructor.

param
targetNamespace
param
grammarDesc the XMLGrammarDescription corresponding to this objec at the least a systemId should always be known.
param
symbolTable needed for annotation support

        fTargetNamespace = targetNamespace;
        fGrammarDescription = grammarDesc;
        fSymbolTable = symbolTable;

        // REVISIT: do we know the numbers of the following global decls
        // when creating this grammar? If so, we can pass the numbers in,
        // and use that number to initialize the following hashtables.
        fGlobalAttrDecls  = new SymbolHash();
        fGlobalAttrGrpDecls = new SymbolHash();
        fGlobalElemDecls = new SymbolHash();
        fGlobalGroupDecls = new SymbolHash();
        fGlobalNotationDecls = new SymbolHash();
        fGlobalIDConstraintDecls = new SymbolHash();

        // if we are parsing S4S, put built-in types in first
        // they might get overwritten by the types from S4S, but that's
        // considered what the application wants to do.
        if (fTargetNamespace == SchemaSymbols.URI_SCHEMAFORSCHEMA)
            fGlobalTypeDecls = SG_SchemaNS.fGlobalTypeDecls.makeClone();
        else
            fGlobalTypeDecls = new SymbolHash();
    
Methods Summary
public voidaddAnnotation(com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl annotation)

        if(annotation == null)
            return;
        if(fAnnotations == null) {
            fAnnotations = new XSAnnotationImpl[2];
        } else if(fNumAnnotations == fAnnotations.length) {
            XSAnnotationImpl[] newArray = new XSAnnotationImpl[fNumAnnotations << 1];
            System.arraycopy(fAnnotations, 0, newArray, 0, fNumAnnotations);
            fAnnotations = newArray;
        }
        fAnnotations[fNumAnnotations++] = annotation;
    
public voidaddComplexTypeDecl(com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl decl, com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator locator)
add one complex type decl: for later constraint checking


                  
          
        if (fCTCount == fComplexTypeDecls.length) {
            fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount+INC_SIZE);
            fCTLocators = resize(fCTLocators, fCTCount+INC_SIZE);
        }
        fCTLocators[fCTCount] = locator;
        fComplexTypeDecls[fCTCount++] = decl;
    
public synchronized voidaddDocument(java.lang.Object document, java.lang.String location)

    
           
        if (fDocuments == null) {
            fDocuments = new Vector();
            fLocations = new Vector();
        }
        fDocuments.addElement(document);
        fLocations.addElement(location);
    
public voidaddGlobalAttributeDecl(com.sun.org.apache.xerces.internal.impl.xs.XSAttributeDecl decl)
register one global attribute

        fGlobalAttrDecls.put(decl.fName, decl);
    
public voidaddGlobalAttributeGroupDecl(com.sun.org.apache.xerces.internal.impl.xs.XSAttributeGroupDecl decl)
register one global attribute group

        fGlobalAttrGrpDecls.put(decl.fName, decl);
    
public voidaddGlobalElementDecl(com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl decl)
register one global element

        fGlobalElemDecls.put(decl.fName, decl);

        // if there is a substitution group affiliation, store in an array,
        // for further constraint checking: UPA, PD, EDC
        if (decl.fSubGroup != null) {
            if (fSubGroupCount == fSubGroups.length)
                fSubGroups = resize(fSubGroups, fSubGroupCount+INC_SIZE);
            fSubGroups[fSubGroupCount++] = decl;
        }
    
public voidaddGlobalGroupDecl(com.sun.org.apache.xerces.internal.impl.xs.XSGroupDecl decl)
register one global group

        fGlobalGroupDecls.put(decl.fName, decl);
    
public voidaddGlobalNotationDecl(com.sun.org.apache.xerces.internal.impl.xs.XSNotationDecl decl)
register one global notation

        fGlobalNotationDecls.put(decl.fName, decl);
    
public voidaddGlobalTypeDecl(com.sun.org.apache.xerces.internal.xs.XSTypeDefinition decl)
register one global type

        fGlobalTypeDecls.put(decl.getName(), decl);
    
public final voidaddIDConstraintDecl(com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl elmDecl, com.sun.org.apache.xerces.internal.impl.xs.identity.IdentityConstraint decl)
register one identity constraint

        elmDecl.addIDConstraint(decl);
        fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(), decl);
    
public voidaddRedefinedGroupDecl(com.sun.org.apache.xerces.internal.impl.xs.XSGroupDecl derived, com.sun.org.apache.xerces.internal.impl.xs.XSGroupDecl base, com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator locator)
add a group redefined by restriction: for later constraint checking

        if (fRGCount == fRedefinedGroupDecls.length) {
            // double array size each time.
            fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount << 1);
            fRGLocators = resize(fRGLocators, fRGCount);
        }
        fRGLocators[fRGCount/2] = locator;
        fRedefinedGroupDecls[fRGCount++] = derived;
        fRedefinedGroupDecls[fRGCount++] = base;
    
public com.sun.org.apache.xerces.internal.xs.XSObjectListgetAnnotations()

see
com.sun.org.apache.xerces.internal.xs.XSNamespaceItem#getAnnotations()

        return new XSObjectListImpl(fAnnotations, fNumAnnotations);
    
public com.sun.org.apache.xerces.internal.xs.XSAttributeDeclarationgetAttributeDeclaration(java.lang.String name)
Convenience method. Returns a top-level attribute declaration.

param
name The name of the declaration.
return
A top-level attribute declaration or null if such declaration does not exist.

        return getGlobalAttributeDecl(name);
    
public com.sun.org.apache.xerces.internal.xs.XSAttributeGroupDefinitiongetAttributeGroup(java.lang.String name)
Convenience method. Returns a top-level attribute group definition.

param
name The name of the definition.
return
A top-level attribute group definition or null if such definition does not exist.

        return getGlobalAttributeGroupDecl(name);
    
public synchronized com.sun.org.apache.xerces.internal.xs.XSNamedMapgetComponents(short objectType)
[schema components]: a list of top-level components, i.e. element declarations, attribute declarations, etc.

param
objectType The type of the declaration, i.e. ELEMENT_DECLARATION. Note that XSTypeDefinition.SIMPLE_TYPE and XSTypeDefinition.COMPLEX_TYPE can also be used as the objectType to retrieve only complex types or simple types, instead of all types.
return
A list of top-level definition of the specified type in objectType or an empty XSNamedMap if no such definitions exist.

        if (objectType <= 0 || objectType > MAX_COMP_IDX ||
            !GLOBAL_COMP[objectType]) {
            return XSNamedMapImpl.EMPTY_MAP;
        }
        
        if (fComponents == null)
            fComponents = new XSNamedMap[MAX_COMP_IDX+1];

        // get the hashtable for this type of components
        if (fComponents[objectType] == null) {
            SymbolHash table = null;
            switch (objectType) {
            case XSConstants.TYPE_DEFINITION:
            case XSTypeDefinition.COMPLEX_TYPE:
            case XSTypeDefinition.SIMPLE_TYPE:
                table = fGlobalTypeDecls;
                break;
            case XSConstants.ATTRIBUTE_DECLARATION:
                table = fGlobalAttrDecls;
                break;
            case XSConstants.ELEMENT_DECLARATION:
                table = fGlobalElemDecls;
                break;
            case XSConstants.ATTRIBUTE_GROUP:
                table = fGlobalAttrGrpDecls;
                break;
            case XSConstants.MODEL_GROUP_DEFINITION:
                table = fGlobalGroupDecls;
                break;
            case XSConstants.NOTATION_DECLARATION:
                table = fGlobalNotationDecls;
                break;
            }
            
            // for complex/simple types, create a special implementation,
            // which take specific types out of the hash table
            if (objectType == XSTypeDefinition.COMPLEX_TYPE ||
                objectType == XSTypeDefinition.SIMPLE_TYPE) {
                fComponents[objectType] = new XSNamedMap4Types(fTargetNamespace, table, objectType);
            }
            else {
                fComponents[objectType] = new XSNamedMapImpl(fTargetNamespace, table);
            }
        }
        
        return fComponents[objectType];
    
synchronized com.sun.org.apache.xerces.internal.parsers.DOMParsergetDOMParser()

        if (fDOMParser != null) return fDOMParser;
        // REVISIT:  when schema handles XML 1.1, will need to 
        // revisit this (and the practice of not prepending an XML decl to the annotation string
        IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable);
        // note that this should never produce errors or require
        // entity resolution, so just a barebones configuration with
        // a couple of feature  set will do fine
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
        fDOMParser = new DOMParser(config);
        return fDOMParser;
    
public com.sun.org.apache.xerces.internal.xs.StringListgetDocumentLocations()
[document location]

see
[document location]
return
a list of document information item

        return new StringListImpl(fLocations);
    
public com.sun.org.apache.xerces.internal.xs.XSElementDeclarationgetElementDeclaration(java.lang.String name)
Convenience method. Returns a top-level element declaration.

param
name The name of the declaration.
return
A top-level element declaration or null if such declaration does not exist.

        return getGlobalElementDecl(name);
    
public final com.sun.org.apache.xerces.internal.impl.xs.XSAttributeDeclgetGlobalAttributeDecl(java.lang.String declName)
get one global attribute

        return(XSAttributeDecl)fGlobalAttrDecls.get(declName);
    
public final com.sun.org.apache.xerces.internal.impl.xs.XSAttributeGroupDeclgetGlobalAttributeGroupDecl(java.lang.String declName)
get one global attribute group

        return(XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declName);
    
public final com.sun.org.apache.xerces.internal.impl.xs.XSElementDeclgetGlobalElementDecl(java.lang.String declName)
get one global element

        return(XSElementDecl)fGlobalElemDecls.get(declName);
    
public final com.sun.org.apache.xerces.internal.impl.xs.XSGroupDeclgetGlobalGroupDecl(java.lang.String declName)
get one global group

        return(XSGroupDecl)fGlobalGroupDecls.get(declName);
    
public final com.sun.org.apache.xerces.internal.impl.xs.XSNotationDeclgetGlobalNotationDecl(java.lang.String declName)
get one global notation

        return(XSNotationDecl)fGlobalNotationDecls.get(declName);
    
public final com.sun.org.apache.xerces.internal.xs.XSTypeDefinitiongetGlobalTypeDecl(java.lang.String declName)
get one global type

        return(XSTypeDefinition)fGlobalTypeDecls.get(declName);
    
public com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescriptiongetGrammarDescription()

        return fGrammarDescription;
    
public final com.sun.org.apache.xerces.internal.impl.xs.identity.IdentityConstraintgetIDConstraintDecl(java.lang.String declName)
get one identity constraint

        return(IdentityConstraint)fGlobalIDConstraintDecls.get(declName);
    
public java.util.VectorgetImportedGrammars()

        return fImported;
    
public com.sun.org.apache.xerces.internal.xs.XSModelGroupDefinitiongetModelGroupDefinition(java.lang.String name)
Convenience method. Returns a top-level model group definition.

param
name The name of the definition.
return
A top-level model group definition definition or null if such definition does not exist.

        return getGlobalGroupDecl(name);
    
public com.sun.org.apache.xerces.internal.xs.XSNotationDeclarationgetNotationDeclaration(java.lang.String name)
Convenience method. Returns a top-level notation declaration.

param
name The name of the declaration.
return
A top-level notation declaration or null if such declaration does not exist.

        return getGlobalNotationDecl(name);
    
final com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator[]getRGLocators()
get the error locator of all redefined groups

        if (fRGCount < fRedefinedGroupDecls.length) {
            fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount);
            fRGLocators = resize(fRGLocators, fRGCount/2);
        }
        return fRGLocators;
    
final com.sun.org.apache.xerces.internal.impl.xs.XSGroupDecl[]getRedefinedGroupDecls()
get all redefined groups: for later constraint checking

        if (fRGCount < fRedefinedGroupDecls.length) {
            fRedefinedGroupDecls = resize(fRedefinedGroupDecls, fRGCount);
            fRGLocators = resize(fRGLocators, fRGCount/2);
        }
        return fRedefinedGroupDecls;
    
synchronized com.sun.org.apache.xerces.internal.parsers.SAXParsergetSAXParser()

        if (fSAXParser != null) return fSAXParser;
        // REVISIT:  when schema handles XML 1.1, will need to 
        // revisit this (and the practice of not prepending an XML decl to the annotation string
        IntegratedParserConfiguration config = new IntegratedParserConfiguration(fSymbolTable);
        // note that this should never produce errors or require
        // entity resolution, so just a barebones configuration with
        // a couple of feature  set will do fine
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
        fSAXParser = new SAXParser(config);
        return fSAXParser;
    
public java.lang.StringgetSchemaNamespace()
[schema namespace]

see
[schema namespace]
return
The target namespace of this item.

        return fTargetNamespace;
    
final com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl[]getSubstitutionGroups()
get all substitution group information: for the 3 constraint checking


                   
       
        if (fSubGroupCount < fSubGroups.length)
            fSubGroups = resize(fSubGroups, fSubGroupCount);
        return fSubGroups;
    
public final java.lang.StringgetTargetNamespace()
Returns this grammar's target namespace.

        return fTargetNamespace;
    
public com.sun.org.apache.xerces.internal.xs.XSTypeDefinitiongetTypeDefinition(java.lang.String name)
Convenience method. Returns a top-level simple or complex type definition.

param
name The name of the definition.
return
An XSTypeDefinition or null if such definition does not exist.

        return getGlobalTypeDecl(name);
    
final com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator[]getUncheckedCTLocators()
get the error locator of all complex type decls

        if (fCTCount < fCTLocators.length) {
            fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
            fCTLocators = resize(fCTLocators, fCTCount);
        }
        return fCTLocators;
    
final com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl[]getUncheckedComplexTypeDecls()
get all complex type decls: for later constraint checking

        if (fCTCount < fComplexTypeDecls.length) {
            fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
            fCTLocators = resize(fCTLocators, fCTCount);
        }
        return fComplexTypeDecls;
    
public final booleanhasIDConstraints()
get one identity constraint

        return fGlobalIDConstraintDecls.getLength() > 0;
    
public booleanisNamespaceAware()

        return true;
    
static final com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl[]resize(com.sun.org.apache.xerces.internal.impl.xs.XSComplexTypeDecl[] oldArray, int newSize)


           
        XSComplexTypeDecl[] newArray = new XSComplexTypeDecl[newSize];
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
        return newArray;
    
static final com.sun.org.apache.xerces.internal.impl.xs.XSGroupDecl[]resize(com.sun.org.apache.xerces.internal.impl.xs.XSGroupDecl[] oldArray, int newSize)

        XSGroupDecl[] newArray = new XSGroupDecl[newSize];
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
        return newArray;
    
static final com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl[]resize(com.sun.org.apache.xerces.internal.impl.xs.XSElementDecl[] oldArray, int newSize)

        XSElementDecl[] newArray = new XSElementDecl[newSize];
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
        return newArray;
    
static final com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator[]resize(com.sun.org.apache.xerces.internal.impl.xs.util.SimpleLocator[] oldArray, int newSize)

        SimpleLocator[] newArray = new SimpleLocator[newSize];
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
        return newArray;
    
public voidsetImportedGrammars(java.util.Vector importedGrammars)


        
        fImported = importedGrammars;
    
final voidsetUncheckedTypeNum(int newSize)
after the first-round checking, some types don't need to be checked against UPA again. here we trim the array to the proper size.

        fCTCount = newSize;
        fComplexTypeDecls = resize(fComplexTypeDecls, fCTCount);
        fCTLocators = resize(fCTLocators, fCTCount);
    
public com.sun.org.apache.xerces.internal.xs.XSModeltoXSModel()
Return an XSModel that represents components in this schema grammar.

return
an XSModel representing this schema grammar

        return new XSModelImpl(new SchemaGrammar[]{this});
    
public com.sun.org.apache.xerces.internal.xs.XSModeltoXSModel(com.sun.org.apache.xerces.internal.xni.grammars.XSGrammar[] grammars)

        if (grammars == null || grammars.length == 0)
            return toXSModel();

        int len = grammars.length;
        boolean hasSelf = false;
        for (int i = 0; i < len; i++) {
            if (grammars[i] == this) {
                hasSelf = true;
                break;
            }
        }

        SchemaGrammar[] gs = new SchemaGrammar[hasSelf ? len : len+1];
        for (int i = 0; i < len; i++)
            gs[i] = (SchemaGrammar)grammars[i];
        if (!hasSelf)
            gs[len] = this;
        return new XSModelImpl(gs);