Package net.sf.saxon.trans
Class DynamicLoader
- java.lang.Object
-
- net.sf.saxon.trans.DynamicLoader
-
- All Implemented Interfaces:
IDynamicLoader
- Direct Known Subclasses:
DynamicLoaderPE
public class DynamicLoader extends java.lang.Object implements IDynamicLoader
Utility class used to perform dynamic loading of user-hook implementations
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.HashMap<java.lang.String,java.lang.Class<?>>
knownClasses
-
Constructor Summary
Constructors Constructor Description DynamicLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Class<?>
getClass(java.lang.String className, Logger traceOut, java.lang.ClassLoader classLoader)
Load a class using the class name provided.java.lang.ClassLoader
getClassLoader()
Get the ClassLoader supplied using the methodsetClassLoader(java.lang.ClassLoader)
.java.lang.Object
getInstance(java.lang.String className, java.lang.ClassLoader classLoader)
Instantiate a class using the class name provided.java.lang.Object
getInstance(java.lang.String className, Logger traceOut, java.lang.ClassLoader classLoader)
Instantiate a class using the class name provided, with the option of tracing Note that the method does not check that the object is of the right class.java.io.InputStream
getResourceAsStream(java.lang.String name)
Get a resource from a supplied URI using the classpath URI scheme.protected void
registerKnownClasses()
Register classes that might be dynamically loaded even though they are contained within Saxon itself.void
setClassLoader(java.lang.ClassLoader loader)
Set a ClassLoader to be used when loading external classes.
-
-
-
Method Detail
-
registerKnownClasses
protected void registerKnownClasses()
Register classes that might be dynamically loaded even though they are contained within Saxon itself. This typically occurs for default implementations of classes that can be substituted or subclassed by the user.
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader loader)
Set a ClassLoader to be used when loading external classes. Examples of classes that are loaded include SAX parsers, localization modules for formatting numbers and dates, extension functions, external object models. In an environment such as Eclipse that uses its own ClassLoader, this ClassLoader should be nominated to ensure that any class loaded by Saxon is identical to a class of the same name loaded by the external environment.- Specified by:
setClassLoader
in interfaceIDynamicLoader
- Parameters:
loader
- the ClassLoader to be used in this configuration
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Get the ClassLoader supplied using the methodsetClassLoader(java.lang.ClassLoader)
. If none has been supplied, return null.- Returns:
- the ClassLoader used in this configuration
-
getClass
public java.lang.Class<?> getClass(java.lang.String className, Logger traceOut, java.lang.ClassLoader classLoader) throws XPathException
Load a class using the class name provided. Note that the method does not check that the object is of the right class.This method is intended for internal use only.
- Specified by:
getClass
in interfaceIDynamicLoader
- Parameters:
className
- A string containing the name of the class, for example "com.microstar.sax.LarkDriver"traceOut
- if diagnostic tracing is required, the destination for the output; otherwise nullclassLoader
- The ClassLoader to be used to load the class. If this is null, then the classLoader used will be the first one available of: the classLoader registered with the Configuration usingsetClassLoader(java.lang.ClassLoader)
; the context class loader for the current thread; or failing that, the class loader invoked implicitly by a call of Class.forName() (which is the ClassLoader that was used to load the Configuration object itself).- Returns:
- an instance of the class named, or null if it is not loadable.
- Throws:
XPathException
- if the class cannot be loaded.
-
getInstance
public java.lang.Object getInstance(java.lang.String className, java.lang.ClassLoader classLoader) throws XPathException
Instantiate a class using the class name provided. Note that the method does not check that the object is of the right class.This method is intended for internal use only.
- Specified by:
getInstance
in interfaceIDynamicLoader
- Parameters:
className
- A string containing the name of the class, for example "com.microstar.sax.LarkDriver"classLoader
- The ClassLoader to be used to load the class. If this is null, then the classLoader used will be the first one available of: the classLoader registered with the Configuration usingsetClassLoader(java.lang.ClassLoader)
; the context class loader for the current thread; or failing that, the class loader invoked implicitly by a call of Class.forName() (which is the ClassLoader that was used to load the Configuration object itself).- Returns:
- an instance of the class named, or null if it is not loadable.
- Throws:
XPathException
- if the class cannot be loaded.
-
getInstance
public java.lang.Object getInstance(java.lang.String className, Logger traceOut, java.lang.ClassLoader classLoader) throws XPathException
Instantiate a class using the class name provided, with the option of tracing Note that the method does not check that the object is of the right class.This method is intended for internal use only.
- Specified by:
getInstance
in interfaceIDynamicLoader
- Parameters:
className
- A string containing the name of the class, for example "com.microstar.sax.LarkDriver"traceOut
- if attempts to load classes are to be traced, then the destination for the trace output; otherwise nullclassLoader
- The ClassLoader to be used to load the class. If this is null, then the classLoader used will be the first one available of: the classLoader registered with the Configuration usingsetClassLoader(java.lang.ClassLoader)
; the context class loader for the current thread; or failing that, the class loader invoked implicitly by a call of Class.forName() (which is the ClassLoader that was used to load the Configuration object itself).- Returns:
- an instance of the class named, or null if it is not loadable.
- Throws:
XPathException
- if the class cannot be loaded.
-
getResourceAsStream
public java.io.InputStream getResourceAsStream(java.lang.String name)
Description copied from interface:IDynamicLoader
Get a resource from a supplied URI using the classpath URI scheme.- Specified by:
getResourceAsStream
in interfaceIDynamicLoader
- Parameters:
name
- the path name from the URI- Returns:
- the content of the relevant resource
-
-