org.quartz.xml
Class XMLSchedulingDataProcessor

java.lang.Object
  extended by org.quartz.xml.XMLSchedulingDataProcessor
All Implemented Interfaces:
org.xml.sax.ErrorHandler

public class XMLSchedulingDataProcessor
extends java.lang.Object
implements org.xml.sax.ErrorHandler

Parses 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_1_8.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
protected  ClassLoadHelper classLoadHelper
           
protected static java.text.SimpleDateFormat dateFormat
           
protected  java.util.List<java.lang.String> jobGroupsToDelete
           
protected  java.util.List<java.lang.String> jobGroupsToNeverDelete
           
protected  java.util.List<JobKey> jobsToDelete
           
protected  java.util.List<JobDetail> loadedJobs
           
protected  java.util.List<Trigger> loadedTriggers
           
static java.lang.String QUARTZ_NS
           
static java.lang.String QUARTZ_SCHEMA_WEB_URL
           
static java.lang.String QUARTZ_SYSTEM_ID_JAR_PREFIX
           
static java.lang.String QUARTZ_XML_DEFAULT_FILE_NAME
           
static java.lang.String QUARTZ_XSD_PATH_IN_JAR
           
protected  java.util.List<java.lang.String> triggerGroupsToDelete
           
protected  java.util.List<java.lang.String> triggerGroupsToNeverDelete
           
protected  java.util.List<TriggerKey> triggersToDelete
           
protected  java.util.Collection validationExceptions
           
protected static java.lang.String XSD_DATE_FORMAT
          XML Schema dateTime datatype format.
 
Constructor Summary
XMLSchedulingDataProcessor(ClassLoadHelper clh)
          Constructor for JobSchedulingDataLoader.
 
Method Summary
 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.
protected  void addJobToSchedule(JobDetail job)
           
 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.
protected  void addTriggerToSchedule(Trigger trigger)
           
protected  void addValidationException(org.xml.sax.SAXException e)
          Adds a detected validation exception.
protected  void clearValidationExceptions()
          Resets the the number of detected validation exceptions.
 void error(org.xml.sax.SAXParseException e)
          ErrorHandler interface.
protected  void executePreProcessCommands(Scheduler scheduler)
           
 void fatalError(org.xml.sax.SAXParseException e)
          ErrorHandler interface.
protected  java.lang.Boolean getBoolean(javax.xml.xpath.XPath xpath, java.lang.String elementName, org.w3c.dom.Document document)
           
protected  java.io.InputStream getInputStream(java.lang.String fileName)
          Returns an InputStream from 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 a List of jobs loaded from the xml file.
protected  java.util.List<Trigger> getLoadedTriggers()
          Returns a List of triggers loaded from the xml file.
protected  java.lang.String getSystemIdForFileName(java.lang.String fileName)
          For the given fileName, 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.String getTrimmedToNullString(javax.xml.xpath.XPath xpath, java.lang.String elementName, org.w3c.dom.Node parentNode)
           
protected  java.net.URL getURL(java.lang.String fileName)
          Returns an URL from the fileName as a resource.
