Upgraded to Quartz 1.8 and Velocity 1.7

This commit is contained in:
Juergen Hoeller
2013-03-19 23:02:57 +01:00
parent a272fd790a
commit e3fe9b1171
12 changed files with 58 additions and 163 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ import org.springframework.util.ReflectionUtils;
* JobFactory implementation that supports {@link java.lang.Runnable}
* objects as well as standard Quartz {@link org.quartz.Job} instances.
*
* <p>Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1.
* <p>Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0.
*
* @author Juergen Hoeller
* @since 2.0

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ import org.springframework.util.ReflectionUtils;
* You need to implement your own Quartz Job as a thin wrapper for each case
* where you want a persistent job to delegate to a specific service method.
*
* <p>Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1.
* <p>Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0.
*
* @author Juergen Hoeller
* @author Alef Arendsen

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,9 +48,6 @@ import org.springframework.util.ReflectionUtils;
* implement the Quartz {@link org.quartz.StatefulJob} interface to
* mark your concrete job bean as stateful.
*
* <p>This version of QuartzJobBean requires Quartz 1.5 or higher,
* due to the support for trigger-specific job data.
*
* <p><b>Note that as of Spring 2.0 and Quartz 1.5, the preferred way
* to apply dependency injection to Job instances is via a JobFactory:</b>
* that is, to specify {@link SpringBeanJobFactory} as Quartz JobFactory

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ import org.quartz.SchedulerListener;
import org.quartz.Trigger;
import org.quartz.TriggerListener;
import org.quartz.spi.ClassLoadHelper;
import org.quartz.xml.XMLSchedulingDataProcessor;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ResourceLoader;
@@ -51,7 +52,7 @@ import org.springframework.util.ReflectionUtils;
* <p>For concrete usage, check out the {@link SchedulerFactoryBean} and
* {@link SchedulerAccessorBean} classes.
*
* <p>Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1.
* <p>Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0.
*
* @author Juergen Hoeller
* @since 2.5.6
@@ -115,7 +116,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
* "job_scheduling_data_1_5" XSD or better. Can be specified to automatically
* register jobs that are defined in such a file, possibly in addition
* to jobs defined directly on this SchedulerFactoryBean.
* @see org.quartz.xml.XmlSchedulingDataProcessor
* @see org.quartz.xml.XMLSchedulingDataProcessor
*/
public void setJobSchedulingDataLocation(String jobSchedulingDataLocation) {
this.jobSchedulingDataLocations = new String[] {jobSchedulingDataLocation};
@@ -126,7 +127,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
* "job_scheduling_data_1_5" XSD or better. Can be specified to automatically
* register jobs that are defined in such files, possibly in addition
* to jobs defined directly on this SchedulerFactoryBean.
* @see org.quartz.xml.XmlSchedulingDataProcessor
* @see org.quartz.xml.XMLSchedulingDataProcessor
*/
public void setJobSchedulingDataLocations(String[] jobSchedulingDataLocations) {
this.jobSchedulingDataLocations = jobSchedulingDataLocations;
@@ -251,30 +252,14 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
if (this.transactionManager != null) {
transactionStatus = this.transactionManager.getTransaction(new DefaultTransactionDefinition());
}
try {
try {
if (this.jobSchedulingDataLocations != null) {
ClassLoadHelper clh = new ResourceLoaderClassLoadHelper(this.resourceLoader);
clh.initialize();
try {
// Quartz 1.8 or higher?
Class dataProcessorClass = getClass().getClassLoader().loadClass("org.quartz.xml.XMLSchedulingDataProcessor");
logger.debug("Using Quartz 1.8 XMLSchedulingDataProcessor");
Object dataProcessor = dataProcessorClass.getConstructor(ClassLoadHelper.class).newInstance(clh);
Method processFileAndScheduleJobs = dataProcessorClass.getMethod("processFileAndScheduleJobs", String.class, Scheduler.class);
for (String location : this.jobSchedulingDataLocations) {
processFileAndScheduleJobs.invoke(dataProcessor, location, getScheduler());
}
}
catch (ClassNotFoundException ex) {
// Quartz 1.6
Class dataProcessorClass = getClass().getClassLoader().loadClass("org.quartz.xml.JobSchedulingDataProcessor");
logger.debug("Using Quartz 1.6 JobSchedulingDataProcessor");
Object dataProcessor = dataProcessorClass.getConstructor(ClassLoadHelper.class, boolean.class, boolean.class).newInstance(clh, true, true);
Method processFileAndScheduleJobs = dataProcessorClass.getMethod("processFileAndScheduleJobs", String.class, Scheduler.class, boolean.class);
for (String location : this.jobSchedulingDataLocations) {
processFileAndScheduleJobs.invoke(dataProcessor, location, getScheduler(), this.overwriteExistingJobs);
}
XMLSchedulingDataProcessor dataProcessor = new XMLSchedulingDataProcessor(clh);
for (String location : this.jobSchedulingDataLocations) {
dataProcessor.processFileAndScheduleJobs(location, getScheduler());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ import org.springframework.beans.factory.ListableBeanFactory;
* Spring bean-style class for accessing a Quartz Scheduler, i.e. for registering jobs,
* triggers and listeners on a given {@link org.quartz.Scheduler} instance.
*
* <p>Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1.
* <p>Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0.
*
* @author Juergen Hoeller
* @since 2.5.6

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,7 +74,7 @@ import org.springframework.util.CollectionUtils;
* automatically apply to Scheduler operations performed within those scopes.
* Alternatively, you may add transactional advice for the Scheduler itself.
*
* <p>Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1.
* <p>Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0.
*
* @author Juergen Hoeller
* @since 18.02.2004

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ import org.springframework.util.ReflectionUtils;
* as bean property values. If no matching bean property is found, the entry
* is by default simply ignored. This is analogous to QuartzJobBean's behavior.
*
* <p>Compatible with Quartz 1.5+ as well as Quartz 2.0/2.1, as of Spring 3.1.
* <p>Compatible with Quartz 1.8 as well as Quartz 2.0/2.1, as of Spring 4.0.
*
* @author Juergen Hoeller
* @since 2.0

View File

@@ -1,63 +0,0 @@
/*
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.velocity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.runtime.log.LogSystem;
/**
* Velocity LogSystem implementation for Jakarta Commons Logging.
* Used by VelocityConfigurer to redirect log output.
*
* <p><b>NOTE:</b> To be replaced by Velocity 1.5's {@code LogChute} mechanism
* and Velocity 1.6's {@code CommonsLogLogChute} implementation once we
* upgrade to Velocity 1.6+ (likely Velocity 1.7+) in a future version of Spring.
*
* @author Juergen Hoeller
* @since 07.08.2003
* @see VelocityEngineFactoryBean
* @deprecated as of Spring 3.2, in favor of Velocity 1.6's {@code CommonsLogLogChute}
*/
@Deprecated
public class CommonsLoggingLogSystem implements LogSystem {
private static final Log logger = LogFactory.getLog(VelocityEngine.class);
public void init(RuntimeServices runtimeServices) {
}
public void logVelocityMessage(int type, String msg) {
switch (type) {
case ERROR_ID:
logger.error(msg);
break;
case WARN_ID:
logger.warn(msg);
break;
case INFO_ID:
logger.info(msg);
break;
case DEBUG_ID:
logger.debug(msg);
break;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.log.CommonsLogLogChute;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
@@ -198,8 +199,7 @@ public class VelocityEngineFactory {
/**
* Set whether Velocity should log via Commons Logging, i.e. whether Velocity's
* log system should be set to CommonsLoggingLogSystem. Default value is true.
* @see CommonsLoggingLogSystem
* log system should be set to {@link CommonsLogLogChute}. Default is "true".
*/
public void setOverrideLogging(boolean overrideLogging) {
this.overrideLogging = overrideLogging;
@@ -236,7 +236,7 @@ public class VelocityEngineFactory {
// Log via Commons Logging?
if (this.overrideLogging) {
velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLoggingLogSystem());
velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
}
// Apply properties to VelocityEngine.
@@ -246,23 +246,8 @@ public class VelocityEngineFactory {
postProcessVelocityEngine(velocityEngine);
try {
// Perform actual initialization.
velocityEngine.init();
}
catch (IOException ex) {
throw ex;
}
catch (VelocityException ex) {
throw ex;
}
catch (RuntimeException ex) {
throw ex;
}
catch (Exception ex) {
logger.error("Why does VelocityEngine throw a generic checked exception, after all?", ex);
throw new VelocityException(ex.toString());
}
// Perform actual initialization.
velocityEngine.init();
return velocityEngine;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@ import java.io.StringWriter;
import java.io.Writer;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
@@ -35,9 +33,6 @@ import org.apache.velocity.exception.VelocityException;
*/
public abstract class VelocityEngineUtils {
private static final Log logger = LogFactory.getLog(VelocityEngineUtils.class);
/**
* Merge the specified Velocity template with the given model and write
* the result to the given Writer.
@@ -54,20 +49,8 @@ public abstract class VelocityEngineUtils {
VelocityEngine velocityEngine, String templateLocation, Map<String, Object> model, Writer writer)
throws VelocityException {
try {
VelocityContext velocityContext = new VelocityContext(model);
velocityEngine.mergeTemplate(templateLocation, velocityContext, writer);
}
catch (VelocityException ex) {
throw ex;
}
catch (RuntimeException ex) {
throw ex;
}
catch (Exception ex) {
logger.error("Why does VelocityEngine throw a generic checked exception, after all?", ex);
throw new VelocityException(ex.toString());
}
VelocityContext velocityContext = new VelocityContext(model);
velocityEngine.mergeTemplate(templateLocation, velocityContext, writer);
}
/**
@@ -84,20 +67,8 @@ public abstract class VelocityEngineUtils {
VelocityEngine velocityEngine, String templateLocation, String encoding,
Map<String, Object> model, Writer writer) throws VelocityException {
try {
VelocityContext velocityContext = new VelocityContext(model);
velocityEngine.mergeTemplate(templateLocation, encoding, velocityContext, writer);
}
catch (VelocityException ex) {
throw ex;
}
catch (RuntimeException ex) {
throw ex;
}
catch (Exception ex) {
logger.error("Why does VelocityEngine throw a generic checked exception, after all?", ex);
throw new VelocityException(ex.toString());
}
VelocityContext velocityContext = new VelocityContext(model);
velocityEngine.mergeTemplate(templateLocation, encoding, velocityContext, writer);
}
/**