Package com.saxonica.ee.schema
Class PreparedSchema
- java.lang.Object
-
- com.saxonica.ee.schema.PreparedSchema
-
- All Implemented Interfaces:
NotationSet
- Direct Known Subclasses:
SingleNamespaceSchema
public class PreparedSchema extends java.lang.Object implements NotationSet
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
Fields Modifier and Type Field Description static int
NAMESPACE_KNOWN
static int
NAMESPACE_SEALED
static int
NAMESPACE_UNDER_CONSTRUCTION
static int
NAMESPACE_UNKNOWN
-
Constructor Summary
Constructors Modifier Constructor Description protected
PreparedSchema()
Create a dummy schema definition.PreparedSchema(EnterpriseConfiguration config)
Create a new Schema definition
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAnonymousType(SchemaType type)
Register an anonymous type defined in this schemavoid
addAttributeDecl(AttributeDecl attribute)
Adds the given global attribute declaration to this Schema.void
addAttributeGroup(AttributeGroupDecl attributeGroup)
Adds the given attribute group declaration to this Schema.void
addComponent(UserSchemaComponent obj)
Add an object that might contain a forwards reference to be fixed up latervoid
addElementDecl(ElementDecl elementDecl)
Adds the given global element declaration to this Schema definitionvoid
addGlobalParam(GlobalParam param)
Declare a global parameter for XPath expressions in this schema document (Saxon extension)void
addGroup(ModelGroupDefinition group)
Adds the given group (xs:group) to this Schema.void
addIdentityConstraint(IdentityConstraint constraint)
Add an identity constraintvoid
addNotation(Notation notation)
Adds the given Notation declaration to this Schema defintionvoid
addType(SchemaType type)
Adds the given type definition to this Schema.void
copyTo(PreparedSchema destination, SchemaCompiler compiler)
Copy the components of this schema to another schemajava.lang.Iterable<AttributeGroupDecl>
getAllAttributeGroups()
Get an iterator over all the named attribute groups defined in this schemajava.lang.Iterable<ModelGroupDefinition>
getAllModelGroups()
Get an iterator over all the named model groups defined in this schemajava.lang.Iterable<Notation>
getAllNotations()
Get an iterator over all the notations defined in this schema.java.lang.Iterable<SchemaType>
getAllTypes()
Get all the named simple and complex types defined in this schema.AttributeDecl
getAttributeDecl(int fingerprint)
Get the attribute declaration with a given name if there is one.AttributeDecl
getAttributeDecl(StructuredQName name)
Get the attribute declaration with a given name if there is one.java.lang.Iterable<AttributeDecl>
getAttributeDeclarations()
Get all the global attribute declarations defined in this schemaAttributeGroupDecl
getAttributeGroup(StructuredQName name)
Get the attribute declaration with a given name if there is one.EnterpriseConfiguration
getConfiguration()
Get the configurationElementDecl
getElementDecl(int fingerprint)
Get the global element declaration with a given fingerprintElementDecl
getElementDecl(StructuredQName name)
Get the global element declaration with a given namejava.lang.Iterable<ElementDecl>
getElementDeclarations()
Get an iterator over all the global element declarations defined in this schema.java.util.Set<UserComplexType>
getExtensionsOfBuiltInType(int fp)
Get the set of user-defined complex types that extend a given built-in typeGlobalParam
getGlobalParam(StructuredQName name)
Get the GlobalParam object representing a named parameter (Saxon extension)java.util.Collection<GlobalParam>
getGlobalParams()
Return the set of global parameters defined in this schema documentModelGroupDefinition
getGroup(StructuredQName name)
Get the model group with a given name if there is one.IdentityConstraint
getIdentityConstraint(StructuredQName name)
Get the identity constraint whose name has a given fingerprintjava.lang.Iterable<IdentityConstraint>
getIdentityConstraints()
Get an iterator over all the identity constraints defined in this schema (that is, unique, key, and keyref components).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 licenseNamePool
getNamePool()
Get the NamePool used by this schemaNotation
getNotation(StructuredQName notationName)
Get the notation with a given nameSchemaType
getSchemaType(StructuredQName name)
Get the type with a given name if there is one.SimpleType
getSimpleType(StructuredQName name)
Get the simple type with a given name if there is one.java.util.Set<java.lang.String>
getTargetNamespaces()
Get the set of all target namespaces of components present in this schemaSchemaType
getType(StructuredQName name)
Get type defined in this schema, searching both named and anonymous typesboolean
isDeclaredNotation(java.lang.String uri, java.lang.String local)
Ask whether a given notation name is present in this set of notationsstatic PreparedSchema
merge(PreparedSchema ps1, PreparedSchema ps2)
Merge two PreparedSchemas into one, rejecting any components that are defined in both.void
registerExtensionOfBuiltInType(int fp, UserComplexType extension)
Register a complex type that extends a built-in simple typevoid
setConfiguration(EnterpriseConfiguration config)
Set the configurationvoid
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 licenseboolean
validate(SchemaCompiler compiler)
Checks the validity of this Schema definition, and if valid, adds the schema to the cache held by the EnterpriseConfigurationstatic SchemaComponent
validateReference(ComponentReference ref, SchemaCompiler compiler, boolean fatal)
Helper method to validate that a reference to a schema component can be resolved
-
-
-
Field Detail
-
NAMESPACE_UNKNOWN
public static final int NAMESPACE_UNKNOWN
- See Also:
- Constant Field Values
-
NAMESPACE_UNDER_CONSTRUCTION
public static final int NAMESPACE_UNDER_CONSTRUCTION
- See Also:
- Constant Field Values
-
NAMESPACE_KNOWN
public static final int NAMESPACE_KNOWN
- See Also:
- Constant Field Values
-
NAMESPACE_SEALED
public static final int NAMESPACE_SEALED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PreparedSchema
protected PreparedSchema()
Create a dummy schema definition. This constructor is defined only for use by subclasses
-
PreparedSchema
public PreparedSchema(EnterpriseConfiguration config)
Create a new Schema definition- Parameters:
config
- The configuration object holding system configuration information
-
-
Method Detail
-
setConfiguration
public void setConfiguration(EnterpriseConfiguration config)
Set the configuration
-
getConfiguration
public EnterpriseConfiguration getConfiguration()
Get the configuration
-
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
-
addComponent
public void addComponent(UserSchemaComponent obj)
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.
-
getAttributeDecl
public AttributeDecl getAttributeDecl(StructuredQName name)
Get the attribute declaration with a given name if there is one.- Parameters:
name
- the name of the required attribute declaration- Returns:
- the attribute declaration if found, or null otherwise
-
getAttributeDecl
public AttributeDecl getAttributeDecl(int fingerprint)
Get the attribute declaration with a given name if there is one.- Parameters:
fingerprint
- the NamePool fingerprint of the name of the required attribute declaration- Returns:
- the attribute declaration if found, or null otherwise
-
getAttributeDeclarations
public java.lang.Iterable<AttributeDecl> 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
public void addAttributeDecl(AttributeDecl attribute)
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
public AttributeGroupDecl getAttributeGroup(StructuredQName name)
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
public java.lang.Iterable<AttributeGroupDecl> 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
public void addAttributeGroup(AttributeGroupDecl attributeGroup)
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
public ModelGroupDefinition getGroup(StructuredQName name)
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
public java.lang.Iterable<ModelGroupDefinition> 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
public void addGroup(ModelGroupDefinition group)
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
public SchemaType getSchemaType(StructuredQName name)
Get the type with a given name if there is one. This method will also find built-in types.- Parameters:
name
- the name of the required schema type- Returns:
- the named simple or complex type if found, or null otherwise
-
getSimpleType
public SimpleType getSimpleType(StructuredQName name)
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
-
getAllTypes
public java.lang.Iterable<SchemaType> getAllTypes()
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.
-
addType
public void addType(SchemaType type)
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
public void addAnonymousType(SchemaType type)
Register an anonymous type defined in this schema- Parameters:
type
- the anonymous type to be added
-
getType
public SchemaType getType(StructuredQName name)
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
-
registerExtensionOfBuiltInType
public void registerExtensionOfBuiltInType(int fp, UserComplexType extension)
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)
-
getExtensionsOfBuiltInType
public java.util.Set<UserComplexType> getExtensionsOfBuiltInType(int fp)
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
public void addElementDecl(ElementDecl elementDecl)
Adds the given global element declaration to this Schema definition- Parameters:
elementDecl
- the ElementDecl to add to this Schema
-
getElementDecl
public ElementDecl getElementDecl(StructuredQName name)
Get the global element declaration with a given name- Parameters:
name
- the name of the element- Returns:
- the element declaration, or null if not found.
-
getElementDecl
public ElementDecl getElementDecl(int fingerprint)
Get the global element declaration with a given fingerprint- Parameters:
fingerprint
- the NamePool fingerprint of the name of the element- Returns:
- the element declaration, or null if not found.
-
getElementDeclarations
public java.lang.Iterable<ElementDecl> 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
public void addNotation(Notation notation)
Adds the given Notation declaration to this Schema defintion- Parameters:
notation
- the Notation to add to this Schema
-
getNotation
public Notation getNotation(StructuredQName notationName)
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
public java.lang.Iterable<Notation> 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
public void addIdentityConstraint(IdentityConstraint constraint)
Add an identity constraint- Parameters:
constraint
- the identity constraint to be added
-
getIdentityConstraint
public IdentityConstraint getIdentityConstraint(StructuredQName name)
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
public java.lang.Iterable<IdentityConstraint> 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
public java.util.Set<java.lang.String> getTargetNamespaces()
Get the set of all target namespaces of components present in this schema- Returns:
- the set of all target namespaces for these components
-
getNamePool
public NamePool getNamePool()
Get the NamePool used by this schema- Returns:
- the namepool
-
addGlobalParam
public void addGlobalParam(GlobalParam param) throws SchemaException
Declare a global parameter for XPath expressions in this schema document (Saxon extension)- Parameters:
param
- the details of the parameter- Throws:
SchemaException
-
getGlobalParam
public GlobalParam getGlobalParam(StructuredQName name)
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
public java.util.Collection<GlobalParam> getGlobalParams()
Return the set of global parameters defined in this schema document- Returns:
- the set of global parameters
-
copyTo
public void copyTo(PreparedSchema destination, SchemaCompiler compiler) throws SchemaException
Copy the components of this schema to another schema- Parameters:
destination
- the destination of the copycompiler
- 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)
-
validate
public boolean validate(SchemaCompiler compiler) throws SchemaException
Checks the validity of this Schema definition, and if valid, adds the schema to the cache held by the EnterpriseConfiguration- 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
-
merge
public static PreparedSchema merge(PreparedSchema ps1, PreparedSchema ps2) throws SchemaException
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
public boolean isDeclaredNotation(java.lang.String uri, java.lang.String local)
Description copied from interface:NotationSet
Ask whether a given notation name is present in this set of notations- Specified by:
isDeclaredNotation
in 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
-
-