Package com.saxonica.ee.schema
Class PreparedSchema
java.lang.Object
com.saxonica.ee.schema.PreparedSchema
- All Implemented Interfaces:
NotationSet,Schema
- Direct Known Subclasses:
SingleNamespaceSchema
A schema is a collection of schema components. It may be derived from a single schema
document (an xs:schema element), in which case it contains those components defined in that
schema document, the components defined in the included documents (expanded
transitively), and the components defined in imported schema documents (not
expanded transitively). Alternatively, it may be a collection of schema components
derived from multiple independent schema documents.
All components in the schema are indexed by name. In addition, elements, attributes, and types are indexed by their integer NamePool fingerprint.
Construction of the PreparedSchema is not thread-safe; all creation of new components must happen in a single thread.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new Schema definition -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnonymousType(SchemaType type) Register an anonymous type defined in this schemavoidaddAttributeDecl(AttributeDecl attribute) Adds the given global attribute declaration to this Schema.voidaddAttributeGroup(AttributeGroupDecl attributeGroup) Adds the given attribute group declaration to this Schema.voidaddBuiltInNamespace(NamespaceUri namespace) voidAdd an object that might contain a forwards reference to be fixed up latervoidaddElementDecl(ElementDecl elementDecl) Adds the given global element declaration to this Schema definitionvoidaddGlobalParam(GlobalParam param) Declare a global parameter for XPath expressions in this schema document (Saxon extension)voidaddGroup(ModelGroupDefinition group) Adds the given group (xs:group) to this Schema.voidaddIdentityConstraint(IdentityConstraint constraint) Add an identity constraintvoidaddNotation(Notation notation) Adds the given Notation declaration to this Schema defintionvoidaddSchema(PreparedSchema pschema) Add a schema (a collection of schema components) to the cachevoidaddSchemaDocument(String location) voidaddSchemaDocument(NamespaceUri targetNamespace, String location) voidaddSchemaSource(Source schemaSource, ErrorReporter errorReporter, SchemaCompiler compiler) Load a schema, which will be available for use by all subsequent operations using this EnterpriseConfiguration.voidaddSubstitutionGroupMember(ElementDecl owner, ElementDecl member) voidaddType(SchemaType type) Adds the given type definition to this Schema.static booleanapparentlyEqual(SchemaType t1, SchemaType t2) booleancompareWith(PreparedSchema other) Determine whether this schema is equivalent to another schema, compatible with another schema, or incompatible.compileComplexType(SchemaCompiler compiler, UserComplexType type) voidcopyTo(PreparedSchema destination, SchemaCompiler compiler) Copy the components of this schema to another schemavoidexportComponents(Receiver out) Get all the anonymous simple and complex types defined in this schema.Get an iterator over all the named attribute groups defined in this schemaGet an iterator over all the named model groups defined in this schemaGet all the named simple and complex types defined in this schema.Get an iterator over all the notations defined in this schema.getAttributeDecl(int fingerprint) Get the attribute declaration with a given name if there is one.Get the attribute declaration with a given name if there is one.Get all the global attribute declarations defined in this schemaGet the attribute declaration with a given name if there is one.Get the configurationgetDocumentValidator(Receiver receiver, String systemId, ParseOptions validationOptions, Location initiatingLocation) Get a document-level validator to add to a Receiver pipelinegetElementDecl(int fingerprint) Get the global element declaration with a given fingerprintGet the global element declaration with a given nameGet an iterator over all the global element declarations defined in this schema.getElementValidator(Receiver receiver, ParseOptions options, Location location) Get a Receiver that can be used to validate an element, and that passes the validated element on to a target receiver.getExtensionsOfBuiltInType(int fp) Get the set of user-defined complex types that extend a given built-in typeGet the set of complex types that have been defined as extensions of a given type.Get the GlobalParam object representing a named parameter (Saxon extension)Return the set of global parameters defined in this schema documentgetGroup(StructuredQName name) Get the model group with a given name if there is one.Get the identity constraint whose name has a given fingerprintGet an iterator over all the identity constraints defined in this schema (that is, unique, key, and keyref components).intGet the local license id, identifying any local license in the case where this package was loaded from a compiled package that contained its own embedded licenseGet the NamePool used by this schemaintgetNamespaceStatus(NamespaceUri namespace) Get the status of a particular schema namespace.getNotation(StructuredQName notationName) Get the notation with a given namegetSchemaType(StructuredQName name) Get the type with a given name if there is one.getSimpleType(StructuredQName name) Get the simple type with a given name if there is one.Get the members of the substitution group of an elementGet the set of all target namespaces of components present in this schemagetType(StructuredQName name) Get type defined in this schema, searching both named and anonymous typesgetUuid()Get the UUID of this schemaintGet the version of XSD used to create this schemavoidimportComponents(Source source) Import a precompiled Schema Component Model from a given Source.static PreparedSchemaimportComponentsFrom(Source source, Configuration config) booleanincludesSchemaLocation(String location) booleanincludesTargetNamespace(NamespaceUri target) booleanisDeclaredNotation(NamespaceUri uri, String local) Ask whether a given notation name is present in this set of notationsmakeSchemaAttributeTest(int fp) Make aschema-attributenode test for a given attribute namemakeSchemaElementTest(int fp) Make aschema-elementnode test for a given element namestatic PreparedSchemamerge(PreparedSchema ps1, PreparedSchema ps2) Merge two PreparedSchemas into one, rejecting any components that are defined in both.rebuildComplexType(UserComplexType type, FiniteStateMachine fsm) voidregisterExtensionOfBuiltInType(int fp, UserComplexType extension) Register a complex type that extends a built-in simple typevoidregisterExtensionOfUserDefinedType(UserDefinedType baseType, UserComplexType extension) Register a complex type that extends a user-defined typevoidsetLocalLicenseId(int id) Set the local license id, identifying any local license in the case where this package was loaded from a compiled package that contained its own embedded licensevoidsetNamespaceStatus(NamespaceUri namespace, int status) Set the status of a particular schema namespace.voidsetSubstitutionGroupMembers(ElementDecl owner, Set<ElementDecl> members) voidSet a UUID on this schemavoidsetXsdVersion(int version) Set the version of XSD used to create this schemabooleanvalidate(SchemaCompiler compiler) Checks the validity of this Schema definitionvalidateAttribute(StructuredQName nodeName, UnicodeString value, int validation) Validate an attribute value (XSLT only)static SchemaComponentvalidateReference(ComponentReference ref, SchemaCompiler compiler, boolean fatal) Helper method to validate that a reference to a schema component can be resolved
-
Field Details
-
NAMESPACE_UNKNOWN
public static final int NAMESPACE_UNKNOWN- See Also:
-
NAMESPACE_UNDER_CONSTRUCTION
public static final int NAMESPACE_UNDER_CONSTRUCTION- See Also:
-
NAMESPACE_KNOWN
public static final int NAMESPACE_KNOWN- See Also:
-
-
Constructor Details
-
PreparedSchema
Create a new Schema definition- Parameters:
config- The configuration object holding system configuration information
-
-
Method Details
-
getConfiguration
Get the configuration- Specified by:
getConfigurationin interfaceSchema
-
setXsdVersion
public void setXsdVersion(int version) Set the version of XSD used to create this schema- Parameters:
version-Configuration.XSD10orConfiguration.XSD11
-
getXsdVersion
public int getXsdVersion()Get the version of XSD used to create this schema- Returns:
Configuration.XSD10orConfiguration.XSD11
-
setLocalLicenseId
public void setLocalLicenseId(int id) Set the local license id, identifying any local license in the case where this package was loaded from a compiled package that contained its own embedded license- Parameters:
id- identifier used to distinguish this local license
-
getLocalLicenseId
public int getLocalLicenseId()Get the local license id, identifying any local license in the case where this package was loaded from a compiled package that contained its own embedded license- Returns:
- integer identifying the local license, or -1 if there is none
-
setUuid
Set a UUID on this schema- Parameters:
uuid- the UUID to be used
-
getUuid
Get the UUID of this schema- Returns:
- the UUID of the schema; null if none has been allocated
-
addComponent
Add an object that might contain a forwards reference to be fixed up later- Parameters:
obj- the component to be added. The caller should ensure that the same component is not added twice.
-
makeSchemaElementTest
Make aschema-elementnode test for a given element name- Specified by:
makeSchemaElementTestin interfaceSchema- Parameters:
fp- the integer fingerprint of the element name- Returns:
- a node test corresponding to the XPath item type syntax schema-element(E)
- Throws:
SchemaException- if there is no element declaration with this name in the schema
-
makeSchemaAttributeTest
Make aschema-attributenode test for a given attribute name- Specified by:
makeSchemaAttributeTestin interfaceSchema- Parameters:
fp- the integer fingerprint of the attribute name- Returns:
- a node test corresponding to the XPath item type syntax schema-attribute(E)
- Throws:
SchemaException- if there is no attribute declaration with this name in the schema
-
getAttributeDecl
Get the attribute declaration with a given name if there is one.- Specified by:
getAttributeDeclin interfaceSchema- Parameters:
name- the name of the required attribute declaration- Returns:
- the attribute declaration if found, or null otherwise
-
getAttributeDecl
Get the attribute declaration with a given name if there is one.- Specified by:
getAttributeDeclin interfaceSchema- Parameters:
fingerprint- the NamePool fingerprint of the name of the required attribute declaration- Returns:
- the attribute declaration if found, or null otherwise
-
getAttributeDeclarations
Get all the global attribute declarations defined in this schema- Returns:
- an iterable collection of attribute declarations. Each item returned by
the iterator will be an instance of
AttributeDecl
-
addAttributeDecl
Adds the given global attribute declaration to this Schema. It will overwrite any existing attribute declaration with the same name.- Parameters:
attribute- the AttributeDecl to add
-
getAttributeGroup
Get the attribute declaration with a given name if there is one.- Parameters:
name- the name of the required attribute group- Returns:
- the attribute declaration if found, or null otherwise
-
getAllAttributeGroups
Get an iterator over all the named attribute groups defined in this schema- Returns:
- an iterator over the attribute groups. Each item returned by
the iterator will be an instance of
AttributeGroupDecl
-
addAttributeGroup
Adds the given attribute group declaration to this Schema. It will overwrite any existing attribute group declaration with the same name, unless the existing attribute has a higher redefinition level.- Parameters:
attributeGroup- the AttributeDecl to add
-
getGroup
Get the model group with a given name if there is one.- Parameters:
name- the name of the required named model group- Returns:
- the group if found, or null otherwise
-
getAllModelGroups
Get an iterator over all the named model groups defined in this schema- Returns:
- an iterator over the model groups. Each item returned by
the iterator will be an instance of
ModelGroupDefinition
-
addGroup
Adds the given group (xs:group) to this Schema. It will overwrite any existing group with the same name.- Parameters:
group- the group to add
-
getSchemaType
Get the type with a given name if there is one. This method will also find built-in types.- Specified by:
getSchemaTypein interfaceSchema- Parameters:
name- the name of the required schema type- Returns:
- the named simple or complex type if found, or null otherwise
-
getSimpleType
Get the simple type with a given name if there is one. This method will also find built-in types.- Parameters:
name- the name of the required simple type- Returns:
- the simple type if found, or null otherwise
-
getCompiledComplexType
-
getCompiledComplexTypes
-
getAllNamedTypes
Get all the named simple and complex types defined in this schema. This iterable will not include built-in types or anonymous types.- Returns:
- an iterable of the types.
-
getAllAnonymousTypes
Get all the anonymous simple and complex types defined in this schema.- Returns:
- an iterable of the types.
-
addType
Adds the given type definition to this Schema. If another type with this name already exists, it is overwritten, unless it has a higher redefinition level- Parameters:
type- the type to add to this Schema
-
addAnonymousType
Register an anonymous type defined in this schema- Parameters:
type- the anonymous type to be added
-
getType
Get type defined in this schema, searching both named and anonymous types- Parameters:
name- the name of the required schema type- Returns:
- the schema type if found, else null
-
getExtensionsOfType
Get the set of complex types that have been defined as extensions of a given type. Note that we do not seal the schema namespace, so this list is not necessarily final; we must assume that new extensions of built-in simple types can be added at any time- Parameters:
type- the type whose extensions are required
-
registerExtensionOfBuiltInType
Register a complex type that extends a built-in simple type- Parameters:
fp- the fingerprint of the built-in typeextension- the complex type that extends the built-in (directly or indirectly)
-
registerExtensionOfUserDefinedType
Register a complex type that extends a user-defined type- Parameters:
baseType- the user-defined type that is extendedextension- the complex type that extends the base type
-
getExtensionsOfBuiltInType
Get the set of user-defined complex types that extend a given built-in type- Parameters:
fp- the fingerprint of the built-in type- Returns:
- the set of user-defined complex types that have been registered as extensions of this built-in type
-
addElementDecl
Adds the given global element declaration to this Schema definition- Parameters:
elementDecl- the ElementDecl to add to this Schema
-
getElementDecl
Get the global element declaration with a given name- Specified by:
getElementDeclin interfaceSchema- Parameters:
name- the name of the element- Returns:
- the element declaration, or null if not found.
-
getElementDecl
Get the global element declaration with a given fingerprint- Specified by:
getElementDeclin interfaceSchema- Parameters:
fingerprint- the NamePool fingerprint of the name of the element- Returns:
- the element declaration, or null if not found.
-
getSubstitutionGroupMembers
Get the members of the substitution group of an element- Parameters:
owner- the element declaration owning the substitution group- Returns:
- the set of element declarations in this schema that are members of the substitution group. Note that an element declaration may appear in multiple schemas and have different substitution group membership in each one.
-
addSubstitutionGroupMember
-
setSubstitutionGroupMembers
-
getElementDeclarations
Get an iterator over all the global element declarations defined in this schema.- Returns:
- an iterator over the global element declarations. Each item returned by
the iterator will be an instance of
ElementDecl
-
addNotation
Adds the given Notation declaration to this Schema defintion- Parameters:
notation- the Notation to add to this Schema
-
getNotation
Get the notation with a given name- Parameters:
notationName- identifies the name of the notation- Returns:
- the element notation, or null if not found.
-
getAllNotations
Get an iterator over all the notations defined in this schema.- Returns:
- an iterator over the notations. Each item returned by
the iterator will be an instance of
Notation
-
addIdentityConstraint
Add an identity constraint- Parameters:
constraint- the identity constraint to be added
-
getIdentityConstraint
Get the identity constraint whose name has a given fingerprint- Parameters:
name- the name of the required constraint- Returns:
- the identity constraint, or null if there is none with that name
-
getIdentityConstraints
Get an iterator over all the identity constraints defined in this schema (that is, unique, key, and keyref components).- Returns:
- an iterator over the identity constraints. Each item returned by
the iterator will be an instance of
IdentityConstraint
-
getTargetNamespaces
Get the set of all target namespaces of components present in this schema- Returns:
- the set of all target namespaces for these components
-
includesTargetNamespace
- Specified by:
includesTargetNamespacein interfaceSchema
-
getTargetNamespaceMap
-
addSchemaDocument
-
addSchemaDocument
-
includesSchemaLocation
-
getNamePool
Get the NamePool used by this schema- Returns:
- the namepool
-
addGlobalParam
Declare a global parameter for XPath expressions in this schema document (Saxon extension)- Parameters:
param- the details of the parameter- Throws:
SchemaException
-
getGlobalParam
Get the GlobalParam object representing a named parameter (Saxon extension)- Parameters:
name- the parameter name- Returns:
- the GlobalParam object if a parameter with this name exists, else null
-
getGlobalParams
Return the set of global parameters defined in this schema document- Returns:
- the set of global parameters
-
copyTo
Copy the components of this schema to another schema- Parameters:
destination- the destination of the copy. The destination schema is modified; this schema is unchanged.compiler- used for error reporting- Throws:
SchemaException- if there are name clashes between this schema and the destination schema (that is, the same name used to refer to different components. Components are compared by checking their name and origin, where the origin is the SystemId and line number of the schema document from which they were initially derived)
-
addBuiltInNamespace
-
validate
Checks the validity of this Schema definition- Parameters:
compiler- a SchemaCompiler to which all errors should be reported- Returns:
- true if validation succeeds, false if it fails
- Throws:
SchemaException- if the SchemaCompiler decides that an error is fatal
-
validateReference
public static SchemaComponent validateReference(ComponentReference ref, SchemaCompiler compiler, boolean fatal) throws SchemaException Helper method to validate that a reference to a schema component can be resolved- Parameters:
ref- The Component reference that needs to be resolvedcompiler- used for error reportingfatal- True if failure to resolve the reference is an error rather than a warning- Returns:
- the target of the reference
- Throws:
SchemaException- if the reference cannot be resolved
-
compareWith
Determine whether this schema is equivalent to another schema, compatible with another schema, or incompatible.- Parameters:
other- the other schema- Returns:
- true if the two schemas are identical, false if they are different but compatible
- Throws:
SchemaException- if the two schemas are incompatible: specifically, if there is a name that is present in both schemas but refers to different components.
-
merge
Merge two PreparedSchemas into one, rejecting any components that are defined in both.- Parameters:
ps1- the first PreparedSchemaps2- the second PreparedSchema- Returns:
- the merged PreparedSchema
- Throws:
SchemaException- if there are inconsistencies between the two schemas, for example different components with the same name
-
isDeclaredNotation
Description copied from interface:NotationSetAsk whether a given notation name is present in this set of notations- Specified by:
isDeclaredNotationin interfaceNotationSet- Parameters:
uri- the URI part of the notation namelocal- the local part of the notation name- Returns:
- true if the notation name is present
-
addSchemaSource
public void addSchemaSource(Source schemaSource, ErrorReporter errorReporter, SchemaCompiler compiler) throws SchemaException Load a schema, which will be available for use by all subsequent operations using this EnterpriseConfiguration.- Parameters:
schemaSource- the JAXP Source object identifying the schema document to be loaded. This may be either a source schema document in XSD format, or a compiled schema in Saxon's SCM formaterrorReporter- the ErrorListener to be notified of any errors in the schema. If null, the configuration's errorListener is usedcompiler- the schema compiler to be used. This allows a cache of schema documents (retained by the schema compiler) to be reused when compiling multiple schema documents. See bug #4982.- Throws:
SchemaException- if the schema cannot be read or parsed or if it is invalid
-
exportComponents
- Throws:
XPathException
-
importComponents
Import a precompiled Schema Component Model from a given Source. The schema components derived from this schema document are added to the cache of schema components maintained by this SchemaManager- Parameters:
source- the XML file containing the schema component model, as generated by a previous call onexportComponents(net.sf.saxon.event.Receiver)- Throws:
XPathException
-
importComponentsFrom
public static PreparedSchema importComponentsFrom(Source source, Configuration config) throws XPathException - Throws:
XPathException
-
addSchema
Add a schema (a collection of schema components) to the cache- Parameters:
pschema- The schema to be added- Throws:
SchemaException- if the schema cannot be added because components in the schema are incompatible with components already in the cache
-
getNamespaceStatus
Get the status of a particular schema namespace.- Parameters:
namespace- the Namespace URI whose status is required (supply "" for the non-namespace)- Returns:
- one of
NAMESPACE_KNOWN,NAMESPACE_UNKNOWN,NAMESPACE_UNDER_CONSTRUCTION}
-
setNamespaceStatus
Set the status of a particular schema namespace.- Parameters:
namespace- the Namespace URI whose status is required (supply "" for the non-namespace)status- one ofNAMESPACE_KNOWN,NAMESPACE_UNKNOWN,NAMESPACE_UNDER_CONSTRUCTION}
-
getDocumentValidator
public Receiver getDocumentValidator(Receiver receiver, String systemId, ParseOptions validationOptions, Location initiatingLocation) Get a document-level validator to add to a Receiver pipeline- Specified by:
getDocumentValidatorin interfaceSchema- Parameters:
receiver- The receiver to which events should be sent after validationsystemId- the base URI of the document being validatedvalidationOptions- Supplies options relevant to XSD validationinitiatingLocation- (optional) Location in query or stylesheet of instruction that requested validation- Returns:
- A Receiver to which events can be sent for validation
-
getElementValidator
public Receiver getElementValidator(Receiver receiver, ParseOptions options, Location location) throws XPathException Get a Receiver that can be used to validate an element, and that passes the validated element on to a target receiver. If validation is not supported, the returned receiver will be the target receiver.- Specified by:
getElementValidatorin interfaceSchema- Parameters:
receiver- the target receiver to receive the validated element; its pipelineConfiguration must be initialized.options- options affecting the way schema validation is donelocation- identifies the location of the element within its source document (or, if preferred, the location of the instruction requesting validation), relative to the LocationProvider in the PipelineConfiguration of the receiver- Returns:
- The newly created receiver, which performs the validation and passes the validated elements on to the target receiver.
- Throws:
XPathException- if a validator for the element cannot be created
-
validateAttribute
public SimpleType validateAttribute(StructuredQName nodeName, UnicodeString value, int validation) throws ValidationException, MissingComponentException Validate an attribute value (XSLT only)- Specified by:
validateAttributein interfaceSchema- Parameters:
nodeName- the name of the attributevalue- the value of the attribute as a stringvalidation- STRICT or LAX- Returns:
- an int, containing the type annotation to apply to the attribute node
- Throws:
ValidationException- if the value is invalidMissingComponentException
-
compileComplexType
public CompiledComplexType compileComplexType(SchemaCompiler compiler, UserComplexType type) throws SchemaException - Throws:
SchemaException
-
rebuildComplexType
public CompiledComplexType rebuildComplexType(UserComplexType type, FiniteStateMachine fsm) throws SchemaException - Throws:
SchemaException
-
apparentlyEqual
-