Stop using Constants utility in CronTriggerFactoryBean

See gh-30851
This commit is contained in:
Sam Brannen
2023-07-16 14:49:25 +02:00
parent 79cf532c2f
commit edba535c8b
2 changed files with 55 additions and 8 deletions

View File

@@ -30,7 +30,6 @@ import org.quartz.impl.triggers.CronTriggerImpl;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.Constants;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -48,6 +47,7 @@ import org.springframework.util.Assert;
* instead of registering the JobDetail separately.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 3.1
* @see #setName
* @see #setGroup
@@ -58,8 +58,16 @@ import org.springframework.util.Assert;
*/
public class CronTriggerFactoryBean implements FactoryBean<CronTrigger>, BeanNameAware, InitializingBean {
/** Constants for the CronTrigger class. */
private static final Constants constants = new Constants(CronTrigger.class);
/**
* Map of constant names to constant values for the misfire instruction constants
* defined in {@link org.quartz.Trigger} and {@link org.quartz.CronTrigger}.
*/
private static final Map<String, Integer> constants = Map.of(
"MISFIRE_INSTRUCTION_SMART_POLICY", CronTrigger.MISFIRE_INSTRUCTION_SMART_POLICY,
"MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY", CronTrigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY,
"MISFIRE_INSTRUCTION_FIRE_ONCE_NOW", CronTrigger.MISFIRE_INSTRUCTION_FIRE_ONCE_NOW,
"MISFIRE_INSTRUCTION_DO_NOTHING", CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING
);
@Nullable
@@ -213,7 +221,10 @@ public class CronTriggerFactoryBean implements FactoryBean<CronTrigger>, BeanNam
* @see org.quartz.CronTrigger#MISFIRE_INSTRUCTION_DO_NOTHING
*/
public void setMisfireInstructionName(String constantName) {
this.misfireInstruction = constants.asNumber(constantName).intValue();
Assert.hasText(constantName, "'constantName' must not be null or blank");
Integer misfireInstruction = constants.get(constantName);
Assert.notNull(misfireInstruction, "Only misfire instruction constants allowed");
this.misfireInstruction = misfireInstruction;
}
/**