Package org.quartz.xml
Class XMLSchedulingDataProcessor
- java.lang.Object
-
- org.quartz.xml.XMLSchedulingDataProcessor
-
- All Implemented Interfaces:
org.xml.sax.ErrorHandler
public class XMLSchedulingDataProcessor extends java.lang.Object implements org.xml.sax.ErrorHandlerParses an XML file that declares Jobs and their schedules (Triggers), and processes the related data. The xml document must conform to the format defined in "job_scheduling_data_2_0.xsd" The same instance can be used again and again, however a single instance is not thread-safe.- Since:
- Quartz 1.8
- Author:
- James House, Past contributions from Chris Bonham, Past contributions from pl47ypus
-
-
Field Summary
Fields Modifier and Type Field Description protected ClassLoadHelperclassLoadHelperprotected java.util.List<java.lang.String>jobGroupsToDeleteprotected java.util.List<java.lang.String>jobGroupsToNeverDeleteprotected java.util.List<JobKey>jobsToDeleteprotected java.util.List<JobDetail>loadedJobsprotected java.util.List<MutableTrigger>loadedTriggersstatic java.lang.StringQUARTZ_NSstatic java.lang.StringQUARTZ_SCHEMA_WEB_URLstatic java.lang.StringQUARTZ_SYSTEM_ID_JAR_PREFIXstatic java.lang.StringQUARTZ_XML_DEFAULT_FILE_NAMEstatic java.lang.StringQUARTZ_XSD_PATH_IN_JARprotected java.util.List<java.lang.String>triggerGroupsToDeleteprotected java.util.List<java.lang.String>triggerGroupsToNeverDeleteprotected java.util.List<TriggerKey>triggersToDeleteprotected java.util.Collection<java.lang.Exception>validationExceptions
-
Constructor Summary
Constructors Constructor Description XMLSchedulingDataProcessor(ClassLoadHelper clh)Constructor for JobSchedulingDataLoader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddJobGroupToNeverDelete(java.lang.String group)Add the given group to the list of job groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.protected voidaddJobToSchedule(JobDetail job)voidaddTriggerGroupToNeverDelete(java.lang.String group)Add the given group to the list of trigger groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.protected voidaddTriggerToSchedule(MutableTrigger trigger)protected voidaddValidationException(org.xml.sax.SAXException e)Adds a detected validation exception.protected voidclearValidationExceptions()Resets the number of detected validation exceptions.voiderror(org.xml.sax.SAXParseException e)ErrorHandler interface.protected voidexecutePreProcessCommands(Scheduler scheduler)voidfatalError(org.xml.sax.SAXParseException e)ErrorHandler interface.protected java.lang.BooleangetBoolean(javax.xml.xpath.XPath xpathToElement, java.lang.String elementName, org.w3c.dom.Document document)protected java.io.InputStreamgetInputStream(java.lang.String fileName)Returns anInputStreamfrom the fileName as a resource.java.util.List<java.lang.String>getJobGroupsToNeverDelete()Get the (unmodifiable) list of job groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.protected java.util.List<JobDetail>getLoadedJobs()Returns aListof jobs loaded from the xml file.protected java.util.List<MutableTrigger>getLoadedTriggers()Returns aListof triggers loaded from the xml file.protected java.lang.StringgetSystemIdForFileName(java.lang.String fileName)For the givenfileName, attempt to expand it to its full path for use as a system id.java.util.List<java.lang.String>getTriggerGroupsToNeverDelete()Get the (unmodifiable) list of trigger groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.protected java.lang.StringgetTrimmedToNullString(javax.xml.xpath.XPath xpathToElement, java.lang.String elementName, org.w3c.dom.Node parentNode)protected java.net.URLgetURL(java.lang.String fileName)Returns anURLfrom the fileName as a resource.protected voidinitDocumentParser()Initializes the XML parser.booleanisIgnoreDuplicates()If true (andOverWriteExistingDatais false) then any job/triggers encountered in this file that have names that already exist in the scheduler will be ignored, and no error will be produced.booleanisOverWriteExistingData()Whether the existing scheduling data (with same identifiers) will be overwritten.protected voidmaybeThrowValidationException()Throws a ValidationException if the number of validationExceptions detected is greater than zero.protected voidprepForProcessing()protected voidprocess(org.xml.sax.InputSource is)protected voidprocessFile()Process the xml file in the default location (a file named "quartz_jobs.xml" in the current working directory).protected voidprocessFile(java.lang.String fileName)Process the xml file namedfileName.protected voidprocessFile(java.lang.String fileName, java.lang.String systemId)Process the xmlfile namedfileNamewith the given system ID.voidprocessFileAndScheduleJobs(java.lang.String fileName, java.lang.String systemId, Scheduler sched)Process the xml file in the given location, and schedule all of the jobs defined within it.voidprocessFileAndScheduleJobs(java.lang.String fileName, Scheduler sched)Process the xml file in the given location, and schedule all of the jobs defined within it.voidprocessFileAndScheduleJobs(Scheduler sched, boolean overWriteExistingJobs)Process the xml file in the default location, and schedule all of the jobs defined within it.voidprocessStreamAndScheduleJobs(java.io.InputStream stream, java.lang.String systemId, Scheduler sched)Process the xmlfile namedfileNamewith the given system ID.booleanremoveJobGroupToNeverDelete(java.lang.String group)Remove the given group to the list of job groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.booleanremoveTriggerGroupToNeverDelete(java.lang.String group)Remove the given group to the list of trigger groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.protected java.lang.ObjectresolveSchemaSource()protected voidscheduleJobs(Scheduler sched)Schedules the given sets of jobs and triggers.voidsetIgnoreDuplicates(boolean ignoreDuplicates)If true (andOverWriteExistingDatais false) then any job/triggers encountered in this file that have names that already exist in the scheduler will be ignored, and no error will be produced.protected voidsetOverWriteExistingData(boolean overWriteExistingData)Whether the existing scheduling data (with same identifiers) will be overwritten.voidwarning(org.xml.sax.SAXParseException e)ErrorHandler interface.
-
-
-
Field Detail
-
QUARTZ_NS
public static final java.lang.String QUARTZ_NS
- See Also:
- Constant Field Values
-
QUARTZ_SCHEMA_WEB_URL
public static final java.lang.String QUARTZ_SCHEMA_WEB_URL
- See Also:
- Constant Field Values
-
QUARTZ_XSD_PATH_IN_JAR
public static final java.lang.String QUARTZ_XSD_PATH_IN_JAR
- See Also:
- Constant Field Values
-
QUARTZ_XML_DEFAULT_FILE_NAME
public static final java.lang.String QUARTZ_XML_DEFAULT_FILE_NAME
- See Also:
- Constant Field Values
-
QUARTZ_SYSTEM_ID_JAR_PREFIX
public static final java.lang.String QUARTZ_SYSTEM_ID_JAR_PREFIX
- See Also:
- Constant Field Values
-
jobGroupsToDelete
protected final java.util.List<java.lang.String> jobGroupsToDelete
-
triggerGroupsToDelete
protected final java.util.List<java.lang.String> triggerGroupsToDelete
-
jobsToDelete
protected final java.util.List<JobKey> jobsToDelete
-
triggersToDelete
protected final java.util.List<TriggerKey> triggersToDelete
-
loadedJobs
protected final java.util.List<JobDetail> loadedJobs
-
loadedTriggers
protected final java.util.List<MutableTrigger> loadedTriggers
-
validationExceptions
protected final java.util.Collection<java.lang.Exception> validationExceptions
-
classLoadHelper
protected final ClassLoadHelper classLoadHelper
-
jobGroupsToNeverDelete
protected final java.util.List<java.lang.String> jobGroupsToNeverDelete
-
triggerGroupsToNeverDelete
protected final java.util.List<java.lang.String> triggerGroupsToNeverDelete
-
-
Constructor Detail
-
XMLSchedulingDataProcessor
public XMLSchedulingDataProcessor(ClassLoadHelper clh) throws javax.xml.parsers.ParserConfigurationException
Constructor for JobSchedulingDataLoader.- Parameters:
clh- class-loader helper to share with digester.- Throws:
javax.xml.parsers.ParserConfigurationException- if the XML parser cannot be configured as needed.
-
-
Method Detail
-
initDocumentParser
protected void initDocumentParser() throws javax.xml.parsers.ParserConfigurationExceptionInitializes the XML parser.- Throws:
javax.xml.parsers.ParserConfigurationException
-
resolveSchemaSource
protected java.lang.Object resolveSchemaSource()
-
isOverWriteExistingData
public boolean isOverWriteExistingData()
Whether the existing scheduling data (with same identifiers) will be overwritten. If false, andIgnoreDuplicatesis not false, and jobs or triggers with the same names already exist as those in the file, an error will occur.- See Also:
isIgnoreDuplicates()
-
setOverWriteExistingData
protected void setOverWriteExistingData(boolean overWriteExistingData)
Whether the existing scheduling data (with same identifiers) will be overwritten. If false, andIgnoreDuplicatesis not false, and jobs or triggers with the same names already exist as those in the file, an error will occur.- See Also:
setIgnoreDuplicates(boolean)
-
isIgnoreDuplicates
public boolean isIgnoreDuplicates()
If true (andOverWriteExistingDatais false) then any job/triggers encountered in this file that have names that already exist in the scheduler will be ignored, and no error will be produced.- See Also:
isOverWriteExistingData()
-
setIgnoreDuplicates
public void setIgnoreDuplicates(boolean ignoreDuplicates)
If true (andOverWriteExistingDatais false) then any job/triggers encountered in this file that have names that already exist in the scheduler will be ignored, and no error will be produced.- See Also:
setOverWriteExistingData(boolean)
-
addJobGroupToNeverDelete
public void addJobGroupToNeverDelete(java.lang.String group)
Add the given group to the list of job groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.
-
removeJobGroupToNeverDelete
public boolean removeJobGroupToNeverDelete(java.lang.String group)
Remove the given group to the list of job groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.
-
getJobGroupsToNeverDelete
public java.util.List<java.lang.String> getJobGroupsToNeverDelete()
Get the (unmodifiable) list of job groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.
-
addTriggerGroupToNeverDelete
public void addTriggerGroupToNeverDelete(java.lang.String group)
Add the given group to the list of trigger groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.
-
removeTriggerGroupToNeverDelete
public boolean removeTriggerGroupToNeverDelete(java.lang.String group)
Remove the given group to the list of trigger groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.
-
getTriggerGroupsToNeverDelete
public java.util.List<java.lang.String> getTriggerGroupsToNeverDelete()
Get the (unmodifiable) list of trigger groups that will never be deleted by this processor, even if a pre-processing-command to delete the group is encountered.
-
processFile
protected void processFile() throws java.lang.ExceptionProcess the xml file in the default location (a file named "quartz_jobs.xml" in the current working directory).- Throws:
java.lang.Exception
-
processFile
protected void processFile(java.lang.String fileName) throws java.lang.ExceptionProcess the xml file namedfileName.- Parameters:
fileName- meta data file name.- Throws:
java.lang.Exception
-
getSystemIdForFileName
protected java.lang.String getSystemIdForFileName(java.lang.String fileName)
For the givenfileName, attempt to expand it to its full path for use as a system id.
-
getURL
protected java.net.URL getURL(java.lang.String fileName)
Returns anURLfrom the fileName as a resource.- Parameters:
fileName- file name.- Returns:
- an
URLfrom the fileName as a resource.
-
prepForProcessing
protected void prepForProcessing()
-
processFile
protected void processFile(java.lang.String fileName, java.lang.String systemId) throws ValidationException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException, SchedulerException, java.lang.ClassNotFoundException, java.text.ParseException, javax.xml.xpath.XPathExceptionProcess the xmlfile namedfileNamewith the given system ID.- Parameters:
fileName- meta data file name.systemId- system ID.- Throws:
ValidationExceptionjavax.xml.parsers.ParserConfigurationExceptionorg.xml.sax.SAXExceptionjava.io.IOExceptionSchedulerExceptionjava.lang.ClassNotFoundExceptionjava.text.ParseExceptionjavax.xml.xpath.XPathException
-
processStreamAndScheduleJobs
public void processStreamAndScheduleJobs(java.io.InputStream stream, java.lang.String systemId, Scheduler sched) throws ValidationException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, javax.xml.xpath.XPathException, java.io.IOException, SchedulerException, java.lang.ClassNotFoundException, java.text.ParseExceptionProcess the xmlfile namedfileNamewith the given system ID.- Parameters:
stream- an input stream containing the xml content.systemId- system ID.- Throws:
ValidationExceptionjavax.xml.parsers.ParserConfigurationExceptionorg.xml.sax.SAXExceptionjavax.xml.xpath.XPathExceptionjava.io.IOExceptionSchedulerExceptionjava.lang.ClassNotFoundExceptionjava.text.ParseException
-
process
protected void process(org.xml.sax.InputSource is) throws org.xml.sax.SAXException, java.io.IOException, java.text.ParseException, javax.xml.xpath.XPathException, java.lang.ClassNotFoundException- Throws:
org.xml.sax.SAXExceptionjava.io.IOExceptionjava.text.ParseExceptionjavax.xml.xpath.XPathExceptionjava.lang.ClassNotFoundException
-
getTrimmedToNullString
protected java.lang.String getTrimmedToNullString(javax.xml.xpath.XPath xpathToElement, java.lang.String elementName, org.w3c.dom.Node parentNode) throws javax.xml.xpath.XPathExpressionException- Throws:
javax.xml.xpath.XPathExpressionException
-
getBoolean
protected java.lang.Boolean getBoolean(javax.xml.xpath.XPath xpathToElement, java.lang.String elementName, org.w3c.dom.Document document) throws javax.xml.xpath.XPathExpressionException- Throws:
javax.xml.xpath.XPathExpressionException
-
processFileAndScheduleJobs
public void processFileAndScheduleJobs(Scheduler sched, boolean overWriteExistingJobs) throws java.lang.Exception
Process the xml file in the default location, and schedule all of the jobs defined within it.Note that we will set overWriteExistingJobs after the default xml is parsed.
- Throws:
java.lang.Exception
-
processFileAndScheduleJobs
public void processFileAndScheduleJobs(java.lang.String fileName, Scheduler sched) throws java.lang.ExceptionProcess the xml file in the given location, and schedule all of the jobs defined within it.- Parameters:
fileName- meta data file name.- Throws:
java.lang.Exception
-
processFileAndScheduleJobs
public void processFileAndScheduleJobs(java.lang.String fileName, java.lang.String systemId, Scheduler sched) throws java.lang.ExceptionProcess the xml file in the given location, and schedule all of the jobs defined within it.- Parameters:
fileName- meta data file name.- Throws:
java.lang.Exception
-
getLoadedJobs
protected java.util.List<JobDetail> getLoadedJobs()
Returns aListof jobs loaded from the xml file.- Returns:
- a
Listof jobs.
-
getLoadedTriggers
protected java.util.List<MutableTrigger> getLoadedTriggers()
Returns aListof triggers loaded from the xml file.- Returns:
- a
Listof triggers.
-
getInputStream
protected java.io.InputStream getInputStream(java.lang.String fileName)
Returns anInputStreamfrom the fileName as a resource.- Parameters:
fileName- file name.- Returns:
- an
InputStreamfrom the fileName as a resource.
-
addJobToSchedule
protected void addJobToSchedule(JobDetail job)
-
addTriggerToSchedule
protected void addTriggerToSchedule(MutableTrigger trigger)
-
executePreProcessCommands
protected void executePreProcessCommands(Scheduler scheduler) throws SchedulerException
- Throws:
SchedulerException
-
scheduleJobs
protected void scheduleJobs(Scheduler sched) throws SchedulerException
Schedules the given sets of jobs and triggers.- Parameters:
sched- job scheduler.- Throws:
SchedulerException- if the Job or Trigger cannot be added to the Scheduler, or there is an internal Scheduler error.
-
warning
public void warning(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXExceptionErrorHandler interface. Receive notification of a warning.- Specified by:
warningin interfaceorg.xml.sax.ErrorHandler- Parameters:
e- The error information encapsulated in a SAX parse exception.- Throws:
org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception.
-
error
public void error(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXExceptionErrorHandler interface. Receive notification of a recoverable error.- Specified by:
errorin interfaceorg.xml.sax.ErrorHandler- Parameters:
e- The error information encapsulated in a SAX parse exception.- Throws:
org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception.
-
fatalError
public void fatalError(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXExceptionErrorHandler interface. Receive notification of a non-recoverable error.- Specified by:
fatalErrorin interfaceorg.xml.sax.ErrorHandler- Parameters:
e- The error information encapsulated in a SAX parse exception.- Throws:
org.xml.sax.SAXException- Any SAX exception, possibly wrapping another exception.
-
addValidationException
protected void addValidationException(org.xml.sax.SAXException e)
Adds a detected validation exception.- Parameters:
e- SAX exception.
-
clearValidationExceptions
protected void clearValidationExceptions()
Resets the number of detected validation exceptions.
-
maybeThrowValidationException
protected void maybeThrowValidationException() throws ValidationExceptionThrows a ValidationException if the number of validationExceptions detected is greater than zero.- Throws:
ValidationException- DTD validation exception.
-
-