Package com.saxonica.ee.schema
Class SchemaCompiler
java.lang.Object
com.saxonica.ee.schema.SchemaCompiler
A SchemaCompiler is capable of reading source schema documents and converting them into collections
of schema components. The Compiler holds all the options relating to schema compilation, including
maintaining information about the schema documents involved in a compilation.
A default SchemaCompiler is available as part of the EnterpriseConfiguration
- Since:
- 8.9
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPendingTypeCheck(IdentityConstraintReference constraint, SchemaType contextItemType) Register an identity constraint that needs to be type-checkedvoidaddSubstitutionGroupMember(ElementDecl owner, ElementDecl member) Add a member of the substitution group that has this element as its head.voidPerform all subsumption checks that have been previously requested.voidcompile()In deferred validation mode, validate and compile the accumulated schema components.doChameleonTransformation(NodeInfo input, SchemaElement referrer) Do the chameleon transformation on a source schema documentdoOverrideTransformation(NodeInfo input, SchemaElement referrer) Do the override transformation on a source schema documentvoidReport an errorGet the configurationintTest whether errors have been reportedGet the ErrorReporter used in this configuration.getExistingSchemaDocument(String systemId, NamespaceUri targetNamespace) Get the root element of the tree representing a schema document that has already been readintGet the XSD language version allowedGet the NamePoolint[]Get the occurrence limits previously set using setOccurrenceLimits (or the default)Get the pipeline configurationGet the PreparedSchema.getSchemaForBuiltInNamespace(NamespaceUri namespace) Add a built-in schema for a given namespace.Get the user-defined SchemaURIResolver for resolving URIs used in "import schema" declarations; if none has been explicitly set, returns the standard schema URI resolver.booleanAsk whether dangling references are allowed.booleanisBeingRead(String systemId) Determine whether a particular URI is currently being readloadSources(Iterable<Source> sources) Load a schema from a set of schema documents.voidCreate determinized finite state automata for all complex types for which this has been previously requestedvoidmarkAsRead(String systemId, XSDSchemaElement schema) Mark a document as having been readvoidbooleanreportMissingComponent(String componentType, StructuredQName componentName) Register that there is an unresolved component referencevoidSchedule the task of creating a finite state automaton for a given complex type.voidSchedule a subsumption check: that is, checking that the finite state automaton for one complex type subsumes the FSA for another complex typevoidsetBeingRead(NamespaceUri targetNamespace, String systemId) Mark a URI as currently being readvoidsetErrorReporter(ErrorReporter reporter) Set the ErrorReporter to be used in this compiler.voidsetLanguageVersion(int version) Set the XSD language version allowed.voidsetOccurrenceLimits(int minimum, int maximum) Set the occurrence limits to be used when compiling a finite state automaton.voidsetPipelineConfiguration(PipelineConfiguration pipelineConfiguration) Set the pipeline configurationvoidsetPreparedSchema(PreparedSchema schema) Set the PreparedSchema.voidsetSchemaURIResolver(SchemaURIResolver resolver) Set the user-defined SchemaURIResolver to be used for resolving URIs used in "import schema" declarations; defaults to theSchemaURIResolverfound in theConfigurationvoidDo all the pending type-checkingvalidate(SchemaDocument doc) Validate the schema represented by a schema document.voidReport a warning
-
Constructor Details
-
SchemaCompiler
Create a SchemaCompiler- Parameters:
config- the Saxon Configuration
-
-
Method Details
-
getConfiguration
Get the configuration- Returns:
- the configuration (which is always schema-aware)
-
getNamePool
Get the NamePool- Returns:
- the name pool
-
setLanguageVersion
public void setLanguageVersion(int version) Set the XSD language version allowed.- Parameters:
version- the language version allowed. Set to 10 for XSD 1.0, 11 for XSD 1.1. The default is taken from the Saxon Configuration properties. Symbolic constantsConfiguration.XSD10andConfiguration.XSD11are available.
-
getLanguageVersion
public int getLanguageVersion()Get the XSD language version allowed- Returns:
- the XSD language version. Returns 10 for XSD 1.0, 11 for XSD 1.1.
Symbolic constants
Configuration.XSD10andConfiguration.XSD11are available.
-
loadSources
Load a schema from a set of schema documents.- Parameters:
sources- the JAXP Source objects identifying the schema documents to be loaded. These may be either source schema documents in XSD format, or a compiled schema in Saxon's SCM format. In addition, instances ofPrecompiledSchemaSourceare accepted; these represent schemas that have already been compiled and cached. If anySourceis anAugmentedSourcewith a required target namespace, then aSchemaExceptionis thrown if the schema document that is read does not have the required namespace.- Returns:
- a PreparedSchema containing the compiled schema.
- Throws:
SchemaException- if the schema cannot be read or parsed or if it is invalid
-
setPreparedSchema
Set the PreparedSchema. Used when validating a schema loaded using the SchemaModelLoader- Parameters:
schema- the schema that has been loaded
-
getPreparedSchema
Get the PreparedSchema. This is a callback available only during a schema validation episode- Returns:
- the PreparedSchema containing all the schema components
-
getErrorReporter
Get the ErrorReporter used in this configuration. If no ErrorReporter has been supplied explicitly, the default ErrorReporter is used.- Returns:
- the ErrorReporter.
- Since:
- 8.9. Changed in 10.0 to use ErrorReporter rather than ErrorListener
-
setErrorReporter
Set the ErrorReporter to be used in this compiler. The ErrorReporter is informed of all errors detected during schema processing. The default is the error reporter created by a call onConfiguration.makeErrorReporter().- Parameters:
reporter- the ErrorReporter to be used- Since:
- 8.9. Changed in 10.0 to use ErrorReporter rather than ErrorListener
-
getErrorCount
public int getErrorCount()Test whether errors have been reported- Returns:
- the number of errors reported
-
setOccurrenceLimits
public void setOccurrenceLimits(int minimum, int maximum) Set the occurrence limits to be used when compiling a finite state automaton.- Parameters:
minimum- The highest value of minOccurs that will be strictly enforced. If the actual value of minOccurs in a schema is higher than this value, it will be treated as if this value had been specified. The default is 100.maximum- The highest value of maxOccurs that will be strictly enforced. If the actual value of maxOccurs in a schema is higher than this value, it will be treated as if "unbounded" had been specified. The default is 250.- Since:
- 8.9
-
getOccurrenceLimits
public int[] getOccurrenceLimits()Get the occurrence limits previously set using setOccurrenceLimits (or the default)- Returns:
- an array of two integers, the minimum occurrence limit and the maximum occurrence limit
- Since:
- 8.9
-
setBeingRead
Mark a URI as currently being read- Parameters:
systemId- the URI of the schema document being read
-
isBeingRead
Determine whether a particular URI is currently being read- Parameters:
systemId- the URI of the document in question- Returns:
- true if the document is currently being read
-
markAsRead
Mark a document as having been read- Parameters:
systemId- the URI of the schema document that has been readschema- the root element of the schema document constructed from this URI
-
isAllowDanglingReferences
public boolean isAllowDanglingReferences()Ask whether dangling references are allowed. Returns false by default; returns true if the configuration propertyFeature.ALLOW_UNRESOLVED_SCHEMA_COMPONENTSis set.- Returns:
- true if the presence of unresolved schema components should not cause the schema to be treated as invalid. Instead, the schema is "repaired" such that it can be used for validation, provided that the absent schema components are not actually required for a particular validation episode.
-
getExistingSchemaDocument
Get the root element of the tree representing a schema document that has already been read- Parameters:
systemId- the URI of the required schema documenttargetNamespace- the expected namespace. If the schema document was previously read but chameleoned into a different namespace, we read it again- Returns:
- the root element of the tree representing this schema document
-
getPipelineConfiguration
Get the pipeline configuration- Returns:
- the pipeline configuration
-
setPipelineConfiguration
Set the pipeline configuration- Parameters:
pipelineConfiguration- the pipeline configuration
-
setSchemaURIResolver
Set the user-defined SchemaURIResolver to be used for resolving URIs used in "import schema" declarations; defaults to theSchemaURIResolverfound in theConfiguration- Parameters:
resolver- the SchemaURIResolver
-
getSchemaURIResolver
Get the user-defined SchemaURIResolver for resolving URIs used in "import schema" declarations; if none has been explicitly set, returns the standard schema URI resolver.- Returns:
- the SchemaURIResolver
-
compile
In deferred validation mode, validate and compile the accumulated schema components. If validation succeeds, the schema components will be added to the cache held by the Configuration.- Throws:
SchemaException- if any of the schema components is invalid, or if the collection of schema components as a whole is invalid, or if there are components present that conflict with components already present in the cache held by the Configuration.
-
validate
Validate the schema represented by a schema document. This method validates the schema components associated with this schema document: that is, the components defined in this document, together with any components referenced by these components if they have not already been validated.- Parameters:
doc- the schema document to be validated- Returns:
- schema the schema, if it is valid
- Throws:
SchemaException- if the schema is invalid
-
recompile
- Throws:
SchemaException
-
reportMissingComponent
Register that there is an unresolved component reference- Parameters:
componentType- the type of component, for example attributeGroupcomponentName- the name of the component- Returns:
- true if this is the first report that this component is missing
-
error
Report an error- Parameters:
message- the error messagelocator- the location of the error
-
warning
Report a warning- Parameters:
message- the warning messageerrorCode- a code associated with the messagelocator- the location of the error
-
addPendingTypeCheck
Register an identity constraint that needs to be type-checked- Parameters:
constraint- the constraint to be checkedcontextItemType- the type of the context node for the XPath expression to be checked
-
typeCheckIdentityConstraints
Do all the pending type-checking- Throws:
SchemaException- if any of the checks fail
-
doChameleonTransformation
public SchemaDocument doChameleonTransformation(NodeInfo input, SchemaElement referrer) throws SchemaException Do the chameleon transformation on a source schema document- Parameters:
input- the included schema document to be transformeedreferrer- the xs:include element referencing this schema document- Returns:
- the transformed schema document
- Throws:
SchemaException- if the transformation fails
-
doOverrideTransformation
public SchemaDocument doOverrideTransformation(NodeInfo input, SchemaElement referrer) throws SchemaException Do the override transformation on a source schema document- Parameters:
input- the schema document being overriddenreferrer- the xs:override element referencing this schema document- Returns:
- the transformed schema document
- Throws:
SchemaException- if the transformation fails
-
scheduleAutomaton
Schedule the task of creating a finite state automaton for a given complex type. This is done at the end, because there may be multiple requests for the same complex type, and doing it once saves effort- Parameters:
type- the complex type for which an FSA is needed
-
scheduleAutomatonCheck
Schedule a subsumption check: that is, checking that the finite state automaton for one complex type subsumes the FSA for another complex type- Parameters:
base- the base (super-) complex typesub- the derived complex type
-
makeAllAutomata
Create determinized finite state automata for all complex types for which this has been previously requested- Throws:
SchemaException- if creation of any FSA fails
-
checkAllAutomata
Perform all subsumption checks that have been previously requested. This can only be done after the determinized FSA's have been constructed.- Throws:
SchemaException- if any restricted type is not validly derived from its base type
-
addSubstitutionGroupMember
public void addSubstitutionGroupMember(ElementDecl owner, ElementDecl member) throws SchemaException Add a member of the substitution group that has this element as its head. For internal use only.This method may be called at any time, for example when a new schema is loaded as a result of validating an instance document. The method is therefore synchronized, since the schema may be used in several threads concurrently. Adding a new member to a substitution group means that all complex type definitions that include this element in their content model must be recompiled.
It is not possible to add to a substitution group once the element declaration has been used, either for validating a source document or for compiling stylesheets or schemas.
- Parameters:
owner- the owner of the substitution groupmember- The element declaration to be added to the substitution group of which this element declaration is the head. Elements are added to each ancestor in the substitution group hierarchy.- Throws:
SchemaException- if a fatal error occurs
-
getSchemaForBuiltInNamespace
Add a built-in schema for a given namespace. This is a no-op if the configuration is not schema-aware- Parameters:
namespace- the namespace. Currently built-in schemas are available for the XML, XSI, and FN namespaces
-