FileDocCategorySizeDatePackage
SchemaGrammar.javaAPI DocApache Xerces 3.0.151107Fri Sep 14 20:33:52 BST 2007org.apache.xerces.impl.xs

SchemaGrammar

public class SchemaGrammar extends Object implements org.apache.xerces.xni.grammars.XSGrammar, org.apache.xerces.xs.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 446734 2006-09-15 20:51:23Z mrglavas $

Fields Summary
String
fTargetNamespace
org.apache.xerces.util.SymbolHash
fGlobalAttrDecls
org.apache.xerces.util.SymbolHash
fGlobalAttrGrpDecls
org.apache.xerces.util.SymbolHash
fGlobalElemDecls
org.apache.xerces.util.SymbolHash
fGlobalGroupDecls
org.apache.xerces.util.SymbolHash
fGlobalNotationDecls
org.apache.xerces.util.SymbolHash
fGlobalIDConstraintDecls
org.apache.xerces.util.SymbolHash
fGlobalTypeDecls
XSDDescription
fGrammarDescription
XSAnnotationImpl[]
fAnnotations
int
fNumAnnotations
private org.apache.xerces.util.SymbolTable
fSymbolTable
private SoftReference
fSAXParser
private SoftReference
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 org.apache.xerces.impl.xs.util.SimpleLocator[]
fCTLocators
private static final int
REDEFINED_GROUP_INIT_SIZE
private int
fRGCount
private XSGroupDecl[]
fRedefinedGroupDecls
private org.apache.xerces.impl.xs.util.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 org.apache.xerces.impl.dv.XSSimpleType
fAnySimpleType
public static final BuiltinSchemaGrammar
SG_XSI
private static final short
MAX_COMP_IDX
private static final boolean[]
GLOBAL_COMP
private org.apache.xerces.xs.XSNamedMap[]
fComponents
private Vector
fDocuments
private Vector
fLocations
Constructors Summary
protected SchemaGrammar()


    //
    // Constructors
    //

    // needed to make BuiltinSchemaGrammar work.
      
public SchemaGrammar(String targetNamespace, XSDDescription grammarDesc, org.apache.xerces.util.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(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(XSComplexTypeDecl decl, org.apache.xerces.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(XSAttributeDecl decl)
register one global attribute

        fGlobalAttrDecls.put(decl.fName, decl);
    
public voidaddGlobalAttributeGroupDecl(XSAttributeGroupDecl decl)
register one global attribute group

        fGlobalAttrGrpDecls.put(decl.fName, decl);
    
public voidaddGlobalElementDecl(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(XSGroupDecl decl)
register one global group

        fGlobalGroupDecls.put(decl.fName, decl);
    
public voidaddGlobalNotationDecl(XSNotationDecl decl)
register one global notation

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

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

        elmDecl.addIDConstraint(decl);
        fGlobalIDConstraintDecls.put(decl.getIdentityConstraintName(), decl);
    
public voidaddRedefinedGroupDecl(XSGroupDecl derived, XSGroupDecl base, org.apache.xerces.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 org.apache.xerces.xs.XSObjectListgetAnnotations()

see
org.apache.xerces.xs.XSNamespaceItem#getAnnotations()

        return new XSObjectListImpl(fAnnotations, fNumAnnotations);
    
public org.apache.xerces.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 org.apache.xerces.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 org.apache.xerces.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 org.apache.xerces.parsers.DOMParsergetDOMParser()

        if (fDOMParser != null) {
            DOMParser parser = (DOMParser) fDOMParser.get();
            if (parser != null) {
                return parser;
            }
        }
        // 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
        XML11Configuration config = new XML11Configuration(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);
        
        DOMParser parser = new DOMParser(config);
        try {
            parser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.DEFER_NODE_EXPANSION_FEATURE, false);
        }
        catch (SAXException exc) {}
        fDOMParser = new SoftReference(parser);
        return parser;
    
public org.apache.xerces.xs.StringListgetDocumentLocations()
[document location]

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

        return new StringListImpl(fLocations);
    
public org.apache.xerces.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 XSAttributeDeclgetGlobalAttributeDecl(java.lang.String declName)
get one global attribute

        return(XSAttributeDecl)fGlobalAttrDecls.get(declName);
    
public final XSAttributeGroupDeclgetGlobalAttributeGroupDecl(java.lang.String declName)
get one global attribute group

        return(XSAttributeGroupDecl)fGlobalAttrGrpDecls.get(declName);
    
public final XSElementDeclgetGlobalElementDecl(java.lang.String declName)
get one global element

        return(XSElementDecl)fGlobalElemDecls.get(declName);
    
public final XSGroupDeclgetGlobalGroupDecl(java.lang.String declName)
get one global group

        return(XSGroupDecl)fGlobalGroupDecls.get(declName);
    
public final XSNotationDeclgetGlobalNotationDecl(java.lang.String declName)
get one global notation

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

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

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

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

        return fImported;
    
public org.apache.xerces.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 org.apache.xerces.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 org.apache.xerces.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 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 org.apache.xerces.parsers.SAXParsergetSAXParser()

        if (fSAXParser != null) {
            SAXParser parser = (SAXParser) fSAXParser.get();
            if (parser != null) {
                return parser;
            }
        }
        // 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
        XML11Configuration config = new XML11Configuration(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);
        SAXParser parser = new SAXParser(config);
        fSAXParser = new SoftReference(parser);
        return parser;
    
public java.lang.StringgetSchemaNamespace()
[schema namespace]

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

        return fTargetNamespace;
    
final 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 org.apache.xerces.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 org.apache.xerces.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 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 XSComplexTypeDecl[]resize(XSComplexTypeDecl[] oldArray, int newSize)


           
        XSComplexTypeDecl[] newArray = new XSComplexTypeDecl[newSize];
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
        return newArray;
    
static final XSGroupDecl[]resize(XSGroupDecl[] oldArray, int newSize)

        XSGroupDecl[] newArray = new XSGroupDecl[newSize];
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
        return newArray;
    
static final XSElementDecl[]resize(XSElementDecl[] oldArray, int newSize)

        XSElementDecl[] newArray = new XSElementDecl[newSize];
        System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize));
        return newArray;
    
static final org.apache.xerces.impl.xs.util.SimpleLocator[]resize(org.apache.xerces.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 org.apache.xerces.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 org.apache.xerces.xs.XSModeltoXSModel(org.apache.xerces.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);