Class ServletLoader
java.lang.Object
net.sf.basedb.clients.web.extensions.ServletLoader
Loads servlet definitions from an XML file. The file format is a
simplified version of the format allowed for
web.xml
files in Tomcat. We have kept only the <servlet> tag
and it's subtags.- Version:
- 2.7
- Author:
- nicklas
- Last modified
- $Date: 2015-04-21 08:26:57 +0200 (ti, 21 apr 2015) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
The name of the servlets namespace.private static final String
The URL pointing to the servlets.xsd schema.private List<ServletWrapper>
private Document
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet a list with all loaded servlet definitions.boolean
Checks if an XML file has passed validation in thevalidateXmlFile(InputStream, String)
method.protected Document
loadDocument
(InputStream xmlFile, String filename) Load and validate the XML file.void
loadLastValidatedFile
(ClassLoader classLoader, boolean clear) Continue loading servlet definitions from the last validated XML file.loadServletClass
(String className, ClassLoader classLoader) Load the servlet class.protected int
loadServlets
(Document dom, ClassLoader classLoader) Load the servlet definitions from an XML document.void
loadXmlFile
(InputStream xmlFile, String filename, ClassLoader classLoader, boolean clear) Load a servlet definition XML file.void
validateXmlFile
(InputStream xmlFile, String filename) Validate an XML file against the servlet definition schema.
-
Field Details
-
schemaFileURL
The URL pointing to the servlets.xsd schema. -
namespace
The name of the servlets namespace.- See Also:
-
validatedDom
-
servlets
-
-
Constructor Details
-
ServletLoader
public ServletLoader()Create a new XML loader instance.
-
-
Method Details
-
loadXmlFile
public void loadXmlFile(InputStream xmlFile, String filename, ClassLoader classLoader, boolean clear) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException Load a servlet definition XML file. This method may be called multiple times with different XML files. The loading may also be done by a two-step process where the first step validates the file and the second step loads the extensions. SeevalidateXmlFile(InputStream, String)
andloadLastValidatedFile(ClassLoader, boolean)
.- Parameters:
xmlFile
- An input stream to read the XML data fromfilename
- The original filename the stream is coming from, or null if not known. This value is only used when generating error messagesclassLoader
- The classloader to use when loading classes that are named in the XML file, or null to use the default classloader (=the same class loader that loaded the BASE core classes)clear
- TRUE to clear all already loaded servlets before loading the servlets in this file- Throws:
IOException
- If there is an error reading the XML fileClassNotFoundException
- If a servlet class named in the XML file can't be foundNoSuchMethodException
- If a servlet class doesn't implement a public, no-argument constructorIllegalAccessException
- If a servlet class constructor isn't public- See Also:
-
validateXmlFile
Validate an XML file against the servlet definition schema. If the file is valid you may continue to load the servlet definitions. SeeloadLastValidatedFile(ClassLoader, boolean)
.- Parameters:
xmlFile
- An input stream to read the XML data fromfilename
- The original filename the stream is coming from, or null if not known. This value is only used when generating error messages- Throws:
IOException
- If there is an error reading the XML file
-
loadLastValidatedFile
public void loadLastValidatedFile(ClassLoader classLoader, boolean clear) throws ClassNotFoundException, IllegalAccessException, NoSuchMethodException Continue loading servlet definitions from the last validated XML file. This is the second step in a two-step process and requires thatvalidateXmlFile(InputStream, String)
has been successfully called first.- Parameters:
classLoader
- The classloader to use when loading classes that are named in the XML file, or null to use the default classloader (=the same class loader that loaded the BASE core classes)clear
- TRUE to clear all already loaded servlets before loading the servlets in this file- Throws:
ClassNotFoundException
- If a servlet class named in the XML file can't be foundNoSuchMethodException
- If a servlet class doesn't implement a public, no-argument constructorIllegalAccessException
- If a servlet class constructor isn't public
-
hasValidFile
public boolean hasValidFile()Checks if an XML file has passed validation in thevalidateXmlFile(InputStream, String)
method. If so, theloadLastValidatedFile(ClassLoader, boolean)
can be called to continue loading the servlet definitions.Note that once the file has been loaded this flag is reset to FALSE.
- Returns:
- TRUE if a file has been validated, FALSE otherwise
-
getServlets
Get a list with all loaded servlet definitions. -
loadDocument
Load and validate the XML file.- Returns:
- A JDOM document object
- Throws:
IOException
-
loadServlets
protected int loadServlets(Document dom, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException Load the servlet definitions from an XML document. -
loadServletClass
protected Class<? extends Servlet> loadServletClass(String className, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException Load the servlet class. The class must implement theServlet
interface and have a public, no-argument contstructor- Parameters:
className
- The name of the servlet classclassLoader
- The classloader to use, or null to use the BASE core classloader- Returns:
- An initialised factory
- Throws:
ClassNotFoundException
NoSuchMethodException
IllegalAccessException
-