public class ServletLoader extends Object
web.xml
files in Tomcat. We have kept only the <servlet> tag
and it's subtags.Modifier and Type | Field and Description |
---|---|
private static String |
namespace
The name of the servlets namespace.
|
private static String |
schemaFileURL
The URL pointing to the servlets.xsd schema.
|
private List<ServletWrapper> |
servlets |
private Document |
validatedDom |
Constructor and Description |
---|
ServletLoader()
Create a new XML loader instance.
|
Modifier and Type | Method and Description |
---|---|
List<ServletWrapper> |
getServlets()
Get a list with all loaded servlet definitions.
|
boolean |
hasValidFile()
Checks if an XML file has passed validation in the
validateXmlFile(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.
|
protected Class<? extends Servlet> |
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.
|
private static final String schemaFileURL
private static final String namespace
private Document validatedDom
private List<ServletWrapper> servlets
public void loadXmlFile(InputStream xmlFile, String filename, ClassLoader classLoader, boolean clear) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException
validateXmlFile(InputStream, String)
and loadLastValidatedFile(ClassLoader, boolean)
.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 fileJDOMException
- If validation of the XML file failsIOException
- 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
publicvalidateXmlFile(InputStream, String)
,
loadLastValidatedFile(ClassLoader, boolean)
public void validateXmlFile(InputStream xmlFile, String filename) throws IOException
loadLastValidatedFile(ClassLoader, boolean)
.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 messagesJDOMException
- If validation of the XML file failsIOException
- If there is an error reading the XML filepublic void loadLastValidatedFile(ClassLoader classLoader, boolean clear) throws ClassNotFoundException, IllegalAccessException, NoSuchMethodException
validateXmlFile(InputStream, String)
has been successfully called
first.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 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
publicpublic boolean hasValidFile()
validateXmlFile(InputStream, String)
method. If so,
the loadLastValidatedFile(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.
public List<ServletWrapper> getServlets()
protected Document loadDocument(InputStream xmlFile, String filename) throws IOException
IOException
protected int loadServlets(Document dom, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException
protected Class<? extends Servlet> loadServletClass(String className, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException
Servlet
interface and have a public, no-argument contstructorclassName
- The name of the servlet classclassLoader
- The classloader to use, or null to use
the BASE core classloaderClassNotFoundException
NoSuchMethodException
IllegalAccessException