Loading a precompiled executable
Use the XCompilationFactory interface and its various load methods to load a precompiled expression, query, or stylesheet. These load methods load the Java classes and return an XPathExecutable, XQueryExecutable, or XSLTExecutable object respectively.
Tasks
- Retrieve the XCompilationFactory by calling the getCompilationFactory method on the XFactory class.
An XCompilationFactory instance is associated with a particular XFactory instance, so they share registered schemas. If a new schema is registered with the XFactory instance, therefore, it is visible to the associated XCompilationFactory instance.
- Create a new XCompilationParameters instance by calling the XCompilationFactory newCompilationParameters method, passing in the base class name of the classes to be loaded.
Configure the parameters further using the set methods described in this table.
The setDirectoryName method is not valid when loading a precompiled executable because the classpath is used to search for the classes. If the directory name is set, it is ignored. The setDirectoryName method can be used when generating precompiled executables to specify the directory to which we want to write the classes.
Set Methods Valid for Loading a Precompiled Executable Description Default setPackageName Package name of the classes to load. Java default package setClassLoader Specify the class loader to use. Class loader used to load the processor - Using one of the load methods on the XCompilationFactory, passing in the XCompilationParameters, to load the precompiled executable.
Example
The following is a basic example of loading a precompiled XPath expression.
// Create the factory XFactory factory = XFactory.newInstance(); // Get the compilation factory XCompilationFactory compileFactory = factory.getCompilationFactory(); // Create the compilation parameters XCompilationParameters params = compileFactory.newCompilationParameters("MyXPath"); params.setPackageName( "org.example.myxpath"); // Load the executable XPathExecutable executable = compileFactory.loadXPath(params); // Create the input source StreamSource input = new StreamSource("simple.xml"); // Execute the XPath expression XSequenceCursor cursor = executable.execute(input);Appropriate load methods are available for XQuery and XSLT as well.
Precompiling using the command-line tools Precompiling in Java