protected  void initDocumentParser()
          Initializes the XML parser.
 boolean isIgnoreDuplicates()
          If true (and OverWriteExistingData is 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.
 boolean isOverWriteExistingData()
          Whether the existing scheduling data (with same identifiers) will be overwritten.
protected  void maybeThrowValidationException()
          Throws a ValidationException if the number of validationExceptions detected is greater than zero.
protected  void prepForProcessing()
           
protected  void process(org.xml.sax.InputSource is)
           
protected  void processFile()
          Process the xml file in the default location (a file named "quartz_jobs.xml" in the current working directory).
protected  void processFile(java.lang.String fileName)
          Process the xml file named fileName.
protected  void processFile(java.lang.String fileName, java.lang.String systemId)
          Process the xmlfile named fileName with the given system ID.
 void processFileAndScheduleJobs(Scheduler sched, boolean overWriteExistingJobs)
          Process the xml file in the default location, and schedule all of the jobs defined within it.
 void processFileAndScheduleJobs(java.lang.String fileName, Scheduler sched)
          Process the xml file in the given location, and schedule all of the jobs defined within it.
 void processFileAndScheduleJobs(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.
 void processStreamAndScheduleJobs(java.io.InputStream stream, java.lang.String systemId, Scheduler sched)
          Process the xmlfile named fileName with the given system ID.
 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.
 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.
protected  java.lang.Object resolveSchemaSource()
           
protected  void scheduleJobs(Scheduler sched)
          Schedules the given sets of jobs and triggers.
 void setIgnoreDuplicates(boolean ignoreDuplicates)
          If true (and OverWriteExistingData is 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  void setOverWriteExistingData(boolean overWriteExistingData)
          Whether the existing scheduling data (with same identifiers) will be overwritten.
 void warning(org.xml.sax.SAXParseException e)
          ErrorHandler interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

XSD_DATE_FORMAT

protected static final java.lang.String XSD_DATE_FORMAT
XML Schema dateTime datatype format.

See http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#dateTime

See Also:
Constant Field Values

dateFormat

protected static final java.text.SimpleDateFormat dateFormat

jobGroupsToDelete

protected java.util.List<java.lang.String> jobGroupsToDelete

triggerGroupsToDelete

protected java.util.List<java.lang.String> triggerGroupsToDelete

jobsToDelete

protected java.util.List<JobKey> jobsToDelete

triggersToDelete

protected java.util.List<TriggerKey> triggersToDelete

loadedJobs

protected java.util.List<JobDetail> loadedJobs

loadedTriggers

protected java.util.List<Trigger> loadedTriggers

validationExceptions

protected java.util.Collection validationExceptions

classLoadHelper

protected ClassLoadHelper classLoadHelper

jobGroupsToNeverDelete

protected java.util.List<java.lang.String> jobGroupsToNeverDelete

triggerGroupsToNeverDelete

protected 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.ParserConfigurationException
Initializes 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, and IgnoreDuplicates is 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, and IgnoreDuplicates is 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 (and OverWriteExistingData is 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 (and OverWriteExistingData is 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.

Parameters:
group -

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.

Parameters:
group -

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.

Parameters:
group -

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.

Parameters:
group -

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.

Parameters:
group -

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.

Parameters:
group -

processFile

protected void processFile()
                    throws java.lang.Exception
Process 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.Exception
Process the xml file named fileName.

Parameters:
fileName - meta data file name.
Throws:
java.lang.Exception

getSystemIdForFileName

protected java.lang.String getSystemIdForFileName(java.lang.String fileName)
For the given fileName, attempt to expand it to its full path for use as a system id.

See Also:
getURL(String), processFile(), processFile(String), processFileAndScheduleJobs(Scheduler, boolean), #processFileAndScheduleJobs(String, Scheduler, boolean)

getURL

protected java.net.URL getURL(java.lang.String fileName)
Returns an URL from the fileName as a resource.

Parameters:
fileName - file name.
Returns:
an URL from 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.XPathException
Process the xmlfile named fileName with the given system ID.

Parameters:
fileName - meta data file name.
systemId - system ID.
Throws:
ValidationException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
SchedulerException
java.lang.ClassNotFoundException
java.text.ParseException
javax.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.ParseException
Process the xmlfile named fileName with the given system ID.

Parameters:
stream - an input stream containing the xml content.
systemId - system ID.
Throws:
ValidationException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
javax.xml.xpath.XPathException
java.io.IOException
SchedulerException
java.lang.ClassNotFoundException
java.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.SAXException
java.io.IOException
java.text.ParseException
javax.xml.xpath.XPathException
java.lang.ClassNotFoundException

getTrimmedToNullString

protected java.lang.String getTrimmedToNullString(javax.xml.xpath.XPath xpath,
                                                  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 xpath,
                                       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 SchedulerException,
                                       java.lang.Exception
Process the xml file in the default location, and schedule all of the jobs defined within it.

Throws:
SchedulerException
java.lang.Exception

processFileAndScheduleJobs

public void processFileAndScheduleJobs(java.lang.String fileName,
                                       Scheduler sched)
                                throws java.lang.Exception
Process 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.Exception
Process 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 a List of jobs loaded from the xml file.

Returns:
a List of jobs.

getLoadedTriggers

protected java.util.List<Trigger> getLoadedTriggers()
Returns a List of triggers loaded from the xml file.

Returns:
a List of triggers.

getInputStream

protected java.io.InputStream getInputStream(java.lang.String fileName)
Returns an InputStream from the fileName as a resource.

Parameters:
fileName - file name.
Returns:
an InputStream from the fileName as a resource.

addJobToSchedule

protected void addJobToSchedule(JobDetail job)

addTriggerToSchedule

protected void addTriggerToSchedule(Trigger 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.SAXException
ErrorHandler interface. Receive notification of a warning.

Specified by:
warning in interface org.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.SAXException
ErrorHandler interface. Receive notification of a recoverable error.

Specified by:
error in interface org.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.SAXException
ErrorHandler interface. Receive notification of a non-recoverable error.

Specified by:
fatalError in interface org.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 the number of detected validation exceptions.


maybeThrowValidationException

protected void maybeThrowValidationException()
                                      throws ValidationException
Throws a ValidationException if the number of validationExceptions detected is greater than zero.

Throws:
ValidationException - DTD validation exception.


Copyright 2001-2019, Terracotta, Inc.