
com.mtvnet.boxspring.scheduling.quartz.PropertyValueParser Maven / Gradle / Ivy
/**
* Copyright (c) 2009, MTV Networks. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.mtvnet.boxspring.scheduling.quartz;
import org.quartz.Trigger;
import org.springframework.beans.factory.InitializingBean;
import java.util.List;
import java.util.Arrays;
/**
*
* Non-extensible base class for creating different parsers for Quartz triggers, as it
* seemed like overkill to make this pluggable.
*
* Currently supports creation of CronTriggerBean and SimpleTriggerBean Trigger instances.
*
* @see com.mtvnet.boxspring.scheduling.quartz.TriggerPropertyEditor
*/
abstract class PropertyValueParser {
/**
* Every trigger needs a unique name, so we need this to ensure uniqueness.
*/
private static volatile int uniqueName = 1;
static Trigger getTrigger(String text) throws Exception {
text = text.trim();
PropertyValueParser parser = null;
if (CronTriggerParser.isCronTrigger(text)) {
parser = new CronTriggerParser(text);
} else {
parser = new RegularAndPeriodicScheduleParser(text);
}
parser.init();
return parser.asTrigger();
}
private void init() throws Exception {
asTrigger().setName(asTrigger().getClass().getName() + "-" + uniqueName++);
parse();
asInitializingBean().afterPropertiesSet();
}
protected abstract void parse() throws Exception;
abstract Trigger asTrigger();
abstract InitializingBean asInitializingBean();
protected List createTokenList(String text) {
return Arrays.asList(text.trim().split("\\s+"));
}
}