/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* 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.7 2010-11-01 04:39:55 joehw Exp $
*/
// the target namespace of grammar
// global decls: map from decl name to decl object
// extended global decls: map from schema location + decl name to decl object
// key is location,name
// A global map of all global element declarations - used for substitution group computation
// (handy when sharing components by reference, since we might end up with duplicate components
// that are not added to either of the global element declarations above)
// the XMLGrammarDescription member
// annotations associated with the "root" schema of this targetNamespace
// number of annotations declared
int fNumAnnotations;
// symbol table for constructing parsers (annotation support)
// parsers for annotation support
// is this grammar immutable? (fully constructed and not changeable)
private boolean fIsImmutable = false;
//
// Constructors
//
// needed to make BuiltinSchemaGrammar work.
protected SchemaGrammar() {}
/**
* 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
*/
// 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();
// Extended tables
fGlobalAttrDeclsExt = new SymbolHash();
fGlobalAttrGrpDeclsExt = new SymbolHash();
fGlobalElemDeclsExt = new SymbolHash();
fGlobalGroupDeclsExt = new SymbolHash();
fGlobalNotationDeclsExt = new SymbolHash();
fGlobalIDConstraintDeclsExt = new SymbolHash();
fGlobalTypeDeclsExt = new SymbolHash();
// All global elements table
fAllGlobalElemDecls = 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.
else
fGlobalTypeDecls = new SymbolHash();
} // <init>(String, XSDDescription)
// Clone an existing schema grammar
//fGrammarDescription.fContextType |= XSDDescription.CONTEXT_COLLISION; // REVISIT
// Extended tables
// All global elements table
// Annotations associated with the "root" schema of this targetNamespace
if (fNumAnnotations > 0) {
}
// All substitution group information declared in this namespace
if (fSubGroupCount > 0) {
}
// Array to store complex type decls for constraint checking
if (fCTCount > 0) {
}
// Groups being redefined by restriction
if (fRGCount > 0) {
}
// List of imported grammars
}
}
// Locations
}
}
} // <init>(String, XSDDescription)
// number of built-in XSTypes we need to create for base and full
// datatype set
// this class makes sure the static, built-in schema grammars
// are immutable.
private static final String EXTENDED_SCHEMA_FACTORY_CLASS = "com.sun.org.apache.xerces.internal.impl.dv.xs.ExtendedSchemaDVFactoryImpl";
/**
* Special constructor to create the grammars for the schema namespaces
*
* @param grammar
*/
}
else {
}
if (grammar == GRAMMAR_XS) {
// target namespace
// grammar description
fGrammarDescription = new XSDDescription();
// no global decls other than types
// no extended global decls
// all global element decls table
// get all built-in types
// assign the built-in schema grammar as the XSNamespaceItem
// for each of the built-in simple type definitions.
for (int i = 0; i < length; ++i) {
if (xtd instanceof XSSimpleTypeDecl) {
}
}
// add anyType
}
else if (grammar == GRAMMAR_XSI) {
// target namespace
// grammar description
fGrammarDescription = new XSDDescription();
// no global decls other than attributes
// no extended global decls
// no all global element decls
// 4 attributes, so initialize the size as 4*2 = 8
// xsi:type
// xsi:nil
// xsi:schemaLocation
type = schemaFactory.createTypeList("#AnonType_schemaLocation", SchemaSymbols.URI_XSI, (short)0, anyURI, null);
if (type instanceof XSSimpleTypeDecl) {
}
// xsi:noNamespaceSchemaLocation
}
} // <init>(int)
// return the XMLGrammarDescription corresponding to this
// object
return fGrammarDescription.makeClone();
} // getGrammarDescription(): XMLGrammarDescription
// override these methods solely so that these
// objects cannot be modified once they're created.
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// annotation support
return null;
}
return null;
}
}
/**
* <p>A partial schema for schemas for validating annotations.</p>
*
* @xerces.internal
*
* @author Michael Glavassevich, IBM
*/
/**
* Singleton instance.
*/
/**
* Special constructor to create a schema
* capable of validating annotations.
*/
private Schema4Annotations() {
// target namespace
// grammar description
fGrammarDescription = new XSDDescription();
// no global decls other than types and
// element declarations for <annotation>, <documentation> and <appinfo>.
// no extended global decls
// all global element declarations
// get all built-in types
// create element declarations for <annotation>, <documentation> and <appinfo>
// add global element declarations
// create complex type declarations for <annotation>, <documentation> and <appinfo>
// set the types on their element declarations
// create attribute groups for <annotation>, <documentation> and <appinfo>
// fill in attribute groups
{
// create and fill attribute uses for <annotation>, <documentation> and <appinfo>
annotationIDAttr.fAttrDecl.setValues(SchemaSymbols.ATT_ID, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ID),
documentationSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI),
documentationLangAttr.fAttrDecl.setValues("lang".intern(), NamespaceContext.XML_URI, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_LANGUAGE),
appinfoSourceAttr.fAttrDecl.setValues(SchemaSymbols.ATT_SOURCE, null, (XSSimpleType) fGlobalTypeDecls.get(SchemaSymbols.ATTVAL_ANYURI),
// create lax attribute wildcard for <annotation>, <documentation> and <appinfo>
// add attribute uses and wildcards to attribute groups for <annotation>, <documentation> and <appinfo>
}
// create particles for <annotation>
{
}
// create wildcard particle for <documentation> and <appinfo>
// fill complex types
annotationType.setValues("#AnonType_" + SchemaSymbols.ELT_ANNOTATION, fTargetNamespace, SchemaGrammar.fAnyType,
XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
XSComplexTypeDecl.CONTENTTYPE_ELEMENT, false, annotationAttrs, null, annotationParticle, new XSObjectListImpl(null, 0));
documentationType.setValues("#AnonType_" + SchemaSymbols.ELT_DOCUMENTATION, fTargetNamespace, SchemaGrammar.fAnyType,
XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
XSComplexTypeDecl.CONTENTTYPE_MIXED, false, documentationAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0));
appinfoType.setValues("#AnonType_" + SchemaSymbols.ELT_APPINFO, fTargetNamespace, SchemaGrammar.fAnyType,
XSConstants.DERIVATION_RESTRICTION, XSConstants.DERIVATION_NONE, (short) (XSConstants.DERIVATION_EXTENSION | XSConstants.DERIVATION_RESTRICTION),
XSComplexTypeDecl.CONTENTTYPE_MIXED, false, appinfoAttrs, null, anyWCSequenceParticle, new XSObjectListImpl(null, 0));
} // <init>(int)
// return the XMLGrammarDescription corresponding to this
// object
return fGrammarDescription.makeClone();
} // getGrammarDescription(): XMLGrammarDescription
// override these methods solely so that these
// objects cannot be modified once they're created.
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// ignore
}
// annotation support
return null;
}
return null;
}
//
// private helper methods
//
eDecl.setIsGlobal();
return eDecl;
}
return particle;
}
return particle;
}
return particle;
}
return particle;
}
}
// Grammar methods
// return the XMLGrammarDescription corresponding to this
// object
return fGrammarDescription;
} // getGrammarDescription(): XMLGrammarDescription
// DTDGrammar methods
public boolean isNamespaceAware () {
return true;
} // isNamespaceAware():boolean
}
return fImported;
}
/**
* Returns this grammar's target namespace.
*/
return fTargetNamespace;
} // getTargetNamespace():String
/**
* register one global attribute
*/
decl.setNamespaceItem(this);
}
decl.setNamespaceItem(this);
}
}
/**
* register one global attribute group
*/
decl.setNamespaceItem(this);
}
decl.setNamespaceItem(this);
}
}
/**
* register one global element
*/
// if there is a substitution group affiliation, store in an array,
// for further constraint checking: UPA, PD, EDC
}
}
}
decl.setNamespaceItem(this);
}
decl.setNamespaceItem(this);
}
}
/**
* register one global group
*/
decl.setNamespaceItem(this);
}
decl.setNamespaceItem(this);
}
}
/**
* register one global notation
*/
decl.setNamespaceItem(this);
}
decl.setNamespaceItem(this);
}
}
/**
* register one global type
*/
if (decl instanceof XSComplexTypeDecl) {
}
else if (decl instanceof XSSimpleTypeDecl) {
}
}
if (decl instanceof XSComplexTypeDecl) {
}
else if (decl instanceof XSSimpleTypeDecl) {
}
}
}
/**
* register one global complex type
*/
decl.setNamespaceItem(this);
}
decl.setNamespaceItem(this);
}
}
/**
* register one global simple type
*/
if (decl instanceof XSSimpleTypeDecl) {
}
}
}
}
/**
* register one identity constraint
*/
}
public final void addIDConstraintDecl(XSElementDecl elmDecl, IdentityConstraint decl, String location) {
fGlobalIDConstraintDeclsExt.put(((location != null) ? location : "") + "," + decl.getIdentityConstraintName(), decl);
}
/**
* get one global attribute
*/
}
return(XSAttributeDecl)fGlobalAttrDeclsExt.get(((location != null) ? location : "") + "," + declName);
}
/**
* get one global attribute group
*/
}
return(XSAttributeGroupDecl)fGlobalAttrGrpDeclsExt.get(((location != null) ? location : "") + "," + declName);
}
/**
* get one global element
*/
}
return(XSElementDecl)fGlobalElemDeclsExt.get(((location != null) ? location : "") + "," + declName);
}
/**
* get one global group
*/
}
}
/**
* get one global notation
*/
}
return(XSNotationDecl)fGlobalNotationDeclsExt.get(((location != null) ? location : "") + "," + declName);
}
/**
* get one global type
*/
}
return(XSTypeDefinition)fGlobalTypeDeclsExt.get(((location != null) ? location : "") + "," + declName);
}
/**
* get one identity constraint
*/
}
return(IdentityConstraint)fGlobalIDConstraintDeclsExt.get(((location != null) ? location : "") + "," + declName);
}
/**
* get one identity constraint
*/
public final boolean hasIDConstraints() {
}
// array to store complex type decls
// an array to store groups being redefined by restriction
// even-numbered elements are the derived groups, odd-numbered ones their bases
// a flag to indicate whether we have checked the 3 constraints on this
// grammar.
boolean fFullChecked = false;
/**
* add one complex type decl: for later constraint checking
*/
}
}
/**
* add a group redefined by restriction: for later constraint checking
*/
// double array size each time.
}
}
/**
* get all complex type decls: for later constraint checking
*/
}
return fComplexTypeDecls;
}
/**
* get the error locator of all complex type decls
*/
}
return fCTLocators;
}
/**
* get all redefined groups: for later constraint checking
*/
}
return fRedefinedGroupDecls;
}
/**
* get the error locator of all redefined groups
*/
}
return fRGLocators;
}
/**
* 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.
*/
}
// used to store all substitution group information declared in
// this namespace
/**
* get all substitution group information: for the 3 constraint checking
*/
return fSubGroups;
}
// anyType and anySimpleType: because there are so many places where
// we need direct access to these two types
public XSAnyType () {
fBaseType = this;
}
// overridden methods
short block, short contentType,
// don't allow this.
}
// don't allow this.
}
public void setIsAbstractType() {
// null implementation
}
public void setContainsTypeID() {
// null implementation
}
public void setIsAnonymous() {
// null implementation
}
public void reset() {
// null implementation
}
return XSObjectListImpl.EMPTY_LIST;
}
return attrGrp;
}
return wildcard;
}
// the wildcard used in anyType (content and attribute)
// the spec will change strict to skip for anyType
// the particle for the content wildcard
// the model group of a sequence of the above particle
// the content of anyType: particle of the above model group
return particleG;
}
return XSObjectListImpl.EMPTY_LIST;
}
return SG_SchemaNS;
}
}
super.fTargetNamespace = tns;
}
// ignore this call.
}
public void reset () {
// also ignore this call.
}
return null;
}
return SG_XSI;
}
} // class BuiltinAttrDecl
// the grammars to hold components of the schema namespace
public final static BuiltinSchemaGrammar SG_SchemaNS = new BuiltinSchemaGrammar(GRAMMAR_XS, Constants.SCHEMA_VERSION_1_0);
private final static BuiltinSchemaGrammar SG_SchemaNSExtended = new BuiltinSchemaGrammar(GRAMMAR_XS, Constants.SCHEMA_VERSION_1_0_EXTENDED);
public final static XSSimpleType fAnySimpleType = (XSSimpleType)SG_SchemaNS.getGlobalTypeDecl(SchemaSymbols.ATTVAL_ANYSIMPLETYPE);
// the grammars to hold components of the schema-instance namespace
public final static BuiltinSchemaGrammar SG_XSI = new BuiltinSchemaGrammar(GRAMMAR_XSI, Constants.SCHEMA_VERSION_1_0);
return SG_SchemaNS;
}
else {
return SG_SchemaNSExtended;
}
}
return newArray;
}
return newArray;
}
return newArray;
}
return newArray;
}
// XSNamespaceItem methods
// the max index / the max value of XSObject type
true, // attribute
true, // element
true, // type
false, // attribute use
true, // attribute group
true, // group
false, // model group
false, // particle
false, // wildcard
false, // idc
true, // notation
false, // annotation
false, // facet
false, // multi value facet
true, // complex type
true // simple type
};
// store a certain kind of components from all namespaces
// store the documents and their locations contributing to this namespace
// REVISIT: use StringList and XSObjectList for there fields.
if (fDocuments == null) {
fDocuments = new Vector();
fLocations = new Vector();
}
}
if (fDocuments != null &&
index >= 0 &&
}
}
/**
* [schema namespace]
* @see <a href="http://www.w3.org/TR/xmlschema-1/#nsi-schema_namespace">[schema namespace]</a>
* @return The target namespace of this item.
*/
return fTargetNamespace;
}
// annotation support
if (fDOMParser != 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
// 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
try {
}
catch (SAXException exc) {}
return parser;
}
if (fSAXParser != 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
// 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
return parser;
}
/**
* [schema components]: a list of top-level components, i.e. element
* declarations, attribute declarations, etc.
* @param objectType The type of the declaration, i.e.
* <code>ELEMENT_DECLARATION</code>. Note that
* <code>XSTypeDefinition.SIMPLE_TYPE</code> and
* <code>XSTypeDefinition.COMPLEX_TYPE</code> can also be used as the
* <code>objectType</code> to retrieve only complex types or simple
* types, instead of all types.
* @return A list of top-level definition of the specified type in
* <code>objectType</code> or an empty <code>XSNamedMap</code> if no
* such definitions exist.
*/
!GLOBAL_COMP[objectType]) {
return XSNamedMapImpl.EMPTY_MAP;
}
if (fComponents == null)
// get the hashtable for this type of components
switch (objectType) {
case XSConstants.TYPE_DEFINITION:
case XSTypeDefinition.COMPLEX_TYPE:
case XSTypeDefinition.SIMPLE_TYPE:
break;
break;
break;
case XSConstants.ATTRIBUTE_GROUP:
break;
break;
break;
}
// which take specific types out of the hash table
}
else {
}
}
return fComponents[objectType];
}
!GLOBAL_COMP[objectType]) {
return ObjectListImpl.EMPTY_LIST;
}
if (fComponentsExt == null)
// get the hashtable for this type of components
switch (objectType) {
case XSConstants.TYPE_DEFINITION:
case XSTypeDefinition.COMPLEX_TYPE:
case XSTypeDefinition.SIMPLE_TYPE:
break;
break;
break;
case XSConstants.ATTRIBUTE_GROUP:
break;
break;
break;
}
}
return fComponentsExt[objectType];
}
public synchronized void resetComponents() {
fComponents = null;
}
/**
* Convenience method. Returns a top-level simple or complex type
* definition.
* @param name The name of the definition.
* @return An <code>XSTypeDefinition</code> or null if such definition
* does not exist.
*/
return getGlobalTypeDecl(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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* [document location]
* @see <a href="http://www.w3.org/TR/xmlschema-1/#sd-document_location">[document location]</a>
* @return a list of document information item
*/
return new StringListImpl(fLocations);
}
/**
* Return an <code>XSModel</code> that represents components in this schema
* grammar.
*
* @return an <code>XSModel</code> representing this schema grammar
*/
return new XSModelImpl(new SchemaGrammar[]{this});
}
return toXSModel();
boolean hasSelf = false;
for (int i = 0; i < len; i++) {
if (grammars[i] == this) {
hasSelf = true;
break;
}
}
for (int i = 0; i < len; i++)
if (!hasSelf)
return new XSModelImpl(gs);
}
/**
* @see org.apache.xerces.xs.XSNamespaceItem#getAnnotations()
*/
if (fNumAnnotations == 0) {
return XSObjectListImpl.EMPTY_LIST;
}
}
if (annotation == null) {
return;
}
if (fAnnotations == null) {
}
}
}
}
public boolean isImmutable() {
return fIsImmutable;
}
} // class SchemaGrammar