Package net.sf.saxon.style
Class Compilation
- java.lang.Object
-
- net.sf.saxon.style.Compilation
-
public class Compilation extends java.lang.Object
Represents an XSLT compilation episode, compiling a single package.
-
-
Constructor Summary
Constructors Constructor Description Compilation(Configuration config, CompilerInfo info)
Create a compilation object ready to perform an XSLT compilation
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearParameters()
Clear the values of all stylesheet parameters that have been set using thesetParameter(net.sf.saxon.om.StructuredQName, net.sf.saxon.om.GroundedValue)
method; and decouple the parameters held by this Compilation from those defined in the originating CompilerInfoPrincipalStylesheetModule
compilePackage(javax.xml.transform.Source source)
Compile a stylesheet packagestatic PreparedStylesheet
compileSingletonPackage(Configuration config, CompilerInfo compilerInfo, javax.xml.transform.Source source)
Static factory method: Compile an XSLT stylesheet consisting of a single packagevoid
declareStaticVariable(StructuredQName name, GroundedValue value, NestedIntegerValue precedence, boolean isParam)
Declare a static variable.CompilerInfo
getCompilerInfo()
Get the compilation options used by this compilationConfiguration
getConfiguration()
Get the Saxon Configuration used by this Compilationint
getErrorCount()
Get the number of errors reported so farjava.util.Stack<DocumentKey>
getImportStack()
Get the stack of include/imports, used to detect circularitiesPackageData
getPackageData()
Get information about the package that was compiled in the course of this CompilationGlobalParameterSet
getParameters()
Get the values of all stylesheet parameters that have been set using thesetParameter(net.sf.saxon.om.StructuredQName, net.sf.saxon.om.GroundedValue)
method.PrincipalStylesheetModule
getPrincipalStylesheetModule()
Get the (most recent) stylesheet package compiled using this CompilationQNameParser
getQNameParser()
Get the QNameParser for parsing QNames in this compilation Note that the namespaceResolver will be unitializedGroundedValue
getStaticVariable(StructuredQName name)
Get the value of a static variableNestedIntegerValue
getStaticVariablePrecedence(StructuredQName name)
Get the precedence of a static variableStyleNodeFactory
getStyleNodeFactory(boolean topLevel)
Get the StyleNodeFactory used to build the stylesheet treejava.util.Map<DocumentKey,TreeInfo>
getStylesheetModules()
Get the map of stylesheet modules.boolean
isCreatesSecondaryResultDocuments()
Ask whether the package has encountered an xsl:result-document instructionboolean
isFallbackToNonStreaming()
Ask whether a non-streamable construct has been found, forcing the entire stylesheet to fall back to unstreamed processingboolean
isLibraryPackage()
Ask whether the package being compiled is a library packageboolean
isPreScan()
Ask whether this is the compile-time phase of a just-in-time compilation, during which template rules are not fully processedboolean
isSchemaAware()
Ask whether this compilation is schema-aware.void
registerPackageDependency(UsePack use)
Method called internally while compiling a package to register that an xsl:use-package declaration has been encountered.void
reportError(XmlProcessingError err)
Report a compile time error.void
reportError(XPathException err)
Report a compile time error.void
reportWarning(java.lang.String message, java.lang.String errorCode, Location location)
void
reportWarning(XPathException err)
Report a compile time warning.void
satisfyPackageDependencies(XSLPackage thisPackage)
After the first phase of processing, we have gathered information about the xsl:use-package elements in the stylesheet.void
setCreatesSecondaryResultDocuments(boolean createsSecondaryResultDocuments)
Say whether the compilation has encountered an xsl:result-document instructionvoid
setExpectedNameAndVersion(VersionedPackageName vpn)
void
setFallbackToNonStreaming(boolean fallbackToNonStreaming)
This method is called when a non-streamable construct is found, and the configuration optionFeature.STREAMING_FALLBACK
has been set; the effect is to mark the whole stylesheet as non-streamablevoid
setLibraryPackage(boolean libraryPackage)
Say whether the package being compiled is a library packagevoid
setMinimalPackageData()
void
setPackageData(PackageData pack)
void
setParameter(StructuredQName name, GroundedValue seq)
Set the value of a stylesheet parameter.void
setPreScan(boolean preScan)
Say whether this is the compile-time phase of a just-in-time compilation, during which template rules are not fully processedvoid
setSchemaAware(boolean schemaAware)
Say that this compilation is schema-aware.void
setUsingPackages(java.util.List<VersionedPackageName> users)
Supply the name/version of the package that invoked this compilation by virtue of an xsl:use-package declaration, together with the users of that package, recursively.
-
-
-
Field Detail
-
TIMING
public static boolean TIMING
-
timer
public Timer timer
-
-
Constructor Detail
-
Compilation
public Compilation(Configuration config, CompilerInfo info)
Create a compilation object ready to perform an XSLT compilation- Parameters:
config
- the Saxon Configurationinfo
- compilation options
-
-
Method Detail
-
compileSingletonPackage
public static PreparedStylesheet compileSingletonPackage(Configuration config, CompilerInfo compilerInfo, javax.xml.transform.Source source) throws XPathException
Static factory method: Compile an XSLT stylesheet consisting of a single package- Parameters:
config
- the Saxon ConfigurationcompilerInfo
- the compilation optionssource
- the source of the root stylesheet module in the package to be compiled. This may contain an xsl:package element at its root, or it may be a conventional xsl:stylesheet or xsl:transform, or a "simplified stylesheet" rooted at a literal result element- Returns:
- the PreparedStylesheet representing the result of the compilation
- Throws:
XPathException
- if any errors occur. The errors will have been reported to the ErrorListener contained in the CompilerInfo.
-
setUsingPackages
public void setUsingPackages(java.util.List<VersionedPackageName> users)
Supply the name/version of the package that invoked this compilation by virtue of an xsl:use-package declaration, together with the users of that package, recursively. The package is not allowed to use the packages in this list, because that would create a cycle of dependencies- Parameters:
users
- the packages that directly or indirectly use this package.
-
setPackageData
public void setPackageData(PackageData pack)
-
setMinimalPackageData
public void setMinimalPackageData()
-
setExpectedNameAndVersion
public void setExpectedNameAndVersion(VersionedPackageName vpn)
-
registerPackageDependency
public void registerPackageDependency(UsePack use)
Method called internally while compiling a package to register that an xsl:use-package declaration has been encountered.- Parameters:
use
- details of the package dependency (name and version of the dependee package)
-
satisfyPackageDependencies
public void satisfyPackageDependencies(XSLPackage thisPackage) throws XPathException
After the first phase of processing, we have gathered information about the xsl:use-package elements in the stylesheet. We now ensure that these dependencies are satisfied and are bound to actual loaded packages, invoking the compiler recursively to load the package if necessary. If there are cyclic references, these must be detected.- Throws:
XPathException
-
compilePackage
public PrincipalStylesheetModule compilePackage(javax.xml.transform.Source source) throws XPathException
Compile a stylesheet package- Parameters:
source
- the XML document containing the top-level stylesheet module in the package, which may be an xsl:package element, an xsl:stylesheet or xsl:transform element, or a "simplified stylesheet" rooted at a literal result element- Returns:
- the StylesheetPackage representing the result of the compilation
- Throws:
XPathException
- if any error occurs while compiling the package
-
getConfiguration
public Configuration getConfiguration()
Get the Saxon Configuration used by this Compilation- Returns:
- the Saxon Configuration
-
getCompilerInfo
public CompilerInfo getCompilerInfo()
Get the compilation options used by this compilation- Returns:
- the compilation options
-
getPackageData
public PackageData getPackageData()
Get information about the package that was compiled in the course of this Compilation- Returns:
- package information
-
isSchemaAware
public boolean isSchemaAware()
Ask whether this compilation is schema-aware. It is schema-aware either if this is explicitly requested in the supplied CompilerInfo, or if this is explicitly requested within the stylesheet source code, for example by the presence of anxsl:import-schema
declaration or avalidation
attribute- Returns:
- true if the compilation is schema-aware
-
setSchemaAware
public void setSchemaAware(boolean schemaAware)
Say that this compilation is schema-aware. This method is called internally during the course of a compilation if anxsl:import-schema
declaration is encountered.- Parameters:
schemaAware
- true if the compilation is schema-aware.
-
getStyleNodeFactory
public StyleNodeFactory getStyleNodeFactory(boolean topLevel)
Get the StyleNodeFactory used to build the stylesheet tree- Parameters:
topLevel
- true if the factory is for the top-level (package) module of a package- Returns:
- the StyleNodeFactory
-
getPrincipalStylesheetModule
public PrincipalStylesheetModule getPrincipalStylesheetModule()
Get the (most recent) stylesheet package compiled using this Compilation- Returns:
- the most recent stylesheet package compiled
-
reportError
public void reportError(XmlProcessingError err)
Report a compile time error. This calls the errorListener to output details of the error, and increments an error count.- Parameters:
err
- the exception containing details of the error
-
reportError
public void reportError(XPathException err)
Report a compile time error. This calls the errorListener to output details of the error, and increments an error count.- Parameters:
err
- the exception containing details of the error
-
getErrorCount
public int getErrorCount()
Get the number of errors reported so far- Returns:
- the number of errors reported
-
reportWarning
public void reportWarning(XPathException err)
Report a compile time warning. This calls the errorListener to output details of the warning.- Parameters:
err
- an exception holding details of the warning condition to be reported
-
reportWarning
public void reportWarning(java.lang.String message, java.lang.String errorCode, Location location)
-
declareStaticVariable
public void declareStaticVariable(StructuredQName name, GroundedValue value, NestedIntegerValue precedence, boolean isParam) throws XPathException
Declare a static variable. This is called internally by the stylesheet compiler when a static variable declaration is encountered.- Parameters:
name
- the name of the variablevalue
- the value of the variableprecedence
- the import precedence in the form of a "decimal" value (e.g. 2.14.6)isParam
- true if this is an xsl:param rather than an xsl:variable- Throws:
XPathException
- if, for example, the value of the variable is incompatible with other variables having the same name
-
getStaticVariable
public GroundedValue getStaticVariable(StructuredQName name)
Get the value of a static variable- Parameters:
name
- the name of the required variable- Returns:
- the value of the variable if there is one, or null if the variable is undeclared
-
getStaticVariablePrecedence
public NestedIntegerValue getStaticVariablePrecedence(StructuredQName name)
Get the precedence of a static variable- Parameters:
name
- the name of the required variable- Returns:
- the precedence of the variable if there is one, or null if the variable is undeclared
-
getStylesheetModules
public java.util.Map<DocumentKey,TreeInfo> getStylesheetModules()
Get the map of stylesheet modules. This includes an entry for every stylesheet module in the compilation; the key is the absolute URI, and the value is the corresponding document.- Returns:
- the map from absolute URIs to (documents containing) stylesheet modules
-
getImportStack
public java.util.Stack<DocumentKey> getImportStack()
Get the stack of include/imports, used to detect circularities- Returns:
- the include/import stack
-
getQNameParser
public QNameParser getQNameParser()
Get the QNameParser for parsing QNames in this compilation Note that the namespaceResolver will be unitialized- Returns:
- the QNameParser
-
isPreScan
public boolean isPreScan()
Ask whether this is the compile-time phase of a just-in-time compilation, during which template rules are not fully processed- Returns:
- true if just-in-time compilation is in force and this is the static processing phase in which code is not fully processed. Return false if just-in-time compilation is not in force, or if this is the run-time phase during which full static analysis and code generation takes place.
-
setPreScan
public void setPreScan(boolean preScan)
Say whether this is the compile-time phase of a just-in-time compilation, during which template rules are not fully processed- Parameters:
preScan
- true if just-in-time compilation is in force and this is the static processing phase in which code is not fully processed. Set to false if just-in-time compilation is not in force, or if this is the run-time phase during which full static analysis and code generation takes place.
-
isCreatesSecondaryResultDocuments
public boolean isCreatesSecondaryResultDocuments()
Ask whether the package has encountered an xsl:result-document instruction- Returns:
- true if the package contains an xsl:result-document instruction
-
setCreatesSecondaryResultDocuments
public void setCreatesSecondaryResultDocuments(boolean createsSecondaryResultDocuments)
Say whether the compilation has encountered an xsl:result-document instruction- Parameters:
createsSecondaryResultDocuments
- true if the package contains an xsl:result-document instruction
-
isLibraryPackage
public boolean isLibraryPackage()
Ask whether the package being compiled is a library package- Returns:
- true if this is a library package
-
setLibraryPackage
public void setLibraryPackage(boolean libraryPackage)
Say whether the package being compiled is a library package- Parameters:
libraryPackage
- if this is a library package
-
setParameter
public void setParameter(StructuredQName name, GroundedValue seq)
Set the value of a stylesheet parameter. Static (compile-time) parameters must be provided using this method on the XsltCompiler object, prior to stylesheet compilation. Non-static parameters may also be provided using this method if their values will not vary from one transformation to another. No error occurs at this stage if the parameter is unknown, or if the value is incorrect for the parameter. Setting a value for a parameter overwrites any previous value set for the same parameter.- Parameters:
name
- the name of the stylesheet parameterseq
- the value of the stylesheet parameter
-
getParameters
public GlobalParameterSet getParameters()
Get the values of all stylesheet parameters that have been set using thesetParameter(net.sf.saxon.om.StructuredQName, net.sf.saxon.om.GroundedValue)
method.- Returns:
- the set of all parameters that have been set.
-
clearParameters
public void clearParameters()
Clear the values of all stylesheet parameters that have been set using thesetParameter(net.sf.saxon.om.StructuredQName, net.sf.saxon.om.GroundedValue)
method; and decouple the parameters held by this Compilation from those defined in the originating CompilerInfo
-
isFallbackToNonStreaming
public boolean isFallbackToNonStreaming()
Ask whether a non-streamable construct has been found, forcing the entire stylesheet to fall back to unstreamed processing- Returns:
- true if the stylesheet must fall back to unstreamed processing
-
setFallbackToNonStreaming
public void setFallbackToNonStreaming(boolean fallbackToNonStreaming)
This method is called when a non-streamable construct is found, and the configuration optionFeature.STREAMING_FALLBACK
has been set; the effect is to mark the whole stylesheet as non-streamable- Parameters:
fallbackToNonStreaming
- true if a construct has been found that is declared streamable but not actually streamable, if fallback processing was requested.
-
-