org.quartz.xml
Class XMLSchedulingDataProcessor

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

public class XMLSchedulingDataProcessor
extends Object
implements 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_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
protected  ClassLoadHelper classLoadHelper
           
protected  List<String> jobGroupsToDelete
           
protected  List<String> jobGroupsToNeverDelete
           
protected  List<JobKey> jobsToDelete
           
protected  List<JobDetail> loadedJobs
           
protected  List<MutableTrigger> loadedTriggers
           
static String QUARTZ_NS
           
static String QUARTZ_SCHEMA_WEB_URL
           
static String QUARTZ_SYSTEM_ID_JAR_PREFIX
           
static String QUARTZ_XML_DEFAULT_FILE_NAME
           
static String QUARTZ_XSD_PATH_IN_JAR
           
protected  List<String> triggerGroupsToDelete
           
protected  List<String> triggerGroupsToNeverDelete
           
protected  List<TriggerKey> triggersToDelete
           
protected  Collection<Exception> validationExceptions
           
 
Constructor Summary
XMLSchedulingDataProcessor(ClassLoadHelper clh)
          Constructor for JobSchedulingDataLoader.
 
Method Summary
 void addJobGroupToNeverDelete(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(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(MutableTrigger trigger)
           
protected  void addValidationException(SAXException e)
          Adds a detected validation exception.
protected  void clearValidationExceptions()
          Resets the the number of detected validation exceptions.
 void error(SAXParseException e)
          ErrorHandler interface.
protected  void executePreProcessCommands(Scheduler scheduler)
           
 void fatalError(SAXParseException e)
          ErrorHandler interface.
protected  Boolean getBoolean(XPath xpathToElement, String elementName, Document document)
           
protected  InputStream getInputStream(String fileName)
          Returns an InputStream from the fileName as a resource.
 List<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  List<JobDetail> getLoadedJobs()
          Returns a List of jobs loaded from the xml file.
protected  List<MutableTrigger> getLoadedTriggers()
          Returns a List of triggers loaded from the xml file.
protected  String getSystemIdForFileName(String fileName)
          For the given fileName, attempt to expand it to its full path for use as a system id.
 List<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  String getTrimmedToNullString(XPath xpathToElement, String elementName, Node parentNode)
           
protected  URL getURL(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(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(String fileName)
          Process the xml file named fileName.
protected  void processFile(String fileName, 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(String fileName, Scheduler sched)
          Process the xml file in the given location, and schedule all of the jobs defined within it.
 void processFileAndScheduleJobs(String fileName, String systemId, Scheduler sched)
          Process the xml file in the given location, and schedule all of the jobs defined within it.
 void processStreamAndScheduleJobs(InputStream stream, String systemId, Scheduler sched)
          Process the xmlfile named fileName with the given system ID.
 boolean removeJobGroupToNeverDelete(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(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  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(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 String QUARTZ_NS
See Also:
Constant Field Values

QUARTZ_SCHEMA_WEB_URL

public static final String QUARTZ_SCHEMA_WEB_URL
See Also:
Constant Field Values

QUARTZ_XSD_PATH_IN_JAR

public static final String QUARTZ_XSD_PATH_IN_JAR
See Also:
Constant Field Values

QUARTZ_XML_DEFAULT_FILE_NAME

public static final String QUARTZ_XML_DEFAULT_FILE_NAME
See Also:
Constant Field Values

QUARTZ_SYSTEM_ID_JAR_PREFIX

public static final String QUARTZ_SYSTEM_ID_JAR_PREFIX
See Also:
Constant Field Values

jobGroupsToDelete

protected List<String> jobGroupsToDelete

triggerGroupsToDelete

protected List<String> triggerGroupsToDelete

jobsToDelete

protected List<JobKey> jobsToDelete

triggersToDelete

protected List<TriggerKey> triggersToDelete

loadedJobs

protected List<JobDetail> loadedJobs

loadedTriggers

protected List<MutableTrigger> loadedTriggers

validationExceptions

protected Collection<Exception> validationExceptions

classLoadHelper

protected ClassLoadHelper classLoadHelper

jobGroupsToNeverDelete

protected List<String> jobGroupsToNeverDelete

triggerGroupsToNeverDelete

protected List<String> triggerGroupsToNeverDelete
Constructor Detail

XMLSchedulingDataProcessor

public XMLSchedulingDataProcessor(ClassLoadHelper clh)
                           throws ParserConfigurationException
Constructor for JobSchedulingDataLoader.

Parameters:
clh - class-loader helper to share with digester.
Throws:
ParserConfigurationException - if the XML parser cannot be configured as needed.
Method Detail

initDocumentParser

protected void initDocumentParser()
                           throws ParserConfigurationException
Initializes the XML parser.

Throws:
ParserConfigurationException

resolveSchemaSource

protected 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(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(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 List<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(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(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 List<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 Exception
Process the xml file in the default location (a file named "quartz_jobs.xml" in the current working directory).

Throws:
Exception

processFile

protected void processFile(String fileName)
                    throws Exception
Process the xml file named fileName.

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

getSystemIdForFileName

protected String getSystemIdForFileName(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, org.quartz.Scheduler)

getURL

protected URL getURL(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(String fileName,
                           String systemId)
                    throws ValidationException,
                           ParserConfigurationException,
                           SAXException,
                           IOException,
                           SchedulerException,
                           ClassNotFoundException,
                           ParseException,
                           XPathException
Process the xmlfile named fileName with the given system ID.

Parameters:
fileName - meta data file name.
systemId - system ID.
Throws:
ValidationException
ParserConfigurationException
SAXException
IOException
SchedulerException
ClassNotFoundException
ParseException
XPathException

processStreamAndScheduleJobs

public void processStreamAndScheduleJobs(InputStream stream,
                                         String systemId,
                                         Scheduler sched)
                                  throws ValidationException,
                                         ParserConfigurationException,
                                         SAXException,
                                         XPathException,
                                         IOException,
                                         SchedulerException,
                                         ClassNotFoundException,
                                         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
ParserConfigurationException
SAXException
XPathException
IOException
SchedulerException
ClassNotFoundException
ParseException

process

protected void process(InputSource is)
                throws SAXException,
                       IOException,
                       ParseException,
                       XPathException,
                       ClassNotFoundException
Throws:
SAXException
IOException
ParseException
XPathException
ClassNotFoundException

getTrimmedToNullString

protected String getTrimmedToNullString(XPath xpathToElement,
                                        String elementName,
                                        Node parentNode)
                                 throws XPathExpressionException
Throws:
XPathExpressionException

getBoolean

protected Boolean getBoolean(XPath xpathToElement,
                             String elementName,
                             Document document)
                      throws XPathExpressionException
Throws:
XPathExpressionException

processFileAndScheduleJobs

public void processFileAndScheduleJobs(Scheduler sched,
                                       boolean overWriteExistingJobs)
                                throws 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:
Exception

processFileAndScheduleJobs

public void processFileAndScheduleJobs(String fileName,
                                       Scheduler sched)
                                throws 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:
Exception

processFileAndScheduleJobs

public void processFileAndScheduleJobs(String fileName,
                                       String systemId,
                                       Scheduler sched)
                                throws 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:
Exception

getLoadedJobs

protected List<JobDetail> getLoadedJobs()
Returns a List of jobs loaded from the xml file.

Returns:
a List of jobs.

getLoadedTriggers

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

Returns:
a List of triggers.

getInputStream

protected InputStream getInputStream(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(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(SAXParseException e)
             throws SAXException
ErrorHandler interface. Receive notification of a warning.

Specified by:
warning in interface ErrorHandler
Parameters:
e - The error information encapsulated in a SAX parse exception.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

error

public void error(SAXParseException e)
           throws SAXException
ErrorHandler interface. Receive notification of a recoverable error.

Specified by:
error in interface ErrorHandler
Parameters:
e - The error information encapsulated in a SAX parse exception.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

fatalError

public void fatalError(SAXParseException e)
                throws SAXException
ErrorHandler interface. Receive notification of a non-recoverable error.

Specified by:
fatalError in interface ErrorHandler
Parameters:
e - The error information encapsulated in a SAX parse exception.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

addValidationException

protected void addValidationException(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.